@@ -649,33 +649,172 @@ int SourceMIDITemp::addNote(int track, double startTime, double endTime, uint8_t
649
649
650
650
int SourceMIDITemp::setNoteTime (int track, int index,
651
651
double startTime, double endTime) {
652
- /* * TODO */
652
+ /* * Limit Track Index */
653
+ if (track < 0 || track >= this ->eventList .size ()) { return -1 ; }
654
+
655
+ /* * Limit Time */
656
+ if (endTime <= startTime) { return -1 ; }
657
+
658
+ /* * Get Note Data */
659
+ auto & list = this ->eventList .getReference (track);
660
+ if (index < 0 || index >= list.size ()) { return -1 ; }
661
+ auto pNote = dynamic_cast <Note*>(list[index]);
662
+ if (!pNote) { return -1 ; }
663
+
664
+ uint8_t channel = pNote->channel ;
665
+ uint8_t pitch = pNote->pitch ;
666
+ uint8_t vel = pNote->vel ;
667
+ juce::String lyrics = pNote->lyrics ;
668
+
669
+ /* * Change Note */
670
+ if (this ->removeNote (track, index)) {
671
+ return this ->addNote (
672
+ track, startTime, endTime,
673
+ channel, pitch, vel, lyrics);
674
+ }
653
675
return -1 ;
654
676
}
655
677
656
678
bool SourceMIDITemp::setNoteChannel (int track, int index, uint8_t channel) {
657
- /* * TODO */
658
- return -1 ;
679
+ /* * Limit Track Index */
680
+ if (track < 0 || track >= this ->eventList .size ()) { return false ; }
681
+
682
+ /* * Get Note Pointer */
683
+ auto & list = this ->eventList .getReference (track);
684
+ if (index < 0 || index >= list.size ()) { return false ; }
685
+ auto pNote = dynamic_cast <Note*>(list[index]);
686
+ if (!pNote) { return false ; }
687
+
688
+ /* * Get Note Off */
689
+ int offIndex = pNote->eventOffIndex ;
690
+ if (offIndex < 0 || offIndex >= list.size ()) { return false ; }
691
+ auto pNoteOff = dynamic_cast <NoteOffMarker*>(list[offIndex]);
692
+ if (!pNoteOff) { return false ; }
693
+
694
+ /* * Set Channel */
695
+ pNote->channel = channel;
696
+ pNoteOff->channel = channel;
697
+
698
+ return true ;
659
699
}
660
700
661
701
bool SourceMIDITemp::setNotePitch (int track, int index, uint8_t pitch) {
662
- /* * TODO */
663
- return false ;
702
+ /* * Limit Track Index */
703
+ if (track < 0 || track >= this ->eventList .size ()) { return false ; }
704
+
705
+ /* * Get Note Pointer */
706
+ auto & list = this ->eventList .getReference (track);
707
+ if (index < 0 || index >= list.size ()) { return false ; }
708
+ auto pNote = dynamic_cast <Note*>(list[index]);
709
+ if (!pNote) { return false ; }
710
+
711
+ /* * Set Pitch */
712
+ pNote->pitch = pitch;
713
+
714
+ return true ;
664
715
}
665
716
666
717
bool SourceMIDITemp::setNoteVelocity (int track, int index, uint8_t vel) {
667
- /* * TODO */
668
- return false ;
718
+ /* * Limit Track Index */
719
+ if (track < 0 || track >= this ->eventList .size ()) { return false ; }
720
+
721
+ /* * Get Note Pointer */
722
+ auto & list = this ->eventList .getReference (track);
723
+ if (index < 0 || index >= list.size ()) { return false ; }
724
+ auto pNote = dynamic_cast <Note*>(list[index]);
725
+ if (!pNote) { return false ; }
726
+
727
+ /* * Set Velocity */
728
+ pNote->vel = vel;
729
+
730
+ return true ;
669
731
}
670
732
671
733
bool SourceMIDITemp::setNoteLyrics (int track, int index, const juce::String& lyrics) {
672
- /* * TODO */
673
- return false ;
734
+ /* * Limit Track Index */
735
+ if (track < 0 || track >= this ->eventList .size ()) { return false ; }
736
+
737
+ /* * Get Note Pointer */
738
+ auto & list = this ->eventList .getReference (track);
739
+ if (index < 0 || index >= list.size ()) { return false ; }
740
+ auto pNote = dynamic_cast <Note*>(list[index]);
741
+ if (!pNote) { return false ; }
742
+
743
+ /* * Set Lyrics */
744
+ pNote->lyrics = lyrics;
745
+
746
+ return true ;
674
747
}
675
748
676
749
bool SourceMIDITemp::removeNote (int track, int index) {
677
- /* * TODO */
678
- return false ;
750
+ /* * Check Track Index */
751
+ if (track < 0 || track >= this ->eventList .size ()) { return false ; }
752
+
753
+ /* * Get End Index */
754
+ auto & list = this ->eventList .getReference (track);
755
+ if (index < 0 || index >= list.size ()) { return false ; }
756
+ int offIndex = -1 ;
757
+ if (auto pNote = dynamic_cast <Note*>(list[index])) {
758
+ offIndex = pNote->eventOffIndex ;
759
+ }
760
+ if (offIndex < 0 || offIndex >= list.size ()) { return false ; }
761
+ if (offIndex <= index) { return false ; }
762
+
763
+ /* * Remove Note Off */
764
+ list.remove (offIndex);
765
+
766
+ /* * Update Index */
767
+ for (int i = 0 ; i < list.size (); i++) {
768
+ if (i != offIndex) {
769
+ auto ptr = list.getUnchecked (i);
770
+ if (ptr->eventIndex > offIndex) {
771
+ ptr->eventIndex --;
772
+ }
773
+
774
+ if (auto pNote = dynamic_cast <Note*>(ptr)) {
775
+ if (pNote->eventIndex != index &&
776
+ pNote->eventOffIndex > offIndex) {
777
+ pNote->eventOffIndex --;
778
+ }
779
+ }
780
+
781
+ else if (auto pNoteOff = dynamic_cast <NoteOffMarker*>(ptr)) {
782
+ if (pNoteOff->eventOnIndex > offIndex) {
783
+ pNoteOff->eventOnIndex --;
784
+ }
785
+ }
786
+ }
787
+ }
788
+
789
+ /* * Remove Note */
790
+ list.remove (index);
791
+
792
+ /* * Update Index */
793
+ for (int i = 0 ; i < list.size (); i++) {
794
+ if (i != index) {
795
+ auto ptr = list.getUnchecked (i);
796
+ if (ptr->eventIndex > index) {
797
+ ptr->eventIndex --;
798
+ }
799
+
800
+ if (auto pNote = dynamic_cast <Note*>(ptr)) {
801
+ if (pNote->eventOffIndex > index) {
802
+ pNote->eventOffIndex --;
803
+ }
804
+ }
805
+
806
+ else if (auto pNoteOff = dynamic_cast <NoteOffMarker*>(ptr)) {
807
+ if (pNoteOff->eventOnIndex > index) {
808
+ pNoteOff->eventOnIndex --;
809
+ }
810
+ }
811
+ }
812
+ }
813
+
814
+ /* * Rebuild Index Temp */
815
+ this ->updateIndexs (track);
816
+
817
+ return true ;
679
818
}
680
819
681
820
int SourceMIDITemp::binarySearchStart (
0 commit comments