DISTRHO Plugin Framework
DISTRHO Plugin Framework

DISTRHO Plugin Framework (or DPF for short) is a plugin framework designed to make development of new plugins an easy and enjoyable task.
It allows developers to create plugins with custom UIs using a simple C++ API.
The framework facilitates exporting various different plugin formats from the same code-base.

DPF can build for LADSPA, DSSI, LV2 and VST2 formats.
A JACK/Standalone mode is also available, allowing you to quickly test plugins.

Macros

You start by creating a "DistrhoPluginInfo.h" file describing the plugin via macros, see Plugin Macros.
This file is included in the main DPF code to select which features to activate for each plugin format.

For example, a plugin (with UI) that use states will require LV2 hosts to support Atom and Worker extensions for message passing from the UI to the plugin.
If your plugin does not make use of states, the Worker extension is not set as a required feature.

Plugin

The next step is to create your plugin code by subclassing DPF's Plugin class.
You need to pass the number of parameters in the constructor and also the number of programs and states, if any.

Here's an example of an audio plugin that simply mutes the host output:

class MutePlugin : public Plugin
{
public:
/**
Plugin class constructor.
*/
MutePlugin()
: Plugin(0, 0, 0) // 0 parameters, 0 programs and 0 states
{
}
protected:
/* ----------------------------------------------------------------------------------------
* Information */
/**
Get the plugin label.
This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
*/
const char* getLabel() const override
{
return "Mute";
}
/**
Get the plugin author/maker.
*/
const char* getMaker() const override
{
return "DPF";
}
/**
Get the plugin license name (a single line of text).
For commercial plugins this should return some short copyright information.
*/
const char* getLicense() const override
{
return "MIT";
}
/**
Get the plugin version, in hexadecimal.
TODO format to be defined
*/
uint32_t getVersion() const override
{
return 0x1000;
}
/**
Get the plugin unique Id.
This value is used by LADSPA, DSSI and VST plugin formats.
*/
int64_t getUniqueId() const override
{
return cconst('M', 'u', 't', 'e');
}
/* ----------------------------------------------------------------------------------------
* This example has no parameters, so skip parameter stuff */
void initParameter(uint32_t, Parameter&) override {}
float getParameterValue(uint32_t) const override { return 0.0f; }
void setParameterValue(uint32_t, float) override {}
/* ----------------------------------------------------------------------------------------
* Audio/MIDI Processing */
/**
Run/process function for plugins without MIDI input.
NOTE: Some parameters might be null if there are no audio inputs or outputs.
*/
void run(const float**, float** outputs, uint32_t frames) override
{
// get the left and right audio outputs
float* const outL = outputs[0];
float* const outR = outputs[1];
// mute audio
std::memset(outL, 0, sizeof(float)*frames);
std::memset(outR, 0, sizeof(float)*frames);
}
};

See the Plugin class for more information and to understand what each function does.

Parameters

A plugin is nothing without parameters.
In DPF parameters can be inputs or outputs.
They have hints to describe how they behave plus a name and a symbol identifying them.
Parameters also have 'ranges' – a minimum, maximum and default value.

Input parameters are "read-only": the plugin can read them but not change them. (the exception being when changing programs, more on that below)
It's the host responsibility to save, restore and set input parameters.

Output parameters can be changed at anytime by the plugin.
The host will simply read their values and not change them.

Here's an example of an audio plugin that has 1 input parameter:

class GainPlugin : public Plugin
{
public:
/**
Plugin class constructor.
You must set all parameter values to their defaults, matching ParameterRanges::def.
*/
GainPlugin()
: Plugin(1, 0, 0), // 1 parameter, 0 programs and 0 states
fGain(1.0f)
{
}
protected:
/* ----------------------------------------------------------------------------------------
* Information */
const char* getLabel() const override
{
return "Gain";
}
const char* getMaker() const override
{
return "DPF";
}
const char* getLicense() const override
{
return "MIT";
}
uint32_t getVersion() const override
{
return 0x1000;
}
int64_t getUniqueId() const override
{
return cconst('G', 'a', 'i', 'n');
}
/* ----------------------------------------------------------------------------------------
* Init */
/**
Initialize a parameter.
This function will be called once, shortly after the plugin is created.
*/
void initParameter(uint32_t index, Parameter& parameter) override
{
// we only have one parameter so we can skip checking the index
parameter.name = "Gain";
parameter.symbol = "gain";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 2.0f;
parameter.ranges.def = 1.0f;
}
/* ----------------------------------------------------------------------------------------
* Internal data */
/**
Get the current value of a parameter.
*/
float getParameterValue(uint32_t index) const override
{
// same as before, ignore index check
return fGain;
}
/**
Change a parameter value.
*/
void setParameterValue(uint32_t index, float value) override
{
// same as before, ignore index check
fGain = value;
}
/* ----------------------------------------------------------------------------------------
* Audio/MIDI Processing */
void run(const float**, float** outputs, uint32_t frames) override
{
// get the mono input and output
const float* const in = inputs[0];
/* */ float* const out = outputs[0];
// apply gain against all samples
for (uint32_t i=0; i < frames; ++i)
out[i] = in[i] * fGain;
}
private:
float fGain;
};

See the Parameter struct for more information about parameters.

Programs

Programs in DPF refer to plugin-side presets (usually called "factory presets"), an initial set of presets provided by plugin authors included in the actual plugin.

To use programs you must first enable them by setting DISTRHO_PLUGIN_WANT_PROGRAMS to 1 in your DistrhoPluginInfo.h file.
When enabled you'll need to override 2 new function in your plugin code, Plugin::initProgramName(uint32_t, String&) and Plugin::loadProgram(uint32_t).

Here's an example of a plugin with a "default" program:

class PluginWithPresets : public Plugin
{
public:
PluginWithPresets()
: Plugin(2, 1, 0), // 2 parameters, 1 program and 0 states
fGainL(1.0f),
fGainR(1.0f),
{
}
protected:
/* ----------------------------------------------------------------------------------------
* Information */
const char* getLabel() const override
{
return "Prog";
}
const char* getMaker() const override
{
return "DPF";
}
const char* getLicense() const override
{
return "MIT";
}
uint32_t getVersion() const override
{
return 0x1000;
}
int64_t getUniqueId() const override
{
return cconst('P', 'r', 'o', 'g');
}
/* ----------------------------------------------------------------------------------------
* Init */
/**
Initialize a parameter.
This function will be called once, shortly after the plugin is created.
*/
void initParameter(uint32_t index, Parameter& parameter) override
{
parameter.ranges.min = 0.0f;
parameter.ranges.max = 2.0f;
parameter.ranges.def = 1.0f;
switch (index)
{
case 0;
parameter.name = "Gain Right";
parameter.symbol = "gainR";
break;
case 1;
parameter.name = "Gain Left";
parameter.symbol = "gainL";
break;
}
}
/**
Set the name of the program @a index.
This function will be called once, shortly after the plugin is created.
*/
void initProgramName(uint32_t index, String& programName)
{
switch(index)
{
case 0:
programName = "Default";
break;
}
}
/* ----------------------------------------------------------------------------------------
* Internal data */
/**
Get the current value of a parameter.
*/
float getParameterValue(uint32_t index) const override
{
switch (index)
{
case 0;
return fGainL;
case 1;
return fGainR;
}
}
/**
Change a parameter value.
*/
void setParameterValue(uint32_t index, float value) override
{
switch (index)
{
case 0;
fGainL = value;
break;
case 1;
fGainR = value;
break;
}
}
/**
Load a program.
*/
void loadProgram(uint32_t index)
{
switch(index)
{
case 0:
fGainL = 1.0f;
fGainR = 1.0f;
break;
}
}
/* ----------------------------------------------------------------------------------------
* Audio/MIDI Processing */
void run(const float**, float** outputs, uint32_t frames) override
{
// get the left and right audio buffers
const float* const inL = inputs[0];
const float* const inR = inputs[0];
/* */ float* const outL = outputs[0];
/* */ float* const outR = outputs[0];
// apply gain against all samples
for (uint32_t i=0; i < frames; ++i)
{
outL[i] = inL[i] * fGainL;
outR[i] = inR[i] * fGainR;
}
}
private:
float fGainL, fGainR;
};

States

describe them

MIDI

describe them

Latency

describe it

Time-Position

describe it

UI

describe them