In Juce 5.3.2 I used this code to create a wrapperprocessor that loads a VST2 plugin:
class WrapperProcessor
: public juce::AudioProcessor
{
public:
WrapperProcessor(juce::AudioPluginInstance* processorToUse): AudioProcessor(getBusesPropertiesFromProcessor(processorToUse)),plugin(processorToUse)
…
auto instance = new WrapperProcessor(pluginFormatManager.createPluginInstance(*pluginDescriptions[0], 44100.0, 512, msg));
This code does not longer work in Juce 5.4. It returns an error:
|Error|C2664|WrapperProcessor::WrapperProcessor(juce::AudioPluginInstance *) : Coversation of Argument 1 from std::unique_ptr<juce::AudioPluginInstance,std::default_deletejuce::AudioPluginInstance> to juce::AudioPluginInstance * not possible
What is the correct way of doing this in juce 5.4 and 6.1?
It now returns a std::unique_ptr<AudioPluginInstance>. This interface makes it clearer that the resutling plugin instance is intended to be owned by the caller. You should adjust the constructor of WrapperProcessor to take a std::unique_ptr<AudioPluginInstance> argument:
class WrapperProcessor : public juce::AudioProcessor
{
public:
WrapperProcessor (std::unique_ptr<juce::AudioPluginInstance> processorToUse)
: AudioProcessor (getBusesPropertiesFromProcessor (*processorToUse)),
plugin (std::move (processorToUse))
{
}
// etc.
private:
std::unique_ptr<juce::AudioPluginInstance> plugin;
};
I’d strongly advise against using a “raw” new call. Instead, prefer to use types that automatically manage resources, such as smart pointers.
auto wrapped = pluginFormatManager.createPluginInstance (*pluginDescriptions[0], 44100.0, 512, msg);
auto instance = std::make_unique<WrapperProcessor> (std::move (wrapped));
I assume that getBusesPropertiesFromProcessor is a function you’ve written. You could either update its signature to take a const AudioProcessor& instead of an AudioProcessor*, or you could pass processorToUse.get() instead of *processorToUse.
I didn’t realise that the new was inside createPluginFilter - this is one of the situations where it’s sort of fine (as long as you return the newed object immediately!). You could also release the unique_ptr after creating it.
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
auto wrapped = pluginFormatManager.createPluginInstance (*pluginDescriptions[0], 44100.0, 512, msg);
return std::make_unique<WrapperProcessor> (std::move (wrapped)).release();
// or
// return new WrapperProcessor (std::move (wrapped));
}