Browse Source

Save&restore connections on patchbay-plugin

tags/1.9.5
falkTX 10 years ago
parent
commit
65fcdf868e
2 changed files with 73 additions and 3 deletions
  1. +1
    -1
      source/backend/engine/CarlaEngine.cpp
  2. +72
    -2
      source/backend/engine/CarlaEngineNative.cpp

+ 1
- 1
source/backend/engine/CarlaEngine.cpp View File

@@ -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";


+ 72
- 2
source/backend/engine/CarlaEngineNative.cpp View File

@@ -1333,6 +1333,33 @@ protected:
}
}

if (fIsPatchbay)
{
if (const char* const* const patchbayConns = getPatchbayConnections())
{
if (! firstPlugin)
out << "\n";

out << " <Patchbay>\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 << " <Connection>\n";
out << " <Source>" << connSource << "</Source>\n";
out << " <Target>" << connTarget << "</Target>\n";
out << " </Connection>\n";
}

out << " </Patchbay>\n";
}
}

out << "</CARLA-PROJECT>\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> 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);
}


Loading…
Cancel
Save