view annotationCalculatorSrc/BeatAnnotationReader.cpp @ 43:b7ad807c9cde

Added annotation writing and the src for the result calculator
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Fri, 04 May 2012 15:33:36 +0100
parents
children 73fbbc92fdfb
line wrap: on
line source
/*
 *  BeatAnnotationReader.cpp
 *  annotationResultCalculator
 *
 *  Created by Andrew on 03/05/2012.
 *  Copyright 2012 QMUL. All rights reserved.
 *
 */

#include "BeatAnnotationReader.h"



void BeatAnnotationReader::readInBeatsFile(std::string& pathName){
	
	// "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv"
	beatTimes.clear();
	
	//	printf("MATCH : 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;
		int lineCount = 0;
		//			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 part = value.substr(start, string::npos);
			
			//printf("%s\n", firstpart.c_str());
			if (lineCount == 0){
				//printf("First part of line found '%s'\n", part.c_str());
				double newBeatTime = atof(part.c_str());
				beatTimes.push_back(newBeatTime);
			}
			lineCount++;
			/*
			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.audioTime = atof(part.c_str());
			n.midiTime = atof(secondpart.c_str());
			matchData.push_back(n);
			 */
		}//end while reading line
		iss.clear();
		
		
	}//end while
	
		printBeatTimes();
	//	printf("There are %i MATCH annotations\n", (int)matchData.size());
	
}

void BeatAnnotationReader::printBeatTimes(){
	for (int i = 0;i < beatTimes.size();i++){
		printf("Beat[%i] = %f\n", i, beatTimes[i]);
	}
}

void BeatAnnotationReader::readInMultiAlignmentFile(std::string pathName){
	
	alignmentTimes.clear();
	
	DoubleVector fileTimes;
	DoubleVector multialignTimes;
	
	ifstream file ( pathName.c_str());
	string value, tmpLine;
	stringstream iss;
	int count = 0;
	
	while ( file.good() )
	{
		getline(file, tmpLine);
		iss << tmpLine;
		int lineCount = 0;
		//			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 part = value.substr(start, string::npos);
			
			//printf("%s\n", firstpart.c_str());
			if (lineCount == 0){
				printf("First part of align found '%s'\n", part.c_str());
				double newBeatTime = atof(part.c_str());
				fileTimes.push_back(newBeatTime);
			}
			if (lineCount == 1){
				printf("Second part of align found '%s'\n", part.c_str());
				double newAlignTime = atof(part.c_str());
				multialignTimes.push_back(newAlignTime);
				
			}
			lineCount++;
		
		}//end while reading line
		iss.clear();
		
		
	}//end while
	
	alignmentTimes.push_back(fileTimes);
	alignmentTimes.push_back(multialignTimes);

}