# HG changeset patch # User Andrew N Robertson # Date 1323916129 0 # Node ID 5a1b0c6fa1fb77d332fe0b67f81223a9c6c2d82b # Parent 6cd3e0075adf55064baa17c49943593a5ac9387b 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 diff -r 6cd3e0075adf -r 5a1b0c6fa1fb jnmr/Annotations.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jnmr/Annotations.cpp Thu Dec 15 02:28:49 2011 +0000 @@ -0,0 +1,84 @@ +/* + * 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 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); + } +} + + diff -r 6cd3e0075adf -r 5a1b0c6fa1fb jnmr/Annotations.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jnmr/Annotations.h Thu Dec 15 02:28:49 2011 +0000 @@ -0,0 +1,36 @@ +/* + * annotations.h + * jnmr_MidiFollower + * + * Created by Andrew on 15/12/2011. + * Copyright 2011 QMUL. All rights reserved. + * + */ + +#ifndef ANNOTATIONS +#define ANNOTATIONS + +#include "ofMain.h" + +// basic file operations for text file stuff +#include +#include +using namespace std; + +struct Notation { + int midiNote; + float beatLocation; + float eventTime; +}; + +class Annotations{ +public: + Annotations(); + void readInSomeValues(); + //~Annotations(); + void printAnnotations(); + vector rwcAnnotations; + +}; +#endif + diff -r 6cd3e0075adf -r 5a1b0c6fa1fb jnmr/midiEventHolder.cpp --- a/jnmr/midiEventHolder.cpp Wed Dec 14 17:28:17 2011 +0000 +++ b/jnmr/midiEventHolder.cpp Thu Dec 15 02:28:49 2011 +0000 @@ -11,10 +11,14 @@ //Main file to look at here is newNoteEvent() - this calls everything else to update the Bayesian array #include "midiEventHolder.h" -#include -#include + +//#include +//#include midiEventHolder::midiEventHolder(){ + + myNotation.readInSomeValues(); + // recordedNoteOnIndex = 0; alignmentPosition = 0; @@ -803,10 +807,28 @@ playingTime -= startPlayingTime; //now at the last one + + while (smoothIndex < recordedEventTimes.size() && recordedEventTimes[smoothIndex] < newPosition){ + float annotationTime = 0; + int annotationNote = 0; + if (smoothIndex < myNotation.rwcAnnotations.size()){ + annotationTime = myNotation.rwcAnnotations[smoothIndex].eventTime; + annotationNote = myNotation.rwcAnnotations[smoothIndex].midiNote; + } + + if ((*fileOutput).is_open()){ - (*fileOutput) << beatPositions[smoothIndex] <<", " << recordedNoteOnMatrix[smoothIndex][1] << ", "; - (*fileOutput) << playingTime << "\n"; + (*fileOutput) << fixed << beatPositions[smoothIndex] <<",\t" << recordedNoteOnMatrix[smoothIndex][1] << ",\t"; + (*fileOutput) << playingTime ; + float difference = playingTime - (annotationTime*1000.0); + if ( recordedNoteOnMatrix[smoothIndex][1] == annotationNote){ + (*fileOutput) << " corresponds to " << annotationTime; + } + (*fileOutput) << " \n"; + + printf("midi %i beat pos %f now at %f :: annotaion %i time %f diff \t%f ms\n", recordedNoteOnMatrix[smoothIndex][1], + beatPositions[smoothIndex], playingTime, annotationNote, annotationTime, difference); } smoothIndex++; diff -r 6cd3e0075adf -r 5a1b0c6fa1fb jnmr/midiEventHolder.h --- a/jnmr/midiEventHolder.h Wed Dec 14 17:28:17 2011 +0000 +++ b/jnmr/midiEventHolder.h Thu Dec 15 02:28:49 2011 +0000 @@ -11,6 +11,7 @@ #include "ofMain.h" #include "BayesianArrayStructure.h" +#include "Annotations.h" class midiEventHolder{ @@ -181,5 +182,6 @@ DoubleVector beatPositions; ofstream *fileOutput; + Annotations myNotation; }; #endif \ No newline at end of file diff -r 6cd3e0075adf -r 5a1b0c6fa1fb jnmr/testApp.cpp --- a/jnmr/testApp.cpp Wed Dec 14 17:28:17 2011 +0000 +++ b/jnmr/testApp.cpp Thu Dec 15 02:28:49 2011 +0000 @@ -7,6 +7,7 @@ //-------------------------------------------------------------- void testApp::setup(){ + midiEvents.fileOutput = &myfile; @@ -609,6 +610,44 @@ }//new end of load function +/* +void testApp::readInSomeValues(){ + + 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; + 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); + break; + case 2: + printf("reading %s\n", part.c_str()); + my_int = atoi(part.c_str()); + printf("float is %i\n", i); + break; + + default: + break; + } + count++; + } + +} + */ + diff -r 6cd3e0075adf -r 5a1b0c6fa1fb jnmr/testApp.h --- a/jnmr/testApp.h Wed Dec 14 17:28:17 2011 +0000 +++ b/jnmr/testApp.h Thu Dec 15 02:28:49 2011 +0000 @@ -30,7 +30,7 @@ #include "ofxOsc.h" #include "MidiInputStream.h" #include "ofxArgs.h" - +#include "Annotations.h" // basic file operations for text file stuff #include @@ -130,12 +130,13 @@ bool readyToStart; void prepareToStartOnNextNote(); void drawMuseScoreText(); - + void readInSomeValues(); //file output ofstream myfile; + }; #endif