From 788314e4f90511d2f6fe53641d2c8273daac55c3 Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 7 Jan 2015 05:45:13 +0000 Subject: [PATCH] Clear group connections before removing in internal patchbay mode --- source/backend/CarlaPlugin.hpp | 1 + source/backend/engine/CarlaEngineGraph.cpp | 62 +++++++++++++++++++--- source/backend/engine/CarlaEngineGraph.hpp | 1 + source/backend/plugin/CarlaPluginDSSI.cpp | 1 + 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/source/backend/CarlaPlugin.hpp b/source/backend/CarlaPlugin.hpp index 57d575415..a1bcf68b5 100644 --- a/source/backend/CarlaPlugin.hpp +++ b/source/backend/CarlaPlugin.hpp @@ -422,6 +422,7 @@ public: * Set the plugin's id to @a newId. * * @see getId() + * @note RT call */ virtual void setId(const uint newId) noexcept; diff --git a/source/backend/engine/CarlaEngineGraph.cpp b/source/backend/engine/CarlaEngineGraph.cpp index d36211e9e..68a6151ef 100644 --- a/source/backend/engine/CarlaEngineGraph.cpp +++ b/source/backend/engine/CarlaEngineGraph.cpp @@ -1229,9 +1229,19 @@ void PatchbayGraph::replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* con CARLA_SAFE_ASSERT_RETURN(oldPlugin != newPlugin,); CARLA_SAFE_ASSERT_RETURN(oldPlugin->getId() == newPlugin->getId(),); - // FIXME + CarlaEngine* const engine(oldPlugin->getEngine()); + CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); + + AudioProcessorGraph::Node* const oldNode(graph.getNodeForId(oldPlugin->getPatchbayNodeId())); + CARLA_SAFE_ASSERT_RETURN(oldNode != nullptr,); + + if (! ignorePathbay) + { + disconnectGroup(engine, oldNode->nodeId); + removeNodeFromPatchbay(engine, oldNode->nodeId, oldNode->getProcessor()); + } - graph.removeNode(oldPlugin->getPatchbayNodeId()); + graph.removeNode(oldNode->nodeId); CarlaPluginInstance* const instance(new CarlaPluginInstance(newPlugin)); AudioProcessorGraph::Node* const node(graph.addNode(instance)); @@ -1258,10 +1268,13 @@ void PatchbayGraph::removePlugin(CarlaPlugin* const plugin) CARLA_SAFE_ASSERT_RETURN(node != nullptr,); if (! ignorePathbay) - removeNodeFromPatchbay(engine, plugin->getPatchbayNodeId(), node->getProcessor()); + { + disconnectGroup(engine, node->nodeId); + removeNodeFromPatchbay(engine, node->nodeId, node->getProcessor()); + } // Fix plugin Ids properties - for (uint i=plugin->getId(), count=engine->getCurrentPluginCount(); igetId()+1, count=engine->getCurrentPluginCount(); igetPlugin(i)); CARLA_SAFE_ASSERT_BREAK(plugin2 != nullptr); @@ -1269,11 +1282,11 @@ void PatchbayGraph::removePlugin(CarlaPlugin* const plugin) if (AudioProcessorGraph::Node* const node2 = graph.getNodeForId(plugin2->getPatchbayNodeId())) { CARLA_SAFE_ASSERT_CONTINUE(node2->properties.getWithDefault("pluginId", -1) != juce::var(-1)); - node2->properties.set("pluginId", static_cast(plugin2->getId())); + node2->properties.set("pluginId", static_cast(i-1)); } } - CARLA_SAFE_ASSERT_RETURN(graph.removeNode(plugin->getPatchbayNodeId()),); + CARLA_SAFE_ASSERT_RETURN(graph.removeNode(node->nodeId),); } void PatchbayGraph::removeAllPlugins(CarlaEngine* const engine) @@ -1290,7 +1303,10 @@ void PatchbayGraph::removeAllPlugins(CarlaEngine* const engine) CARLA_SAFE_ASSERT_CONTINUE(node != nullptr); if (! ignorePathbay) + { + disconnectGroup(engine, node->nodeId); removeNodeFromPatchbay(engine, node->nodeId, node->getProcessor()); + } graph.removeNode(node->nodeId); } @@ -1363,6 +1379,39 @@ bool PatchbayGraph::disconnect(CarlaEngine* const engine, const uint connectionI return false; } +void PatchbayGraph::disconnectGroup(CarlaEngine* const engine, const uint groupId) noexcept +{ + CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); + + for (LinkedList::Itenerator it=connections.list.begin(); it.valid(); it.next()) + { + static const ConnectionToId fallback = { 0, 0, 0, 0, 0 }; + + const ConnectionToId& connectionToId(it.getValue(fallback)); + CARLA_SAFE_ASSERT_CONTINUE(connectionToId.id != 0); + + if (connectionToId.groupA != groupId && connectionToId.groupB != groupId) + continue; + + /* + uint adjustedPortA = connectionToId.portA; + uint adjustedPortB = connectionToId.portB; + + if (! adjustPatchbayPortIdForJuce(adjustedPortA)) + return false; + if (! adjustPatchbayPortIdForJuce(adjustedPortB)) + return false; + + graph.removeConnection(connectionToId.groupA, static_cast(adjustedPortA), + connectionToId.groupB, static_cast(adjustedPortB)); + */ + + engine->callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED, connectionToId.id, 0, 0, 0.0f, nullptr); + + connections.list.remove(it); + } +} + void PatchbayGraph::clearConnections() { connections.clear(); @@ -1376,6 +1425,7 @@ void PatchbayGraph::refreshConnections(CarlaEngine* const engine) CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); connections.clear(); + graph.removeIllegalConnections(); for (int i=0, count=graph.getNumNodes(); i