Mercurial > hg > midi-score-follower
comparison src/midiEventHolder.cpp @ 15:9e972948d654
looking at offline version - need to do updateBestEstimate routine which presently only works for realtime
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 15 Nov 2011 13:10:12 +0000 |
parents | 3f103cf78148 |
children | f0abb0e414ec |
comparison
equal
deleted
inserted
replaced
14:3f103cf78148 | 15:9e972948d654 |
---|---|
4 * | 4 * |
5 * Created by Andrew on 19/07/2011. | 5 * Created by Andrew on 19/07/2011. |
6 * Copyright 2011 QMUL. All rights reserved. | 6 * Copyright 2011 QMUL. All rights reserved. |
7 * | 7 * |
8 */ | 8 */ |
9 //hello | |
10 | 9 |
11 #include "midiEventHolder.h" | 10 #include "midiEventHolder.h" |
12 | 11 |
13 midiEventHolder::midiEventHolder(){ | 12 midiEventHolder::midiEventHolder(){ |
14 // recordedNoteOnIndex = 0; | 13 // recordedNoteOnIndex = 0; |
146 playedEventTimes.push_back(timePlayed); | 145 playedEventTimes.push_back(timePlayed); |
147 | 146 |
148 // double timeDifference = ofGetElapsedTimeMillis() - bayesStruct.lastEventTime; | 147 // double timeDifference = ofGetElapsedTimeMillis() - bayesStruct.lastEventTime; |
149 double timeDifference = timePlayed - bayesStruct.lastEventTime; | 148 double timeDifference = timePlayed - bayesStruct.lastEventTime; |
150 | 149 |
151 // printf("note %i played at %f and last event %f\n", pitch, timePlayed, bayesStruct.lastEventTime); | 150 |
151 | |
152 printf("note %i played at %f and last event %f time difference %f and current best estmate %f\n", pitch, timePlayed, bayesStruct.lastEventTime, timeDifference, bayesStruct.bestEstimate); | |
152 //addnoise to the tempo distribution | 153 //addnoise to the tempo distribution |
153 //bayesStruct.decaySpeedDistribution(timeDifference); | 154 //bayesStruct.decaySpeedDistribution(timeDifference); |
154 if (timeDifference > 50){ | 155 if (timeDifference > 50){ |
155 bayesStruct.addGaussianNoiseToSpeedPosterior(timeDifference * 10 / 100.); | 156 bayesStruct.addGaussianNoiseToSpeedPosterior(timeDifference * 10 / 100.); |
156 // bayesStruct.addTriangularNoiseToSpeedPosterior(timeDifference * 10 / 100.); | 157 // bayesStruct.addTriangularNoiseToSpeedPosterior(timeDifference * 10 / 100.); |
231 //here we find the matches to the new note within appropriate range | 232 //here we find the matches to the new note within appropriate range |
232 | 233 |
233 matchString = ""; | 234 matchString = ""; |
234 | 235 |
235 windowStartTime = max(0.0,(bayesStruct.bestEstimate - matchWindowWidth/2));//was playPositionInMillis | 236 windowStartTime = max(0.0,(bayesStruct.bestEstimate - matchWindowWidth/2));//was playPositionInMillis |
237 cout << "best estimate is " << bayesStruct.bestEstimate << endl; | |
236 int numberOfMatches = findMatch(notePitch, windowStartTime, windowStartTime + matchWindowWidth); | 238 int numberOfMatches = findMatch(notePitch, windowStartTime, windowStartTime + matchWindowWidth); |
237 | 239 |
238 | 240 |
239 matchString += " pitch: "+ofToString(notePitch)+" matches "+ofToString(numberOfMatches)+" win start "+ofToString(windowStartTime); | 241 matchString += " pitch: "+ofToString(notePitch)+" matches "+ofToString(numberOfMatches)+" win start "+ofToString(windowStartTime); |
240 | 242 |
327 | 329 |
328 | 330 |
329 matchMatrix.push_back(v); | 331 matchMatrix.push_back(v); |
330 matchConfidence.push_back(d); | 332 matchConfidence.push_back(d); |
331 | 333 |
332 printf("BEST MATCH TO note %i,time %i is recorded time %i, confidence %0.2f\n", notePitch, startTime, (int) recordedEventTimes[bestMatchIndex], minimumConfidence); | 334 printf("BEST MATCH TO note %i, start time %i, endtime %i, time %i is recorded time %i, confidence %0.2f\n", notePitch, startTime, endTime, (int) recordedEventTimes[bestMatchIndex], minimumConfidence); |
333 | 335 |
334 return size; | 336 return size; |
335 } | 337 } |
336 | 338 |
337 bool midiEventHolder::checkIfMatchedNote(const int& tmpIndex){ | 339 bool midiEventHolder::checkIfMatchedNote(const int& tmpIndex){ |
481 //in actual fact if we are changing the speed of the play position | 483 //in actual fact if we are changing the speed of the play position |
482 //we will need to update this via the file | 484 //we will need to update this via the file |
483 | 485 |
484 //actually time since beginning of file i think | 486 //actually time since beginning of file i think |
485 | 487 |
486 double timeDifference = ofGetElapsedTimeMillis() - lastPeriodUpdateTime;//elpased - lastperiodupdatetime | 488 double timeDifference = 0; |
489 if (runningInRealTime) | |
490 timeDifference = ofGetElapsedTimeMillis() - lastPeriodUpdateTime;//elpased - lastperiodupdatetime | |
491 | |
487 //this is time diff in milliseconds | 492 //this is time diff in milliseconds |
488 //then we have | 493 //then we have |
489 double quarterNoteIntervals = (timeDifference / period); | 494 double quarterNoteIntervals = (timeDifference / period); |
490 tickLocation = quarterNoteIntervals * pulsesPerQuarternote; | 495 tickLocation = quarterNoteIntervals * pulsesPerQuarternote; |
491 | 496 |