view annotationCalculatorSrc/MatchMultitrackAnnotationReader.cpp @ 50:93d21c20cfbc

Added Markers and the ability to switch to these points in the file when playing
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 14 Jun 2012 20:04:49 +0100
parents ba36a1721538
children
line wrap: on
line source
/*
 *  MatchMultitrackAnnotationReader.cpp
 *  annotationResultCalculator
 *
 *  Created by Andrew on 08/05/2012.
 *  Copyright 2012 QMUL. All rights reserved.
 *
 */

#include "MatchMultitrackAnnotationReader.h"

#include <iostream>
#include <algorithm>
#include <vector>

void MatchMultitrackAnnotationReader::readInMatchFile(std::string& pathName){
	
	// "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv"
	matchData.clear();
	matchLiveTimes.clear();
	matchRehearsalTimes.clear();
	
	//	printf("MATCH : READ FILE %s\n", pathName.c_str());
	ifstream file ( pathName.c_str());
	string value, tmpLine;
	stringstream iss;
	int count = 0;
	MatchNotation n;
	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/
			//	cout << string( value, 1, value.length()-2 ); // display value removing the first and the last character from it
			//		printf("line:%s\n", value.c_str());
			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);
			//		printf("part:%s,%s\n", part.c_str(), secondpart.c_str());
			MatchNotation n;
			n.firstTime = atof(part.c_str());
			n.secondTime = atof(secondpart.c_str());
			matchLiveTimes.push_back(atof(part.c_str()));
			matchRehearsalTimes.push_back(atof(secondpart.c_str()));
			
			matchData.push_back(n);
		}//end while reading line
		iss.clear();
		
		
	}//end while
	
	//	printAnnotations();
	//	printf("There are %i MATCH annotations\n", (int)matchData.size());
	
}

void MatchMultitrackAnnotationReader::reverseAnnotations(){
	//when its the forwards path
	reverse(matchLiveTimes.begin(),matchLiveTimes.end());
	reverse(matchRehearsalTimes.begin(),matchRehearsalTimes.end());
}

void MatchMultitrackAnnotationReader::printAnnotations(){
	//rwcAnnotations.size()
	for (int i = 0;i < min(200, (int)matchData.size());i++){
		printf("MATCH audio times %f, midi played time %f \n", 
			   matchData[i].firstTime,
			   matchData[i].secondTime);
	}
}