view jnmr/Annotations.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
/*
 *  annotations.cpp
 *  jnmr_MidiFollower
 *
 *  Created by Andrew on 15/12/2011.
 *  Copyright 2011 QMUL. All rights reserved.
 *
 */

#include "Annotations.h"

Annotations::Annotations(){

}

void Annotations::readInRWCfile(std::string& pathName){
	
// "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv"
	rwcAnnotations.clear();
	
//	printf("ANNOTATIONS : READ FILE %s\n", pathName.c_str());
	ifstream file ( pathName.c_str()); // declare file stream: http://www.cplusplus.com/reference/iostream/ifstream/
	string value, tmpLine;
	stringstream iss;
	int count = 0;
	Notation n;
	while ( file.good() )
	{
		getline(file, tmpLine);
			iss << tmpLine;
//			printf("tmp line %s\n", tmpLine.c_str());
			while(getline ( iss, value, ',' )){ // 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
				
		string::size_type start = value.find_first_not_of(" ,\t\v\n");
		string part = value.substr(start, string::npos);
//		printf("%s (%i)\n", part.c_str(), count);
		float my_float;
		int my_int;
	//	printf("reading %s\n", part.c_str());
		switch (count%7) {
	
			case 0:
				my_float = atof(part.c_str());
				n.midiTime = my_float;
				break;
				
			case 1:
			
				my_float = atof(part.c_str());
			//	printf("count%i, beat loc float is %f\n", count, my_float);
				n.beatLocation = my_float;
				break;
			case 2:
			
				my_int = atoi(part.c_str());
			//	printf("count %i, MIDI note float is %i\n", count, my_int);
				n.midiNote = my_int;
				break;	
			
		
				
			case 6:
				my_float = atof(part.c_str());
				n.eventTime = my_float;
				rwcAnnotations.push_back(n);
				//	printf("count%i, event time float is %f\n", count, my_float);
				break;
				
				
			default:
				break;
				
				
		}
				count++;
			}//end while reading line
			iss.clear();
	
		
	}//end while
	
//	printAnnotations();
//	printf("There are %i annotations\n", (int)rwcAnnotations.size());
	
}

void Annotations::printAnnotations(){
//rwcAnnotations.size()
	for (int i = 0;i < min(100, (int)rwcAnnotations.size());i++){
	printf("Annotation: Loaded Beat position %f, note %i happens at time %f midi played time %f \n", 
		   rwcAnnotations[i].beatLocation, rwcAnnotations[i].midiNote, rwcAnnotations[i].eventTime,
		   rwcAnnotations[i].midiTime);
	}
}

/*
 ifstream fp ("/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv");
 //FILE *fp = fopen("/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv", "r");
 int x, y, z;
 float a, b, c, d;
 std::vector<float> vec;
 
 while (fscanf(fp, "%f,    %f, %d,    %f, %d, %d,    %f", &a, &b, &x, &c, &y, &z, &d) == 6) {
 printf("a is %f", a);
 }
 fclose(fp);
 */