view jnmr/Annotations.cpp @ 36:5a1b0c6fa1fb

Added class to read in the csv Annotation file, then write out the respective difference between the performed piece as followed here, and the annotation of RWC by Ewert and Muller
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 15 Dec 2011 02:28:49 +0000
parents
children 795a99987875
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::readInSomeValues(){
	
	/*
	 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);
	 */
	rwcAnnotations.clear();
	
	printf("READ FILE\n");
	ifstream file ( "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv" ); // declare file stream: http://www.cplusplus.com/reference/iostream/ifstream/
	string value;
	int count = 0;
	Notation n;
	while ( file.good() )
	{
		getline ( file, 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");
		string part = value.substr(start, string::npos);
		//printf("%s (%i)\n", part.c_str(), count);
		float my_float;
		int my_int;
		
		switch (count%6) {
			case 1:
			//	printf("reading %s\n", part.c_str());
				my_float = atof(part.c_str());
			//	printf("float is %f\n", my_float);
				n.beatLocation = my_float;
				break;
			case 2:
			//	printf("reading %s\n", part.c_str());
				my_int = atoi(part.c_str());
			//	printf("float is %i\n", my_int);
				n.midiNote = my_int;
				break;	
			case 0:
				my_float = atof(part.c_str());
				n.eventTime = my_float;
				break;
			case 3:
				rwcAnnotations.push_back(n);
				break;
			default:
				break;
		}
		count++;
	}
	
	printAnnotations();
	
}

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