Out of curiosity, I gave ChatGPT (AI that can respond to queries) the following prompt :
“please give me the JUCE C++ Code to host a VST3 plugin.”. Here’s a screenshot of its response, as well as the code (yet to try).
Code:
#include "../JuceLibraryCode/JuceHeader.h"
#include "Vst3PluginFormat.h"
// This example assumes that you have a VST3 plugin with the class name "MyVST3Plugin"
// located in a binary file called "MyVST3Plugin.vst3"
class VST3Host : public AudioAppComponent
{
public:
VST3Host()
{
// Initialize the VST3 plugin format manager
vst3PluginFormatManager.addDefaultFormats();
// Load the VST3 plugin
File vst3PluginFile ("MyVST3Plugin.vst3");
KnownPluginList::addToBlacklist (vst3PluginFile);
pluginInstance = vst3PluginFormatManager.createPluginInstance (vst3PluginFile, getSampleRate());
// Set the plugin's preset
pluginInstance->setCurrentProgram (0);
// Set the plugin's number of channels
pluginInstance->setPlayConfigDetails (2, 2, getSampleRate(), getBlockSize());
// Set the plugin's editor to visible
pluginInstance->setEditorState (true);
// Set the plugin's sample rate and block size
pluginInstance->setSampleRate (getSampleRate());
pluginInstance->setBlockSize (getBlockSize());
}
~VST3Host() override
{
// Release the plugin instance
pluginInstance = nullptr;
}
void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override
{
// Set the plugin's sample rate and block size
pluginInstance->setSampleRate (sampleRate);
pluginInstance->setBlockSize (samplesPerBlockExpected);
}
void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override
{
// Process the audio using the VST3 plugin
pluginInstance->processBlock (bufferToFill.buffer, bufferToFill.startSample, bufferToFill.numSamples);
}
void releaseResources() override {}
private:
VST3PluginFormatManager vst3PluginFormatManager;
AudioPluginInstance::Ptr pluginInstance;
};
// Declare the audio app and start it running
START_JUCE_APPLICATION (VST3Host)