Loading FXP

I’m trying to load a VST patch (fxp file) to a plugin instance using VSTPluginFormat::loadFromFXBFile (following another post: Possible to load fxb/fxp files from disk?)

bool ProcessDescription::applyProcessorSettings(AudioProcessor * processor, std::string patch)
{
  AudioPluginInstance* plugin = dynamic_cast<AudioPluginInstance*>(processor);
  if (plugin == NULL) throw std::invalid_argument("Passed processor argument cannot be cast to a plugin instance.");
  File f(patch);
  MemoryBlock mb;
  f.loadFileAsData(mb);
  VSTPluginFormat::loadFromFXBFile(plugin, mb.getData(), mb.getSize());
}

However, this does nothing. Looking at the implementation of loadFromFXBFile() inside the juce_VSTPluginFormat.cpp, it expects an argument of type VSTPluginInstance:

bool VSTPluginFormat::loadFromFXBFile (AudioPluginInstance* plugin, const void* data, size_t dataSize)
{
    if (VSTPluginInstance* vst = dynamic_cast<VSTPluginInstance*> (plugin))
        return vst->loadFromFXBFile (data, dataSize);

    return false;
}

Debugging shows that the argument I pass cannot be cast to VSTPluginInstance, so loadFromFXBFile just returns false. The AudioProcessor I pass was loaded from a vst3. Also, the declaration of VSTPluginInstance is hidden inside juce_VSTPluginFormat.cpp so I can’t cast/create an object/pointer of that type to pass to loadFromFXBFile.

How then should I pass a plugin instance for loadFromFXBFile to work…?

Any ideas would be greatly appreciated!

You can do that by using AudioPluginFormatManager:

ScopedPointer<AudioPluginFormatManager> pluginFormatManager = new AudioPluginFormatManager();
pluginFormatManager->addDefaultFormats();
KnownPluginList plist;
OwnedArray<juce::PluginDescription> pluginDescriptions;
juce::VSTPluginFormat format;
plist.scanAndAddFile(A_PATH_WITH_YOUR_PLUGINS, true, pluginDescriptions, format);
// here you have to know which plugin should be used for creating your plugin instance
AudioPluginInstance* instance = pluginFormatManager->createPluginInstance(*pluginDescriptions[0], 0, 0, msg);

Then you should be able to load .fxp and .fxb files from your harddisk:

MemoryBlock mb;
file.loadFileAsData (mb);
VSTPluginFormat::loadFromFXBFile (instance, mb.getData(), mb.getSize());

That’s how it works fine in my application.
Regards
ricochet

1 Like