changeset 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 5685ef75550c
files .DS_Store jnmr/Annotations.cpp jnmr/Annotations.h jnmr/midiEventHolder.cpp jnmr/testApp.cpp jnmr/testApp.h
diffstat 6 files changed, 59 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
Binary file .DS_Store has changed
--- a/jnmr/Annotations.cpp	Thu Dec 15 13:02:52 2011 +0000
+++ b/jnmr/Annotations.cpp	Fri Dec 16 17:37:44 2011 +0000
@@ -13,24 +13,13 @@
 
 }
 
-void Annotations::readInSomeValues(){
+void Annotations::readInRWCfile(std::string& pathName){
 	
-	/*
-	 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);
-	 */
+// "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv"
 	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/
+	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;
@@ -71,14 +60,26 @@
 		count++;
 	}
 	
-	//printAnnotations();
+	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);
+//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);
+ */
--- a/jnmr/Annotations.h	Thu Dec 15 13:02:52 2011 +0000
+++ b/jnmr/Annotations.h	Fri Dec 16 17:37:44 2011 +0000
@@ -26,7 +26,8 @@
 class Annotations{
 public:
 	Annotations();
-	void readInSomeValues();
+	//void readInSomeValues();
+	void readInRWCfile(std::string& pathName);
 	//~Annotations();
 	void 	printAnnotations();
 	vector<Notation> rwcAnnotations;
--- a/jnmr/midiEventHolder.cpp	Thu Dec 15 13:02:52 2011 +0000
+++ b/jnmr/midiEventHolder.cpp	Fri Dec 16 17:37:44 2011 +0000
@@ -17,7 +17,7 @@
 
 midiEventHolder::midiEventHolder(){
 	
-	myNotation.readInSomeValues();
+
 	
 //	recordedNoteOnIndex = 0;
 	alignmentPosition = 0;
@@ -811,10 +811,12 @@
 	
 	while (smoothIndex < recordedEventTimes.size() && recordedEventTimes[smoothIndex] < newPosition){
 		float annotationTime = 0;
+		float annotationLocation = 0;
 		int annotationNote = 0;
 		if (smoothIndex < myNotation.rwcAnnotations.size()){
 			annotationTime = myNotation.rwcAnnotations[smoothIndex].eventTime;
 			annotationNote = myNotation.rwcAnnotations[smoothIndex].midiNote;
+			annotationLocation = myNotation.rwcAnnotations[smoothIndex].beatLocation;
 		}
 		
 		float difference = playingTime - (annotationTime*1000.0);
@@ -828,13 +830,15 @@
 				}
 			(*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);
+
 	
 		}
 	
 		if ((*differenceOutput).is_open()){
 			(*differenceOutput) << beatPositions[smoothIndex] << "," << difference << "\n";
+			printf("midi %i beat pos %f now at %f :: annotaion %i loc % f time %f diff \t%f ms\n",  recordedNoteOnMatrix[smoothIndex][1], 
+				   beatPositions[smoothIndex], playingTime, 
+				   annotationNote, annotationLocation, annotationTime, difference);
 		}
 		
 		smoothIndex++;
--- a/jnmr/testApp.cpp	Thu Dec 15 13:02:52 2011 +0000
+++ b/jnmr/testApp.cpp	Fri Dec 16 17:37:44 2011 +0000
@@ -16,22 +16,14 @@
 	outputFileRoot = "../../../data/FilesOut/rwcOutputData_RM-C0";
 	
 	myfile.open("../../../data/FilesOut/exampletest2.txt");
-	diffFile.open("../../../data/FilesOut/diffTest.txt");
-	
-	if (myfile.is_open())
-	{
-	//	myfile << "This is a line.\n";
-	//	myfile << "This is another line.\n";
-//		myfile.close();
-		printf("WRITING TO TEXT FILE\n");
-	}
-	else cout << "Unable to open example file";
-	
+//	diffFile.open("../../../data/FilesOut/diffTest.txt");
 	
 	this->args->printArgs();
 	this->args->printOpts();
 
 	loadRWCfileNumber(2);
+	openOutputFile(2);
+	loadAnnotation(2);
 
 /*	if (this->args->getCount() > 0){
 		museScoreFilename = this->args->getString(1);
@@ -217,6 +209,7 @@
 		if ( m.getAddress() == "/RWCfile" ){
 			openOutputFile(m.getArgAsInt32(0));
 			loadRWCfileNumber(m.getArgAsInt32(0));
+			loadAnnotation(m.getArgAsInt32(0));
 		}
 		
 		
@@ -605,14 +598,14 @@
 void testApp::openOutputFile(const int& i){
 	if (diffFile.is_open())
 		diffFile.close();
-	
-	string outputFileName;
-	
+	string endBit = ".txt";
+	string outputFileName = makeRWCfilename(outputFileRoot, i, endBit);
+	/*
 	if (i >= 10)
 		outputFileName = outputFileRoot + ofToString(i)+".txt";
 	else
 		outputFileName = outputFileRoot + "0"+ofToString(i)+".txt";
-	
+	*/
 	diffFile.open(outputFileName.c_str());
 }
 
@@ -629,6 +622,26 @@
 	}
 }
 
+std::string testApp::makeRWCfilename(std::string& root, const int& fileID, std::string& endPart){
+	std::string pathName;
+	if (fileID >= 1 && fileID <= 64){
+	
+		if (fileID >= 10)
+			pathName = root + ofToString(fileID)+endPart;
+		else
+			pathName = root + "0"+ofToString(fileID)+endPart;
+		
+		printf("MAKE FILE:%s\n", midiFileName.c_str());
+	}
+		return pathName;
+}
+
+void testApp::loadAnnotation(const int& fileID){
+	string annotationRoot = "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C0";
+	string annotationEnding = "_annotation+WavPos.csv";
+	string path = makeRWCfilename(annotationRoot, fileID, annotationEnding );
+	midiEvents.myNotation.readInRWCfile(path);
+}
 
 int testApp::cannamMainFunction(){
 
--- a/jnmr/testApp.h	Thu Dec 15 13:02:52 2011 +0000
+++ b/jnmr/testApp.h	Fri Dec 16 17:37:44 2011 +0000
@@ -140,7 +140,8 @@
 	int  midiFileNumber;
 	void loadRWCfileNumber(const int& i);
 	void openOutputFile(const int& i);
-	
+	std::string makeRWCfilename(std::string& root, const int& fileID,  std::string& endPart);
+	void loadAnnotation(const int& fileID);
 };
 
 #endif