Mercurial > hg > midi-score-follower
view matchAnnotationSrc/testApp.cpp @ 52:13194a9dca77 tip
Added exporting of image and text data
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 17 Jul 2012 22:13:10 +0100 |
parents | ef30f465a904 |
children |
line wrap: on
line source
#include "testApp.h" const int totalNumberFiles = 61; //-------------------------------------------------------------- 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/"; //set which parameter set to test jnmrPlayerRoot += "rwc_output_likelihood0pt6";//width 100ms // jnmrPlayerRoot += "rwcOutput_likelihood0pt8_width50"; // jnmrPlayerRoot += "completeTestsTempoMAPestimate_likelihood0pt2"; jnmrPlayerRoot += "/rwcOutputData_RM-C0"; // matchRoot = "/Users/andrew/Documents/work/programming/Shell Scripts/MatchAudioToMidiOutput/RWCmatch_RM-C";//ACTUAL AUDIO VERSION OF WARPED matchRoot = "/Users/andrew/Documents/work/programming/Shell Scripts/MatchMidiToMidiOutput/RWCmatch_RM-C";//MIDI VERSION OF WARPED createRWCfilenameStrings(); fileNumberToTest = 0; while (fileNumberToTest < totalNumberFiles){ loadAnnotation(fileNumberToTest); getResults(fileNumberToTest); fileNumberToTest++; } calculateOverallPercentiles(); calculateOverallMatchPercentiles(); } void testApp::calculateOverallPercentiles(){ int numberToCount = 61;//totalNumberFiles; printf("\nFINAL PERCENTILES for %i files\n", numberToCount); final_JNMR_Midi.count = 0; for (int i =0;i < numberToCount;i++){ for (int k = 0;k < 7;k++){ final_JNMR_Midi.percentileCount[k] += JNMR_MidiMatcher_results[i].percentileCount[k]; //printf("file %i, precentile count[%i] is %f\n", i, k, JNMR_MidiMatcher_results[i].percentileCount[k]); } final_JNMR_Midi.count += JNMR_MidiMatcher_results[i].count; } for (int p = 0;p < 7;p++){ final_JNMR_Midi.percentiles[p] = final_JNMR_Midi.percentileCount[p] / final_JNMR_Midi.count; printf("final JNMR percentile [%i] = %.2f, count %i, perc count %.1f\n", p, final_JNMR_Midi.percentiles[p]*100.0, final_JNMR_Midi.count, final_JNMR_Midi.percentileCount[p]); } for (int i = 0;i < 7;i++){ printf("%.1f &", final_JNMR_Midi.percentiles[i]*100.0); } } void testApp::calculateOverallMatchPercentiles(){ int numberToCount = 61;//totalNumberFiles; printf("\n FINAL MATCH FORWARDS PERCENTILES for %i files\n", numberToCount); final_Match_OF.count = 0; final_Match_OB.count = 0; for (int i =0;i < numberToCount;i++){ for (int k = 0;k < 7;k++){ final_Match_OF.percentileCount[k] += matchOF_results[i].percentileCount[k]; final_Match_OB.percentileCount[k] += matchOB_results[i].percentileCount[k]; } final_Match_OF.count += matchOF_results[i].count; final_Match_OB.count += matchOB_results[i].count; } for (int p = 0;p < 7;p++){ final_Match_OF.percentiles[p] = final_Match_OF.percentileCount[p] / final_Match_OF.count; final_Match_OB.percentiles[p] = final_Match_OB.percentileCount[p] / final_Match_OB.count; printf("final Match_OF percentile [%i] = %.2f, count %i, perc count %.1f\n", p, final_Match_OF.percentiles[p]*100., final_Match_OF.count, final_Match_OF.percentileCount[p]); } printf("\n FINAL MATCH BACKWARDS PERCENTILES for %i files\n", numberToCount); for (int p = 0;p < 7;p++){ printf("final Match_OB percentile [%i] = %.2f, count %i, perc count %.1f\n", p, final_Match_OB.percentiles[p]*100., final_Match_OB.count, final_Match_OB.percentileCount[p]); } printf("\nOB: "); for (int i = 0;i < 7;i++){ printf("%.1f &", final_Match_OB.percentiles[i]*100.0); } printf("\nOF: "); for (int i = 0;i < 7;i++){ printf("%.1f &", final_Match_OF.percentiles[i]*100.0); } } 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){ 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 t.median = diffVec[(int)(diffVec.size()/2)]; t.mean = total; t.count = count; printf("Count %i Median %3.1f, mean is %3.1f\n", count, diffVec[(int)(diffVec.size()/2)], total); 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); */