Mercurial > hg > midi-score-follower
diff jnmr/midiEventHolder.cpp @ 48:803edc47e825
Adding files, possibly some minor code changes
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 06 Mar 2012 17:11:46 +0000 |
parents | 1726189a6317 |
children | 3ce6dadd8167 |
line wrap: on
line diff
--- a/jnmr/midiEventHolder.cpp Sun Feb 05 22:07:55 2012 +0000 +++ b/jnmr/midiEventHolder.cpp Tue Mar 06 17:11:46 2012 +0000 @@ -132,6 +132,9 @@ smoothIndex = 0; smoothPlayPosition = 0.0; + causalPlayPosition = 0; + lastCausalUpdateTime = getTimeNow(0); + // relativeSpeedForSmooth = 1.0; // storedSmoothPlayPosition = smoothPlayPosition; // lastSmoothUpdateTime = getTimeNow(0); @@ -783,7 +786,7 @@ if (runningInRealTime){ - bayesStruct.updateBestEstimate(timeDifference); + bayesStruct.updateBestEstimate(0);//was timedifference // bayesStruct.updateTmpBestEstimate(timeDifference); } @@ -794,6 +797,8 @@ //smoothPlayPosition = bayesStruct.bestEstimate; } + updateCausalPlayPosition(getTimeNow(bayesStruct.lastBestEstimateUpdateTime)); + // playPositionInMillis = timeDifference;//based on updating from when we change period //this to be added @@ -857,12 +862,10 @@ (*fileOutput) << " corresponds to " << annotationTime; } (*fileOutput) << " \n"; - - - + } - printf("annotaions: rec tick time %i vs %i midi %i beat pos %f playing time now at %f :: annotaion %i loc % f time %f diff \t%f ms\n", + printf("annotations: rec tick time %i vs %i midi %i beat pos %f playing time now at %f :: annotaion %i loc % f time %f diff \t%f ms\n", recordedNoteOnMatrix[smoothIndex][0], annotationTick, recordedNoteOnMatrix[smoothIndex][1], beatPositions[smoothIndex], playingTime, annotationNote, annotationLocation, annotationTime, difference); @@ -872,7 +875,7 @@ if ((*differenceOutput).is_open()){ - (*differenceOutput) << beatPositions[smoothIndex] << "," << difference << "\n"; + (*differenceOutput) << beatPositions[smoothIndex] << "," << difference << "," << playingTime << "," << (annotationTime*1000.0) << "\n"; // printf("midi %i beat pos %f playing time now at %f :: annotaion %i loc % f time %f diff \t%f ms\n", // recordedNoteOnMatrix[smoothIndex][1], // beatPositions[smoothIndex], playingTime, @@ -889,6 +892,20 @@ } +void midiEventHolder::updateCausalPlayPosition(const double& timeNow){ + //projected position + double timeProjectionToMeet = 1000;//ms in future they will intersect + double difference = bayesStruct.bestEstimate - causalPlayPosition; + causalSpeed = bayesStruct.speedEstimate; + causalSpeed += (difference/timeProjectionToMeet); + + if (causalSpeed < 0) + causalSpeed = 0; + + causalPlayPosition += causalSpeed * (timeNow - lastCausalUpdateTime); + lastCausalUpdateTime = timeNow; + +} /* void midiEventHolder::updatePeriodValue(const double& millis){ @@ -985,9 +1002,12 @@ xLocation = getLocationFromMillis(smoothPlayPosition);//bayesStruct.tmpBestEstimate ofSetColor(0,250,0);//250,150, 250,100,0); + // ofLine(xLocation, 0, xLocation, (*screenHeight)); + + xLocation = getLocationFromMillis(causalPlayPosition);//bayesStruct.tmpBestEstimate + ofSetColor(0,250,0);//250,150, 250,100,0); ofLine(xLocation, 0, xLocation, (*screenHeight)); - //lines where matching window start and end are ofSetColor(0);//0,100,255); xLocation = getLocationFromMillis(windowStartTime);