Mercurial > hg > midi-score-follower
view matchAnnotationSrc/jnmrMidiPlayerAnnotations.cpp @ 52:13194a9dca77 tip
Added exporting of image and text data
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 17 Jul 2012 22:13:10 +0100 |
parents | 158f5f38e9d3 |
children |
line wrap: on
line source
/* * jnmrMidiPlayerannotations.cpp * matchJNMRannotationReader * * Created by Andrew on 23/03/2012. * Copyright 2012 QMUL. All rights reserved. * */ #include "jnmrMidiPlayerAnnotations.h" void jnmrMidiPlayerAnnotations::readInjnmrMidiPlayerFile(std::string& pathName){ jnmrMidiPlayerData.clear(); differences.clear(); // printf("jnmrMidiPlayer : READ FILE %s\n", pathName.c_str()); ifstream file ( pathName.c_str()); string value, tmpLine; stringstream iss; int count = 0; while ( file.good() ) { getline(file, tmpLine); iss << tmpLine; // printf("tmp line %s\n", tmpLine.c_str()); while(getline ( iss, value, '\t' )){ // read a string until next comma: http://www.cplusplus.com/reference/string/getline/ jnmrMidiPlayerNotation n; // string::size_type start = value.find_first_not_of(" ,\t\v\n"); // string part = value.substr(start, string::npos); string::size_type start = value.find_first_not_of(" ,\t\v\n"); string firstpart = value.substr(start, string::npos); string::size_type end = firstpart.find_first_of(" ,\t\v\n"); string part = firstpart.substr(0, end); string secondpart = firstpart.substr(end, string::npos); start = secondpart.find_first_not_of(" ,\t\v\n"); secondpart = secondpart.substr(start , string::npos); end = secondpart.find_first_of(" ,\t\v\n"); secondpart = secondpart.substr(0, end); n.difference = atof(secondpart.c_str()); n.midiTime = 0; n.audioTime = 0; jnmrMidiPlayerData.push_back(n); differences.push_back(atof(secondpart.c_str())); // printf("%s (%i) second part:%s\n", part.c_str(), count, secondpart.c_str()); float my_float; int my_int; // printf("reading %s\n", part.c_str()); switch (count%4) { case 0: my_float = atof(part.c_str()); n.midiTime = my_float; break; case 1: my_float = atof(part.c_str()); // printf("count%i, DIFF %f\n", count, my_float); n.difference = my_float; break; case 2: my_float = atof(part.c_str()); n.audioTime = my_float; break; case 3: my_float = atof(part.c_str()); n.midiTime = my_float; jnmrMidiPlayerData.push_back(n); break; default: break; } count++; }//end while reading line iss.clear(); }//end while //printAnnotations(); // printf("There are %i JNMR annotations\n", (int)jnmrMidiPlayerData.size()); } void jnmrMidiPlayerAnnotations::printAnnotations(){ //rwcAnnotations.size() for (int i = 0;i < min(200, (int)jnmrMidiPlayerData.size());i++){ // printf("jnmrMidiPlayer audio times %f, midi played time %f \n", // jnmrMidiPlayerData[i].audioTime, // jnmrMidiPlayerData[i].midiTime); printf("jnmrMidiPlayer diff %f \n", jnmrMidiPlayerData[i].difference); } }