From 4fa4fdf49840a9e7563de5f3bcd9a28815fae890 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 9 Sep 2024 00:16:33 +0200 Subject: [PATCH] Remove patch change GUI Flag when MIDI model changes Previously patch changes were only removed when the removal was initiated by the GUI. --- gtk2_ardour/midi_region_view.cc | 26 ++++++++++---------------- gtk2_ardour/midi_region_view.h | 3 +-- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index c14fbb094f..6563997f60 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -1356,9 +1356,14 @@ MidiRegionView::display_patch_changes () { MidiTimeAxisView* const mtv = dynamic_cast(&trackview); uint16_t chn_mask = mtv->midi_track()->get_playback_channel_mask(); + PatchChanges to_remove = _patch_changes; for (uint8_t i = 0; i < 16; ++i) { - display_patch_changes_on_channel (i, chn_mask & (1 << i)); + display_patch_changes_on_channel (i, chn_mask & (1 << i), to_remove); + } + + for (auto const& i : to_remove) { + _patch_changes.erase (i.first); } } @@ -1366,8 +1371,9 @@ MidiRegionView::display_patch_changes () * them `greyed-out' (as on an inactive channel) */ void -MidiRegionView::display_patch_changes_on_channel (uint8_t channel, bool active_channel) +MidiRegionView::display_patch_changes_on_channel (uint8_t channel, bool active_channel, PatchChanges& to_remove) { + for (MidiModel::PatchChanges::const_iterator i = _model->patch_changes().begin(); i != _model->patch_changes().end(); ++i) { std::shared_ptr p; @@ -1392,6 +1398,8 @@ MidiRegionView::display_patch_changes_on_channel (uint8_t channel, bool active_c p->show(); } + to_remove.erase (p->patch ()); + } else { add_canvas_patch_change (*i); } @@ -2037,18 +2045,6 @@ MidiRegionView::add_canvas_patch_change (MidiModel::PatchChangePtr patch) _patch_changes.insert (make_pair (patch, patch_change)); } -void -MidiRegionView::remove_canvas_patch_change (PatchChange* pc) -{ - /* remove the canvas item */ - for (PatchChanges::iterator x = _patch_changes.begin(); x != _patch_changes.end(); ++x) { - if (x->second->patch() == pc->patch()) { - _patch_changes.erase (x); - break; - } - } -} - MIDI::Name::PatchPrimaryKey MidiRegionView::patch_change_to_patch_key (MidiModel::PatchChangePtr p) { @@ -2102,7 +2098,6 @@ MidiRegionView::change_patch_change (PatchChange& pc, const MIDI::Name::PatchPri _model->apply_diff_command_as_commit (*trackview.session(), c); - remove_canvas_patch_change (&pc); display_patch_changes (); } @@ -2180,7 +2175,6 @@ MidiRegionView::delete_patch_change (PatchChange* pc) c->remove (pc->patch ()); _model->apply_diff_command_as_commit (*trackview.session(), c); - remove_canvas_patch_change (pc); display_patch_changes (); } diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 3534bd01a2..424658ad6e 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -132,7 +132,6 @@ public: void paste_internal (Temporal::timepos_t const & pos, unsigned paste_count, float times, const MidiCutBuffer&); void add_canvas_patch_change (ARDOUR::MidiModel::PatchChangePtr patch); - void remove_canvas_patch_change (PatchChange* pc); /** Look up the given time and channel in the 'automation' and set keys accordingly. * @param time the time of the patch change event @@ -541,7 +540,7 @@ public: void maybe_select_by_position (GdkEventButton* ev, double x, double y); void get_events (Events& e, Evoral::Sequence::NoteOperator op, uint8_t val, int chan_mask = 0); - void display_patch_changes_on_channel (uint8_t, bool); + void display_patch_changes_on_channel (uint8_t, bool, PatchChanges&); void connect_to_diskstream (); void data_recorded (std::weak_ptr);