Mercurial > hg > midi-score-follower
diff jnmr/midiEventHolder.cpp @ 42:3837125603e8
Annotations are correctly loaded so the time difference between observed notes and the predictor is output to saved file
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 24 Jan 2012 00:26:15 +0000 |
parents | 60c1f0fbc8f4 |
children | 6c8a048720c3 |
line wrap: on
line diff
--- a/jnmr/midiEventHolder.cpp Mon Jan 23 20:54:50 2012 +0000 +++ b/jnmr/midiEventHolder.cpp Tue Jan 24 00:26:15 2012 +0000 @@ -14,6 +14,7 @@ #include <iostream> #include <fstream> +#include <assert.h> midiEventHolder::midiEventHolder(){ @@ -795,11 +796,15 @@ } void midiEventHolder::updateSmoothPositionTo(const double& newPosition){ + //smooth play position was where we last outputted notes from. + //checking index is there to make sense. while (smoothIndex > 0 && recordedEventTimes[smoothIndex] > smoothPlayPosition){ smoothIndex--; + //printf("going backewaers on smooth, "); } while (smoothIndex < recordedEventTimes.size()-1 && recordedEventTimes[smoothIndex] < smoothPlayPosition){ smoothIndex++; + //printf("outputting smooth\n "); } @@ -813,6 +818,7 @@ while (smoothIndex < recordedEventTimes.size() && recordedEventTimes[smoothIndex] < newPosition){ float annotationTime = 0; float annotationLocation = 0; + int annotationTick = 0; int annotationNote = 0; float difference = 10000;//very big float currentLocationDifference = 1.0; @@ -820,40 +826,13 @@ if (smoothIndex < myNotation.rwcAnnotations.size()){ //add in test here to find closest matching note - /* - int testIndex = smoothIndex; - while (testIndex >= 0 && abs(smoothLocation - myNotation.rwcAnnotations[testIndex].beatLocation) < range){ - - if (myNotation.rwcAnnotations[testIndex].midiNote == currentNote){ - if (abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation) < currentLocationDifference){ - currentLocationDifference = abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation); - difference = playingTime - (myNotation.rwcAnnotations[testIndex].eventTime*1000.0); - annotationNote = myNotation.rwcAnnotations[testIndex].midiNote; - annotationLocation = myNotation.rwcAnnotations[testIndex].beatLocation; - annotationTime = myNotation.rwcAnnotations[testIndex].eventTime; - } - } - testIndex--; - } - - testIndex = smoothIndex; - while (testIndex >= 0 && testIndex < myNotation.rwcAnnotations.size() && abs(smoothLocation - myNotation.rwcAnnotations[testIndex].beatLocation) < range){ - - if (myNotation.rwcAnnotations[testIndex].midiNote == currentNote){ - if (abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation) < currentLocationDifference){ - currentLocationDifference = abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation); - difference = playingTime - (myNotation.rwcAnnotations[testIndex].eventTime*1000.0); - annotationNote = myNotation.rwcAnnotations[testIndex].midiNote; - annotationLocation = myNotation.rwcAnnotations[testIndex].beatLocation; - annotationTime = myNotation.rwcAnnotations[testIndex].eventTime; - } - } - testIndex++; - } - */ + annotationTime = myNotation.rwcAnnotations[smoothIndex].eventTime; annotationNote = myNotation.rwcAnnotations[smoothIndex].midiNote; annotationLocation = myNotation.rwcAnnotations[smoothIndex].beatLocation; + annotationTick = round(annotationLocation*480.0); + }else{ + printf("No annotaion size %i\n", (int)myNotation.rwcAnnotations.size()); } difference = playingTime - (annotationTime*1000.0); @@ -871,12 +850,23 @@ } + printf("assert 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); + +// assert(annotationNote == recordedNoteOnMatrix[smoothIndex][1]); + assert(annotationTick == recordedNoteOnMatrix[smoothIndex][0]); + + if ((*differenceOutput).is_open()){ (*differenceOutput) << beatPositions[smoothIndex] << "," << difference << "\n"; - printf("midi %i beat pos %f now at %f :: annotaion %i loc % f time %f diff \t%f ms\n", - recordedNoteOnMatrix[smoothIndex][1], - beatPositions[smoothIndex], playingTime, - annotationNote, annotationLocation, annotationTime, difference); + // 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, + // annotationNote, annotationLocation, annotationTime, difference); + }else{ + printf("file not open\n"); } smoothIndex++; @@ -1172,7 +1162,7 @@ void midiEventHolder::setStartPlayingTimes(){ startPlayingTime = getTimeNow(0);//ofGetElapsedTimeMillis(); //startTime = startPlayingTime; - + printf("starting playing at time %f\n", startPlayingTime); /* bayesStruct.lastEventTime = 0;//ofGetElapsedTimeMillis(); bayesStruct.bestEstimate = 0; @@ -1409,3 +1399,36 @@ } */ +/* +JUNK SMOOTH StuffHex + /* + int testIndex = smoothIndex; + while (testIndex >= 0 && abs(smoothLocation - myNotation.rwcAnnotations[testIndex].beatLocation) < range){ + + if (myNotation.rwcAnnotations[testIndex].midiNote == currentNote){ + if (abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation) < currentLocationDifference){ + currentLocationDifference = abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation); + difference = playingTime - (myNotation.rwcAnnotations[testIndex].eventTime*1000.0); + annotationNote = myNotation.rwcAnnotations[testIndex].midiNote; + annotationLocation = myNotation.rwcAnnotations[testIndex].beatLocation; + annotationTime = myNotation.rwcAnnotations[testIndex].eventTime; + } + } + testIndex--; + } + + testIndex = smoothIndex; + while (testIndex >= 0 && testIndex < myNotation.rwcAnnotations.size() && abs(smoothLocation - myNotation.rwcAnnotations[testIndex].beatLocation) < range){ + + if (myNotation.rwcAnnotations[testIndex].midiNote == currentNote){ + if (abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation) < currentLocationDifference){ + currentLocationDifference = abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation); + difference = playingTime - (myNotation.rwcAnnotations[testIndex].eventTime*1000.0); + annotationNote = myNotation.rwcAnnotations[testIndex].midiNote; + annotationLocation = myNotation.rwcAnnotations[testIndex].beatLocation; + annotationTime = myNotation.rwcAnnotations[testIndex].eventTime; + } + } + testIndex++; + } + */