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, VST2 and VST3 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 during compilation of 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 (DSP) 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.

Do note all of DPF code is within its own C++ namespace (DISTRHO for DSP/plugin stuff, DGL for UI stuff).
You can use START_NAMESPACE_DISTRHO / END_NAMESPACE_DISTRHO combo around your code, or globally set USE_NAMESPACE_DISTRHO.
These are defined as compiler macros so that you can override the namespace name during build. When in doubt, just follow the examples.

Examples

Let's begin with some examples.
Here is one of a stereo audio plugin that simply mutes the host output:

/* Make DPF related classes available for us to use without any extra namespace references */
/**
Our custom plugin class.
Subclassing `Plugin` from DPF is how this all works.
By default, only information-related functions and `run` are pure virtual (that is, must be reimplemented).
When enabling certain features (such as programs or states, more on that below), a few extra functions also need to be reimplemented.
*/
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.
*/
uint32_t getVersion() const override
{
return d_version(1, 0, 0);
}
/**
Get the plugin unique Id.
This value is used by LADSPA, DSSI and VST plugin formats.
*/
int64_t getUniqueId() const override
{
return d_cconst('M', 'u', 't', 'e');
}
/* ----------------------------------------------------------------------------------------
* Audio/MIDI Processing */
/**
Run/process function for plugins without MIDI input.
*/
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);
}
};
/**
Create an instance of the Plugin class.
This is the entry point for DPF plugins.
DPF will call this to either create an instance of your plugin for the host or to fetch some initial information for internal caching.
*/
{
return new MutePlugin();
}

See the Plugin class for more information.

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 by default "read-only": the plugin can read them but not change them. (there are exceptions and possibly a request to the host to change values, 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 never 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 d_version(1, 0, 0);
}
int64_t getUniqueId() const override
{
return d_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").
This is meant as 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 d_version(1, 0, 0);
}
int64_t getUniqueId() const override
{
return d_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)
{
// we only have one program so we can skip checking the index
programName = "Default";
}
/* ----------------------------------------------------------------------------------------
* 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)
{
// same as before, ignore index check
fGainL = 1.0f;
fGainR = 1.0f;
}
/* ----------------------------------------------------------------------------------------
* 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;
};

This is a work-in-progress documentation page. States, MIDI, Latency, Time-Position and UI are still TODO.

Plugin::getVersion
virtual uint32_t getVersion() const =0
String
Definition: String.hpp:30
Parameter::ranges
ParameterRanges ranges
Definition: DistrhoPlugin.hpp:493
Parameter
Definition: DistrhoPlugin.hpp:447
d_version
static constexpr uint32_t d_version(const uint8_t major, const uint8_t minor, const uint8_t micro) noexcept
Definition: DistrhoUtils.hpp:84
Plugin::getMaker
virtual const char * getMaker() const =0
Plugin::setParameterValue
virtual void setParameterValue(uint32_t index, float value)
d_cconst
static constexpr int64_t d_cconst(const uint8_t a, const uint8_t b, const uint8_t c, const uint8_t d) noexcept
Definition: DistrhoUtils.hpp:75
Plugin::initProgramName
virtual void initProgramName(uint32_t index, String &programName)=0
Plugin::getLabel
virtual const char * getLabel() const =0
ParameterRanges::def
float def
Definition: DistrhoPlugin.hpp:251
Parameter::name
String name
Definition: DistrhoPlugin.hpp:459
Parameter::symbol
String symbol
Definition: DistrhoPlugin.hpp:474
Plugin::getLicense
virtual const char * getLicense() const =0
Plugin::getUniqueId
virtual int64_t getUniqueId() const =0
Plugin
Definition: DistrhoPlugin.hpp:807
Plugin::run
virtual void run(const float **inputs, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount)=0
createPlugin
Plugin * createPlugin()
kParameterIsAutomable
static const uint32_t kParameterIsAutomable
Definition: DistrhoPlugin.hpp:92
USE_NAMESPACE_DISTRHO
#define USE_NAMESPACE_DISTRHO
Definition: DistrhoInfo.hpp:840
Plugin::loadProgram
virtual void loadProgram(uint32_t index)
ParameterRanges::max
float max
Definition: DistrhoPlugin.hpp:261
ParameterRanges::min
float min
Definition: DistrhoPlugin.hpp:256
Plugin::getParameterValue
virtual float getParameterValue(uint32_t index) const
Plugin::initParameter
virtual void initParameter(uint32_t index, Parameter &parameter)
Parameter::hints
uint32_t hints
Definition: DistrhoPlugin.hpp:452