From 27155732ffec22cbce96b04d34bcb163636ca1f0 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 21 Apr 2023 22:34:52 +0200 Subject: [PATCH] MIDI input input follows selection groups This also mitigates an issue that selecting a track in a group may select other tracks. Previously the last selected track's input was connected to MIDI ports, which is usually not the track that the user clicked on. --- libs/ardour/session_midi.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libs/ardour/session_midi.cc b/libs/ardour/session_midi.cc index f6e8439cdc..ad2b3e19b7 100644 --- a/libs/ardour/session_midi.cc +++ b/libs/ardour/session_midi.cc @@ -49,6 +49,7 @@ #include "ardour/midi_track.h" #include "ardour/midi_ui.h" #include "ardour/profile.h" +#include "ardour/route_group.h" #include "ardour/session.h" #include "ardour/transport_master.h" #include "ardour/transport_fsm.h" @@ -771,6 +772,11 @@ Session::rewire_selected_midi (std::shared_ptr new_midi_target) return; } + /* TODO: return, if this is triggered multiple times due to + * group selection. Only handle this for the first route + * in a group. + */ + vector msp; AudioEngine::instance()->get_midi_selection_ports (msp); @@ -780,6 +786,15 @@ Session::rewire_selected_midi (std::shared_ptr new_midi_target) disconnect_port_for_rewire (*p); /* connect it to the new target */ new_midi_target->input()->connect (new_midi_target->input()->nth(0), (*p), this); + /* and grouped tracks */ + RouteGroup* group = new_midi_target->route_group (); + if (group && group->is_active () && group->is_select ()) { + for (auto const& r : *group->route_list ()) { + if (dynamic_pointer_cast (r)) { + r->input()->connect (r->input()->nth(0), (*p), this); + } + } + } } } @@ -811,5 +826,14 @@ Session::rewire_midi_selection_ports () for (vector::const_iterator p = msp.begin(); p != msp.end(); ++p) { disconnect_port_for_rewire (*p); target->input()->connect (target->input()->nth (0), (*p), this); + + RouteGroup* group = target->route_group (); + if (group && group->is_active () && group->is_select ()) { + for (auto const& r : *group->route_list ()) { + if (dynamic_pointer_cast (r)) { + r->input()->connect (r->input()->nth(0), (*p), this); + } + } + } } }