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