annotate src/MatchMarkers.cpp @ 56:4394c9490716 tip

minor changes
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Mon, 24 Dec 2012 18:58:39 +0000
parents 2eca10a31ae2
children
rev   line source
andrew@50 1 /*
andrew@50 2 * MatchMarkers.cpp
andrew@50 3 * MultipleAudioMathcher
andrew@50 4 *
andrew@50 5 * Created by Andrew on 14/06/2012.
andrew@50 6 * Copyright 2012 QMUL. All rights reserved.
andrew@50 7 *
andrew@50 8 */
andrew@50 9
andrew@50 10 #include "MatchMarkers.h"
andrew@50 11
andrew@50 12 MatchMarkers::MatchMarkers(){
andrew@51 13 load();
andrew@50 14 }
andrew@50 15
andrew@50 16
andrew@50 17 void MatchMarkers::addMarker(const double& markerTime){
andrew@50 18 int i = 0;
andrew@50 19 while (i < markers.size() && markers[i] < markerTime){
andrew@50 20 i++;
andrew@50 21 }
andrew@50 22 vector<double>::iterator it;
andrew@50 23 it = markers.begin();
andrew@50 24 markers.insert(it + i, markerTime);
andrew@50 25
andrew@50 26 printf("\n");
andrew@50 27 for (i = 0;i< markers.size();i++)
andrew@50 28 printf("marker[%i] %f\n", i, markers[i]);
andrew@50 29
andrew@50 30 }
andrew@50 31
andrew@50 32
andrew@50 33 void MatchMarkers::deleteMarker(const int& markerIndex){
andrew@50 34 if (markerIndex >= 0 && markerIndex < markers.size()){
andrew@50 35 vector<double>::iterator it;
andrew@50 36 it = markers.begin();
andrew@50 37 markers.erase(it+markerIndex);
andrew@50 38 }
andrew@50 39 }
andrew@50 40
andrew@50 41 void MatchMarkers::saveMarkers(){
andrew@50 42 std::string filePath = "../../../data/markers.txt";
andrew@50 43 saveMarkers(filePath);
andrew@50 44
andrew@50 45 }
andrew@50 46
andrew@50 47 void MatchMarkers::saveMarkers(const std::string& filePath){
andrew@50 48 if (!markerOutputFile.is_open()){
andrew@50 49 markerOutputFile.open(filePath.c_str());
andrew@50 50 for (int i = 0;i < markers.size();i++){
andrew@50 51 markerOutputFile << markers[i] << endl;
andrew@50 52 }
andrew@50 53 markerOutputFile.close();
andrew@50 54 }
andrew@50 55 }
andrew@50 56
andrew@51 57 void MatchMarkers::load(){
andrew@51 58 loadMarkerFile("/Users/andrew/Documents/work/programming/of_preRelease_v007_osx/apps/myOpenFrameworks007/MultipleAudioMatcher/bin/data/lewesSavedMarkers.txt");
andrew@51 59 }
andrew@51 60
andrew@51 61
andrew@51 62
andrew@51 63 void MatchMarkers::loadMarkerFile(std::string filePath){
andrew@51 64 markers.clear();
andrew@51 65
andrew@51 66 printf("MARKERS : READ FILE '%s'\n", filePath.c_str());
andrew@51 67
andrew@51 68 ifstream file ( filePath.c_str());
andrew@51 69 string tmpLine, value;
andrew@51 70 stringstream iss;
andrew@51 71
andrew@51 72 while ( file.good() )
andrew@51 73 {
andrew@51 74 getline(file, tmpLine);
andrew@51 75 iss << tmpLine;
andrew@51 76 // printf("tmp line %s\n", tmpLine.c_str());
andrew@51 77
andrew@51 78 while(getline ( iss, value, '\n' )){ // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
andrew@51 79 // cout << string( value, 1, value.length()-2 ); // display value removing the first and the last character from it
andrew@51 80 // printf("line:%s\n", value.c_str());
andrew@51 81 string::size_type start = value.find_first_not_of(" ,\t\v\n");
andrew@51 82 string firstpart = value.substr(start, string::npos);
andrew@51 83 string::size_type end = firstpart.find_first_of(" ,\t\v\n");
andrew@51 84 string part = firstpart.substr(0, end);
andrew@51 85 markers.push_back(atof(part.c_str()));
andrew@51 86 printf("marker[%i]: %f ms\n", (int)markers.size()-1, markers[markers.size()-1]);
andrew@51 87
andrew@51 88 }//end while reading line
andrew@51 89 iss.clear();
andrew@51 90
andrew@51 91 }//end while
andrew@51 92
andrew@51 93
andrew@51 94 }
andrew@51 95
andrew@51 96
andrew@51 97 //--------------------------------------------------------------
andrew@51 98 void MatchMarkers::loadFile(){
andrew@51 99 // first, create a string that will hold the URL
andrew@51 100 string fileName;
andrew@51 101 // openFile(string& URL) returns 1 if a file was picked
andrew@51 102 // returns 0 when something went wrong or the user pressed 'cancel'
andrew@51 103 int response = ofxFileDialogOSX::openFile(fileName);
andrew@51 104 if(response){
andrew@51 105 loadMarkerFile(fileName);
andrew@51 106 }else {
andrew@51 107 printf("Could not open marker file\n");
andrew@51 108 }
andrew@51 109 }
andrew@51 110
andrew@51 111
andrew@51 112 //--------------------------------------------------------------
andrew@51 113 void MatchMarkers::saveFile(){
andrew@51 114 // create a string to hold the folder URL
andrew@51 115 string folderURL;
andrew@51 116 // and one for the filename
andrew@51 117 string fileName;
andrew@51 118 // saveFile(string& folderURL, string& fileName) returns 1 if a folder + file were specified
andrew@51 119 // returns 0 when something went wrong or the user pressed 'cancel'
andrew@51 120 int response = ofxFileDialogOSX::saveFile(folderURL, fileName);
andrew@51 121 if(response){
andrew@51 122 // now you can use the folder URL and the filename.
andrew@51 123 printf("\nfolder:'%s'\nfile'%s'\n", folderURL.c_str(), fileName.c_str());
andrew@51 124 saveMarkers(folderURL+"/"+fileName);
andrew@51 125 }else {
andrew@51 126 printf("Could not save marker file\n");
andrew@51 127 }
andrew@51 128 }
andrew@51 129