Mercurial > hg > midi-score-follower
comparison src/midiEventHolder.cpp @ 16:f0abb0e414ec
reorders the MIDI matrix once loaded from all channels, chop the beginning now less relevant - check how this might work...
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 15 Nov 2011 19:35:05 +0000 |
parents | 9e972948d654 |
children | d75d16c57eac |
comparison
equal
deleted
inserted
replaced
15:9e972948d654 | 16:f0abb0e414ec |
---|---|
663 printf("%i , ", matchMatrix[i][k]); | 663 printf("%i , ", matchMatrix[i][k]); |
664 } | 664 } |
665 printf("\n"); | 665 printf("\n"); |
666 } | 666 } |
667 | 667 |
668 | 668 } |
669 } | 669 |
670 | |
671 | |
672 void midiEventHolder::printRecordedEvents(){ | |
673 printf("Recorded Events:\n"); | |
674 for (int i = 0;i < recordedNoteOnMatrix.size() && i < recordedEventTimes.size();i++){ | |
675 for (int k = 0;k < recordedNoteOnMatrix[i].size();k++){ | |
676 printf("[%i] = %i ,", i, recordedNoteOnMatrix[i][k]); | |
677 } | |
678 printf("time %f \n", recordedEventTimes[i]); | |
679 } | |
680 | |
681 } | |
682 | |
683 | |
684 | |
685 void midiEventHolder::reorderMatrixFromNoteTimes(IntMatrix& noteOnMatrix){ | |
686 double currentTime = -19999.; | |
687 for (int i = 0;i < noteOnMatrix.size();i++){ | |
688 int nextIndex = getIndexOfMinimumAboveTime(currentTime, noteOnMatrix); | |
689 cout << "index of min time " << currentTime << " is " << nextIndex << " at time " << noteOnMatrix[nextIndex][0] << endl; | |
690 // cout << "next index " << nextIndex << " time " << noteOnMatrix[nextIndex][0] << endl; | |
691 if (nextIndex >= 0 && nextIndex > i && noteOnMatrix[nextIndex][0] < noteOnMatrix[i][0] ){ | |
692 //which it should be | |
693 cout << " index " << nextIndex << " at time " << noteOnMatrix[nextIndex][0] << " swaps with inex " << i << " at time " << noteOnMatrix[i][0] << endl; | |
694 noteOnMatrix[i].swap(noteOnMatrix[nextIndex]); | |
695 currentTime = noteOnMatrix[i][0]; | |
696 } | |
697 | |
698 } | |
699 | |
700 | |
701 } | |
702 | |
703 int midiEventHolder::getIndexOfMinimumAboveTime(const double& time, IntMatrix& noteOnMatrix){ | |
704 int index = 0; | |
705 double minimumTime = 100000000.; | |
706 int bestIndex = -1; | |
707 while (index < noteOnMatrix.size()){ | |
708 | |
709 if (noteOnMatrix[index][0] > time && noteOnMatrix[index][0] < minimumTime){ | |
710 bestIndex = index; | |
711 minimumTime = noteOnMatrix[index][0]; | |
712 } | |
713 index++; | |
714 } | |
715 return bestIndex; | |
716 } | |
717 | |
718 | |
719 void midiEventHolder::correctTiming(IntMatrix& noteOnMatrix){ | |
720 | |
721 if (noteOnMatrix.size() > 0 && noteOnMatrix[0][0] < 0) { | |
722 int offset = noteOnMatrix[0][0]; | |
723 for (int i = 0;i < noteOnMatrix.size();i++){ | |
724 noteOnMatrix[i][0] -= offset; | |
725 } | |
726 } | |
727 | |
728 } |