sure, this is my func “create new node”:
void NodeGraphProcessor::createNewNode (const PluginDescriptionAndPreference& description,
const Point<float>* position0to1,
UndoManager* undoManager,
Uuid uuid,
std::function<void(AudioProcessorGraph::Node::Ptr)> callBeforeListeners)
{
Point<float> pos = (position0to1) ? *position0to1 : Point<float>{ Random::getSystemRandom().nextFloat(),
Random::getSystemRandom().nextFloat() };
//===========================================================
std::function<void(AudioProcessorGraph::Node::Ptr)> callback = [this, pos, uuid, callBeforeListeners] (AudioProcessorGraph::Node::Ptr node) {
node->properties.set (ayra::IDs::uuid, uuid.toDashedString());
if (callBeforeListeners) { callBeforeListeners(node); }
if (AudioPluginInstance* instance = dynamic_cast<AudioPluginInstance*>(node->getProcessor()))
{
instance->addHostedParameter(std::make_unique<AudioParameterBool>( ParameterID { "shutdown node", 1 }, "shutdown node", false));
instance->addHostedParameter(std::make_unique<AudioParameterBool>( ParameterID { "bypass node", 2 }, "bypass node", false));
instance->addHostedParameter(std::make_unique<AudioParameterBool>( ParameterID { "editor open", 3 }, "editor open", false));
instance->addListener(this);
}
needUpdatePlayhead();
updateEditorComponentsAsync();
for (ayra::NodeGraphProcessor::Listener* listener : graphListeners) { listener->onNodeCreated(this, node); }
};
//===========================================================
if (!undoManager)
{
if (isGraphInitialized())
{
performInGraphShutdown([this, description, pos, callback]() {
pluginsManager.createNewPlugin(description, graph, pos, callback);
});
} else {
pluginsManager.createNewPlugin(description, graph, pos, callback);
}
} else {
undoManager->perform (new CreateOrRemoveNodeAction (*this, description,
pos, uuid,
callBeforeListeners,
false));
}
}
That calls this one:
void PluginsManager::createNewPlugin (const PluginDescriptionAndPreference& description,
AudioProcessorGraph& graph, Point<float> position,
std::function<void (AudioProcessorGraph::Node::Ptr)> callback)
{
std::shared_ptr<ScopedDPIAwarenessDisabler> dpiDisabler = makeDPIAwarenessDisablerForPlugin(description.pluginDescription);
formatManager.createPluginInstanceAsync (description.pluginDescription,
graph.getSampleRate(),
graph.getBlockSize(),
[this, &graph, position, dpiDisabler, useARA = description.useARA, callback] (std::unique_ptr<AudioPluginInstance> instance, const String& error)
{
addPluginCallback (std::move (instance), graph, error, position, useARA, callback);
});
}
That calls this one:
void PluginsManager::addPluginCallback (std::unique_ptr<AudioPluginInstance> instance,
AudioProcessorGraph& graph,
const String& error,
Point<float> pos,
PluginDescriptionAndPreference::UseARA useARA,
std::function<void(AudioProcessorGraph::Node::Ptr)> callback)
{
if (instance == nullptr)
{
AlertWindow::showMessageBoxAsync (MessageBoxIconType::WarningIcon,
TRANS("Couldn't create plugin"),
error);
}
else
{
#if JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX
if (useARA == PluginDescriptionAndPreference::UseARA::yes
&& instance->getPluginDescription().hasARAExtension)
{
instance = std::make_unique<ARAPluginInstanceWrapper> (std::move (instance));
}
#endif
instance->enableAllBuses();
if (AudioProcessorGraph::Node::Ptr node = graph.addNode (std::move (instance)))
{
AudioProcessor* processor = node->getProcessor();
if (!processor)
{
AlertWindow::showMessageBoxAsync (MessageBoxIconType::WarningIcon,
TRANS("Couldn't find processor for node selected"),
"Couldn't find processor for node selected");
return;
}
node->properties.set (ayra::IDs::name, processor->getName());
node->properties.set (ayra::IDs::uid, (int)node->nodeID.uid);
node->properties.set (ayra::IDs::shutdown, processor->isSuspended());
node->properties.set (ayra::IDs::bypass, node->isBypassed());
node->properties.set (ayra::IDs::posX, pos.x);
node->properties.set (ayra::IDs::posY, pos.y);
Component* editor = processor->getActiveEditor();
DocumentWindow* window = getParentWindowForComponent(editor);
node->properties.set (ayra::IDs::editorOpened, (bool)editor);
node->properties.set (ayra::IDs::windowBounds, ((bool)window) ? window->getWindowStateAsString() : "");
node->properties.set (ayra::IDs::useARA, useARA == PluginDescriptionAndPreference::UseARA::yes);
if (callback) { callback(node); }
sendActionMessage(ayra::Messages::pluginAdded);
}
}
}
(I reused some code from AudioPluginHost)