From 044aec656356f6837b934e089e2ff8c8a90f2f38 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 21 Jun 2024 22:19:28 -0600 Subject: [PATCH] basics of MIDI clip editing notification via model swap --- gtk2_ardour/midi_cue_view.cc | 13 +++++++++++++ gtk2_ardour/midi_cue_view.h | 3 +++ gtk2_ardour/midi_view.cc | 6 +++++- gtk2_ardour/midi_view.h | 3 +++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gtk2_ardour/midi_cue_view.cc b/gtk2_ardour/midi_cue_view.cc index 89011d35fa..062bfa9413 100644 --- a/gtk2_ardour/midi_cue_view.cc +++ b/gtk2_ardour/midi_cue_view.cc @@ -118,3 +118,16 @@ MidiCueView::set_samples_per_pixel (double spp) reset_width_dependent_items (_editing_context.duration_to_pixels (duration)); } + + +std::shared_ptr +MidiCueView::model_to_edit() const +{ + return std::shared_ptr (new ARDOUR::MidiModel (*_model, *(midi_region()->midi_source()))); +} + +void +MidiCueView::post_edit (std::shared_ptr edited_model, ARDOUR::MidiModel::NoteDiffCommand const & diff_command) +{ + _model = edited_model; +} diff --git a/gtk2_ardour/midi_cue_view.h b/gtk2_ardour/midi_cue_view.h index c1e49a7135..6ca8f2e8e9 100644 --- a/gtk2_ardour/midi_cue_view.h +++ b/gtk2_ardour/midi_cue_view.h @@ -51,6 +51,9 @@ class MidiCueView : public MidiView std::shared_ptr tempo_map; ArdourCanvas::Rectangle* event_rect; + + std::shared_ptr model_to_edit() const; + void post_edit (std::shared_ptr, ARDOUR::MidiModel::NoteDiffCommand const &); }; diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index 6290c692d2..703a20d7d3 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -907,10 +907,13 @@ MidiView::apply_note_diff (bool as_subcommand, bool was_copy) } } + std::shared_ptr op_model = model_to_edit (); + { PBD::Unwinder puw (_select_all_notes_after_add, true); /*note that we don't use as_commit here, because that would BEGIN a new undo record; we already have one underway*/ - _model->apply_diff_command_as_subcommand (*_editing_context.session(), _note_diff_command); + op_model->apply_diff_command_as_subcommand (*_editing_context.session(), _note_diff_command); + post_edit (op_model, *_note_diff_command); } if (!as_subcommand) { @@ -924,6 +927,7 @@ MidiView::apply_note_diff (bool as_subcommand, bool was_copy) } _marked_for_velocity.clear(); + } void diff --git a/gtk2_ardour/midi_view.h b/gtk2_ardour/midi_view.h index dcbc22d0cd..288c9bb9e2 100644 --- a/gtk2_ardour/midi_view.h +++ b/gtk2_ardour/midi_view.h @@ -640,6 +640,9 @@ class MidiView : public virtual sigc::trackable void join_notes_on_channel (int channel); void add_split_notes (); + + virtual std::shared_ptr model_to_edit() const { return _model; } + virtual void post_edit (std::shared_ptr, ARDOUR::MidiModel::NoteDiffCommand const &) {} };