10

I'm trying to build a small program that hosts vst effects and I would like to scan a folder for plugin dlls.
I know how to find all the dlls but now I have the following questions:

  • What is the best way to determine if a given dll is a vst plugin?
    I tried to just see if the ddl exports the proper function and this works fine for plugins made with the more recent versions of the vst sdk since it exports a method called "VstPluginMain" but older versions export a rather generic "main" function.
  • How do I determine if the plugin is an effect or an instrument?
  • How do I scan vst shell plugins?
    Shell plugins are basically dlls that somehow contain multiple effects. An example of this are the plugins made by Waves Audio http://www.waves.com/

ps: If there is a library that can do all of this for me please let me know.

Dave Gamble
  • 4,146
  • 23
  • 28
Roald
  • 1,722
  • 11
  • 21

3 Answers3

9

How to determine a VST plugin?

Once you've found main/VSTPluginMain... call it! If what's returned is NULL, it's not a VST. If what's returned is a pointer to the bytes "VstP" (see VstInt32 magic; ///< must be #kEffectMagic ('VstP') in aeffect.h), then you have a VST.

The VSTPluginMain returns a pointer to an AEffect structure. You will need to look at this structure.

Effect or instrument? AEffect::flags | (effFlagsIsSynth = 1 << 8)

Shell VSTs are more complex:

Category will be kPlugCategShell

Support the "shellCategory" canDo.

Use effShellGetNextPlugin to enumerate.

To instance, respond to audioMasterCurrentId in your callback with the ID you want.

Dave Gamble
  • 4,146
  • 23
  • 28
  • Thanks for the answer. There's just something that I don't fully get. Let's assume I find a dll that's not a plugin but exports "main" (which seem a pretty common name...) and then returns something from it. Am I not going to be in trouble if I try to dereference that value looking for "VstP"? – Roald Jul 15 '09 at 03:37
  • 1
    Potentially. You would certainly check to see if the pointer was nonzero. You might also consider checking to see if your callback was called. It would make little sense for a user to have stored a malicious DLL in their VSTPlugIns folder. – Dave Gamble Jul 15 '09 at 04:00
  • @DaveGamble Yea, my main concern was malicious code. Good answer! – Qix - MONICA WAS MISTREATED Sep 14 '12 at 19:36
3

@Dave Gamble nailed it, but I wanted to add a few things on VST shell plugins, since they are a bit tricky to work with.

To determine if a VST is a shell plugin, send the effGetPlugCategory opcode to the plugin dispatcher. If it returns kPlugCategShell, then it's a shell plugin. To get the list of sub-plugins in the shell, you basically call effShellGetNextPlugin until it returns 0. Example code snippit (adapted from a working VST host):

// All this stuff should probably be set up far earlier in your code...
// This assumes that you have already opened the plugin and called VSTPluginMain()
typedef VstIntPtr (*Vst2xPluginDispatcherFunc)(AEffect *effect, VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt);
Vst2xPluginDispatcherFunc dispatcher;
AEffect* plugin;
char nameBuffer[40];

while(true) {
  memset(nameBuffer, 0, 40);
  VstInt32 shellPluginId = dispatcher(pluginHandle, effShellGetNextPlugin, 0, 0, nameBuffer, 0.0f);
  if(shellPluginId == 0 || nameBuffer[0] == '\0') {
    break;
  }
  else {
    // Do something with the name and ID
  }
}

If you actually want to load a plugin in a VST shell, it's a bit trickier. First, your host needs to handle the audioMasterCurrentId opcode in the host callback. When you call the VST's VSTPluginMain() method to instantiate the plugin, it will call the host callback with this opcode and ask for the unique ID which should be loaded.

Because this callback is made before the main function returns (and hence, before it delivers an AEffect* to your host), that means that you probably will need to store the shell plugin ID to load in a global variable, since you will not be able to save a pointer to any meaningful data in void* user field of the AEffect struct in time for it to be passed back to you in the host callback.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
1

If you want to develop your VST Host application in .NET take a look at VST.NET

obiwanjacobi
  • 2,413
  • 17
  • 27