Mercurial > hg > midi-score-follower
comparison jnmr/testApp.cpp @ 34:9d2a651a87b2
autoomatically set prior that matches the durations of the songs. Using 120 bpm as default for the recorded part.
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Wed, 14 Dec 2011 11:35:31 +0000 |
parents | fa527df85c2c |
children | 6cd3e0075adf |
comparison
equal
deleted
inserted
replaced
33:fa527df85c2c | 34:9d2a651a87b2 |
---|---|
6 } | 6 } |
7 | 7 |
8 //-------------------------------------------------------------- | 8 //-------------------------------------------------------------- |
9 void testApp::setup(){ | 9 void testApp::setup(){ |
10 | 10 |
11 | 11 |
12 myfile.open("../../../data/FilesOut/exampletest.txt"); | |
13 if (myfile.is_open()) | |
14 { | |
15 myfile << "This is a line.\n"; | |
16 myfile << "This is another line.\n"; | |
17 myfile.close(); | |
18 printf("WRITING TO TEXT FILE\n"); | |
19 } | |
20 else cout << "Unable to open file"; | |
21 | |
22 | |
12 this->args->printArgs(); | 23 this->args->printArgs(); |
13 this->args->printOpts(); | 24 this->args->printOpts(); |
14 midiFileName = "../../../data/frerejacques.mid"; | 25 midiFileName = "../../../data/frerejacques.mid"; |
15 | 26 |
16 if (this->args->getCount() > 0){ | 27 if (this->args->getCount() > 0){ |
31 //midiPortName = midiIn.portNames(midiPort); | 42 //midiPortName = midiIn.portNames(midiPort); |
32 | 43 |
33 transpose = 0; | 44 transpose = 0; |
34 noteInStream.transposeVal = &transpose; | 45 noteInStream.transposeVal = &transpose; |
35 | 46 |
36 noteInStream.startTime = &midiEvents.startTime;//point start time of note in stream to the same time in MIDI events | 47 noteInStream.startTime = &midiEvents.startPlayingTime;//point start time of note in stream to the same time in MIDI events |
37 | 48 |
38 noteInStream.factor = &midiEvents.ticksFactor; | 49 noteInStream.factor = &midiEvents.ticksFactor; |
39 printf("TICKS FACTOR %f \n", midiEvents.ticksFactor);//noteInStream->factor) | 50 printf("TICKS FACTOR %f \n", midiEvents.ticksFactor);//noteInStream->factor) |
40 | 51 |
41 // portName = "hello";//midiIn.portNames[2]; | 52 // portName = "hello";//midiIn.portNames[2]; |
97 if (velocity != 0){ | 108 if (velocity != 0){ |
98 if (readyToStart){ | 109 if (readyToStart){ |
99 startPlaying(); | 110 startPlaying(); |
100 printf("starting to PLAY!!!"); | 111 printf("starting to PLAY!!!"); |
101 } | 112 } |
102 printf("MIDI NOTE %i \n", newMidiOnPitch); | 113 // printf("MIDI NOTE %i \n", newMidiOnPitch); |
103 midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time); | 114 midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time); |
104 noteInStream.newNoteCounted(newMidiOnPitch); | 115 noteInStream.newNoteCounted(newMidiOnPitch); |
105 } | 116 } |
106 | 117 |
107 } | 118 } |
109 if ( m.getAddress() == "/setSpeedPrior" ) | 120 if ( m.getAddress() == "/setSpeedPrior" ) |
110 { | 121 { |
111 float speedPrior = m.getArgAsFloat(0); | 122 float speedPrior = m.getArgAsFloat(0); |
112 printf("speed prior set to %f\n", speedPrior); | 123 printf("speed prior set to %f\n", speedPrior); |
113 midiEvents.speedPriorValue = speedPrior; | 124 midiEvents.speedPriorValue = speedPrior; |
114 midiEvents.bayesStruct.speedPriorValue = speedPrior; | 125 //midiEvents.bayesStruct.speedPriorValue = speedPrior; |
115 } | 126 } |
116 | 127 |
117 if ( m.getAddress() == "/startplaying" ) | 128 if ( m.getAddress() == "/startplaying" ) |
118 { | 129 { |
119 prepareToStartOnNextNote(); | 130 prepareToStartOnNextNote(); |
178 midiEvents.likelihoodToNoiseRatio = ratio; | 189 midiEvents.likelihoodToNoiseRatio = ratio; |
179 printf("likelihood for events relative to noise uses ratio %f\n", ratio); | 190 printf("likelihood for events relative to noise uses ratio %f\n", ratio); |
180 } | 191 } |
181 | 192 |
182 } | 193 } |
194 | |
195 if ( m.getAddress() == "/duration" ) | |
196 { | |
197 | |
198 float playedDuration = m.getArgAsFloat(0); | |
199 double recordedDuration = midiEvents.recordedEventTimes[midiEvents.recordedEventTimes.size()-1]; | |
200 midiEvents.speedPriorValue = recordedDuration/playedDuration; | |
201 printf("played duration %f, recorded %f\n", playedDuration, recordedDuration); | |
202 printf("speed prior set to %f\n", midiEvents.bayesStruct.speedPriorValue); | |
203 | |
204 } | |
205 | |
183 | 206 |
184 }//end while osc | 207 }//end while osc |
185 if (midiEvents.recordedEventTimes.size() > 0) | 208 if (midiEvents.recordedEventTimes.size() > 0) |
186 checkNewScoreNote(); | 209 checkNewScoreNote(); |
187 | 210 |
325 info += " Last note "; | 348 info += " Last note "; |
326 info += ofToString(lastScoreIndexSent); | 349 info += ofToString(lastScoreIndexSent); |
327 | 350 |
328 ofSetHexColor(0xFF0000); | 351 ofSetHexColor(0xFF0000); |
329 // ofDrawBitmapString(info, 20, 20); | 352 // ofDrawBitmapString(info, 20, 20); |
353 | |
330 midiEvents.drawMidiFile(noteInStream.midiInputEvents); | 354 midiEvents.drawMidiFile(noteInStream.midiInputEvents); |
331 | 355 |
332 // ofDrawBitmapString("Rating "+ofToString(performanceRating*100), 60, 50); | 356 drawMuseScoreText(); |
333 //ofDrawBitmapString("filename "+museScoreFilename, 20, 80); | |
334 string ratingString = ofToString(performanceRating*100,0)+"%"; | |
335 if (performanceRating > 0.84) | |
336 ratingString += "!* *"; | |
337 string extraText = ""; | |
338 if (performanceRating > 0.9){ | |
339 extraText += " pretty good, huh?"; | |
340 } | |
341 if (performanceRating > 0.95) | |
342 extraText = " blimey! "; | |
343 if (performanceRating > 0.97) | |
344 extraText = " maestro!"; | |
345 | |
346 ratingString += extraText; | |
347 verdana30.drawString(ratingString, 20, 60); | |
348 | 357 |
349 ofSetHexColor(0x000000); | 358 ofSetHexColor(0x000000); |
350 ofDrawBitmapString(midiPortName, 20, ofGetHeight() - 20); | 359 ofDrawBitmapString(midiPortName, 20, ofGetHeight() - 20); |
351 | 360 |
361 } | |
362 | |
363 void testApp::drawMuseScoreText(){ | |
364 string ratingString = ofToString(performanceRating*100,0)+"%"; | |
365 if (performanceRating > 0.84) | |
366 ratingString += "!* *"; | |
367 string extraText = ""; | |
368 if (performanceRating > 0.9){ | |
369 extraText += " pretty good, huh?"; | |
370 } | |
371 if (performanceRating > 0.95) | |
372 extraText = " blimey! "; | |
373 if (performanceRating > 0.97) | |
374 extraText = " maestro!"; | |
375 | |
376 ratingString += extraText; | |
377 verdana30.drawString(ratingString, 20, 60); | |
352 } | 378 } |
353 | 379 |
354 //-------------------------------------------------------------- | 380 //-------------------------------------------------------------- |
355 void testApp::keyPressed(int key){ | 381 void testApp::keyPressed(int key){ |
356 | 382 |