# HG changeset patch # User Andrew N Robertson # Date 1321387615 0 # Node ID d75d16c57eac8b3953ecea8bf269a85513af575e # Parent f0abb0e414eca3d37df41e0085544969cd887389 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 diff -r f0abb0e414ec -r d75d16c57eac src/CannamMidiFileLoader.cpp --- 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 - +} diff -r f0abb0e414ec -r d75d16c57eac src/CannamMidiFileLoader.h --- 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; diff -r f0abb0e414ec -r d75d16c57eac src/midiEventHolder.cpp --- 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.; diff -r f0abb0e414ec -r d75d16c57eac src/midiEventHolder.h --- 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