comparison src/midiEventHolder.cpp @ 14:3f103cf78148

Checking to allow offline version
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 10 Nov 2011 17:29:45 +0000
parents 5897a5626f1f
children 9e972948d654
comparison
equal deleted inserted replaced
13:bba4a9da57f1 14:3f103cf78148
33 33
34 bayesStruct.speedLikelihoodNoise = 0.1;//was 0.05 34 bayesStruct.speedLikelihoodNoise = 0.1;//was 0.05
35 bayesStruct.speedDecayWidth = 20; 35 bayesStruct.speedDecayWidth = 20;
36 bayesStruct.speedDecayAmount = 10; 36 bayesStruct.speedDecayAmount = 10;
37 37
38 runningInRealTime = true;
39
38 speedPriorValue = 1.0; 40 speedPriorValue = 1.0;
39 41
40 matchWindowWidth = 8000;//window size for matching in ms 42 matchWindowWidth = 8000;//window size for matching in ms
41 43
42 bayesStruct.resetSize(matchWindowWidth); 44 bayesStruct.resetSize(matchWindowWidth);
64 void midiEventHolder::reset(){ 66 void midiEventHolder::reset(){
65 //called when we start playing 67 //called when we start playing
66 68
67 noteArrayIndex = 0; 69 noteArrayIndex = 0;
68 tickLocation = 0; 70 tickLocation = 0;
69 lastPeriodUpdateTime = ofGetElapsedTimeMillis(); 71 lastPeriodUpdateTime = getTimeNow(0);//ofGetElapsedTimeMillis();
70 bayesStruct.lastEventTime = ofGetElapsedTimeMillis(); 72 bayesStruct.lastEventTime = getTimeNow(0);//ofGetElapsedTimeMillis();
71 numberOfScreensIn = 0; 73 numberOfScreensIn = 0;
72 // recordedNoteOnIndex = 0; 74 // recordedNoteOnIndex = 0;
73 bayesStruct.setNewDistributionOffsets(0); 75 bayesStruct.setNewDistributionOffsets(0);
74 bayesStruct.posterior.offset = 0; 76 bayesStruct.posterior.offset = 0;
75 77
99 playedNoteOnMatrix.clear(); 101 playedNoteOnMatrix.clear();
100 matchMatrix.clear(); 102 matchMatrix.clear();
101 } 103 }
102 104
103 void midiEventHolder::printNotes(){ 105 void midiEventHolder::printNotes(){
104 printf("RECORDED MATRIX"); 106 printf("RECORDED MATRIX\n");
105 for (int i = 0;i < recordedNoteOnMatrix.size();i++){ 107 for (int i = 0;i < recordedNoteOnMatrix.size();i++){
106 printf("%i :: %i @ %f\n", recordedNoteOnMatrix[i][0], recordedNoteOnMatrix[i][1], recordedEventTimes[i]); 108 printf("ticktime %i :: pitch %i @ millis %f\n", recordedNoteOnMatrix[i][0], recordedNoteOnMatrix[i][1], recordedEventTimes[i]);
107 } 109 }
108 } 110 }
109 111
110 112
111 double midiEventHolder::getEventTimeTicks(double millis){ 113 double midiEventHolder::getEventTimeTicks(double millis){
153 bayesStruct.addGaussianNoiseToSpeedPosterior(timeDifference * 10 / 100.); 155 bayesStruct.addGaussianNoiseToSpeedPosterior(timeDifference * 10 / 100.);
154 // bayesStruct.addTriangularNoiseToSpeedPosterior(timeDifference * 10 / 100.); 156 // bayesStruct.addTriangularNoiseToSpeedPosterior(timeDifference * 10 / 100.);
155 } 157 }
156 158
157 bayesStruct.updateTmpBestEstimate(timeDifference);// debug - didnt work bayesStruct.bestEstimate = bayesStruct.tmpBestEstimate; 159 bayesStruct.updateTmpBestEstimate(timeDifference);// debug - didnt work bayesStruct.bestEstimate = bayesStruct.tmpBestEstimate;
158 bayesStruct.updateBestEstimate(); 160 bayesStruct.updateBestEstimate(timeDifference);
159 bayesStruct.lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); 161 bayesStruct.lastBestEstimateUpdateTime = getTimeNow(timePlayed);
160 162
161 // double newMAPestimateTime = bayesStruct.posterior.getIndexInRealTerms(bayesStruct.posterior.MAPestimate); 163 // double newMAPestimateTime = bayesStruct.posterior.getIndexInRealTerms(bayesStruct.posterior.MAPestimate);
162 //was offset + bayesStruct.posterior.MAPestimate; but this doesnt include scalar to convert to millis 164 //was offset + bayesStruct.posterior.MAPestimate; but this doesnt include scalar to convert to millis
163 165
164 timeString = "Pitch:"+ofToString(pitch); 166 timeString = "Pitch:"+ofToString(pitch);
215 217
216 //bayesStruct.addGaussianNoiseToSpeedPosterior(10); 218 //bayesStruct.addGaussianNoiseToSpeedPosterior(10);
217 219
218 } 220 }
219 221
222 double midiEventHolder::getTimeNow(double eventTime){
223 double timeNow = eventTime;
224 if (runningInRealTime)
225 timeNow = ofGetElapsedTimeMillis();
226 return timeNow;
227 }
228
220 int midiEventHolder::findLocalMatches(int notePitch){ 229 int midiEventHolder::findLocalMatches(int notePitch){
221 230
222 //here we find the matches to the new note within appropriate range 231 //here we find the matches to the new note within appropriate range
223 232
224 matchString = ""; 233 matchString = "";
317 //} 326 //}
318 327
319 328
320 matchMatrix.push_back(v); 329 matchMatrix.push_back(v);
321 matchConfidence.push_back(d); 330 matchConfidence.push_back(d);
331
332 printf("BEST MATCH TO note %i,time %i is recorded time %i, confidence %0.2f\n", notePitch, startTime, (int) recordedEventTimes[bestMatchIndex], minimumConfidence);
322 333
323 return size; 334 return size;
324 } 335 }
325 336
326 bool midiEventHolder::checkIfMatchedNote(const int& tmpIndex){ 337 bool midiEventHolder::checkIfMatchedNote(const int& tmpIndex){
468 void midiEventHolder::updatePlayPosition(){ 479 void midiEventHolder::updatePlayPosition(){
469 480
470 //in actual fact if we are changing the speed of the play position 481 //in actual fact if we are changing the speed of the play position
471 //we will need to update this via the file 482 //we will need to update this via the file
472 483
473 double timeDifference = ofGetElapsedTimeMillis() - lastPeriodUpdateTime; 484 //actually time since beginning of file i think
485
486 double timeDifference = ofGetElapsedTimeMillis() - lastPeriodUpdateTime;//elpased - lastperiodupdatetime
474 //this is time diff in milliseconds 487 //this is time diff in milliseconds
475 //then we have 488 //then we have
476 double quarterNoteIntervals = (timeDifference / period); 489 double quarterNoteIntervals = (timeDifference / period);
477 tickLocation = quarterNoteIntervals * pulsesPerQuarternote; 490 tickLocation = quarterNoteIntervals * pulsesPerQuarternote;
478 491
479 playPositionInMillis = timeDifference;//based on updating from when we change period 492 playPositionInMillis = timeDifference;//based on updating from when we change period
480 //this to be added 493 //this to be added
481 494
482 bayesStruct.updateBestEstimate(); 495 if (runningInRealTime)
496 bayesStruct.updateBestEstimate(timeDifference);
483 497
484 } 498 }
485 499
486 500
487 void midiEventHolder::drawMidiFile(){ 501 void midiEventHolder::drawMidiFile(){
520 ofSetColor(255,0,255); 534 ofSetColor(255,0,255);
521 }else{ 535 }else{
522 ofSetColor(255,255,255); 536 ofSetColor(255,255,255);
523 } 537 }
524 538
525 539 if (tmpIndex == bestMatchIndex)
540 ofSetColor(255,0,0);//best recent match is in red
526 541
527 // XXX replace ofgetwidth below 542 // XXX replace ofgetwidth below
528 //if (tmpIndex >= 0 && tmpIndex < size) 543 //if (tmpIndex >= 0 && tmpIndex < size)
529 int xLocation = (float)(recordedNoteOnMatrix[tmpIndex][0] - numberOfScreensIn*ticksPerScreen)*(*screenWidth)/(float)ticksPerScreen; 544 int xLocation = (float)(recordedNoteOnMatrix[tmpIndex][0] - numberOfScreensIn*ticksPerScreen)*(*screenWidth)/(float)ticksPerScreen;
530 int duration = (float)(recordedNoteOnMatrix[tmpIndex][3]*(*screenWidth))/(float)ticksPerScreen; 545 int duration = (float)(recordedNoteOnMatrix[tmpIndex][3]*(*screenWidth))/(float)ticksPerScreen;
620 635
621 } 636 }
622 637
623 638
624 void midiEventHolder::setStartPlayingTimes(){ 639 void midiEventHolder::setStartPlayingTimes(){
625 lastPeriodUpdateTime = ofGetElapsedTimeMillis(); 640 lastPeriodUpdateTime = getTimeNow(0);//ofGetElapsedTimeMillis();
626 startTime = lastPeriodUpdateTime; 641 startTime = lastPeriodUpdateTime;
627 642
628 /* 643 /*
629 bayesStruct.lastEventTime = 0;//ofGetElapsedTimeMillis(); 644 bayesStruct.lastEventTime = 0;//ofGetElapsedTimeMillis();
630 bayesStruct.bestEstimate = 0; 645 bayesStruct.bestEstimate = 0;