view matchAnnotationSrc/matchAnnotations.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
/*
 *  matchAnnotations.cpp
 *  matchJNMRannotationReader
 *
 *  Created by Andrew on 22/03/2012.
 *  Copyright 2012 QMUL. All rights reserved.
 *
 */

#include "matchAnnotations.h"


void matchAnnotations::readInMatchFile(std::string& pathName){
	
	// "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv"
	matchData.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.audioTime = atof(part.c_str());
			n.midiTime = 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 matchAnnotations::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].audioTime,
			   matchData[i].midiTime);
	}
}