comparison src/midiEventHolder.cpp @ 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
comparison
equal deleted inserted replaced
16:f0abb0e414ec 17:d75d16c57eac
669 669
670 670
671 671
672 void midiEventHolder::printRecordedEvents(){ 672 void midiEventHolder::printRecordedEvents(){
673 printf("Recorded Events:\n"); 673 printf("Recorded Events:\n");
674 for (int i = 0;i < recordedNoteOnMatrix.size() && i < recordedEventTimes.size();i++){ 674 for (int i = 0;i < recordedNoteOnMatrix.size();i++){
675 for (int k = 0;k < recordedNoteOnMatrix[i].size();k++){ 675 for (int k = 0;k < recordedNoteOnMatrix[i].size();k++){
676 printf("[%i] = %i ,", i, recordedNoteOnMatrix[i][k]); 676 printf("[%i] = %i ,", i, recordedNoteOnMatrix[i][k]);
677 } 677 }
678 printf("time %f \n", recordedEventTimes[i]); 678 if (i < recordedEventTimes.size())
679 printf("time %f \n", recordedEventTimes[i]);
680 else
681 printf("\n");
679 } 682 }
680 683
681 } 684 }
682 685
683 686
694 noteOnMatrix[i].swap(noteOnMatrix[nextIndex]); 697 noteOnMatrix[i].swap(noteOnMatrix[nextIndex]);
695 currentTime = noteOnMatrix[i][0]; 698 currentTime = noteOnMatrix[i][0];
696 } 699 }
697 700
698 } 701 }
699 702
700 703 printRecordedEvents();
701 } 704
705 }
706
707
708
709
710 void midiEventHolder::doublecheckOrder(IntMatrix& noteOnMatrix){
711
712 for (int i = 0;i < noteOnMatrix.size();i++){
713 int nextIndex = getIndexOfMinimumAboveIndex(i, noteOnMatrix);
714 if (nextIndex > i){
715 noteOnMatrix[i].swap(noteOnMatrix[nextIndex]);
716 }
717 }
718 }
719
720 int midiEventHolder::getIndexOfMinimumAboveIndex(const int& index, IntMatrix& noteOnMatrix){
721 int returnIndex = index;
722 int min = noteOnMatrix[index][0];
723 for (int i = index;i < noteOnMatrix.size();i++){
724 if (noteOnMatrix[i][0] < min){
725 returnIndex = i;
726 min = noteOnMatrix[i][0];
727 }
728 }
729 return returnIndex;
730 }
731
702 732
703 int midiEventHolder::getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix){ 733 int midiEventHolder::getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix){
704 int index = 0; 734 int index = 0;
705 double minimumTime = 100000000.; 735 double minimumTime = 100000000.;
706 int bestIndex = -1; 736 int bestIndex = -1;