Dusk Audio Framework
Loading...
Searching...
No Matches
Overview

The Dusk Audio Framework (or DAF 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.

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

Macros

You start by creating a "DafPluginInfo.h" file describing the plugin via macros, see PluginMacros.
This file is included during compilation of the main DAF 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 DAF'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 DAF code is within its own C++ namespace (DAF for DSP/plugin stuff, DGL for UI stuff).
You can use START_NAMESPACE_DAF / END_NAMESPACE_DAF combo around your code, or globally set USE_NAMESPACE_DAF.
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:

/* DAF plugin include */
#include "DafPlugin.hpp"
/* Make DAF related classes available for us to use without any extra namespace references */
/**
Our custom plugin class.
Subclassing `Plugin` from DAF 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 "DAF";
}
/**
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, VST2 and VST3 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 DAF plugins.
DAF 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();
}
Definition DafPlugin.hpp:61
Plugin * createPlugin()
#define USE_NAMESPACE_DAF
Definition DafInfo.hpp:1002

See the Plugin class for more information.

Parameters

A plugin is nothing without parameters.
In DAF 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 "DAF";
}
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.hints = kParameterIsAutomatable;
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;
};
float max
Definition DafDetails.hpp:366
float min
Definition DafDetails.hpp:361
float def
Definition DafDetails.hpp:356
ParameterRanges ranges
Definition DafDetails.hpp:653
uint32_t hints
Definition DafDetails.hpp:612
String symbol
Definition DafDetails.hpp:634
String name
Definition DafDetails.hpp:619

See the Parameter struct for more information about parameters.

Programs

Programs in DAF 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 DAF_PLUGIN_WANT_PROGRAMS to 1 in your DafPluginInfo.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 "DAF";
}
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.hints = kParameterIsAutomatable;
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;
default:
return 0.f;
}
}
/**
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.