andrew@45: /* andrew@45: * MatchMultitrackAnnotationReader.cpp andrew@45: * annotationResultCalculator andrew@45: * andrew@45: * Created by Andrew on 08/05/2012. andrew@45: * Copyright 2012 QMUL. All rights reserved. andrew@45: * andrew@45: */ andrew@45: andrew@45: #include "MatchMultitrackAnnotationReader.h" andrew@45: andrew@46: #include andrew@46: #include andrew@46: #include andrew@45: andrew@45: void MatchMultitrackAnnotationReader::readInMatchFile(std::string& pathName){ andrew@45: andrew@45: // "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv" andrew@45: matchData.clear(); andrew@45: matchLiveTimes.clear(); andrew@45: matchRehearsalTimes.clear(); andrew@45: andrew@45: // printf("MATCH : READ FILE %s\n", pathName.c_str()); andrew@45: ifstream file ( pathName.c_str()); andrew@45: string value, tmpLine; andrew@45: stringstream iss; andrew@45: int count = 0; andrew@45: MatchNotation n; andrew@45: while ( file.good() ) andrew@45: { andrew@45: getline(file, tmpLine); andrew@45: iss << tmpLine; andrew@45: // printf("tmp line %s\n", tmpLine.c_str()); andrew@45: while(getline ( iss, value, '\t' )){ // read a string until next comma: http://www.cplusplus.com/reference/string/getline/ andrew@45: // cout << string( value, 1, value.length()-2 ); // display value removing the first and the last character from it andrew@45: // printf("line:%s\n", value.c_str()); andrew@45: string::size_type start = value.find_first_not_of(" ,\t\v\n"); andrew@45: string firstpart = value.substr(start, string::npos); andrew@45: string::size_type end = firstpart.find_first_of(" ,\t\v\n"); andrew@45: string part = firstpart.substr(0, end); andrew@45: string secondpart = firstpart.substr(end, string::npos); andrew@45: start = secondpart.find_first_not_of(" ,\t\v\n"); andrew@45: secondpart = secondpart.substr(start , string::npos); andrew@45: // printf("part:%s,%s\n", part.c_str(), secondpart.c_str()); andrew@45: MatchNotation n; andrew@45: n.firstTime = atof(part.c_str()); andrew@45: n.secondTime = atof(secondpart.c_str()); andrew@45: matchLiveTimes.push_back(atof(part.c_str())); andrew@45: matchRehearsalTimes.push_back(atof(secondpart.c_str())); andrew@45: andrew@45: matchData.push_back(n); andrew@45: }//end while reading line andrew@45: iss.clear(); andrew@45: andrew@45: andrew@45: }//end while andrew@45: andrew@45: // printAnnotations(); andrew@45: // printf("There are %i MATCH annotations\n", (int)matchData.size()); andrew@45: andrew@45: } andrew@45: andrew@46: void MatchMultitrackAnnotationReader::reverseAnnotations(){ andrew@46: //when its the forwards path andrew@46: reverse(matchLiveTimes.begin(),matchLiveTimes.end()); andrew@46: reverse(matchRehearsalTimes.begin(),matchRehearsalTimes.end()); andrew@46: } andrew@46: andrew@45: void MatchMultitrackAnnotationReader::printAnnotations(){ andrew@45: //rwcAnnotations.size() andrew@45: for (int i = 0;i < min(200, (int)matchData.size());i++){ andrew@45: printf("MATCH audio times %f, midi played time %f \n", andrew@45: matchData[i].firstTime, andrew@45: matchData[i].secondTime); andrew@45: } andrew@45: } andrew@45: