Browse Source

More internal patchbay work, can now remove plugins

tags/1.9.5
falkTX 10 years ago
parent
commit
8c8fac87d6
4 changed files with 79 additions and 14 deletions
  1. +4
    -1
      source/backend/engine/CarlaEngine.cpp
  2. +73
    -11
      source/backend/engine/CarlaEngineGraph.cpp
  3. +1
    -1
      source/backend/engine/CarlaEngineGraph.hpp
  4. +1
    -1
      source/backend/engine/CarlaEngineInternal.hpp

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

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


+ 73
- 11
source/backend/engine/CarlaEngineGraph.cpp View File

@@ -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(); i<numInputs; ++i)
{
engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED, groupId, static_cast<int>(kAudioInputPortOffset)+i,
0, 0.0f, nullptr);
}

for (int i=0, numOutputs=proc->getNumOutputChannels(); i<numOutputs; ++i)
{
engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED, groupId, static_cast<int>(kAudioOutputPortOffset)+i,
0, 0.0f, nullptr);
}

if (proc->acceptsMidi())
{
engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED, groupId, static_cast<int>(kMidiInputPortOffset),
0, 0.0f, nullptr);
}

if (proc->producesMidi())
{
engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED, groupId, static_cast<int>(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<EngineEvent>(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(); i<count; ++i)
for (uint i=plugin->getId(), count=engine->getCurrentPluginCount(); i<count; ++i)
{
CarlaPlugin* const plugin2(engine->getPlugin(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<int>(plugin2->getId()));
CARLA_SAFE_ASSERT_CONTINUE(node2->properties.getWithDefault("pluginId", -1) != juce::var(-1));
node2->properties.set("pluginId", static_cast<int>(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; i<count; ++i)
{
CarlaPlugin* const plugin(engine->getPluginUnchecked(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);
}

// -----------------------------------------------------------------------


+ 1
- 1
source/backend/engine/CarlaEngineGraph.hpp View File

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


+ 1
- 1
source/backend/engine/CarlaEngineInternal.hpp View File

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


Loading…
Cancel
Save