From 8c8fac87d62668243d7cafb1e3fb01a5413bf081 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 24 Aug 2014 18:30:41 +0100 Subject: [PATCH] More internal patchbay work, can now remove plugins --- source/backend/engine/CarlaEngine.cpp | 5 +- source/backend/engine/CarlaEngineGraph.cpp | 84 ++++++++++++++++--- source/backend/engine/CarlaEngineGraph.hpp | 2 +- source/backend/engine/CarlaEngineInternal.hpp | 2 +- 4 files changed, 79 insertions(+), 14 deletions(-) diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index bfbb82aa8..0814ca9a8 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -606,6 +606,9 @@ bool CarlaEngine::removePlugin(const uint id) plugin2->updateOscURL(); } + // TESTING used in patchbay removal + CARLA_SAFE_ASSERT(plugin->getId() == id); + if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY) pData->graph.removePlugin(plugin); @@ -645,7 +648,7 @@ bool CarlaEngine::removeAllPlugins() #ifndef BUILD_BRIDGE if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY) - pData->graph.removeAllPlugins(); + pData->graph.removeAllPlugins(this, curPluginCount); #endif callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr); diff --git a/source/backend/engine/CarlaEngineGraph.cpp b/source/backend/engine/CarlaEngineGraph.cpp index d8ae7c2d7..b9096e6cd 100644 --- a/source/backend/engine/CarlaEngineGraph.cpp +++ b/source/backend/engine/CarlaEngineGraph.cpp @@ -863,6 +863,39 @@ void addNodeToPatchbay(CarlaEngine* const engine, const uint32_t groupId, const } } +static inline +void removeNodeFromPatchbay(CarlaEngine* const engine, const uint32_t groupId, const AudioProcessor* const proc) +{ + CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); + CARLA_SAFE_ASSERT_RETURN(proc != nullptr,); + + for (int i=0, numInputs=proc->getNumInputChannels(); icallback(ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED, groupId, static_cast(kAudioInputPortOffset)+i, + 0, 0.0f, nullptr); + } + + for (int i=0, numOutputs=proc->getNumOutputChannels(); icallback(ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED, groupId, static_cast(kAudioOutputPortOffset)+i, + 0, 0.0f, nullptr); + } + + if (proc->acceptsMidi()) + { + engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED, groupId, static_cast(kMidiInputPortOffset), + 0, 0.0f, nullptr); + } + + if (proc->producesMidi()) + { + engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED, groupId, static_cast(kMidiOutputPortOffset), + 0, 0.0f, nullptr); + } + + engine->callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED, groupId, 0, 0, 0.0f, nullptr); +} + // ----------------------------------------------------------------------- class CarlaPluginInstance : public AudioPluginInstance @@ -925,6 +958,18 @@ public: void processBlock(AudioSampleBuffer& audio, MidiBuffer& midi) { + CarlaEngine* const engine(fPlugin->getEngine()); + CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); + + if (! fPlugin->isEnabled() || ! fPlugin->tryLock(engine->isOffline())) + { + audio.clear(); + midi.clear(); + return; + } + + fPlugin->initBuffers(); + if (CarlaEngineEventPort* const port = fPlugin->getDefaultEventInPort()) { EngineEvent* const engineEvents(port->fBuffer); @@ -992,6 +1037,8 @@ public: fillJuceMidiBufferFromEngineEvents(midi, engineEvents); carla_zeroStruct(engineEvents, kMaxEngineEventInternalCount); } + + fPlugin->unlock(); } const String getInputChannelName(int i) const override @@ -1135,6 +1182,7 @@ void PatchbayGraph::setOffline(const bool offline) void PatchbayGraph::addPlugin(CarlaPlugin* const plugin) { CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,); + carla_debug("PatchbayGraph::addPlugin(%p)", plugin); CarlaPluginInstance* const instance(new CarlaPluginInstance(plugin)); AudioProcessorGraph::Node* const node(graph.addNode(instance)); @@ -1174,34 +1222,48 @@ void PatchbayGraph::replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* con void PatchbayGraph::removePlugin(CarlaPlugin* const plugin) { CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,); + carla_debug("PatchbayGraph::removePlugin(%p)", plugin); CarlaEngine* const engine(plugin->getEngine()); CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); - // TODO - //removePluginFromPatchbay(plugin); + AudioProcessorGraph::Node* const node(graph.getNodeForId(plugin->getPatchbayNodeId())); + CARLA_SAFE_ASSERT_RETURN(node != nullptr,); + + removeNodeFromPatchbay(engine, plugin->getPatchbayNodeId(), node->getProcessor()); // Fix plugin Ids properties - for (uint i=0, count=engine->getCurrentPluginCount(); igetId(), count=engine->getCurrentPluginCount(); igetPlugin(i)); CARLA_SAFE_ASSERT_BREAK(plugin2 != nullptr); - if (AudioProcessorGraph::Node* const node = graph.getNodeForId(plugin2->getPatchbayNodeId())) + if (AudioProcessorGraph::Node* const node2 = graph.getNodeForId(plugin2->getPatchbayNodeId())) { - CARLA_SAFE_ASSERT_CONTINUE(node->properties.getWithDefault("pluginId", -1) != juce::var(-1)); - node->properties.set("pluginId", static_cast(plugin2->getId())); + CARLA_SAFE_ASSERT_CONTINUE(node2->properties.getWithDefault("pluginId", -1) != juce::var(-1)); + node2->properties.set("pluginId", static_cast(plugin2->getId())); } } CARLA_SAFE_ASSERT_RETURN(graph.removeNode(plugin->getPatchbayNodeId()),); } -void PatchbayGraph::removeAllPlugins() +void PatchbayGraph::removeAllPlugins(CarlaEngine* const engine, const uint32_t count) { - graph.clear(); + CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); + carla_debug("PatchbayGraph::removeAllPlugins(%p, %u)", engine, count); - // TODO + for (uint i=0; igetPluginUnchecked(i)); + CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr); + + AudioProcessorGraph::Node* const node(graph.getNodeForId(plugin->getPatchbayNodeId())); + CARLA_SAFE_ASSERT_CONTINUE(node != nullptr); + + removeNodeFromPatchbay(engine, node->nodeId, node->getProcessor()); + graph.removeNode(node->nodeId); + } } bool PatchbayGraph::connect(CarlaEngine* const engine, const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept @@ -1636,10 +1698,10 @@ void EngineInternalGraph::removePlugin(CarlaPlugin* const plugin) fPatchbay->removePlugin(plugin); } -void EngineInternalGraph::removeAllPlugins() +void EngineInternalGraph::removeAllPlugins(CarlaEngine* const engine, const uint32_t count) { CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,); - fPatchbay->removeAllPlugins(); + fPatchbay->removeAllPlugins(engine, count); } // ----------------------------------------------------------------------- diff --git a/source/backend/engine/CarlaEngineGraph.hpp b/source/backend/engine/CarlaEngineGraph.hpp index badcb28f6..0cc1f6832 100644 --- a/source/backend/engine/CarlaEngineGraph.hpp +++ b/source/backend/engine/CarlaEngineGraph.hpp @@ -131,7 +131,7 @@ struct PatchbayGraph { void addPlugin(CarlaPlugin* const plugin); void replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin); void removePlugin(CarlaPlugin* const plugin); - void removeAllPlugins(); + void removeAllPlugins(CarlaEngine* const engine, const uint32_t count); bool connect(CarlaEngine* const engine, const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept; bool disconnect(CarlaEngine* const engine, const uint connectionId) noexcept; diff --git a/source/backend/engine/CarlaEngineInternal.hpp b/source/backend/engine/CarlaEngineInternal.hpp index a868dade4..a6a3a4dbd 100644 --- a/source/backend/engine/CarlaEngineInternal.hpp +++ b/source/backend/engine/CarlaEngineInternal.hpp @@ -81,7 +81,7 @@ public: void addPlugin(CarlaPlugin* const plugin); void replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin); void removePlugin(CarlaPlugin* const plugin); - void removeAllPlugins(); + void removeAllPlugins(CarlaEngine* const engine, const uint32_t count); private: bool fIsRack;