Mercurial > hg > multitrack-audio-matcher
changeset 51:6f6461b0d07f
Marker loading and saving via dialog box
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Thu, 14 Jun 2012 23:12:36 +0100 |
parents | 93d21c20cfbc |
children | e359b9bad811 |
files | src/AudioEventMatcher.cpp src/MatchMarkers.cpp src/MatchMarkers.h src/testApp.cpp |
diffstat | 4 files changed, 97 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/AudioEventMatcher.cpp Thu Jun 14 20:04:49 2012 +0100 +++ b/src/AudioEventMatcher.cpp Thu Jun 14 23:12:36 2012 +0100 @@ -43,7 +43,7 @@ bayesianStruct.startingWindowWidth = 100;//matchWindowWidth / 8; bayesianStruct.matchWindowWidth = matchWindowWidth; - drawLikelihoods = false; + drawLikelihoods = true; drawPosterior = false; temporal.printOutput = printInfo; @@ -279,10 +279,14 @@ while (m < markedPoints.markers.size() && markedPoints.markers[m] < currentAlignmentPosition) m++; - if (m > 0 && markedPoints.markers[m-1] < currentAlignmentPosition){ + if (m > 1 && markedPoints.markers[m-1] + 300 > currentAlignmentPosition) + setPlaybackPosition(markedPoints.markers[m-2]); + else if (m > 0 && markedPoints.markers[m-1] < currentAlignmentPosition){ setPlaybackPosition(markedPoints.markers[m-1]); printf("move to marker %f from current pos %f\n", markedPoints.markers[m], currentAlignmentPosition); } + + } void AudioEventMatcher::deleteNearestMarker(){
--- a/src/MatchMarkers.cpp Thu Jun 14 20:04:49 2012 +0100 +++ b/src/MatchMarkers.cpp Thu Jun 14 23:12:36 2012 +0100 @@ -10,7 +10,7 @@ #include "MatchMarkers.h" MatchMarkers::MatchMarkers(){ - + load(); } @@ -55,3 +55,76 @@ } +void MatchMarkers::load(){ + loadMarkerFile("/Users/andrew/Documents/work/programming/of_preRelease_v007_osx/apps/myOpenFrameworks007/MultipleAudioMatcher/bin/data/lewesSavedMarkers.txt"); +} + + + +void MatchMarkers::loadMarkerFile(std::string filePath){ + markers.clear(); + + printf("MARKERS : READ FILE '%s'\n", filePath.c_str()); + + ifstream file ( filePath.c_str()); + string tmpLine, value; + stringstream iss; + + while ( file.good() ) + { + getline(file, tmpLine); + iss << tmpLine; + // printf("tmp line %s\n", tmpLine.c_str()); + + while(getline ( iss, value, '\n' )){ // read a string until next comma: http://www.cplusplus.com/reference/string/getline/ + // cout << string( value, 1, value.length()-2 ); // display value removing the first and the last character from it + // printf("line:%s\n", value.c_str()); + string::size_type start = value.find_first_not_of(" ,\t\v\n"); + string firstpart = value.substr(start, string::npos); + string::size_type end = firstpart.find_first_of(" ,\t\v\n"); + string part = firstpart.substr(0, end); + markers.push_back(atof(part.c_str())); + printf("marker[%i]: %f ms\n", (int)markers.size()-1, markers[markers.size()-1]); + + }//end while reading line + iss.clear(); + + }//end while + + +} + + +//-------------------------------------------------------------- +void MatchMarkers::loadFile(){ + // first, create a string that will hold the URL + string fileName; + // openFile(string& URL) returns 1 if a file was picked + // returns 0 when something went wrong or the user pressed 'cancel' + int response = ofxFileDialogOSX::openFile(fileName); + if(response){ + loadMarkerFile(fileName); + }else { + printf("Could not open marker file\n"); + } +} + + +//-------------------------------------------------------------- +void MatchMarkers::saveFile(){ + // create a string to hold the folder URL + string folderURL; + // and one for the filename + string fileName; + // saveFile(string& folderURL, string& fileName) returns 1 if a folder + file were specified + // returns 0 when something went wrong or the user pressed 'cancel' + int response = ofxFileDialogOSX::saveFile(folderURL, fileName); + if(response){ + // now you can use the folder URL and the filename. + printf("\nfolder:'%s'\nfile'%s'\n", folderURL.c_str(), fileName.c_str()); + saveMarkers(folderURL+"/"+fileName); + }else { + printf("Could not save marker file\n"); + } +} +
--- a/src/MatchMarkers.h Thu Jun 14 20:04:49 2012 +0100 +++ b/src/MatchMarkers.h Thu Jun 14 23:12:36 2012 +0100 @@ -16,6 +16,7 @@ using namespace std; #include "ofMain.h" +#include "ofxFileDialogOSX.h" class MatchMarkers{ @@ -34,7 +35,14 @@ void saveMarkers(); void saveMarkers(const std::string& filePath); + void loadMarkerFile(std::string filePath); + void load(); + + void loadFile();//from dialog box + void saveFile(); + ofstream markerOutputFile; + string output; }; #endif \ No newline at end of file
--- a/src/testApp.cpp Thu Jun 14 20:04:49 2012 +0100 +++ b/src/testApp.cpp Thu Jun 14 23:12:36 2012 +0100 @@ -188,11 +188,15 @@ if (key == 'd'){ eventMatcher.deleteNearestMarker(); } - if (key == 's'){ - eventMatcher.markedPoints.saveMarkers(); - } +// if (key == 's'){ +// eventMatcher.markedPoints.saveMarkers(); +// } + + if (key == 's') + eventMatcher.markedPoints.saveFile(); - + if (key == 'l') + eventMatcher.markedPoints.loadFile(); if (key == '.'){ @@ -232,7 +236,7 @@ eventMatcher.recordedTracks.zoomIn(); } - if (key == 'l') + if (key == 'k') eventMatcher.drawLikelihoods = !eventMatcher.drawLikelihoods; }