From 79330f909e79c956af752485d01baa79cf8d7da4 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 1 Nov 2021 23:01:27 +0100 Subject: [PATCH] Work around connection loss when re-starting JACK backend If connecting ports using the port-engine fails, ardour forgets the connection. Internal backends only produced an error if a port was already connected, when using ::connect (handle, other), but ignore already existing connection when using port-names. Various ports are connected twice when the engine connects at session load. This worked fine for as long as the engine was never stopped (saving the session asks the port-engine), but failed when the engine went away and internal representation is used. --- libs/ardour/port_engine_shared.cc | 2 +- libs/backends/jack/jack_portengine.cc | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/ardour/port_engine_shared.cc b/libs/ardour/port_engine_shared.cc index cd9c4b3da5..5aae77f2a4 100644 --- a/libs/ardour/port_engine_shared.cc +++ b/libs/ardour/port_engine_shared.cc @@ -81,7 +81,7 @@ BackendPort::connect (BackendPortHandle port, BackendPortHandle self) << " (" << name () << ") -> (" << port->name () << ")" << endmsg; #endif - return -1; + return 0; } store_connection (port); diff --git a/libs/backends/jack/jack_portengine.cc b/libs/backends/jack/jack_portengine.cc index bc78aa95b9..942da6b26b 100644 --- a/libs/backends/jack/jack_portengine.cc +++ b/libs/backends/jack/jack_portengine.cc @@ -617,7 +617,11 @@ int JACKAudioBackend::connect (PortHandle port, const std::string& other) { GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1); - return jack_connect (_priv_jack, jack_port_name (boost::dynamic_pointer_cast(port)->jack_ptr), other.c_str()); + int r = jack_connect (_priv_jack, jack_port_name (boost::dynamic_pointer_cast(port)->jack_ptr), other.c_str()); + if (r == 0 || r == EEXIST) { + return 0; + } + return r; } int JACKAudioBackend::connect (const std::string& src, const std::string& dst) @@ -625,6 +629,9 @@ JACKAudioBackend::connect (const std::string& src, const std::string& dst) GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1); int r = jack_connect (_priv_jack, src.c_str(), dst.c_str()); + if (r == 0 || r == EEXIST) { + return 0; + } return r; }