From 65fcdf868e680c610c5d3108ffbb86d94e5fcdd0 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 24 Aug 2014 19:42:57 +0100 Subject: [PATCH] Save&restore connections on patchbay-plugin --- source/backend/engine/CarlaEngine.cpp | 2 +- source/backend/engine/CarlaEngineNative.cpp | 74 ++++++++++++++++++++- 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index aae85a6a0..594a3d5cf 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -1157,7 +1157,7 @@ bool CarlaEngine::saveProject(const char* const filename) if (saveConnections) { - if (const char* const* patchbayConns = getPatchbayConnections()) + if (const char* const* const patchbayConns = getPatchbayConnections()) { if (! firstPlugin) out << "\n"; diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index 03246390a..303cb6d13 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -1333,6 +1333,33 @@ protected: } } + if (fIsPatchbay) + { + if (const char* const* const patchbayConns = getPatchbayConnections()) + { + if (! firstPlugin) + out << "\n"; + + out << " \n"; + + for (int i=0; patchbayConns[i] != nullptr && patchbayConns[i+1] != nullptr; ++i, ++i ) + { + const char* const connSource(patchbayConns[i]); + const char* const connTarget(patchbayConns[i+1]); + + CARLA_SAFE_ASSERT_CONTINUE(connSource != nullptr && connSource[0] != '\0'); + CARLA_SAFE_ASSERT_CONTINUE(connTarget != nullptr && connTarget[0] != '\0'); + + out << " \n"; + out << " " << connSource << "\n"; + out << " " << connTarget << "\n"; + out << " \n"; + } + + out << " \n"; + } + } + out << "\n"; return strdup(out.toString().toRawUTF8()); @@ -1340,8 +1367,8 @@ protected: void setState(const char* const data) { - const String text(data); - XmlDocument xml(text); + const String state(data); + XmlDocument xml(state); ScopedPointer xmlElement(xml.getDocumentElement(true)); CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr,); @@ -1362,6 +1389,8 @@ protected: StateSave stateSave; stateSave.fillFromXmlElement(elem); + //callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr); + CARLA_SAFE_ASSERT_CONTINUE(stateSave.type != nullptr); const void* extraStuff = nullptr; @@ -1385,11 +1414,52 @@ protected: if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1)) plugin->loadStateSave(stateSave); } + else + carla_stderr2("Failed to load a plugin, error was:\n%s", getLastError()); //pluginsAdded = true; } } + //callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr); + + // now handle connections + for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement()) + { + const String& tagName(elem->getTagName()); + + if (tagName.equalsIgnoreCase("patchbay")) + { + CarlaString sourcePort, targetPort; + + for (XmlElement* patchElem = elem->getFirstChildElement(); patchElem != nullptr; patchElem = patchElem->getNextElement()) + { + const String& patchTag(patchElem->getTagName()); + + sourcePort.clear(); + targetPort.clear(); + + if (! patchTag.equalsIgnoreCase("connection")) + continue; + + for (XmlElement* connElem = patchElem->getFirstChildElement(); connElem != nullptr; connElem = connElem->getNextElement()) + { + const String& tag(connElem->getTagName()); + const String text(connElem->getAllSubText().trim()); + + if (tag.equalsIgnoreCase("source")) + sourcePort = text.toRawUTF8(); + else if (tag.equalsIgnoreCase("target")) + targetPort = text.toRawUTF8(); + } + + if (sourcePort.isNotEmpty() && targetPort.isNotEmpty()) + restorePatchbayConnection(sourcePort, targetPort); + } + break; + } + } + //if (pluginsAdded) // pHost->dispatcher(pHost->handle, HOST_OPCODE_RELOAD_ALL, 0, 0, nullptr, 0.0f); }