From ff1d5e7aebf74e984738d0448265f8964ba5daee Mon Sep 17 00:00:00 2001 From: Todd Naugle Date: Tue, 13 Jul 2021 17:47:33 -0500 Subject: [PATCH] When reconnecting ports, don't give up on first failure. If there are multiple connections, one might fail due to missing hardware, but the rest could still be valid. An easy way to reproduce this was to route "mackie control out" to a device and to the Midi tracer port. When you opened the session again, connection from the "mackie control out" to the device would not get restored because the Midi tracer port does not exist at session start. This most likely caused other issues with connections when changing backends. --- libs/ardour/port.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libs/ardour/port.cc b/libs/ardour/port.cc index 03793c337b..dd5493fc68 100644 --- a/libs/ardour/port.cc +++ b/libs/ardour/port.cc @@ -560,16 +560,23 @@ Port::reconnect () { /* caller must hold process lock; intended to be used only after reestablish() */ - DEBUG_TRACE (DEBUG::Ports, string_compose ("Connect %1 to %2 destinations\n",name(), _connections.size())); + DEBUG_TRACE (DEBUG::Ports, string_compose ("Port::reconnect() Connect %1 to %2 destinations\n",name(), _connections.size())); - for (std::set::iterator i = _connections.begin(); i != _connections.end(); ++i) { - if (connect (*i)) { - _connections.clear (); - return -1; + int count = 0; + std::set::iterator i = _connections.begin(); + + while (i != _connections.end()) { + std::set::iterator current = i++; + if (connect (*current)) { + DEBUG_TRACE (DEBUG::Ports, string_compose ("Port::reconnect() failed to connect %1 to %2\n", name(), (*current))); + _connections.erase (current); + } + else { + ++count; } } - return 0; + return count == 0 ? -1 : 0; } /** @param n Short port name (no port-system client name) */