From fcfa4fecb487465b31b61c7d22c9618c7e92aea5 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 25 Jun 2024 22:59:14 -0600 Subject: [PATCH] more preparation for MIDI cue editing to propagate to the slot (trigger) --- gtk2_ardour/midi_cue_editor.cc | 13 +++++-------- gtk2_ardour/midi_cue_editor.h | 2 +- gtk2_ardour/midi_cue_view.cc | 20 +++++++++++--------- gtk2_ardour/midi_cue_view.h | 15 +++++++++------ gtk2_ardour/midi_view.cc | 15 +++++++++++---- gtk2_ardour/midi_view.h | 3 +-- gtk2_ardour/prh.cc | 8 +++++--- gtk2_ardour/prh.h | 2 +- gtk2_ardour/trigger_page.cc | 2 +- 9 files changed, 45 insertions(+), 35 deletions(-) diff --git a/gtk2_ardour/midi_cue_editor.cc b/gtk2_ardour/midi_cue_editor.cc index 82500ad808..c68884f271 100644 --- a/gtk2_ardour/midi_cue_editor.cc +++ b/gtk2_ardour/midi_cue_editor.cc @@ -401,28 +401,25 @@ MidiCueEditor::toolbox () } void -MidiCueEditor::set_region (std::shared_ptr t, std::shared_ptr r) +MidiCueEditor::set_region (std::shared_ptr t, uint32_t slot_index, std::shared_ptr r) { delete view; view = nullptr; if (!t || !r) { + bg->set_view (nullptr); + prh->set_view (nullptr); return; } - view = new MidiCueView (t, *data_group, *this, *bg, 0xff0000ff); - view->set_region (r); + view = new MidiCueView (t, r, slot_index, *data_group, *this, *bg, 0xff0000ff); bg->set_view (view); - prh->set_view (*view); + prh->set_view (view); double w, h; prh->size_request (w, h); - - /* Move stuff around */ - _timeline_origin = w; - prh->set_position (Duple (0., n_timebars * timebar_height)); data_group->set_position (ArdourCanvas::Duple (w, timebar_height * n_timebars)); h_scroll_group->set_position (Duple (w, 0.)); diff --git a/gtk2_ardour/midi_cue_editor.h b/gtk2_ardour/midi_cue_editor.h index 1556a31449..bdee7c842a 100644 --- a/gtk2_ardour/midi_cue_editor.h +++ b/gtk2_ardour/midi_cue_editor.h @@ -70,7 +70,7 @@ class MidiCueEditor : public CueEditor int32_t get_grid_beat_divisions (Editing::GridType gt) const { return 1; } int32_t get_grid_music_divisions (Editing::GridType gt, uint32_t event_state) const { return 1; } - void set_region (std::shared_ptr, std::shared_ptr); + void set_region (std::shared_ptr, uint32_t slot_index, std::shared_ptr); ArdourCanvas::ScrollGroup* get_hscroll_group () const { return h_scroll_group; } ArdourCanvas::ScrollGroup* get_cursor_scroll_group () const { return cursor_scroll_group; } diff --git a/gtk2_ardour/midi_cue_view.cc b/gtk2_ardour/midi_cue_view.cc index 062bfa9413..273e590a44 100644 --- a/gtk2_ardour/midi_cue_view.cc +++ b/gtk2_ardour/midi_cue_view.cc @@ -18,6 +18,8 @@ #include "ardour/midi_region.h" #include "ardour/midi_source.h" +#include "ardour/midi_track.h" +#include "ardour/triggerbox.h" #include "gtkmm2ext/utils.h" @@ -33,11 +35,14 @@ using namespace Gtkmm2ext; MidiCueView::MidiCueView (std::shared_ptr mt, + std::shared_ptr region, + uint32_t slot_index, ArdourCanvas::Item& parent, EditingContext& ec, MidiViewBackground& bg, uint32_t basic_color) : MidiView (mt, parent, ec, bg, basic_color) + , _slot_index (slot_index) { CANVAS_DEBUG_NAME (_note_group, X_("note group for MIDI cue")); @@ -55,6 +60,7 @@ MidiCueView::MidiCueView (std::shared_ptr mt, _note_group->raise_to_top (); set_extensible (true); + set_region (region); } void @@ -119,15 +125,11 @@ 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) +MidiCueView::post_edit () { - _model = edited_model; + std::cerr << "Post-edit\n"; + std::shared_ptr tb = _midi_track->triggerbox (); + assert (tb); + std::dynamic_pointer_cast(tb->trigger (_slot_index))->edited (); } diff --git a/gtk2_ardour/midi_cue_view.h b/gtk2_ardour/midi_cue_view.h index 6ca8f2e8e9..802a203620 100644 --- a/gtk2_ardour/midi_cue_view.h +++ b/gtk2_ardour/midi_cue_view.h @@ -31,10 +31,13 @@ class MidiCueView : public MidiView { public: MidiCueView (std::shared_ptr mt, - ArdourCanvas::Item& parent, - EditingContext& ec, - MidiViewBackground& bg, - uint32_t basic_color); + std::shared_ptr region, + uint32_t slot_index, + ArdourCanvas::Item& parent, + EditingContext& ec, + MidiViewBackground& bg, + uint32_t basic_color + ); bool canvas_event (GdkEvent*); void set_samples_per_pixel (double); @@ -51,9 +54,9 @@ class MidiCueView : public MidiView std::shared_ptr tempo_map; ArdourCanvas::Rectangle* event_rect; + uint32_t _slot_index; - std::shared_ptr model_to_edit() const; - void post_edit (std::shared_ptr, ARDOUR::MidiModel::NoteDiffCommand const &); + void post_edit (); }; diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index 703a20d7d3..0c8d6af581 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -215,10 +215,12 @@ void MidiView::set_model (std::shared_ptr m) { _model = m; + std::cerr << this << " now has sp " << _model << " with ref " << _model.use_count() << std::endl; assert (_model); //set_height (trackview.current_height()); +#warning paul pianorule needs these fixed /* XXXX region_muted (); region_sync_changed (); @@ -843,6 +845,7 @@ MidiView::start_note_diff_command (string name) { if (!_note_diff_command) { _editing_context.begin_reversible_command (name); + std::cerr << "start note diff on " << _model << " uc " << _model.use_count() << std::endl; _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; @@ -907,17 +910,15 @@ 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*/ - op_model->apply_diff_command_as_subcommand (*_editing_context.session(), _note_diff_command); - post_edit (op_model, *_note_diff_command); + _model->apply_diff_command_as_subcommand (*_editing_context.session(), _note_diff_command); } if (!as_subcommand) { _editing_context.commit_reversible_command (); /*instead, we can explicitly commit the command in progress */ + post_edit (); } _note_diff_command = nullptr; @@ -2748,6 +2749,7 @@ MidiView::note_dropped (NoteBase *, timecnt_t const & d_qn, int8_t dnote, bool c apply_note_diff (true /*subcommand, we don't want this to start a new commit*/, copy); _editing_context.commit_reversible_command (); + post_edit (); // care about notes being moved beyond the upper/lower bounds on the canvas if (lowest_note_in_selection < _midi_context.lowest_note() || @@ -3245,6 +3247,7 @@ MidiView::set_velocities_for_notes (std::vector& notes, std::vectoradd_command (cmd); _editing_context.commit_reversible_command (); + post_edit (); _editing_context.session()->set_dirty (); } diff --git a/gtk2_ardour/midi_view.h b/gtk2_ardour/midi_view.h index 288c9bb9e2..c6c314c647 100644 --- a/gtk2_ardour/midi_view.h +++ b/gtk2_ardour/midi_view.h @@ -641,8 +641,7 @@ class MidiView : public virtual sigc::trackable 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 &) {} + virtual void post_edit () {} }; diff --git a/gtk2_ardour/prh.cc b/gtk2_ardour/prh.cc index 1dacfae315..eb7bfaf0a6 100644 --- a/gtk2_ardour/prh.cc +++ b/gtk2_ardour/prh.cc @@ -104,10 +104,12 @@ PianoRollHeader::resize () } void -PianoRollHeader::set_view (MidiView& v) +PianoRollHeader::set_view (MidiView* v) { - _view = &v; - _view->midi_context().NoteRangeChanged.connect (sigc::mem_fun (*this, &PianoRollHeader::note_range_changed)); + _view = v; + if (_view) { + _view->midi_context().NoteRangeChanged.connect (sigc::mem_fun (*this, &PianoRollHeader::note_range_changed)); + } } void diff --git a/gtk2_ardour/prh.h b/gtk2_ardour/prh.h index 49f0508a09..7f8c93f51c 100644 --- a/gtk2_ardour/prh.h +++ b/gtk2_ardour/prh.h @@ -54,7 +54,7 @@ public: sigc::signal ToggleNoteSelection; sigc::signal ExtendNoteSelection; - void set_view (MidiView&); + void set_view (MidiView*); private: MidiViewBackground& _midi_context; diff --git a/gtk2_ardour/trigger_page.cc b/gtk2_ardour/trigger_page.cc index 8ec9eb4ffa..70468f03a0 100644 --- a/gtk2_ardour/trigger_page.cc +++ b/gtk2_ardour/trigger_page.cc @@ -415,7 +415,7 @@ TriggerPage::selection_changed () std::shared_ptr mr = std::dynamic_pointer_cast (trigger->region()); if (mr) { std::shared_ptr mt = std::dynamic_pointer_cast (entry->strip().stripable()); - _midi_editor->set_region (mt, mr); + _midi_editor->set_region (mt, ref.slot, mr); _midi_editor->viewport().show (); } }