From c3d14b1169e290b1551d4806597b90c4e0d4a00a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 21 Nov 2023 17:07:28 -0700 Subject: [PATCH] basic note-tupling functionality implemented --- gtk2_ardour/ardour.keys.in | 4 ++ gtk2_ardour/midi_region_view.cc | 82 +++++++++++++++++++++++++++++++++ gtk2_ardour/midi_region_view.h | 3 ++ 3 files changed, 89 insertions(+) diff --git a/gtk2_ardour/ardour.keys.in b/gtk2_ardour/ardour.keys.in index 611d008bcd..e6591efa07 100644 --- a/gtk2_ardour/ardour.keys.in +++ b/gtk2_ardour/ardour.keys.in @@ -470,6 +470,10 @@ This mode provides many different operations on both regions and control points, @notes|Notes/nudge-earlier-fine| <@SECONDARY@>Left|Nudge Notes Earlier (fine) @notes|Notes/edit-channels| c|Edit Note Channels @notes|Notes/edit-velocities| v|Edit Note Velocities +@notes|Notes/split-notes-grid| <@PRIMARY@>e|Split Notes By Grid +@notes|Notes/join-notes| <@PRIMARY@>j|Join Notes +@notes|Notes/split-notes-more| <@PRIMARY@>Up|Split Notes More Finely +@notes|Notes/split-notes-less| <@PRIMARY@>Down|Split Notes Less Finely @notes|Notes/transpose-up-octave| <@SECONDARY@>Up|Transpose up (1 octave) @notes|Notes/transpose-down-octave| <@SECONDARY@>Down|Transpose down (1 octave) diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 6297a77f69..a8f262f30a 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -4787,19 +4787,101 @@ MidiRegionView::end_note_splitting () void MidiRegionView::split_notes_grid () { + if (_selection.empty()) { + return; + } + + /* XXX need to adjust pos to be global */ + bool success; + std::shared_ptr base ((*_selection.begin())->note()); + + split_base_note.set_channel (base->channel()); + split_base_note.set_length (base->length()); + split_base_note.set_time (base->time()); + split_base_note.set_note (base->note()); + split_base_note.set_velocity (base->velocity()); + split_base_note.set_off_velocity (base->off_velocity()); + + Temporal::Beats grid = trackview.editor().get_grid_type_as_beats (success, timepos_t (split_base_note.time())); + + if (!success) { + /* No grid => use quarters */ + grid = Beats (1, 0); + } + + split_tuple = split_base_note.length().to_ticks() / grid.to_ticks(); + + start_note_diff_command (_("split notes")); + for (auto & s : _selection) { + note_diff_remove_note (s); + } + add_split_notes (); + apply_note_diff (false); } void MidiRegionView::split_notes_more () { + if (_selection.empty()) { + return; + } + + split_tuple++; + + char buf[64]; + snprintf (buf, sizeof (buf), "Split %s into %d", split_base_note.length().str().c_str(), split_tuple); + show_verbose_cursor (buf, 0, 0); + + start_note_diff_command (_("split notes more")); + for (auto & s : _selection) { + note_diff_remove_note (s); + } + add_split_notes (); + apply_note_diff (false); } void MidiRegionView::split_notes_less () { + if (_selection.empty()) { + return; + } + + if (split_tuple <= 2) { + return; + } + + split_tuple--; + + char buf[64]; + snprintf (buf, sizeof (buf), "Split %s into %d", split_base_note.length().str().c_str(), split_tuple); + show_verbose_cursor (buf, 0, 0); + + start_note_diff_command (_("split notes less")); + for (auto & s : _selection) { + note_diff_remove_note (s); + } + add_split_notes (); + apply_note_diff (false); } void MidiRegionView::join_notes () { } + +void +MidiRegionView::add_split_notes () +{ + Beats b (split_base_note.length()); + + b = b / split_tuple; + + Beats pos (split_base_note.time()); + + for (uint32_t n = 0; n < split_tuple; ++n) { + std::shared_ptr new_note (new NoteType (split_base_note.channel(), pos, b, split_base_note.note(), split_base_note.velocity())); + note_diff_add_note (new_note, true, true); + pos += b; + } +} diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index cad8690bab..1d56c18cba 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -593,6 +593,7 @@ public: uint32_t split_tuple; bool note_splitting; + NoteType split_base_note; void start_note_splitting (); void end_note_splitting (); @@ -601,6 +602,8 @@ public: void split_notes_more (); void split_notes_less (); void join_notes (); + + void add_split_notes (); };