13
0

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
This commit is contained in:
Robin Gareus 2023-09-26 04:18:33 +02:00
parent 70c3142c2c
commit 3c5ea74aca
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -485,7 +485,9 @@ void
PatchChangeWidget::refresh () PatchChangeWidget::refresh ()
{ {
if (get_visible ()) { if (get_visible ()) {
on_show (); int chn = _channel;
_channel = -1;
select_channel (chn);
} }
} }
@ -493,7 +495,6 @@ void
PatchChangeWidget::on_show () PatchChangeWidget::on_show ()
{ {
Gtk::VBox::on_show (); Gtk::VBox::on_show ();
cancel_audition ();
_channel = -1; _channel = -1;
select_channel (0); select_channel (0);
} }
@ -524,7 +525,11 @@ PatchChangeWidget::select_channel (uint8_t chn)
_ac_connections.drop_connections (); _ac_connections.drop_connections ();
if (std::dynamic_pointer_cast<MidiTrack> (_route)) { std::shared_ptr<PluginInsert> pi;
if ((pi = std::dynamic_pointer_cast<PluginInsert> (_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<MidiTrack> (_route)) {
std::shared_ptr<AutomationControl> bank_msb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_MSB_BANK), true); std::shared_ptr<AutomationControl> bank_msb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_MSB_BANK), true);
std::shared_ptr<AutomationControl> bank_lsb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_LSB_BANK), true); std::shared_ptr<AutomationControl> bank_lsb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_LSB_BANK), true);
std::shared_ptr<AutomationControl> program = _route->automation_control (Evoral::Parameter (MidiPgmChangeAutomation, chn), true); std::shared_ptr<AutomationControl> 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 ()); boost::bind (&PatchChangeWidget::bank_changed, this), gui_context ());
program->Changed.connect (_ac_connections, invalidator (*this), program->Changed.connect (_ac_connections, invalidator (*this),
boost::bind (&PatchChangeWidget::program_changed, this), gui_context ()); boost::bind (&PatchChangeWidget::program_changed, this), gui_context ());
} else if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) { } else {
if (pi->plugin ()->knows_bank_patch ()) { _no_notifications = true;
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.
}
} }
refill_banks (); refill_banks ();
@ -781,16 +780,17 @@ PatchChangeWidget::note_off_event_handler (int note)
int int
PatchChangeWidget::bank (uint8_t chn) const PatchChangeWidget::bank (uint8_t chn) const
{ {
if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
uint32_t bankpatch = pi->plugin ()->bank_patch (chn);
if (bankpatch != UINT32_MAX) {
return bankpatch >> 7;
}
}
if (std::shared_ptr<MidiTrack> mt = std::dynamic_pointer_cast<MidiTrack> (_route)) { if (std::shared_ptr<MidiTrack> mt = std::dynamic_pointer_cast<MidiTrack> (_route)) {
std::shared_ptr<AutomationControl> bank_msb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_MSB_BANK), true); std::shared_ptr<AutomationControl> bank_msb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_MSB_BANK), true);
std::shared_ptr<AutomationControl> bank_lsb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_LSB_BANK), true); std::shared_ptr<AutomationControl> 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 (); return ((int)bank_msb->get_value () << 7) + (int)bank_lsb->get_value ();
} else if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
uint32_t bankpatch = pi->plugin ()->bank_patch (chn);
if (bankpatch != UINT32_MAX) {
return bankpatch >> 7;
}
} }
return 0; return 0;
} }
@ -798,15 +798,16 @@ PatchChangeWidget::bank (uint8_t chn) const
uint8_t uint8_t
PatchChangeWidget::program (uint8_t chn) const PatchChangeWidget::program (uint8_t chn) const
{ {
if (std::shared_ptr<MidiTrack> mt = std::dynamic_pointer_cast<MidiTrack> (_route)) { if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
std::shared_ptr<AutomationControl> program = _route->automation_control (Evoral::Parameter (MidiPgmChangeAutomation, chn), true);
return program->get_value ();
} else if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
uint32_t bankpatch = pi->plugin ()->bank_patch (chn); uint32_t bankpatch = pi->plugin ()->bank_patch (chn);
if (bankpatch != UINT32_MAX) { if (bankpatch != UINT32_MAX) {
return bankpatch & 127; return bankpatch & 127;
} }
} }
if (std::shared_ptr<MidiTrack> mt = std::dynamic_pointer_cast<MidiTrack> (_route)) {
std::shared_ptr<AutomationControl> program = _route->automation_control (Evoral::Parameter (MidiPgmChangeAutomation, chn), true);
return program->get_value ();
}
return 255; return 255;
} }