Mercurial > hg > midi-score-follower
comparison 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 |
comparison
equal
deleted
inserted
replaced
25:2a025ea7c793 | 26:179365726f07 |
---|---|
11 //ofBackground(255,255,255); | 11 //ofBackground(255,255,255); |
12 | 12 |
13 midiIn.listPorts(); | 13 midiIn.listPorts(); |
14 midiIn.openPort(2); | 14 midiIn.openPort(2); |
15 | 15 |
16 transpose = 24; | 16 transpose = 12; |
17 noteInStream.transposeVal = &transpose; | 17 noteInStream.transposeVal = &transpose; |
18 | 18 |
19 noteInStream.startTime = &midiEvents.startTime;//point start time of note in stream to the same time in MIDI events | 19 noteInStream.startTime = &midiEvents.startTime;//point start time of note in stream to the same time in MIDI events |
20 | 20 |
21 noteInStream.factor = &midiEvents.ticksFactor; | 21 noteInStream.factor = &midiEvents.ticksFactor; |
45 midiEvents.drawTempoMode = false; | 45 midiEvents.drawTempoMode = false; |
46 ofSetFrameRate(30); | 46 ofSetFrameRate(30); |
47 | 47 |
48 midiEvents.ticksPerScreen += 4000; | 48 midiEvents.ticksPerScreen += 4000; |
49 lastScoreIndexSent = 0; | 49 lastScoreIndexSent = 0; |
50 performanceRating = 1.0; | |
50 | 51 |
51 } | 52 } |
52 | 53 |
53 //-------------------------------------------------------------- | 54 //-------------------------------------------------------------- |
54 void testApp::update(){ | 55 void testApp::update(){ |
63 ofxOscMessage m; | 64 ofxOscMessage m; |
64 receiver.getNextMessage( &m ); | 65 receiver.getNextMessage( &m ); |
65 | 66 |
66 if ( m.getAddress() == "/midinoteon" ) | 67 if ( m.getAddress() == "/midinoteon" ) |
67 { | 68 { |
68 int newMidiOnPitch = m.getArgAsInt32(0); | 69 int newMidiOnPitch = m.getArgAsInt32(0) + transpose; |
69 int velocity = m.getArgAsInt32(1); | 70 int velocity = m.getArgAsInt32(1); |
70 double time = m.getArgAsFloat(2); | 71 double time = m.getArgAsFloat(2); |
71 | 72 |
72 if (velocity != 0) | 73 if (velocity != 0){ |
73 midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time); | 74 midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time); |
75 noteInStream.newNoteCounted(newMidiOnPitch); | |
76 } | |
74 | 77 |
75 } | 78 } |
76 | 79 |
77 if ( m.getAddress() == "/setSpeedPrior" ) | 80 if ( m.getAddress() == "/setSpeedPrior" ) |
78 { | 81 { |
153 while (lastMeasureSent < midiEvents.measureVector.size() && midiEvents.measureVector[lastMeasureSent] < ticks) { | 156 while (lastMeasureSent < midiEvents.measureVector.size() && midiEvents.measureVector[lastMeasureSent] < ticks) { |
154 lastMeasureSent++; | 157 lastMeasureSent++; |
155 } | 158 } |
156 if (lastMeasureSent != tmpMeasure){ | 159 if (lastMeasureSent != tmpMeasure){ |
157 sendMeasureToMuseScore(); | 160 sendMeasureToMuseScore(); |
158 } | 161 performanceRating = noteInStream.calculateTotalScore(midiEvents); |
159 | 162 } |
160 | 163 |
164 | |
165 } | |
166 | |
167 void testApp::sendBlackNotes(){ | |
168 ofxOscMessage m; | |
169 m.setAddress( "/plugin" ); | |
170 string noteString; | |
171 noteString = "blacknotes.js"; | |
172 m.addStringArg( noteString); | |
173 sender.sendMessage( m ); | |
161 } | 174 } |
162 | 175 |
163 void testApp::sendNoteToMuseScore(){ | 176 void testApp::sendNoteToMuseScore(){ |
164 int ticks = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][0]; | 177 int ticks = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][0]; |
165 int pitch = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][1]; | 178 int pitch = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][1]; |
166 printf("sending to muse score %i, %i \n", ticks, pitch); | 179 printf("sending to muse score %i, %i \n", ticks, pitch); |
167 | 180 |
168 ofxOscMessage m; | 181 /* |
169 m.setAddress( "/plugin" ); | 182 ofxOscMessage m; |
183 m.setAddress( "/plugin" ); | |
184 string noteString; | |
185 noteString = "blackNotes.js"; | |
186 m.addStringArg( noteString); | |
187 sender.sendMessage( m ); | |
188 */ | |
189 | |
190 ofxOscMessage m; | |
191 m.setAddress( "/plugin" ); | |
192 string noteString; | |
193 noteString = "coloronenote.js"; | |
194 noteString += ",myTick,"+ofToString(ticks)+",myPitch,"+ofToString(pitch); | |
195 // printf("%s\n", noteString); | |
196 m.addStringArg( noteString); | |
197 sender.sendMessage( m ); | |
198 /* | |
170 m.addStringArg( "coloronenote.js" ); | 199 m.addStringArg( "coloronenote.js" ); |
171 m.addStringArg("mytick"); | 200 m.addStringArg("mytick"); |
172 m.addIntArg( ticks ); | 201 m.addIntArg( ticks ); |
173 m.addStringArg("mypitch"); | 202 m.addStringArg("mypitch"); |
174 m.addIntArg( pitch); | 203 m.addIntArg( pitch); |
175 sender.sendMessage( m ); | 204 */ |
176 | 205 |
177 // /plugin coloronenote.js mytick 100 mypitch 56; | 206 // /plugin coloronenote.js mytick 100 mypitch 56; |
178 } | 207 } |
179 | 208 |
180 | 209 |
237 | 266 |
238 ofSetHexColor(0x000000); | 267 ofSetHexColor(0x000000); |
239 ofDrawBitmapString(info, 20, 20); | 268 ofDrawBitmapString(info, 20, 20); |
240 midiEvents.drawMidiFile(noteInStream.midiInputEvents); | 269 midiEvents.drawMidiFile(noteInStream.midiInputEvents); |
241 | 270 |
271 ofDrawBitmapString("Rating "+ofToString(performanceRating*100), 20, 50); | |
242 } | 272 } |
243 | 273 |
244 //-------------------------------------------------------------- | 274 //-------------------------------------------------------------- |
245 void testApp::keyPressed(int key){ | 275 void testApp::keyPressed(int key){ |
246 | 276 |
259 midiEvents.exampleCrossUpdate(); | 289 midiEvents.exampleCrossUpdate(); |
260 timenow *= -1; | 290 timenow *= -1; |
261 timenow += ofGetElapsedTimeMillis(); | 291 timenow += ofGetElapsedTimeMillis(); |
262 printf("CROSS UPDATE TOOK %f", timenow); | 292 printf("CROSS UPDATE TOOK %f", timenow); |
263 } | 293 } |
294 | |
295 if (key == OF_KEY_LEFT){ | |
296 | |
297 } | |
298 | |
299 if (key == OF_KEY_RIGHT) | |
264 | 300 |
265 if (key == OF_KEY_RETURN) | 301 if (key == OF_KEY_RETURN) |
266 stopPlaying(); | 302 stopPlaying(); |
267 | 303 |
268 if (key == OF_KEY_UP){ | 304 if (key == OF_KEY_UP){ |
274 | 310 |
275 if (key == 'm'){ | 311 if (key == 'm'){ |
276 // midiEvents.findMatch(84, 0, 10000); | 312 // midiEvents.findMatch(84, 0, 10000); |
277 } | 313 } |
278 | 314 |
315 if (key == 'b'){ | |
316 sendBlackNotes(); | |
317 } | |
318 | |
279 if (key == OF_KEY_DOWN){ | 319 if (key == OF_KEY_DOWN){ |
280 if (midiEvents.ticksPerScreen >= 4000) | 320 if (midiEvents.ticksPerScreen >= 4000) |
281 midiEvents.ticksPerScreen -= 2000; | 321 midiEvents.ticksPerScreen -= 2000; |
282 else if (midiEvents.ticksPerScreen > 500) | 322 else if (midiEvents.ticksPerScreen > 500) |
283 midiEvents.ticksPerScreen -= 500; | 323 midiEvents.ticksPerScreen -= 500; |
305 | 345 |
306 if (key == 'r'){ | 346 if (key == 'r'){ |
307 noteInStream.reset(); | 347 noteInStream.reset(); |
308 liveInputPlaying = false; | 348 liveInputPlaying = false; |
309 stopPlaying(); | 349 stopPlaying(); |
350 lastMeasureSent = 0; | |
351 sendMeasureToMuseScore(); | |
352 sendBlackNotes(); | |
353 lastScoreIndexSent = 0; | |
354 | |
310 } | 355 } |
311 | 356 |
312 if (key == 'o'){ | 357 if (key == 'o'){ |
313 //open audio file | 358 //open audio file |
314 string *filePtr; | 359 string *filePtr; |
360 | 405 |
361 | 406 |
362 void testApp::startPlaying(){ | 407 void testApp::startPlaying(){ |
363 playing = !playing; | 408 playing = !playing; |
364 midiEvents.reset(); | 409 midiEvents.reset(); |
410 noteInStream.reset(); | |
365 midiEvents.setStartPlayingTimes(); | 411 midiEvents.setStartPlayingTimes(); |
366 | 412 sendBlackNotes(); |
367 //this is where we stop and start playing | 413 //this is where we stop and start playing |
368 } | 414 } |
369 | 415 |
370 void testApp::stopPlaying(){ | 416 void testApp::stopPlaying(){ |
417 midiEvents.printNoteCounter(); | |
418 noteInStream.printTotalCount(); | |
419 noteInStream.calculateTotalScore(midiEvents); | |
420 | |
421 | |
371 playing = false; | 422 playing = false; |
372 liveInputPlaying = false; | 423 liveInputPlaying = false; |
373 lastScoreIndexSent = 0; | 424 lastScoreIndexSent = 0; |
374 midiEvents.bestMatchIndex = 0; | 425 midiEvents.bestMatchIndex = 0; |
375 sendNoteToMuseScore(); | 426 sendNoteToMuseScore(); |
427 | |
376 } | 428 } |
377 | 429 |
378 bool testApp::getFilenameFromDialogBox(string* fileNameToSave){ | 430 bool testApp::getFilenameFromDialogBox(string* fileNameToSave){ |
379 //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully | 431 //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully |
380 // first, create a string that will hold the URL | 432 // first, create a string that will hold the URL |