Loading Plugins in a Plugin

I know this is an old question, but before I go nuts trying to figure things all at once, I just want to know if I’m doing things right. I’m using the Plugin example. It compiles a VST DLL and it runs on Orion. Now, I want to load the Wusik Station VST (.dll file) inside it, and play it, without doing anything extra. I’m using the following to load the VST and connect to a graph object, which seems to be working fine.

[code] // Load VST //
AudioPluginFormatManager::getInstance()->addDefaultFormats();
String errorMessage;
AudioPluginInstance* VSTinstance = 0;
AudioPluginInstance* AudioOutinstance = 0;
AudioPluginInstance* MidiIninstance = 0;
PluginDescription PlugDesc;
PlugDesc.pluginFormatName = T(“vst”);
PlugDesc.fileOrIdentifier = T(“c:\vstplugins\Wusikstation.dll”);
VSTinstance = AudioPluginFormatManager::getInstance()->createPluginInstance (PlugDesc, errorMessage);

AudioProcessorGraph::Node* node = 0;

static juce::uint32 MidiInputID = 0;
static juce::uint32 AudioOutID = 0;
static juce::uint32 VstID = 0;

if (VSTinstance != 0) 
{
	node = graph.addNode (VSTinstance);
	VstID = node->id;

    AudioProcessorGraph::AudioGraphIOProcessor p (AudioProcessorGraph::AudioGraphIOProcessor::audioOutputNode);
    p.fillInPluginDescription (PlugDesc);

	AudioProcessorGraph::AudioGraphIOProcessor p2 (AudioProcessorGraph::AudioGraphIOProcessor::midiInputNode);
    p2.fillInPluginDescription (PlugDesc);

	AudioOutinstance = AudioPluginFormatManager::getInstance()->createPluginInstance (PlugDesc, errorMessage);
	MidiIninstance = AudioPluginFormatManager::getInstance()->createPluginInstance (PlugDesc, errorMessage);

	if (AudioOutinstance != 0)
	{
		node = graph.addNode (VSTinstance);
		AudioOutID = node->id;

		node = graph.addNode (MidiIninstance);
		MidiInputID = node->id;

		bool didConnect = true;
		if (!graph.addConnection(VstID,0,AudioOutID,0)) didConnect = false;
		if (!graph.addConnection(VstID,1,AudioOutID,1)) didConnect = false;
		if (!graph.addConnection(MidiInputID,4096,VstID,4096)) didConnect = false;

		if (!didConnect) AlertWindow::showMessageBox (AlertWindow::WarningIcon,T("Error!"),T("Error Connecting!"));
	}
	else
	{
		AlertWindow::showMessageBox (AlertWindow::WarningIcon,T("Error Loading Wusikstation.dll VST!"),errorMessage);
	}
}
else
{
	AlertWindow::showMessageBox (AlertWindow::WarningIcon,T("Error Loading Wusikstation.dll VST!"),errorMessage);
}

graphPlayer.setProcessor(&graph);[/code]

Now I need to figure out how to play graphPlayer, I guess. In any event, I’m sure that once I rest a bit I can figure it out, but just in case I’m doing something totally stupid and wrong, here’s my current code. :wink:

Best Regards, WilliamK

Surly you don’t want to play the graph through the audio system, you want to expose it as your VST’s effect? A graph is an AudioProcessor, so you’d need to connect that directly to your own AudioPluginInstance, so that any calls are passed straight through.

Got it, thanks. I just need to figure out how to do that. :oops:

Wk

Ok, now, I found a much easier way to load my VST inside my VST. :wink: I just wonder if this is the right way to do this… :oops:

AudioPluginFormatManager::getInstance()->addDefaultFormats(); String errorMessage; PluginDescription PlugDesc; PlugDesc.pluginFormatName = T("vst"); PlugDesc.fileOrIdentifier = T("c:\\vstplugins\\Wusikstation.dll"); VstInstance = AudioPluginFormatManager::getInstance()->createPluginInstance (PlugDesc, errorMessage);

VstInstance is declard in my FilterComponent.h. (AudioPluginInstance* VstInstance;)

void FilterComponent::prepareToPlay (double sampleRate, int samplesPerBlock) { // do your pre-playback setup stuff here.. keyboardState.reset(); VstInstance->prepareToPlay(sampleRate,samplesPerBlock); }

[code]void FilterComponent::processBlock (AudioSampleBuffer& buffer,
MidiBuffer& midiMessages)
{

VstInstance->processBlock(buffer,midiMessages);

keyboardState.processNextMidiBuffer (midiMessages,
                                   0, buffer.getNumSamples(),
                                 true);

}
[/code]

[code]FilterComponent::~FilterComponent()
{
ApplicationProperties::getInstance()->closeFiles();

deleteAndZero(defaultSettings);
deleteAndZero(VstInstance);

}
[/code]

It plays and it works. But I want to ask now, am I missing something, or is that all?

Now I need to figure out how to open the VST GUI in my VST Main Window. 8)

Wk

Yep, you’re on the right track there!

Ok, adding the VST GUI is easier than I first anticipated. Thanks to Juce’s code. 8)

In

I just do:

vstEditor = 0; if (getFilter()->VstInstance != 0) vstEditor = getFilter()->VstInstance->createEditor();

The vstEditor is “AudioProcessorEditor* vstEditor;”

Now, I just do:

And it shows up and it works.

I just need to figure out a bug with Wusik Station and Juce. When I try to load a new preset. But I’m sure its something wrong I’m doing. :wink:

Wk

PRESTO! Its all working now! :mrgreen:

Now I need to handle the plugin state and also some other small things… them I will have a new Wusik Station with the nice TreeView on the Right. Maybe even a global ARP on the side, after I finish this up. :wink: With time, I can also replace my current VST loading code for the effects, and use Juce instead. I could keep wrapping the main Wusik Station VST inside it, until I can re-do the whole code with Juce, which may take 2 or 4 months to complete… Eeek… but that would get me MAC and Linux support, not to mention the other plugin formats. :shock:

Wk

Just one small problem I’m facing now… I want to load a file and send as a Chunk to the VST, but I can’t make it work. The setChunk from Wusik Station is not even called with the code below.

MemoryBlock result2; fileLoad.loadFileAsData(result2); getFilter()->VstInstance->setStateInformation(result2.getData(),result2.getSize());

While the below works without problems:

MemoryBlock result; getFilter()->VstInstance->getStateInformation(result); Thread::sleep(1000); getFilter()->VstInstance->setStateInformation(result.getData(),result.getSize()); Thread::sleep(1000);

I added the Sleep so I could check things out. :wink:

Wk

Ok, I understand a bit better now. The MemoryBlock must be in FXB/FXP format. I see the loadFromFXBFile code now. :shock:

The problem is that I can’t figure out how to arrange my loaded file into a FXB file. I will have to check how to do that.

Wk

I’m trying to load a FXP file into the memory, and pass it up, but its not working. Does it check the VST ID?

Wk

I still can’t get that to work, do you mind pointing me to the right direction? As I want to add multiple VSTs, and the Graph really helps me out with that task. :wink:

Thanks, Wk

I really haven’t time to go through it in detail, but you’re basically writing an AudioPluginInstance that contains an AudioProcessorGraph and which just passes all of its method calls straight through.

Thanks Jules, sorry for such basic questions. I will try harder to figure it out on my own. :oops:

Wk