Mercurial > hg > midi-score-follower
diff hackday/testApp.cpp @ 26:179365726f07
live input, calculates score rating
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sun, 04 Dec 2011 00:02:26 +0000 |
parents | 2a025ea7c793 |
children | fa1890efa044 |
line wrap: on
line diff
--- a/hackday/testApp.cpp Sat Dec 03 21:09:13 2011 +0000 +++ b/hackday/testApp.cpp Sun Dec 04 00:02:26 2011 +0000 @@ -13,7 +13,7 @@ midiIn.listPorts(); midiIn.openPort(2); - transpose = 24; + transpose = 12; noteInStream.transposeVal = &transpose; noteInStream.startTime = &midiEvents.startTime;//point start time of note in stream to the same time in MIDI events @@ -47,6 +47,7 @@ midiEvents.ticksPerScreen += 4000; lastScoreIndexSent = 0; + performanceRating = 1.0; } @@ -65,12 +66,14 @@ if ( m.getAddress() == "/midinoteon" ) { - int newMidiOnPitch = m.getArgAsInt32(0); + int newMidiOnPitch = m.getArgAsInt32(0) + transpose; int velocity = m.getArgAsInt32(1); double time = m.getArgAsFloat(2); - if (velocity != 0) - midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time); + if (velocity != 0){ + midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time); + noteInStream.newNoteCounted(newMidiOnPitch); + } } @@ -155,24 +158,50 @@ } if (lastMeasureSent != tmpMeasure){ sendMeasureToMuseScore(); + performanceRating = noteInStream.calculateTotalScore(midiEvents); } } +void testApp::sendBlackNotes(){ + ofxOscMessage m; + m.setAddress( "/plugin" ); + string noteString; + noteString = "blacknotes.js"; + m.addStringArg( noteString); + sender.sendMessage( m ); +} + void testApp::sendNoteToMuseScore(){ int ticks = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][0]; int pitch = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][1]; printf("sending to muse score %i, %i \n", ticks, pitch); - ofxOscMessage m; - m.setAddress( "/plugin" ); + /* + ofxOscMessage m; + m.setAddress( "/plugin" ); + string noteString; + noteString = "blackNotes.js"; + m.addStringArg( noteString); + sender.sendMessage( m ); + */ + + ofxOscMessage m; + m.setAddress( "/plugin" ); + string noteString; + noteString = "coloronenote.js"; + noteString += ",myTick,"+ofToString(ticks)+",myPitch,"+ofToString(pitch); + // printf("%s\n", noteString); + m.addStringArg( noteString); + sender.sendMessage( m ); + /* m.addStringArg( "coloronenote.js" ); m.addStringArg("mytick"); m.addIntArg( ticks ); m.addStringArg("mypitch"); m.addIntArg( pitch); - sender.sendMessage( m ); + */ // /plugin coloronenote.js mytick 100 mypitch 56; } @@ -239,6 +268,7 @@ ofDrawBitmapString(info, 20, 20); midiEvents.drawMidiFile(noteInStream.midiInputEvents); + ofDrawBitmapString("Rating "+ofToString(performanceRating*100), 20, 50); } //-------------------------------------------------------------- @@ -261,6 +291,12 @@ timenow += ofGetElapsedTimeMillis(); printf("CROSS UPDATE TOOK %f", timenow); } + + if (key == OF_KEY_LEFT){ + + } + + if (key == OF_KEY_RIGHT) if (key == OF_KEY_RETURN) stopPlaying(); @@ -276,6 +312,10 @@ // midiEvents.findMatch(84, 0, 10000); } + if (key == 'b'){ + sendBlackNotes(); + } + if (key == OF_KEY_DOWN){ if (midiEvents.ticksPerScreen >= 4000) midiEvents.ticksPerScreen -= 2000; @@ -307,6 +347,11 @@ noteInStream.reset(); liveInputPlaying = false; stopPlaying(); + lastMeasureSent = 0; + sendMeasureToMuseScore(); + sendBlackNotes(); + lastScoreIndexSent = 0; + } if (key == 'o'){ @@ -362,17 +407,24 @@ void testApp::startPlaying(){ playing = !playing; midiEvents.reset(); + noteInStream.reset(); midiEvents.setStartPlayingTimes(); - + sendBlackNotes(); //this is where we stop and start playing } void testApp::stopPlaying(){ + midiEvents.printNoteCounter(); + noteInStream.printTotalCount(); + noteInStream.calculateTotalScore(midiEvents); + + playing = false; liveInputPlaying = false; lastScoreIndexSent = 0; midiEvents.bestMatchIndex = 0; sendNoteToMuseScore(); + } bool testApp::getFilenameFromDialogBox(string* fileNameToSave){