From 3c5ea74acab621d2a53085256ba10ca39279e97f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 26 Sep 2023 04:18:33 +0200 Subject: [PATCH] Fix patch-change dialog channel switch * Correctly show initial patch when switching channels prefer plugin's information, if available * Retain channel and bank when MIDNAM is updated --- gtk2_ardour/patch_change_widget.cc | 41 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/gtk2_ardour/patch_change_widget.cc b/gtk2_ardour/patch_change_widget.cc index 07c6ebd90b..9f159adcd8 100644 --- a/gtk2_ardour/patch_change_widget.cc +++ b/gtk2_ardour/patch_change_widget.cc @@ -485,7 +485,9 @@ void PatchChangeWidget::refresh () { if (get_visible ()) { - on_show (); + int chn = _channel; + _channel = -1; + select_channel (chn); } } @@ -493,7 +495,6 @@ void PatchChangeWidget::on_show () { Gtk::VBox::on_show (); - cancel_audition (); _channel = -1; select_channel (0); } @@ -524,7 +525,11 @@ PatchChangeWidget::select_channel (uint8_t chn) _ac_connections.drop_connections (); - if (std::dynamic_pointer_cast (_route)) { + std::shared_ptr pi; + if ((pi = std::dynamic_pointer_cast (_route->the_instrument ())) && pi->plugin ()->knows_bank_patch ()) { + pi->plugin ()->BankPatchChange.connect (_ac_connections, invalidator (*this), + boost::bind (&PatchChangeWidget::bankpatch_changed, this, _1), gui_context ()); + } else if (std::dynamic_pointer_cast (_route)) { std::shared_ptr bank_msb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_MSB_BANK), true); std::shared_ptr bank_lsb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_LSB_BANK), true); std::shared_ptr program = _route->automation_control (Evoral::Parameter (MidiPgmChangeAutomation, chn), true); @@ -535,14 +540,8 @@ PatchChangeWidget::select_channel (uint8_t chn) boost::bind (&PatchChangeWidget::bank_changed, this), gui_context ()); program->Changed.connect (_ac_connections, invalidator (*this), boost::bind (&PatchChangeWidget::program_changed, this), gui_context ()); - } else if (std::shared_ptr pi = std::dynamic_pointer_cast (_route->the_instrument ())) { - if (pi->plugin ()->knows_bank_patch ()) { - pi->plugin ()->BankPatchChange.connect (_ac_connections, invalidator (*this), - boost::bind (&PatchChangeWidget::bankpatch_changed, this, _1), gui_context ()); - } else { - _no_notifications = true; - // TODO add note: instrument does not report changes. - } + } else { + _no_notifications = true; } refill_banks (); @@ -781,16 +780,17 @@ PatchChangeWidget::note_off_event_handler (int note) int PatchChangeWidget::bank (uint8_t chn) const { + if (std::shared_ptr pi = std::dynamic_pointer_cast (_route->the_instrument ())) { + uint32_t bankpatch = pi->plugin ()->bank_patch (chn); + if (bankpatch != UINT32_MAX) { + return bankpatch >> 7; + } + } if (std::shared_ptr mt = std::dynamic_pointer_cast (_route)) { std::shared_ptr bank_msb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_MSB_BANK), true); std::shared_ptr bank_lsb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_LSB_BANK), true); return ((int)bank_msb->get_value () << 7) + (int)bank_lsb->get_value (); - } else if (std::shared_ptr pi = std::dynamic_pointer_cast (_route->the_instrument ())) { - uint32_t bankpatch = pi->plugin ()->bank_patch (chn); - if (bankpatch != UINT32_MAX) { - return bankpatch >> 7; - } } return 0; } @@ -798,15 +798,16 @@ PatchChangeWidget::bank (uint8_t chn) const uint8_t PatchChangeWidget::program (uint8_t chn) const { - if (std::shared_ptr mt = std::dynamic_pointer_cast (_route)) { - std::shared_ptr program = _route->automation_control (Evoral::Parameter (MidiPgmChangeAutomation, chn), true); - return program->get_value (); - } else if (std::shared_ptr pi = std::dynamic_pointer_cast (_route->the_instrument ())) { + if (std::shared_ptr pi = std::dynamic_pointer_cast (_route->the_instrument ())) { uint32_t bankpatch = pi->plugin ()->bank_patch (chn); if (bankpatch != UINT32_MAX) { return bankpatch & 127; } } + if (std::shared_ptr mt = std::dynamic_pointer_cast (_route)) { + std::shared_ptr program = _route->automation_control (Evoral::Parameter (MidiPgmChangeAutomation, chn), true); + return program->get_value (); + } return 255; }