view jnmr/Annotations.cpp @ 38:c3d32207565f

Annotations autoloading for the various files, still needs proper checker though
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Fri, 16 Dec 2011 17:37:44 +0000
parents 795a99987875
children 60c1f0fbc8f4
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;
	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(){
//rwcAnnotations.size()
	for (int i = 0;i < 100;i++){
	printf("Annotation: Loaded Beat position %f, note %i happens at time %f \n", rwcAnnotations[i].beatLocation, rwcAnnotations[i].midiNote, rwcAnnotations[i].eventTime);
	}
}

/*
 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);
 */