From dcb482e74d186bb80106ceb54f3665ef79990ac1 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 31 Oct 2025 13:23:37 -0600 Subject: [PATCH] MidiView: adjust API to use when brushing multiple notes --- gtk2_ardour/midi_view.cc | 27 +++++++++++++++++++++------ gtk2_ardour/midi_view.h | 5 +++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index 64b5d3654b..e6d36e20a4 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -841,7 +841,7 @@ MidiView::show_list_editor () * \param snap_t true to snap t to the grid, otherwise false. */ void -MidiView::create_note_at (timepos_t const & source_relative_start, double y, Temporal::Beats length, uint32_t state, bool shift_snap) +MidiView::create_note_at (timepos_t const & source_relative_start, double y, Temporal::Beats length, uint32_t state, bool shift_snap, bool control_reversible_command) { if (!_model) { return; @@ -865,16 +865,18 @@ MidiView::create_note_at (timepos_t const & source_relative_start, double y, Tem return; } - start_note_diff_command(_("add note")); + start_note_diff_command(_("add note"), control_reversible_command); note_diff_add_note (new_note, true, false); - apply_note_diff(); + apply_note_diff (!control_reversible_command); // XXX _editing_context.set_selected_midi_region_view (*this); list to_be_selected; to_be_selected.push_back (new_note->id()); select_notes (to_be_selected, true); - play_midi_note (new_note); + if (do_commit) { + play_midi_note (new_note); + } } void @@ -906,20 +908,33 @@ MidiView::display_model (std::shared_ptr model) } void -MidiView::start_note_diff_command (string name) +MidiView::start_note_diff_command (string name, bool with_reversible_command) { if (!_model) { return; } if (!_note_diff_command) { - _editing_context.begin_reversible_command (name); + if (with_reversible_command) { + _editing_context.begin_reversible_command (name); + } _note_diff_command = _model->new_note_diff_command (name); } else { std::cerr << "ERROR: start_note_diff_command command called, but a note_diff_command was already underway" << std::endl; } } +void +MidiView::end_note_diff_command () +{ + if (!_model) { + return; + } + + _editing_context.commit_reversible_command (); + _note_diff_command = nullptr; +} + void MidiView::note_diff_add_note (const std::shared_ptr note, bool selected, bool show_velocity) { diff --git a/gtk2_ardour/midi_view.h b/gtk2_ardour/midi_view.h index 262209584f..1f6bc467d5 100644 --- a/gtk2_ardour/midi_view.h +++ b/gtk2_ardour/midi_view.h @@ -193,7 +193,8 @@ class MidiView : public virtual sigc::trackable, public LineMerger std::shared_ptr model() const { return _model; } /* note_diff commands should start here; this initiates an undo record */ - void start_note_diff_command (std::string name = "midi edit"); + void start_note_diff_command (std::string name = "midi edit", bool with_reversible_command = true); + void end_note_diff_command (); void note_diff_add_change (NoteBase* ev, ARDOUR::MidiModel::NoteDiffCommand::Property, uint8_t val); void note_diff_add_change (NoteBase* ev, ARDOUR::MidiModel::NoteDiffCommand::Property, Temporal::Beats val); @@ -328,7 +329,7 @@ class MidiView : public virtual sigc::trackable, public LineMerger * \param state the keyboard modifier mask for the canvas event (click). * \param shift_snap true alters snap behavior to round down always (false if the gui has already done that). */ - void create_note_at (Temporal::timepos_t const & t, double y, Temporal::Beats length, uint32_t state, bool shift_snap); + void create_note_at (Temporal::timepos_t const & t, double y, Temporal::Beats length, uint32_t state, bool shift_snap, bool control_reversible_command = true); /** An external request to clear the note selection, remove MRV from editor * selection.