andrew@0
|
1 #include "testApp.h"
|
andrew@0
|
2 #include "stdio.h"
|
andrew@0
|
3 //#include "aubio.h"
|
andrew@0
|
4 #include <iostream>
|
andrew@0
|
5 #include <cstring>
|
andrew@0
|
6 #include <string>
|
andrew@0
|
7 #include <cstdlib>
|
andrew@0
|
8
|
andrew@0
|
9
|
andrew@0
|
10 const double samplingFrequency = 44100.0;
|
andrew@0
|
11
|
andrew@0
|
12 //--------------------------------------------------------------
|
andrew@0
|
13 void testApp::setup(){
|
andrew@0
|
14
|
andrew@0
|
15 // 2 output channels,
|
andrew@0
|
16 // 0 input channels
|
andrew@0
|
17 // 22050 samples per second
|
andrew@0
|
18 // 256 samples per buffer
|
andrew@0
|
19 // 4 num buffers (latency)
|
andrew@0
|
20
|
andrew@0
|
21 //nb THIS CODE WOULD BE USEFUL IF WE EVER WANTED REAL-TIME INPUT - VIA ofSoundSteam
|
andrew@0
|
22
|
andrew@0
|
23 receiver.setup( PORT );
|
andrew@0
|
24
|
andrew@0
|
25 sampleRate = 44100;
|
andrew@0
|
26 ofSoundStreamSetup(2,0,this, sampleRate,256, 4);
|
andrew@0
|
27
|
andrew@20
|
28 ofSetFrameRate(20);
|
andrew@0
|
29
|
andrew@1
|
30
|
andrew@16
|
31 eventMatcher.loadAudioFiles();
|
andrew@1
|
32
|
andrew@7
|
33 eventMatcher.setWindowDimensions();
|
andrew@1
|
34 //audioFilePlayer.loadAudioFile(infilename);
|
andrew@1
|
35 }
|
andrew@1
|
36
|
andrew@0
|
37
|
andrew@0
|
38 //--------------------------------------------------------------
|
andrew@0
|
39 void testApp::update(){
|
andrew@9
|
40 eventMatcher.updatePosition();
|
andrew@0
|
41
|
andrew@0
|
42 checkForOSCmessages();
|
andrew@0
|
43
|
andrew@0
|
44 }
|
andrew@0
|
45
|
andrew@0
|
46 void testApp::checkForOSCmessages(){
|
andrew@0
|
47 // check for waiting messages
|
andrew@0
|
48 while( receiver.hasWaitingMessages() )
|
andrew@0
|
49 {
|
andrew@0
|
50 // get the next message
|
andrew@0
|
51 ofxOscMessage m;
|
andrew@0
|
52 receiver.getNextMessage( &m );
|
andrew@0
|
53
|
andrew@0
|
54 // check for mouse moved message
|
andrew@1
|
55 if ( m.getAddress() == "/aubioPitch" ){
|
andrew@6
|
56 int testChannel = m.getArgAsInt32(0);
|
andrew@6
|
57 float pitchIn = m.getArgAsFloat(1);
|
andrew@6
|
58 int timeIn = m.getArgAsInt32(2);
|
andrew@3
|
59 printf("\nAUBIO PITCH RECEIVED %f at time %i\n", pitchIn, timeIn);
|
andrew@6
|
60 eventMatcher.newPitchEvent(testChannel, pitchIn, timeIn);
|
andrew@0
|
61 }
|
andrew@2
|
62
|
andrew@2
|
63 if ( m.getAddress() == "/kick" ){
|
andrew@6
|
64 // float pitchIn = m.getArgAsFloat(0);
|
andrew@6
|
65 int testChannel = m.getArgAsInt32(0);
|
andrew@6
|
66 double timeIn = m.getArgAsInt32(1);
|
andrew@7
|
67 printf("\nKICK RECEIVED at time %f\n", timeIn);
|
andrew@10
|
68
|
andrew@6
|
69 eventMatcher.newKickEvent(testChannel, timeIn);
|
andrew@10
|
70
|
andrew@2
|
71 }
|
andrew@2
|
72
|
andrew@2
|
73 if ( m.getAddress() == "/snare" ){
|
andrew@7
|
74 int testChannel = m.getArgAsInt32(0);
|
andrew@7
|
75 double timeIn = m.getArgAsInt32(1);
|
andrew@7
|
76 printf("\nSNARE RECEIVED at time %f\n", timeIn);
|
andrew@10
|
77
|
andrew@7
|
78 eventMatcher.newSnareEvent(testChannel, timeIn);
|
andrew@2
|
79 }
|
andrew@3
|
80
|
andrew@31
|
81 // check for mouse moved message
|
andrew@31
|
82 if ( m.getAddress() == "/elec" ){
|
andrew@32
|
83 int testChannel = m.getArgAsInt32(0);
|
andrew@32
|
84 double timeIn = m.getArgAsFloat(1);
|
andrew@32
|
85 float chromaIn[12];
|
andrew@32
|
86 printf("CHROMA received at time %f\n", timeIn);
|
andrew@31
|
87 for (int i = 0;i < 12;i++){
|
andrew@32
|
88 chromaIn[i] = m.getArgAsFloat(i+2);
|
andrew@32
|
89 printf("chroma[%i]: %f\n", i, chromaIn[i]);
|
andrew@31
|
90 }
|
andrew@32
|
91 eventMatcher.newChromaEvent(testChannel, chromaIn, timeIn);
|
andrew@31
|
92 }
|
andrew@31
|
93
|
andrew@31
|
94
|
andrew@3
|
95 if ( m.getAddress() == "/start" ){
|
andrew@3
|
96 printf("start!\n");
|
andrew@10
|
97 printf("STRART TIME IN %i\n", ofGetElapsedTimeMillis());
|
andrew@3
|
98 eventMatcher.startPlaying();
|
andrew@10
|
99 printf("TIME OUT %i\n", ofGetElapsedTimeMillis());
|
andrew@3
|
100 }
|
andrew@15
|
101
|
andrew@15
|
102 if ( m.getAddress() == "/stop" ){
|
andrew@15
|
103 printf("stop!\n");
|
andrew@15
|
104 eventMatcher.stopPlaying();
|
andrew@15
|
105 }
|
andrew@15
|
106
|
andrew@16
|
107 if ( m.getAddress() == "/accompanimentRatio" ){
|
andrew@16
|
108 double time = m.getArgAsFloat(0);
|
andrew@16
|
109 double ratio = m.getArgAsFloat(1);
|
andrew@16
|
110 eventMatcher.synchroniser.setPlayingRatio(ratio, time);
|
andrew@16
|
111 }
|
andrew@16
|
112
|
andrew@22
|
113 if ( m.getAddress() == "/rescue" ){
|
andrew@22
|
114 printf("rescue!\n");
|
andrew@22
|
115 eventMatcher.rescue();
|
andrew@22
|
116 }
|
andrew@0
|
117 }
|
andrew@0
|
118 }
|
andrew@0
|
119
|
andrew@0
|
120 //--------------------------------------------------------------
|
andrew@0
|
121 void testApp::draw(){
|
andrew@0
|
122
|
andrew@0
|
123 eventMatcher.draw();
|
andrew@0
|
124
|
andrew@0
|
125 // audioFilePlayer.draw();
|
andrew@0
|
126
|
andrew@0
|
127 }
|
andrew@0
|
128
|
andrew@0
|
129
|
andrew@0
|
130
|
andrew@0
|
131 //--------------------------------------------------------------
|
andrew@0
|
132 void testApp::keyPressed (int key){
|
andrew@0
|
133 if (key == '-'){
|
andrew@0
|
134 volume -= 0.05;
|
andrew@0
|
135 volume = MAX(volume, 0);
|
andrew@0
|
136 } else if (key == '+'){
|
andrew@0
|
137 volume += 0.05;
|
andrew@0
|
138 volume = MIN(volume, 1);
|
andrew@0
|
139 }
|
andrew@0
|
140
|
andrew@0
|
141 if (key == 'q'){
|
andrew@1
|
142 eventMatcher.recordedTracks.switchScreens();
|
andrew@0
|
143 }
|
andrew@0
|
144
|
andrew@0
|
145 if (key == OF_KEY_RIGHT){
|
andrew@0
|
146 // audioFilePlayer.loadedAudio.setPosition(min(1.0, audioFilePlayer.loadedAudio.getPosition() + (audioFilePlayer.fileLoader.audioHolder.audioScaleSamples/(4.0*audioFilePlayer.fileLoader.audioHolder.audioVector.size()))) );
|
andrew@0
|
147
|
andrew@0
|
148 }
|
andrew@0
|
149
|
andrew@0
|
150 if (key == OF_KEY_LEFT){
|
andrew@0
|
151 // audioFilePlayer.loadedAudio.setPosition(max(0.0, audioFilePlayer.loadedAudio.getPosition() - (audioFilePlayer.fileLoader.audioHolder.audioScaleSamples/(4.0*audioFilePlayer.fileLoader.audioHolder.audioVector.size()))));
|
andrew@0
|
152
|
andrew@0
|
153 }
|
andrew@0
|
154
|
andrew@35
|
155 if (key == 'd'){
|
andrew@35
|
156 eventMatcher.useChromaDotProduct = !eventMatcher.useChromaDotProduct;
|
andrew@35
|
157 printf("Use dot product is %i\n", eventMatcher.useChromaDotProduct);
|
andrew@35
|
158 }
|
andrew@0
|
159
|
andrew@0
|
160 if (key == ' '){
|
andrew@1
|
161
|
andrew@1
|
162 eventMatcher.recordedTracks.togglePlay();
|
andrew@0
|
163 }
|
andrew@0
|
164
|
andrew@0
|
165 if (key == OF_KEY_RETURN){
|
andrew@1
|
166
|
andrew@0
|
167
|
andrew@1
|
168 eventMatcher.recordedTracks.stop();
|
andrew@0
|
169 }
|
andrew@0
|
170
|
andrew@0
|
171
|
andrew@0
|
172 if (key == 'o'){
|
andrew@0
|
173 openNewAudioFileWithdialogBox();
|
andrew@0
|
174
|
andrew@0
|
175 }
|
andrew@0
|
176
|
andrew@0
|
177 if (key == 'p'){
|
andrew@3
|
178 eventMatcher.bayesianStruct.posterior.printArray();
|
andrew@0
|
179 }
|
andrew@0
|
180
|
andrew@0
|
181
|
andrew@0
|
182 if (key == OF_KEY_UP){
|
andrew@1
|
183 eventMatcher.recordedTracks.zoomOut();
|
andrew@1
|
184
|
andrew@0
|
185 }
|
andrew@0
|
186
|
andrew@0
|
187 if (key == OF_KEY_DOWN){
|
andrew@1
|
188 eventMatcher.recordedTracks.zoomIn();
|
andrew@0
|
189 }
|
andrew@0
|
190
|
andrew@0
|
191 }
|
andrew@0
|
192
|
andrew@0
|
193 //--------------------------------------------------------------
|
andrew@0
|
194 void testApp::keyReleased (int key){
|
andrew@0
|
195
|
andrew@0
|
196 }
|
andrew@0
|
197
|
andrew@0
|
198
|
andrew@0
|
199 //--------------------------------------------------------------
|
andrew@0
|
200 void testApp::mouseMoved(int x, int y ){
|
andrew@0
|
201
|
andrew@0
|
202
|
andrew@0
|
203 }
|
andrew@0
|
204
|
andrew@0
|
205 //--------------------------------------------------------------
|
andrew@0
|
206 void testApp::mouseDragged(int x, int y, int button){
|
andrew@0
|
207
|
andrew@0
|
208 }
|
andrew@0
|
209
|
andrew@0
|
210 //--------------------------------------------------------------
|
andrew@0
|
211 void testApp::mousePressed(int x, int y, int button){
|
andrew@0
|
212
|
andrew@0
|
213 }
|
andrew@0
|
214
|
andrew@0
|
215
|
andrew@0
|
216 //--------------------------------------------------------------
|
andrew@0
|
217 void testApp::mouseReleased(int x, int y, int button){
|
andrew@0
|
218
|
andrew@0
|
219 }
|
andrew@0
|
220
|
andrew@0
|
221 //--------------------------------------------------------------
|
andrew@0
|
222 void testApp::windowResized(int w, int h){
|
andrew@1
|
223
|
andrew@1
|
224 eventMatcher.windowResized(w, h);
|
andrew@0
|
225
|
andrew@0
|
226
|
andrew@0
|
227 }
|
andrew@0
|
228 //--------------------------------------------------------------
|
andrew@0
|
229 void testApp::audioRequested (float * output, int bufferSize, int nChannels){
|
andrew@0
|
230 //pan = 0.5f;
|
andrew@0
|
231 float leftScale = 1 - pan;
|
andrew@0
|
232 float rightScale = pan;
|
andrew@0
|
233
|
andrew@0
|
234 }
|
andrew@0
|
235
|
andrew@0
|
236
|
andrew@0
|
237
|
andrew@0
|
238 //--------------------------------------------------------------
|
andrew@0
|
239 void testApp::openNewAudioFileWithdialogBox(){
|
andrew@0
|
240 std::string filename;
|
andrew@0
|
241 getFilenameFromDialogBox(&filename);
|
andrew@0
|
242 loadNewAudio(filename);
|
andrew@0
|
243
|
andrew@0
|
244 }
|
andrew@0
|
245
|
andrew@0
|
246
|
andrew@0
|
247 void testApp::loadNewAudio(string soundFileName){
|
andrew@0
|
248
|
andrew@1
|
249 eventMatcher.recordedTracks.loadedAudioFiles[0].loadAudioFile(soundFileName);
|
andrew@0
|
250
|
andrew@0
|
251 // for (int i = 0;i < numberOfAudioTracks;i++)
|
andrew@0
|
252 // loadedAudioFiles[i].loadAudioFile(soundFileName);
|
andrew@0
|
253
|
andrew@0
|
254 // audioFilePlayer.loadAudioFile(soundFileName);
|
andrew@0
|
255
|
andrew@0
|
256 }
|
andrew@0
|
257
|
andrew@0
|
258
|
andrew@0
|
259 bool testApp::getFilenameFromDialogBox(std::string* fileNameToSave){
|
andrew@0
|
260 //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully
|
andrew@0
|
261 // first, create a string that will hold the URL
|
andrew@0
|
262 string URL;
|
andrew@0
|
263
|
andrew@0
|
264 // openFile(string& URL) returns 1 if a file was picked
|
andrew@0
|
265 // returns 0 when something went wrong or the user pressed 'cancel'
|
andrew@0
|
266 int response = ofxFileDialogOSX::openFile(URL);
|
andrew@0
|
267 if(response){
|
andrew@0
|
268 // now you can use the URL
|
andrew@0
|
269 *fileNameToSave = URL;
|
andrew@0
|
270 //printf("\n filename is %s \n", soundFileName.c_str());
|
andrew@0
|
271 return true;
|
andrew@0
|
272 }
|
andrew@0
|
273 else {
|
andrew@0
|
274 // soundFileName = "OPEN canceled. ";
|
andrew@0
|
275 printf("\n open file cancelled \n");
|
andrew@0
|
276 return false;
|
andrew@0
|
277 }
|
andrew@0
|
278
|
andrew@0
|
279 }
|
andrew@0
|
280
|
andrew@0
|
281
|
andrew@0
|
282
|
andrew@0
|
283
|
andrew@0
|
284
|