Mercurial > hg > midi-score-follower
comparison hackday/testApp.cpp @ 30:be2e779d76b5
internote calculation added but not running. Better way of waiting for first note to happen before starting.
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Wed, 07 Dec 2011 13:04:59 +0000 |
parents | 69083ce48b83 |
children | 9a70d9abdc8b |
comparison
equal
deleted
inserted
replaced
29:69083ce48b83 | 30:be2e779d76b5 |
---|---|
50 verdana30.loadFont("verdana.ttf", 50, true, true); | 50 verdana30.loadFont("verdana.ttf", 50, true, true); |
51 verdana30.setLineHeight(48.0f); | 51 verdana30.setLineHeight(48.0f); |
52 verdana30.setLetterSpacing(1.035); | 52 verdana30.setLetterSpacing(1.035); |
53 | 53 |
54 playing = false; | 54 playing = false; |
55 | 55 readyToStart = true; |
56 | 56 |
57 receiver.setup( PORT ); | 57 receiver.setup( PORT ); |
58 | 58 |
59 sender.setup( HOST, SEND_PORT ); | 59 sender.setup( HOST, SEND_PORT ); |
60 | 60 |
93 int newMidiOnPitch = m.getArgAsInt32(0) + transpose; | 93 int newMidiOnPitch = m.getArgAsInt32(0) + transpose; |
94 int velocity = m.getArgAsInt32(1); | 94 int velocity = m.getArgAsInt32(1); |
95 double time = m.getArgAsFloat(2); | 95 double time = m.getArgAsFloat(2); |
96 | 96 |
97 if (velocity != 0){ | 97 if (velocity != 0){ |
98 if (readyToStart){ | |
99 startPlaying(); | |
100 printf("starting to PLAY!!!"); | |
101 } | |
102 | |
98 midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time); | 103 midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time); |
99 noteInStream.newNoteCounted(newMidiOnPitch); | 104 noteInStream.newNoteCounted(newMidiOnPitch); |
100 } | 105 } |
101 | 106 |
102 } | 107 } |
109 midiEvents.bayesStruct.speedPriorValue = speedPrior; | 114 midiEvents.bayesStruct.speedPriorValue = speedPrior; |
110 } | 115 } |
111 | 116 |
112 if ( m.getAddress() == "/startplaying" ) | 117 if ( m.getAddress() == "/startplaying" ) |
113 { | 118 { |
114 startPlaying(); | 119 prepareToStartOnNextNote(); |
115 } | 120 } |
116 | 121 |
117 if ( m.getAddress() == "/stopplaying" ) | 122 if ( m.getAddress() == "/stopplaying" ) |
118 { | 123 { |
119 stopPlaying(); | 124 stopPlaying(); |
152 midiEvents.minimumMatchSpeed = minSpeed; | 157 midiEvents.minimumMatchSpeed = minSpeed; |
153 } | 158 } |
154 } | 159 } |
155 | 160 |
156 }//end while osc | 161 }//end while osc |
157 | 162 if (midiEvents.recordedEventTimes.size() > 0) |
158 checkNewScoreNote(); | 163 checkNewScoreNote(); |
159 | 164 |
160 } | 165 } |
161 | 166 |
162 | 167 |
196 m.addStringArg( noteString); | 201 m.addStringArg( noteString); |
197 sender.sendMessage( m ); | 202 sender.sendMessage( m ); |
198 } | 203 } |
199 | 204 |
200 void testApp::sendNoteToMuseScore(){ | 205 void testApp::sendNoteToMuseScore(){ |
206 if (midiEvents.recordedNoteOnMatrix.size() > 0){ | |
201 int ticks = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][0]; | 207 int ticks = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][0]; |
202 int pitch = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][1]; | 208 int pitch = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][1]; |
203 printf("sending to muse score %i, %i \n", ticks, pitch); | 209 printf("sending to muse score %i, %i \n", ticks, pitch); |
204 | 210 sendNoteDataByOsc(pitch, ticks); |
211 } | |
205 /* | 212 /* |
206 ofxOscMessage m; | 213 ofxOscMessage m; |
207 m.setAddress( "/plugin" ); | 214 m.setAddress( "/plugin" ); |
208 string noteString; | 215 string noteString; |
209 noteString = "blackNotes.js"; | 216 noteString = "blackNotes.js"; |
210 m.addStringArg( noteString); | 217 m.addStringArg( noteString); |
211 sender.sendMessage( m ); | 218 sender.sendMessage( m ); |
212 */ | 219 */ |
213 sendNoteDataByOsc(pitch, ticks); | 220 |
214 | 221 |
215 // /color-note 60,3440 | 222 // /color-note 60,3440 |
216 | 223 |
217 //crappy javascript message | 224 //crappy javascript message |
218 /* | 225 /* |
331 | 338 |
332 if (key == ',' && midiPort > 0){ | 339 if (key == ',' && midiPort > 0){ |
333 midiPort--; | 340 midiPort--; |
334 midiIn.openPort(midiPort); | 341 midiIn.openPort(midiPort); |
335 } | 342 } |
336 | 343 |
337 // if (key == ' '){ | |
338 // startPlaying(); | |
339 // } | |
340 if (key == '-') | 344 if (key == '-') |
341 transpose -= 12; | 345 transpose -= 12; |
342 | 346 |
343 if (key == '=') | 347 if (key == '=') |
344 transpose += 12; | 348 transpose += 12; |
376 | 380 |
377 if (key == 'b'){ | 381 if (key == 'b'){ |
378 sendBlackNotes(); | 382 sendBlackNotes(); |
379 } | 383 } |
380 | 384 |
385 | |
386 if (key == 'n'){ | |
387 midiEvents.printInterNoteIntervals(); | |
388 } | |
389 | |
381 if (key == OF_KEY_DOWN){ | 390 if (key == OF_KEY_DOWN){ |
382 if (midiEvents.ticksPerScreen >= 4000) | 391 if (midiEvents.ticksPerScreen >= 4000) |
383 midiEvents.ticksPerScreen -= 2000; | 392 midiEvents.ticksPerScreen -= 2000; |
384 else if (midiEvents.ticksPerScreen > 500) | 393 else if (midiEvents.ticksPerScreen > 500) |
385 midiEvents.ticksPerScreen -= 500; | 394 midiEvents.ticksPerScreen -= 500; |
395 if (key == 'p'){ | 404 if (key == 'p'){ |
396 midiEvents.printNotes(); | 405 midiEvents.printNotes(); |
397 } | 406 } |
398 | 407 |
399 if (key == 'l') | 408 if (key == 'l') |
400 midiEvents.bayesStruct.decaySpeedDistribution(100); | 409 |
410 | |
411 //midiEvents.bayesStruct.decaySpeedDistribution(100); | |
401 | 412 |
402 if (key == 't') | 413 if (key == 't') |
403 midiEvents.drawTempoMode = !midiEvents.drawTempoMode; | 414 midiEvents.drawTempoMode = !midiEvents.drawTempoMode; |
404 | 415 |
405 if (key == 'y') | 416 if (key == 'y') |
416 performanceRating = 0; | 427 performanceRating = 0; |
417 | 428 |
418 } | 429 } |
419 | 430 |
420 if (key == 'o' || key == 'O'){ | 431 if (key == 'o' || key == 'O'){ |
421 //open audio file | 432 loadRecordedMidiFile(); |
422 string *filePtr; | 433 } |
423 filePtr = &midiFileName; | 434 |
424 | 435 |
425 if (getFilenameFromDialogBox(filePtr)){ | 436 |
426 printf("Midifile: Loaded name okay :\n'%s' \n", midiFileName.c_str()); | 437 } |
427 cannamMainFunction(); | 438 |
428 } | 439 void testApp::loadRecordedMidiFile(){ |
429 } | 440 //open audio file |
430 | 441 string *filePtr; |
431 | 442 filePtr = &midiFileName; |
432 | 443 |
444 if (getFilenameFromDialogBox(filePtr)){ | |
445 printf("Midifile: Loaded name okay :\n'%s' \n", midiFileName.c_str()); | |
446 cannamMainFunction(); | |
447 } | |
433 } | 448 } |
434 | 449 |
435 //-------------------------------------------------------------- | 450 //-------------------------------------------------------------- |
436 void testApp::keyReleased(int key){ | 451 void testApp::keyReleased(int key){ |
437 | 452 |
463 screenHeight = h; | 478 screenHeight = h; |
464 midiEvents.noteHeight = screenHeight / (float)(midiEvents.noteMaximum - midiEvents.noteMinimum); | 479 midiEvents.noteHeight = screenHeight / (float)(midiEvents.noteMaximum - midiEvents.noteMinimum); |
465 | 480 |
466 } | 481 } |
467 | 482 |
483 void testApp::prepareToStartOnNextNote(){ | |
484 readyToStart = true; | |
485 } | |
468 | 486 |
469 | 487 |
470 void testApp::startPlaying(){ | 488 void testApp::startPlaying(){ |
471 playing = !playing; | 489 playing = !playing; |
472 midiEvents.reset(); | 490 midiEvents.reset(); |
473 noteInStream.reset(); | 491 noteInStream.reset(); |
474 midiEvents.setStartPlayingTimes(); | 492 midiEvents.setStartPlayingTimes(); |
475 sendBlackNotes(); | 493 sendBlackNotes(); |
494 readyToStart = false; | |
476 //this is where we stop and start playing | 495 //this is where we stop and start playing |
477 } | 496 } |
478 | 497 |
479 void testApp::stopPlaying(){ | 498 void testApp::stopPlaying(){ |
480 midiEvents.printNoteCounter(); | 499 midiEvents.printNoteCounter(); |