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