diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 69fd04604..06bf860c2 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -1469,6 +1469,9 @@ bool CarlaEngine::saveProject(const char* const filename) if (const char* const* patchbayConns = getPatchbayConnections()) { + if (! firstPlugin) + out << "\n"; + out << " \n"; for (int i=0; patchbayConns[i] != nullptr && patchbayConns[i+1] != nullptr; ++i, ++i ) @@ -2074,10 +2077,9 @@ static int getCarlaPortIdFromName(const char* const shortname) noexcept void CarlaEngine::restorePatchbayConnection(const char* const connSource, const char* const connTarget) { - carla_debug("CarlaEngine::restorePatchbayConnection(\"%s\", \"%s\")", connSource, connTarget); - CARLA_SAFE_ASSERT_RETURN(connSource != nullptr && connSource[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(connTarget != nullptr && connTarget[0] != '\0',); + carla_debug("CarlaEngine::restorePatchbayConnection(\"%s\", \"%s\")", connSource, connTarget); if (pData->bufAudio.usePatchbay) { diff --git a/source/backend/engine/CarlaEngineJack.cpp b/source/backend/engine/CarlaEngineJack.cpp index 284bad617..c7e0b6c08 100644 --- a/source/backend/engine/CarlaEngineJack.cpp +++ b/source/backend/engine/CarlaEngineJack.cpp @@ -982,6 +982,73 @@ public: #endif // ------------------------------------------------------------------- + // Patchbay stuff + + const char* const* getPatchbayConnections() const override + { + CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, nullptr); + carla_debug("CarlaEngineJack::getPatchbayConnections()"); + + LinkedList connList; + + if (const char** ports = jackbridge_get_ports(fClient, nullptr, nullptr, 0)) + { + for (int i=0; ports[i] != nullptr; ++i) + { + jack_port_t* const jackPort(jackbridge_port_by_name(fClient, ports[i])); + const char* const fullPortName(ports[i]); + + CARLA_SAFE_ASSERT_CONTINUE(jackPort != nullptr); + + if (const char** connections = jackbridge_port_get_all_connections(fClient, jackPort)) + { + for (int j=0; connections[j] != nullptr; ++j) + { + connList.append(carla_strdup(fullPortName)); + connList.append(carla_strdup(connections[j])); + } + + jackbridge_free(connections); + } + } + + jackbridge_free(ports); + } + + const size_t connCount(connList.count()); + + if (connCount == 0) + return nullptr; + + const char** const retConns = new const char*[connCount+1]; + + for (size_t i=0; i < connCount; ++i) + retConns[i] = connList.getAt(i); + + retConns[connCount] = nullptr; + connList.clear(); + + return retConns; + } + + void restorePatchbayConnection(const char* const connSource, const char* const connTarget) override + { + CARLA_SAFE_ASSERT_RETURN(fClient != nullptr,); + CARLA_SAFE_ASSERT_RETURN(connSource != nullptr && connSource[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(connTarget != nullptr && connTarget[0] != '\0',); + carla_debug("CarlaEngineJack::restorePatchbayConnection(\"%s\", \"%s\")", connSource, connTarget); + + if (jack_port_t* const port = jackbridge_port_by_name(fClient, connTarget)) + { + if (jackbridge_port_by_name(fClient, connSource) == nullptr) + return; + + if (! jackbridge_port_connected_to(port, connSource)) + jackbridge_connect(fClient, connTarget, connSource); + } + } + + // ------------------------------------------------------------------- protected: void handleJackBufferSizeCallback(const uint32_t newBufferSize)