質問編集履歴
2
無駄な部分を省き、質問をわかりやすくしました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
他クラスのPublicの変数をうまく参照できません。c++
|
test
CHANGED
@@ -4,27 +4,19 @@
|
|
4
4
|
|
5
5
|
//ファイル名 ofApp.h
|
6
6
|
|
7
|
-
#pragma once
|
8
|
-
|
9
7
|
#include "ofMain.h"
|
10
8
|
|
11
|
-
|
9
|
+
|
12
10
|
|
13
11
|
class ofApp : public ofBaseApp{
|
14
12
|
|
15
|
-
|
16
|
-
|
17
13
|
public:
|
18
|
-
|
19
|
-
void setup();
|
20
|
-
|
21
|
-
void update();
|
22
14
|
|
23
15
|
void draw();
|
24
16
|
|
25
|
-
|
17
|
+
float curVol, volume;
|
26
18
|
|
27
|
-
|
19
|
+
float getValue() { return volume; };
|
28
20
|
|
29
21
|
```
|
30
22
|
|
@@ -34,33 +26,7 @@
|
|
34
26
|
|
35
27
|
#include "ofApp.h"
|
36
28
|
|
37
|
-
//--------------------------------------------------------------
|
38
29
|
|
39
|
-
void ofApp::setup(){
|
40
|
-
|
41
|
-
ofSoundStreamSetup(0, 1, 44100, 256, 4);
|
42
|
-
|
43
|
-
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
//--------------------------------------------------------------
|
48
|
-
|
49
|
-
void ofApp::audioIn(float*input, int bufferSize, int nChannels) {
|
50
|
-
|
51
|
-
for (int i = 0; i < bufferSize; i++) {
|
52
|
-
|
53
|
-
curVol += input[i] * input[i];
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
curVol /= bufferSize;
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
//--------------------------------------------------------------
|
64
30
|
|
65
31
|
void ofApp::draw(){
|
66
32
|
|
@@ -76,23 +42,21 @@
|
|
76
42
|
|
77
43
|
```c++
|
78
44
|
|
79
|
-
//ファイル名
|
45
|
+
//ファイル名 _tf16_1.h
|
80
46
|
|
81
47
|
#include "ofMain.h"
|
82
48
|
|
83
49
|
#include "ofApp.h" //volumeがあるファイルを読み込み
|
84
50
|
|
85
|
-
class _tf16_1 : public baseScene {
|
86
51
|
|
87
52
|
|
53
|
+
class _tf16_1 : public baseScene {
|
88
54
|
|
89
55
|
public:
|
90
56
|
|
91
|
-
void
|
57
|
+
void draw();
|
92
58
|
|
93
|
-
|
59
|
+
float volume1;
|
94
|
-
|
95
|
-
void draw();
|
96
60
|
|
97
61
|
}
|
98
62
|
|
@@ -100,35 +64,19 @@
|
|
100
64
|
|
101
65
|
```c++
|
102
66
|
|
103
|
-
//ファイル名
|
67
|
+
//ファイル名 _tf16_1.cpp
|
104
68
|
|
105
|
-
#include "
|
69
|
+
#include "_tf16_1.h"
|
106
|
-
|
107
|
-
//--------------------------------------------------------------
|
108
|
-
|
109
|
-
void _tf16_1::setup(){
|
110
|
-
|
111
|
-
}
|
112
70
|
|
113
71
|
|
114
72
|
|
115
|
-
|
73
|
+
void _tf16_1::draw(){
|
116
74
|
|
117
|
-
void _tf16_1::update(){
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
//--------------------------------------------------------------
|
124
|
-
|
125
|
-
|
75
|
+
ofApp reference;
|
126
76
|
|
127
77
|
ofApp *vol;
|
128
78
|
|
129
|
-
volume1 = vol->volume
|
79
|
+
volume1 = vol -> getValue();//volume1に値がうまく入りません。
|
130
|
-
|
131
|
-
//ここで参照失敗
|
132
80
|
|
133
81
|
}
|
134
82
|
|
@@ -136,15 +84,9 @@
|
|
136
84
|
|
137
85
|
```
|
138
86
|
|
139
|
-
どのようにすれば
|
87
|
+
どのようにすれば volumeの値 を volume1 に代入できるでしょうか。
|
140
88
|
|
141
|
-
|
142
|
-
|
143
|
-
|
89
|
+
詳しい方ご教授下さい。
|
144
|
-
|
145
|
-
背景:openframeworksで複数のシーンを切り替えて表示させており、```ofSoundStreamSetup関数```を何度も呼び出す羽目になってしまったため、参照元である```ofApp.cpp```で計算だけさせその結果を```A.cpp```で使おう。という意図になります
|
146
|
-
|
147
|
-
参考: [http://www.slideshare.net/tado/tamabi-ma131111](http://www.slideshare.net/tado/tamabi-ma131111)
|
148
90
|
|
149
91
|
|
150
92
|
|
1
誤字を修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -82,7 +82,7 @@
|
|
82
82
|
|
83
83
|
#include "ofApp.h" //volumeがあるファイルを読み込み
|
84
84
|
|
85
|
-
class
|
85
|
+
class _tf16_1 : public baseScene {
|
86
86
|
|
87
87
|
|
88
88
|
|