From 83acd850a20a5f3b6c9cd66b1f084cc87f67e1ba Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 24 Sep 2020 00:38:35 +0100 Subject: [PATCH] Fix plugins having wrong id when switched around in patchbay mode Closes #1259 Signed-off-by: falkTX --- source/backend/engine/CarlaEngine.cpp | 2 +- source/backend/engine/CarlaEngineGraph.cpp | 23 +++++++++++++++++++ source/backend/engine/CarlaEngineGraph.hpp | 1 + source/backend/engine/CarlaEngineInternal.hpp | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 8573b366e..06b769b96 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -992,7 +992,7 @@ bool CarlaEngine::switchPlugins(const uint idA, const uint idB) noexcept const ScopedThreadStopper sts(this); if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY) - pData->graph.replacePlugin(pluginA, pluginB); + pData->graph.switchPlugins(pluginA, pluginB); const ScopedActionLock sal(this, kEnginePostActionSwitchPlugins, idA, idB); diff --git a/source/backend/engine/CarlaEngineGraph.cpp b/source/backend/engine/CarlaEngineGraph.cpp index 1f969035e..bd4f06bf0 100644 --- a/source/backend/engine/CarlaEngineGraph.cpp +++ b/source/backend/engine/CarlaEngineGraph.cpp @@ -1932,6 +1932,23 @@ void PatchbayGraph::renamePlugin(const CarlaPluginPtr plugin, const char* const newName); } +void PatchbayGraph::switchPlugins(CarlaPluginPtr pluginA, CarlaPluginPtr pluginB) +{ + CARLA_SAFE_ASSERT_RETURN(pluginA.get() != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pluginB.get() != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pluginA != pluginB,); + CARLA_SAFE_ASSERT_RETURN(pluginA->getId() != pluginB->getId(),); + + AudioProcessorGraph::Node* const nodeA(graph.getNodeForId(pluginA->getPatchbayNodeId())); + CARLA_SAFE_ASSERT_RETURN(nodeA != nullptr,); + + AudioProcessorGraph::Node* const nodeB(graph.getNodeForId(pluginB->getPatchbayNodeId())); + CARLA_SAFE_ASSERT_RETURN(nodeB != nullptr,); + + nodeA->properties.set("pluginId", static_cast(pluginB->getId())); + nodeB->properties.set("pluginId", static_cast(pluginA->getId())); +} + void PatchbayGraph::reconfigureForCV(const CarlaPluginPtr plugin, const uint portIndex, bool added) { CARLA_SAFE_ASSERT_RETURN(plugin.get() != nullptr,); @@ -2733,6 +2750,12 @@ void EngineInternalGraph::renamePlugin(const CarlaPluginPtr plugin, const char* fPatchbay->renamePlugin(plugin, newName); } +void EngineInternalGraph::switchPlugins(CarlaPluginPtr pluginA, CarlaPluginPtr pluginB) +{ + CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,); + fPatchbay->switchPlugins(pluginA, pluginB); +} + void EngineInternalGraph::removePlugin(const CarlaPluginPtr plugin) { CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,); diff --git a/source/backend/engine/CarlaEngineGraph.hpp b/source/backend/engine/CarlaEngineGraph.hpp index e66554420..cf74c372b 100644 --- a/source/backend/engine/CarlaEngineGraph.hpp +++ b/source/backend/engine/CarlaEngineGraph.hpp @@ -193,6 +193,7 @@ public: void addPlugin(CarlaPluginPtr plugin); void replacePlugin(CarlaPluginPtr oldPlugin, CarlaPluginPtr newPlugin); void renamePlugin(CarlaPluginPtr plugin, const char* newName); + void switchPlugins(CarlaPluginPtr pluginA, CarlaPluginPtr pluginB); void reconfigureForCV(CarlaPluginPtr plugin, const uint portIndex, bool added); void reconfigurePlugin(CarlaPluginPtr plugin, bool portsAdded); void removePlugin(CarlaPluginPtr plugin); diff --git a/source/backend/engine/CarlaEngineInternal.hpp b/source/backend/engine/CarlaEngineInternal.hpp index cddabf47f..63a638dca 100644 --- a/source/backend/engine/CarlaEngineInternal.hpp +++ b/source/backend/engine/CarlaEngineInternal.hpp @@ -115,6 +115,7 @@ public: void addPlugin(CarlaPluginPtr plugin); void replacePlugin(CarlaPluginPtr oldPlugin, CarlaPluginPtr newPlugin); void renamePlugin(CarlaPluginPtr plugin, const char* newName); + void switchPlugins(CarlaPluginPtr pluginA, CarlaPluginPtr pluginB); void removePlugin(CarlaPluginPtr plugin); void removeAllPlugins();