Mercurial > hg > multitrack-audio-matcher
diff src/MatchMarkers.cpp @ 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 | 2eca10a31ae2 |
line wrap: on
line diff
--- 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"); + } +} +