Mercurial > hg > midi-score-follower
diff 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 |
line wrap: on
line diff
--- a/jnmr/testApp.cpp Mon Dec 12 12:46:17 2011 +0000 +++ b/jnmr/testApp.cpp Wed Dec 14 11:35:31 2011 +0000 @@ -8,7 +8,18 @@ //-------------------------------------------------------------- void testApp::setup(){ - + + myfile.open("../../../data/FilesOut/exampletest.txt"); + if (myfile.is_open()) + { + myfile << "This is a line.\n"; + myfile << "This is another line.\n"; + myfile.close(); + printf("WRITING TO TEXT FILE\n"); + } + else cout << "Unable to open file"; + + this->args->printArgs(); this->args->printOpts(); midiFileName = "../../../data/frerejacques.mid"; @@ -33,7 +44,7 @@ transpose = 0; noteInStream.transposeVal = &transpose; - noteInStream.startTime = &midiEvents.startTime;//point start time of note in stream to the same time in MIDI events + noteInStream.startTime = &midiEvents.startPlayingTime;//point start time of note in stream to the same time in MIDI events noteInStream.factor = &midiEvents.ticksFactor; printf("TICKS FACTOR %f \n", midiEvents.ticksFactor);//noteInStream->factor) @@ -99,7 +110,7 @@ startPlaying(); printf("starting to PLAY!!!"); } - printf("MIDI NOTE %i \n", newMidiOnPitch); + // printf("MIDI NOTE %i \n", newMidiOnPitch); midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time); noteInStream.newNoteCounted(newMidiOnPitch); } @@ -111,7 +122,7 @@ float speedPrior = m.getArgAsFloat(0); printf("speed prior set to %f\n", speedPrior); midiEvents.speedPriorValue = speedPrior; - midiEvents.bayesStruct.speedPriorValue = speedPrior; + //midiEvents.bayesStruct.speedPriorValue = speedPrior; } if ( m.getAddress() == "/startplaying" ) @@ -181,6 +192,18 @@ } + if ( m.getAddress() == "/duration" ) + { + + float playedDuration = m.getArgAsFloat(0); + double recordedDuration = midiEvents.recordedEventTimes[midiEvents.recordedEventTimes.size()-1]; + midiEvents.speedPriorValue = recordedDuration/playedDuration; + printf("played duration %f, recorded %f\n", playedDuration, recordedDuration); + printf("speed prior set to %f\n", midiEvents.bayesStruct.speedPriorValue); + + } + + }//end while osc if (midiEvents.recordedEventTimes.size() > 0) checkNewScoreNote(); @@ -327,30 +350,33 @@ ofSetHexColor(0xFF0000); // ofDrawBitmapString(info, 20, 20); + midiEvents.drawMidiFile(noteInStream.midiInputEvents); -// ofDrawBitmapString("Rating "+ofToString(performanceRating*100), 60, 50); - //ofDrawBitmapString("filename "+museScoreFilename, 20, 80); - string ratingString = ofToString(performanceRating*100,0)+"%"; - if (performanceRating > 0.84) - ratingString += "!* *"; - string extraText = ""; - if (performanceRating > 0.9){ - extraText += " pretty good, huh?"; - } - if (performanceRating > 0.95) - extraText = " blimey! "; - if (performanceRating > 0.97) - extraText = " maestro!"; - - ratingString += extraText; - verdana30.drawString(ratingString, 20, 60); + drawMuseScoreText(); ofSetHexColor(0x000000); ofDrawBitmapString(midiPortName, 20, ofGetHeight() - 20); } +void testApp::drawMuseScoreText(){ + string ratingString = ofToString(performanceRating*100,0)+"%"; + if (performanceRating > 0.84) + ratingString += "!* *"; + string extraText = ""; + if (performanceRating > 0.9){ + extraText += " pretty good, huh?"; + } + if (performanceRating > 0.95) + extraText = " blimey! "; + if (performanceRating > 0.97) + extraText = " maestro!"; + + ratingString += extraText; + verdana30.drawString(ratingString, 20, 60); +} + //-------------------------------------------------------------- void testApp::keyPressed(int key){