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