13
0

Remove patch change GUI Flag when MIDI model changes

Previously patch changes were only removed when the
removal was initiated by the GUI.
This commit is contained in:
Robin Gareus 2024-09-09 00:16:33 +02:00
parent 3766b22e06
commit 4fa4fdf498
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 11 additions and 18 deletions

View File

@ -1356,9 +1356,14 @@ MidiRegionView::display_patch_changes ()
{ {
MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(&trackview); MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
uint16_t chn_mask = mtv->midi_track()->get_playback_channel_mask(); uint16_t chn_mask = mtv->midi_track()->get_playback_channel_mask();
PatchChanges to_remove = _patch_changes;
for (uint8_t i = 0; i < 16; ++i) { 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) * them `greyed-out' (as on an inactive channel)
*/ */
void 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) { for (MidiModel::PatchChanges::const_iterator i = _model->patch_changes().begin(); i != _model->patch_changes().end(); ++i) {
std::shared_ptr<PatchChange> p; std::shared_ptr<PatchChange> p;
@ -1392,6 +1398,8 @@ MidiRegionView::display_patch_changes_on_channel (uint8_t channel, bool active_c
p->show(); p->show();
} }
to_remove.erase (p->patch ());
} else { } else {
add_canvas_patch_change (*i); 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)); _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 MIDI::Name::PatchPrimaryKey
MidiRegionView::patch_change_to_patch_key (MidiModel::PatchChangePtr p) 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); _model->apply_diff_command_as_commit (*trackview.session(), c);
remove_canvas_patch_change (&pc);
display_patch_changes (); display_patch_changes ();
} }
@ -2180,7 +2175,6 @@ MidiRegionView::delete_patch_change (PatchChange* pc)
c->remove (pc->patch ()); c->remove (pc->patch ());
_model->apply_diff_command_as_commit (*trackview.session(), c); _model->apply_diff_command_as_commit (*trackview.session(), c);
remove_canvas_patch_change (pc);
display_patch_changes (); display_patch_changes ();
} }

View File

@ -132,7 +132,6 @@ public:
void paste_internal (Temporal::timepos_t const & pos, unsigned paste_count, float times, const MidiCutBuffer&); 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 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. /** Look up the given time and channel in the 'automation' and set keys accordingly.
* @param time the time of the patch change event * @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 maybe_select_by_position (GdkEventButton* ev, double x, double y);
void get_events (Events& e, Evoral::Sequence<Temporal::Beats>::NoteOperator op, uint8_t val, int chan_mask = 0); void get_events (Events& e, Evoral::Sequence<Temporal::Beats>::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 connect_to_diskstream ();
void data_recorded (std::weak_ptr<ARDOUR::MidiSource>); void data_recorded (std::weak_ptr<ARDOUR::MidiSource>);