changeset 17:d75d16c57eac

Fixed the ordering of the note matrix when loaded so it has a double check feature that they are ordered min to max. Prevents draw problems down the line
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Tue, 15 Nov 2011 20:06:55 +0000
parents f0abb0e414ec
children c7107e5c8f03
files src/CannamMidiFileLoader.cpp src/CannamMidiFileLoader.h src/midiEventHolder.cpp src/midiEventHolder.h
diffstat 4 files changed, 50 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/CannamMidiFileLoader.cpp	Tue Nov 15 19:35:05 2011 +0000
+++ b/src/CannamMidiFileLoader.cpp	Tue Nov 15 20:06:55 2011 +0000
@@ -11,7 +11,7 @@
 #include "CannamMidiFileLoader.h"
 
 CannamMidiFileLoader::CannamMidiFileLoader(){
-	chopBeginning = false;
+	chopBeginning = true;
 }
 
 int CannamMidiFileLoader::loadFile(std::string& filename, midiEventHolder& myMidiEvents){
@@ -244,11 +244,20 @@
 			
 		}
 	
-		myMidiEvents.printRecordedEvents();
+	myMidiEvents.printRecordedEvents();
 	printf("|||||||||||||||||||||| \n\n\n\n\n\n\n");
 	myMidiEvents.reorderMatrixFromNoteTimes(myMidiEvents.recordedNoteOnMatrix);
 	myMidiEvents.correctTiming(myMidiEvents.recordedNoteOnMatrix);
+	myMidiEvents.doublecheckOrder(myMidiEvents.recordedNoteOnMatrix);
 
+	createEventTiming(myMidiEvents);
+	
+	myMidiEvents.printRecordedEvents();		
+	
+}//end cannam midi main
+	
+
+void CannamMidiFileLoader::createEventTiming( midiEventHolder& myMidiEvents){
 	
 	long t;
 	t = myMidiEvents.recordedNoteOnMatrix[0][0];
@@ -261,13 +270,11 @@
 			myMidiEvents.recordedEventTimes.push_back(myMidiEvents.getEventTimeMillis(t));
 		else {
 			myMidiEvents.recordedEventTimes.push_back(myMidiEvents.getEventTimeMillis(t) - firstNoteTime);
-		
+			
 		}
 	}
-	myMidiEvents.printRecordedEvents();		
 	
-}//end cannam midi main
-	
+}
 	
 
 
--- a/src/CannamMidiFileLoader.h	Tue Nov 15 19:35:05 2011 +0000
+++ b/src/CannamMidiFileLoader.h	Tue Nov 15 20:06:55 2011 +0000
@@ -22,6 +22,8 @@
 	
 	int loadFile(std::string& filename, midiEventHolder& myMidiEvents);
 
+	void createEventTiming( midiEventHolder& myMidiEvents);
+	
 	double firstNoteTime;
 	int firstTickTime;
 	bool chopBeginning;
--- a/src/midiEventHolder.cpp	Tue Nov 15 19:35:05 2011 +0000
+++ b/src/midiEventHolder.cpp	Tue Nov 15 20:06:55 2011 +0000
@@ -671,11 +671,14 @@
 
 void midiEventHolder::printRecordedEvents(){
 	printf("Recorded Events:\n");
-	for (int i = 0;i < recordedNoteOnMatrix.size() && i < recordedEventTimes.size();i++){
+	for (int i = 0;i < recordedNoteOnMatrix.size();i++){
 		for (int k = 0;k < recordedNoteOnMatrix[i].size();k++){
 			printf("[%i] = %i ,", i, recordedNoteOnMatrix[i][k]);
 		}
-		printf("time %f \n", recordedEventTimes[i]);
+		if (i < recordedEventTimes.size())
+			printf("time %f \n", recordedEventTimes[i]);
+		else
+			printf("\n");
 	}
 	
 }
@@ -696,10 +699,37 @@
 		}
 		
 	}	
-	
+		
+	printRecordedEvents();
 
 }
 
+
+
+
+void midiEventHolder::doublecheckOrder(IntMatrix& noteOnMatrix){
+
+	for (int i = 0;i < noteOnMatrix.size();i++){
+		int nextIndex = getIndexOfMinimumAboveIndex(i, noteOnMatrix);
+		if (nextIndex > i){
+			noteOnMatrix[i].swap(noteOnMatrix[nextIndex]);
+		}
+	}	
+}
+
+int midiEventHolder::getIndexOfMinimumAboveIndex(const int& index, IntMatrix& noteOnMatrix){
+	int returnIndex = index;
+	int min = noteOnMatrix[index][0];
+	for (int i = index;i < noteOnMatrix.size();i++){
+		if (noteOnMatrix[i][0] < min){
+			returnIndex = i;
+			min = noteOnMatrix[i][0];
+		}
+	}
+	return returnIndex;
+}
+
+
 int midiEventHolder::getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix){
 	int index = 0;
 	double minimumTime = 100000000.;
--- a/src/midiEventHolder.h	Tue Nov 15 19:35:05 2011 +0000
+++ b/src/midiEventHolder.h	Tue Nov 15 20:06:55 2011 +0000
@@ -132,5 +132,7 @@
 	void reorderMatrixFromNoteTimes(IntMatrix& noteOnMatrix);
 	int getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix);
 	void correctTiming(IntMatrix& noteOnMatrix);
+	void doublecheckOrder(IntMatrix& noteOnMatrix);
+	int getIndexOfMinimumAboveIndex(const int& index, IntMatrix& noteOnMatrix);
 };
 #endif
\ No newline at end of file