Mercurial > hg > midi-score-follower
view matchAnnotationSrc/testApp.cpp @ 50:158f5f38e9d3
outputting exact difference for annotations, comparison with match annotations is now working over all rwc files
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Thu, 29 Mar 2012 13:41:59 +0100 |
parents | 3ce6dadd8167 |
children | ef30f465a904 |
line wrap: on
line source
#include "testApp.h" //-------------------------------------------------------------- void testApp::setup(){ //fixed stuff annotationRoot = "/Users/andrew/Documents/work/Alignment/MuseScore/RWC/ANNOTATION/RM-C0"; jnmrPlayerRoot = "/Users/andrew/Documents/work/programming/of_preRelease_v007_osx/apps/myOpenFrameworks007/JNMR_MidiFollower/bin/data/FilesOut/completeTestsTempoMAPestimate/rwcOutputData_RM-C0"; createRWCfilenameStrings(); fileNumberToTest = 0; loadAnnotation(fileNumberToTest); getResults(fileNumberToTest); } void testApp::getResults(const int& fileID){ std::string txtEnd = ".txt"; //naming convention //match output must also follow the RWC ID //01, 02, 03 etc std::string matchEnd = "_ob.out"; matchPath = makeMatchFilename(fileID, matchEnd);//makeRWCfilename(matchRoot, fileID, matchEnd); printf("MATCH PATH OB: %s\n", matchPath.c_str()); matchNotations.readInMatchFile(matchPath); TimingResult matchObResult; calculateMatchErrors(matchObResult); matchOB_results.push_back(matchObResult); matchEnd = "_of.out"; matchPath = makeMatchFilename(fileID, matchEnd);//makeRWCfilename(matchRoot, fileID, matchEnd); printf("MATCH PATH OF: %s\n", matchPath.c_str()); matchNotations.readInMatchFile(matchPath); TimingResult matchOfResult; calculateMatchForwardErrors(matchOfResult); matchOF_results.push_back(matchOfResult); jnmrPlayerPath = makeRWCfilename(jnmrPlayerRoot, fileID, txtEnd);//+ "rwcOutputData_RM-C003.txt"; jnmrPlayerAnnotations.readInjnmrMidiPlayerFile(jnmrPlayerPath); printf("JNMR DIFFERENCES\n"); TimingResult jnmrResult; sortDifferenceVector(jnmrPlayerAnnotations.differences, jnmrResult); JNMR_MidiMatcher_results.push_back(jnmrResult); printf("\n"); } std::string testApp::makeMatchFilename( const int& fileID, std::string matchEnd){ std::string matchRoot = "/Users/andrew/Documents/work/programming/Shell Scripts/completeMatchOut/RWCmatch_RM-C"; string rootToUse = matchRoot; if (fileID > 8){ rootToUse += "0"; } string matchName = makeRWCfilename(rootToUse, fileID, matchEnd); return matchName; } std::string testApp::makeRWCfilename(std::string& root, const int& fileID, std::string& endPart){ std::string pathName; if (fileID >= 0 && fileID <= 64){ pathName = root + rwcFileNameStrings[fileID]+endPart; /* if (fileID >= 10) pathName = root + ofToString(fileID)+endPart; else pathName = root + "0"+ofToString(fileID)+endPart; */ //printf("RWC PATH:%s\n", pathName.c_str()); } return pathName; } void testApp::createRWCfilenameStrings(){ rwcFileNameStrings.clear(); for (int i = 1;i< 10;i++){ rwcFileNameStrings.push_back("0"+ofToString(i)); } for (int i = 10;i< 23;i++){ rwcFileNameStrings.push_back(ofToString(i)); } rwcFileNameStrings.push_back("23A"); rwcFileNameStrings.push_back("23B"); rwcFileNameStrings.push_back("23C"); rwcFileNameStrings.push_back("23D"); rwcFileNameStrings.push_back("23E"); rwcFileNameStrings.push_back("24A"); rwcFileNameStrings.push_back("24B"); rwcFileNameStrings.push_back("24C"); rwcFileNameStrings.push_back("25A"); rwcFileNameStrings.push_back("25B"); rwcFileNameStrings.push_back("25C"); rwcFileNameStrings.push_back("25D"); for (int i = 26;i< 35;i++){ rwcFileNameStrings.push_back(ofToString(i)); } rwcFileNameStrings.push_back("35A"); rwcFileNameStrings.push_back("35B"); rwcFileNameStrings.push_back("35C"); for (int i = 36;i< 51;i++){ rwcFileNameStrings.push_back(ofToString(i)); } // for (int i = 0;i < rwcFileNameStrings.size();i++) { // printf("RWC{%i}:'%s'\n", i, rwcFileNameStrings[i].c_str()); // } } void testApp::loadAnnotation(const int& fileID){ string annotationEnding = "_annotation+WavPos.csv"; string path = makeRWCfilename(annotationRoot, fileID, annotationEnding ); //printf("read in annotations from\n%s\n", path.c_str()); rwcAnnotations.readInRWCfile(path); } void testApp::calculateMatchErrors(TimingResult& t){ int matchIndex = 0; vector<float> matchDiffs; for (int i = 0;i < rwcAnnotations.rwcAnnotations.size();i++){ // printf("rwc time %f midi time %f\n", rwcAnnotations.rwcAnnotations[i].eventTime, rwcAnnotations.rwcAnnotations[i].midiTime); while (matchIndex < matchNotations.matchData.size() && matchNotations.matchData[matchIndex].midiTime < rwcAnnotations.rwcAnnotations[i].midiTime) matchIndex++; while (matchNotations.matchData[matchIndex].midiTime > rwcAnnotations.rwcAnnotations[i].midiTime) matchIndex--; // float matchFraction = (rwcAnnotations.rwcAnnotations[i].midiTime - matchNotations.matchData[matchIndex].midiTime)/(matchNotations.matchData[matchIndex+1].midiTime - matchNotations.matchData[matchIndex].midiTime); // matchFraction *= (matchNotations.matchData[matchIndex+1].audioTime - matchNotations.matchData[matchIndex].audioTime); float matchTime = matchNotations.matchData[matchIndex].audioTime;// +matchFraction ; // printf("matchTime %f gives event time %f from flat event time %f\n", matchNotations.matchData[matchIndex].midiTime, matchTime, matchNotations.matchData[matchIndex].audioTime); float matchDifference = 1000.0*(matchTime - rwcAnnotations.rwcAnnotations[i].eventTime); // printf("Match diff %f\n", matchDifference); matchDiffs.push_back(fabs(matchDifference)); } sortDifferenceVector(matchDiffs, t); } void testApp::calculateMatchForwardErrors(TimingResult& t){ int matchIndex = 0; vector<float> matchDiffs; for (int i = 0;i < rwcAnnotations.rwcAnnotations.size();i++){ // printf("rwc time %f midi time %f\n", rwcAnnotations.rwcAnnotations[i].eventTime, rwcAnnotations.rwcAnnotations[i].midiTime); while (matchIndex < matchNotations.matchData.size() && matchNotations.matchData[matchIndex].midiTime > rwcAnnotations.rwcAnnotations[i].midiTime) matchIndex++; while (matchNotations.matchData[matchIndex].midiTime < rwcAnnotations.rwcAnnotations[i].midiTime) matchIndex--; // float matchFraction = (rwcAnnotations.rwcAnnotations[i].midiTime - matchNotations.matchData[matchIndex].midiTime)/(matchNotations.matchData[matchIndex+1].midiTime - matchNotations.matchData[matchIndex].midiTime); // matchFraction *= (matchNotations.matchData[matchIndex+1].audioTime - matchNotations.matchData[matchIndex].audioTime); float matchTime = matchNotations.matchData[matchIndex].audioTime;// +matchFraction ; // printf("matchTime %f gives event time %f from flat event time %f\n", matchNotations.matchData[matchIndex].midiTime, matchTime, matchNotations.matchData[matchIndex].audioTime); float matchDifference = 1000.0*(matchTime - rwcAnnotations.rwcAnnotations[i].eventTime); // printf("Match diff %f\n", matchDifference); matchDiffs.push_back(fabs(matchDifference)); } sortDifferenceVector(matchDiffs, t); } void testApp::sortDifferenceVector(vector<float> diffVec, TimingResult& t){ //GETS MEAN AND MEDIAN int count = 0; float total = 0; for (int i = 0;i < diffVec.size();i++){ // printf("M[%i] : %f\n", i, matchDiffs[i]); count++; total += fabs(diffVec[i]); diffVec[i] = fabs(diffVec[i]);//replace with +ve value addToPercentiles(diffVec[i], t); } total /= count; std::sort(diffVec.begin(), diffVec.end());//sort vector /* printf("SORTED TWO HUNDRED\n"); for (int i = 0;i < diffVec.size() ;i++){ printf("Sort[%i] : %f\n", i, diffVec[i]); } */ printf("Count %i Median %3.1f, mean is %3.1f\n", count, diffVec[(int)(diffVec.size()/2)], total); t.median = diffVec[(int)(diffVec.size()/2)]; t.mean = total; t.count = count; for (int i = 0;i < 7;i++){ t.percentiles[i] = t.percentileCount[i] / count; printf("Perc[%i] = %2.1f, ", i, (t.percentiles[i]*100.0)); } printf("\n"); } void testApp::addToPercentiles(float value, TimingResult& t){ if (value <= 20){ t.percentileCount[0]++; } if (value <= 40){ t.percentileCount[1]++; } if (value <= 60){ t.percentileCount[2]++; } if (value <= 100){ t.percentileCount[3]++; } if (value <= 200){ t.percentileCount[4]++; } if (value <= 500){ t.percentileCount[5]++; } if (value <= 1000){ t.percentileCount[6]++; } } //-------------------------------------------------------------- void testApp::update(){ } //-------------------------------------------------------------- void testApp::draw(){ } //-------------------------------------------------------------- void testApp::keyPressed(int key){ if (key == ' '){ fileNumberToTest++; loadAnnotation(fileNumberToTest); getResults(fileNumberToTest); } } //-------------------------------------------------------------- void testApp::keyReleased(int key){ } //-------------------------------------------------------------- void testApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void testApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void testApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void testApp::dragEvent(ofDragInfo dragInfo){ } /* //GETS MEAN AND MEDIAN int count = 0; float total = 0; for (int i = 0;i < matchDiffs.size();i++){ // printf("M[%i] : %f\n", i, matchDiffs[i]); count++; total += fabs(matchDiffs[i]); } total /= count; std::sort(matchDiffs.begin(), matchDiffs.end()); // printf("SORTED TWO HUNDRED\n"); // for (int i = 0;i < matchDiffs.size() ;i++){ // printf("M[%i] : %f\n", i, matchDiffs[i]); // } printf("MATCH median %f, mean is %f\n", matchDiffs[(int)(matchDiffs.size()/2)], total); */