view jnmr/Annotations.cpp @ 37:795a99987875

Added new patcher to test RWC database, automatically loads the file in both Max and the score follower, then stores data to a given text file. Need to fix the annotation checker next
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 15 Dec 2011 13:02:52 +0000
parents 5a1b0c6fa1fb
children c3d32207565f
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);
	}
}