From c778ded41145c75cef41c291d7999bb4b7e9ef59 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 19 Jul 2020 01:07:57 +0200 Subject: [PATCH] Auto-connect MIDI track/bus when output ports change previously this subscription was handle done in Route::add_routes() -> add_routes_inner() for MIDI tracks only. Since f6c0b02d9f0439e5d5ab54 this was only done when adding tracks, after any instruments were loaded (and fanned out). --- libs/ardour/session.cc | 5 ++++- libs/ardour/session_state.cc | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 8b10e2ad2f..49b653a684 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -2556,6 +2556,10 @@ Session::midi_output_change_handler (IOChange change, void * /*src*/, boost::wea { boost::shared_ptr midi_route (wr.lock()); + if (!midi_route) { + return; + } + if ((change.type & IOChange::ConfigurationChanged) && Config->get_output_auto_connect() != ManualConnect) { if (change.after.n_audio() <= change.before.n_audio()) { @@ -3266,7 +3270,6 @@ Session::load_and_connect_instruments (RouteList& new_routes, bool strict_io, bo for (RouteList::iterator r = new_routes.begin(); r != new_routes.end(); ++r) { (*r)->output()->changed.connect_same_thread (*this, boost::bind (&Session::midi_output_change_handler, this, _1, _2, boost::weak_ptr(*r))); } - } void diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index ab18b904fc..0a46da2e4e 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -1846,6 +1846,16 @@ Session::load_routes (const XMLNode& node, int version) add_routes (new_routes, false, false, PresentationInfo::max_order); + /* re-subscribe to MIDI connection handler */ + for (RouteList::iterator r = new_routes.begin(); r != new_routes.end(); ++r) { + boost::shared_ptr mt = boost::dynamic_pointer_cast (*r); + bool is_midi_route = (*r)->n_inputs().n_midi() > 0 && (*r)->n_inputs().n_midi() > 0; + if (mt || is_midi_route) { + (*r)->output()->changed.connect_same_thread (*this, boost::bind (&Session::midi_output_change_handler, this, _1, _2, boost::weak_ptr(*r))); + } + } + + BootMessage (_("Finished adding tracks/busses")); return 0;