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