andrew@49
|
1 /*
|
andrew@49
|
2 * matchAnnotations.cpp
|
andrew@49
|
3 * matchJNMRannotationReader
|
andrew@49
|
4 *
|
andrew@49
|
5 * Created by Andrew on 22/03/2012.
|
andrew@49
|
6 * Copyright 2012 QMUL. All rights reserved.
|
andrew@49
|
7 *
|
andrew@49
|
8 */
|
andrew@49
|
9
|
andrew@49
|
10 #include "matchAnnotations.h"
|
andrew@49
|
11
|
andrew@49
|
12
|
andrew@49
|
13 void matchAnnotations::readInMatchFile(std::string& pathName){
|
andrew@49
|
14
|
andrew@49
|
15 // "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv"
|
andrew@49
|
16 matchData.clear();
|
andrew@49
|
17
|
andrew@50
|
18 // printf("MATCH : READ FILE %s\n", pathName.c_str());
|
andrew@49
|
19 ifstream file ( pathName.c_str());
|
andrew@49
|
20 string value, tmpLine;
|
andrew@49
|
21 stringstream iss;
|
andrew@49
|
22 int count = 0;
|
andrew@49
|
23 MatchNotation n;
|
andrew@49
|
24 while ( file.good() )
|
andrew@49
|
25 {
|
andrew@49
|
26 getline(file, tmpLine);
|
andrew@49
|
27 iss << tmpLine;
|
andrew@49
|
28 // printf("tmp line %s\n", tmpLine.c_str());
|
andrew@49
|
29 while(getline ( iss, value, '\t' )){ // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
andrew@49
|
30 // cout << string( value, 1, value.length()-2 ); // display value removing the first and the last character from it
|
andrew@49
|
31 // printf("line:%s\n", value.c_str());
|
andrew@49
|
32 string::size_type start = value.find_first_not_of(" ,\t\v\n");
|
andrew@49
|
33 string firstpart = value.substr(start, string::npos);
|
andrew@49
|
34 string::size_type end = firstpart.find_first_of(" ,\t\v\n");
|
andrew@49
|
35 string part = firstpart.substr(0, end);
|
andrew@49
|
36 string secondpart = firstpart.substr(end, string::npos);
|
andrew@49
|
37 start = secondpart.find_first_not_of(" ,\t\v\n");
|
andrew@49
|
38 secondpart = secondpart.substr(start , string::npos);
|
andrew@49
|
39 // printf("part:%s,%s\n", part.c_str(), secondpart.c_str());
|
andrew@49
|
40 MatchNotation n;
|
andrew@49
|
41 n.audioTime = atof(part.c_str());
|
andrew@49
|
42 n.midiTime = atof(secondpart.c_str());
|
andrew@49
|
43 matchData.push_back(n);
|
andrew@49
|
44 }//end while reading line
|
andrew@49
|
45 iss.clear();
|
andrew@49
|
46
|
andrew@49
|
47
|
andrew@49
|
48 }//end while
|
andrew@49
|
49
|
andrew@49
|
50 // printAnnotations();
|
andrew@50
|
51 // printf("There are %i MATCH annotations\n", (int)matchData.size());
|
andrew@49
|
52
|
andrew@49
|
53 }
|
andrew@49
|
54
|
andrew@49
|
55 void matchAnnotations::printAnnotations(){
|
andrew@49
|
56 //rwcAnnotations.size()
|
andrew@49
|
57 for (int i = 0;i < min(200, (int)matchData.size());i++){
|
andrew@49
|
58 printf("MATCH audio times %f, midi played time %f \n",
|
andrew@49
|
59 matchData[i].audioTime,
|
andrew@49
|
60 matchData[i].midiTime);
|
andrew@49
|
61 }
|
andrew@49
|
62 }
|
andrew@49
|
63
|