How to show GUI of plugin added into Clip


#1

I was able to add the following code into the PitchAndTimeDemo and amazingly enough it actually makes the Clip play the audio through a plugin. However, I am having problems making the plugin’s GUI appear. Any ideas about that?

auto clip = getClip();
			if (clip != nullptr)
			{
				PopupMenu plugmenu;
				engine.getPluginManager().knownPluginList.addToMenu(plugmenu, KnownPluginList::sortAlphabetically);
				int r = plugmenu.show();
				if (r > 0)
				{
					int plugId = engine.getPluginManager().knownPluginList.getIndexChosenByMenu(r);
					auto plugDesc = engine.getPluginManager().knownPluginList.getType(plugId);
					if (plugDesc != nullptr)
					{
						Logger::writeToLog(plugDesc->name);
						auto plugInst = edit.getPluginCache().createNewPlugin(te::ExternalPlugin::xmlTypeName, 
							*plugDesc);
						if (plugInst != nullptr)
						{
							String canAdd = clip->canAddClipPlugin(*plugInst);
							if (canAdd.isEmpty())
							{
								bool suc = clip->addClipPlugin(plugInst, selectionManager);
								if (!suc)
								{
									Logger::writeToLog("Could not add plugin to clip");
								}
								else
								{
									plugInst->showWindowExplicitly();
								}
							}
							else
							{
								Logger::writeToLog("can add clip plugin error : " + canAdd);
							}
						}
						else
						{
							Logger::writeToLog("Could not create plugin");
						}
						
					}
				}
			}

#2

You’ll probably need to implement UIBehaviour::createPluginWindowConnection to return a PluginWindowConnection::Master* for the plugin you’re trying to load.

We effectively do this:

    PluginWindowConnection::Master* createPluginWindowConnection (PluginWindowState& pws) override
    {
        if (auto ws = dynamic_cast<Plugin::WindowState*> (&pws))
            return createExternalPluginConnection (*ws);

        return nullptr;
    }

then

PluginWindowConnection::Master* createExternalPluginConnection (Plugin::WindowState& ws)
{
    auto w = std::make_unique<PluginWindow> (ws.plugin);

    if (w->getContentComponent() == nullptr)
        w.reset();

    auto slave = w != nullptr ? w->getSlaveConnection() : nullptr;

    return new PluginWindowConnection::Master (ws, ws.plugin.edit, w.release(), slave);
}

Where PluginWindow is essentially a juce::DocumentWindow that constructs an AudioProcessorEditor in it (like the JUCE plugin host demo).

We should probably add a default implementation of this tbh.


#3

OK, thanks. So more complicated than I anticipated. You probably hate adding anything too GUI specific into the Engine code base, but a straightforward way to show the plugin GUIs would certainly be appreciated!


#4

Yeah, it’s a difficult toss-up as it’s not supposed to be a GUI framework and there are a thousand ways you might want to show a plugin UI.

Examples are a good place for this though as we can add simple UI code which achieves one task and doesn’t pollute the module content. I’ll stick it on the list.


#5

I managed to get it working, thanks for the help!

For anyone else wondering, the implementation is here :

No guarantees of it being correct, of course.


#6

Thanks @Xenakios!

For your effort here is a screenshot showing it working. The cutoff of the VST alters the audio perfect.