Mercurial > hg > midi-score-follower
diff src/midiEventHolder.cpp @ 1:1a32ce016bb9
Changed bestEstimate timing to work via time sent from Max not the elapsed time. This had caused some problems, but this version now working surprisingly well on MIDI files with variable timing.
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Thu, 18 Aug 2011 23:27:42 +0100 |
parents | b299a65a3ad0 |
children | 5581023e0de4 |
line wrap: on
line diff
--- a/src/midiEventHolder.cpp Tue Aug 16 11:29:59 2011 +0100 +++ b/src/midiEventHolder.cpp Thu Aug 18 23:27:42 2011 +0100 @@ -25,14 +25,14 @@ noteMinimum = 30; noteMaximum = 96; - minimumMatchSpeed = 0.5; - maximumMatchSpeed = 2.0; + minimumMatchSpeed = 0.7; + maximumMatchSpeed = 1.3; likelihoodWidth = 100; likelihoodToNoiseRatio = 50; - matchWindowWidth = 6000;//window size for matching in ms + matchWindowWidth = 4000;//window size for matching in ms - bayesStruct.resetSize(4000); + bayesStruct.resetSize(matchWindowWidth); bayesStruct.resetSpeedSize(200); bayesStruct.setRelativeSpeedScalar(0.01); bayesStruct.relativeSpeedPrior.getMaximum(); @@ -61,6 +61,18 @@ } +void midiEventHolder::clearAllEvents(){ + recordedNoteOnMatrix.clear(); + matchesFound.clear(); + noteOnMatches.clear(); + recordedEventTimes.clear(); + + //played events: + playedEventTimes.clear(); + playedNoteOnMatrix.clear(); + matchMatrix.clear(); +} + void midiEventHolder::printNotes(){ printf("RECORDED MATRIX"); for (int i = 0;i < recordedNoteOnMatrix.size();i++){ @@ -151,6 +163,7 @@ bayesStruct.lastEventTime = ofGetElapsedTimeMillis(); //do the cross update to find current posterior for location +// totalConfidence= 0; int numberOfMatchesFound = findLocalMatches(pitch); setMatchLikelihoods(numberOfMatchesFound); bayesStruct.calculatePosterior(); @@ -166,11 +179,13 @@ //here we find the matches to the new note within appropriate range - matchString += ", "+ofToString(notePitch); + matchString = ""; windowStartTime = max(0.0,(bayesStruct.bestEstimate - matchWindowWidth/2));//was playPositionInMillis int numberOfMatches = findMatch(notePitch, windowStartTime, windowStartTime + matchWindowWidth); + matchString += " pitch: "+ofToString(notePitch)+" matches "+ofToString(numberOfMatches)+" win start "+ofToString(windowStartTime); + return numberOfMatches; @@ -188,7 +203,11 @@ // printf("match times %i of %i::%f adding likelihood to %f\n", i, numberOfMatches, recordedEventTimes[matchesFound[i]], recordedEventTimes[matchesFound[i]] - bayesStruct.likelihood.offset); //this is the vent time since start of file if (recordedEventTimes[matchesFound[i]] - bayesStruct.likelihood.offset < bayesStruct.likelihood.arraySize){ - bayesStruct.likelihood.addGaussianShape(recordedEventTimes[matchesFound[i]] - bayesStruct.likelihood.offset, likelihoodWidth, 0.5 * likelihoodToNoiseRatio); + // double confidenceMeasure = 0; + // if (totalConfidence > 0) + // confidenceMeasure = bayesStruct.posterior.getValueAtMillis(recordedEventTimes[matchesFound[i]])/totalConfidence; + + bayesStruct.likelihood.addGaussianShape(recordedEventTimes[matchesFound[i]] - bayesStruct.likelihood.offset, likelihoodWidth, 0.5 * likelihoodToNoiseRatio );//* confidenceMeasure }//end if } bayesStruct.likelihood.addConstant(0.01); @@ -211,6 +230,9 @@ while (startIndex < recordedEventTimes.size() && recordedEventTimes[startIndex] < endTime){ if (recordedNoteOnMatrix[startIndex][1] == notePitch){ matchesFound.push_back(startIndex); + double confidence = bayesStruct.posterior.getValueAtMillis(mouseX); + // recordedEventTimes[startIndex]); + matchString += "["+ofToString(startIndex)+"] = "+ofToString(confidence, 3)+" ."; } startIndex++; } @@ -259,18 +281,20 @@ for (int k = 0;k < matchMatrix[previousIndex][0];k++){ int recordedPreviousIndex = matchMatrix[previousIndex][k+1]; - // printf("(%i)", matchMatrix[currentPlayedIndex][i+1]); - // printf("[%i] :: ", recordedPreviousIndex); + double recordedTimeDifference = recordedEventTimes[recordedCurrentIndex] - recordedEventTimes[recordedPreviousIndex]; - /// printf(" rec{%f} vs play(%f) ", recordedTimeDifference, playedTimeDifference); + //we want the speed of the recording relative to that of the playing live double speedRatio = recordedTimeDifference / playedTimeDifference; if (speedRatio <= maximumMatchSpeed && speedRatio >= minimumMatchSpeed){ - - // printf("update on speed ratio %f", speedRatio); + printf("(%i)", matchMatrix[currentPlayedIndex][i+1]); + printf("[%i] :: ", recordedPreviousIndex); + printf(" rec{%f} vs play(%f) ", recordedTimeDifference, playedTimeDifference); + printf("update on speed ratio %f\n", speedRatio); + // matchString += " speed: "+ofToString(speedRatio, 3); // commented for debug bayesStruct.updateTempoDistribution(speedRatio, 0.1);//second paramter is confidence in the match @@ -370,6 +394,8 @@ } + + ofDrawBitmapString(ofToString(timeOffsetForScreen, 1), 20,20); ofDrawBitmapString(timeString, 20, 60); @@ -382,10 +408,16 @@ //need to draw arrays within correct timescope bayesStruct.drawArraysRelativeToTimeframe(timeOffsetForScreen, timeOffsetForScreen + getEventTimeMillis(ticksPerScreen)); - //bayesStruct.drawTempoArrays(); + if (drawTempoMode) + bayesStruct.drawTempoArrays(); + + ofSetColor(0, 0, 0); ofDrawBitmapString(matchString, 20, ofGetHeight() - 20); + double confidence = bayesStruct.posterior.getValueAtMillis(mouseX); + string mouseString = "mouseX "+ofToString(confidence, 3)+" ."; + ofDrawBitmapString(mouseString, 20 , ofGetHeight() - 40); } int midiEventHolder::getLocationFromTicks(double tickPosition){