comparison 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
comparison
equal deleted inserted replaced
50:93d21c20cfbc 51:6f6461b0d07f
8 */ 8 */
9 9
10 #include "MatchMarkers.h" 10 #include "MatchMarkers.h"
11 11
12 MatchMarkers::MatchMarkers(){ 12 MatchMarkers::MatchMarkers(){
13 13 load();
14 } 14 }
15 15
16 16
17 void MatchMarkers::addMarker(const double& markerTime){ 17 void MatchMarkers::addMarker(const double& markerTime){
18 int i = 0; 18 int i = 0;
53 markerOutputFile.close(); 53 markerOutputFile.close();
54 } 54 }
55 55
56 } 56 }
57 57
58 void MatchMarkers::load(){
59 loadMarkerFile("/Users/andrew/Documents/work/programming/of_preRelease_v007_osx/apps/myOpenFrameworks007/MultipleAudioMatcher/bin/data/lewesSavedMarkers.txt");
60 }
61
62
63
64 void MatchMarkers::loadMarkerFile(std::string filePath){
65 markers.clear();
66
67 printf("MARKERS : READ FILE '%s'\n", filePath.c_str());
68
69 ifstream file ( filePath.c_str());
70 string tmpLine, value;
71 stringstream iss;
72
73 while ( file.good() )
74 {
75 getline(file, tmpLine);
76 iss << tmpLine;
77 // printf("tmp line %s\n", tmpLine.c_str());
78
79 while(getline ( iss, value, '\n' )){ // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
80 // cout << string( value, 1, value.length()-2 ); // display value removing the first and the last character from it
81 // printf("line:%s\n", value.c_str());
82 string::size_type start = value.find_first_not_of(" ,\t\v\n");
83 string firstpart = value.substr(start, string::npos);
84 string::size_type end = firstpart.find_first_of(" ,\t\v\n");
85 string part = firstpart.substr(0, end);
86 markers.push_back(atof(part.c_str()));
87 printf("marker[%i]: %f ms\n", (int)markers.size()-1, markers[markers.size()-1]);
88
89 }//end while reading line
90 iss.clear();
91
92 }//end while
93
94
95 }
96
97
98 //--------------------------------------------------------------
99 void MatchMarkers::loadFile(){
100 // first, create a string that will hold the URL
101 string fileName;
102 // openFile(string& URL) returns 1 if a file was picked
103 // returns 0 when something went wrong or the user pressed 'cancel'
104 int response = ofxFileDialogOSX::openFile(fileName);
105 if(response){
106 loadMarkerFile(fileName);
107 }else {
108 printf("Could not open marker file\n");
109 }
110 }
111
112
113 //--------------------------------------------------------------
114 void MatchMarkers::saveFile(){
115 // create a string to hold the folder URL
116 string folderURL;
117 // and one for the filename
118 string fileName;
119 // saveFile(string& folderURL, string& fileName) returns 1 if a folder + file were specified
120 // returns 0 when something went wrong or the user pressed 'cancel'
121 int response = ofxFileDialogOSX::saveFile(folderURL, fileName);
122 if(response){
123 // now you can use the folder URL and the filename.
124 printf("\nfolder:'%s'\nfile'%s'\n", folderURL.c_str(), fileName.c_str());
125 saveMarkers(folderURL+"/"+fileName);
126 }else {
127 printf("Could not save marker file\n");
128 }
129 }
130