Let’s add some presets to our distortion plugin! Presets allow your plugin to store values for its parameters. For now, a preset consists of a name and values for all the parameters. We will later see that you can actually store arbitrary data. Presets are sometimes called programs.
First, let’s make the GUI a little wider so we can see the host’s preset selection better. Open resource.h and change the constant:
// GUI default dimensions
#define GUI_WIDTH 400
In DigitalDistortion.h, declare a private member function:
private:
double mThreshold;
void CreatePresets();
Add the implementation to DigitalDistortion.cpp:
void DigitalDistortion::CreatePresets() {
MakePreset("clean", 100.0);
MakePreset("slightly distorted", 80.0);
MakePreset("woooo", 40.0);
MakePreset("waaaa", 20.0);
MakePreset("buzzz!!!", 0.01);
}
MakePreset
takes the name of the preset, followed by values for all parameters. The order is defined in the enum EParams
at the top of the file. Notice how the values are between 0 and 100, not between 0 and 1. They refer to the parameter kThreshold
, not to the mThreshold
member variable.
Remove the MakeDefaultPreset
call at the end of the constructor and instead call CreatePresets
:
DigitalDistortion::DigitalDistortion(IPlugInstanceInfo instanceInfo)
: IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), mThreshold(1.)
{
// ...
CreatePresets();
}
Finally, we have to change the constant in line 13 (which is passed to the base class constructor call):
const int kNumPrograms = 5;
If this is a higher number than the times you call MakePreset
, the remaining presets will just be called “Empty”.
Run the VST2 target. You may have to remove the plugin from your track and insert it again to get the newly added presets. You can change presets by using the dropdown above your plugin GUI. Change presets and watch how the knob takes different values and the distortion amount changes. Remember, when you change presets, OnParamChange
is called for every parameter.
To the right of the dropdown menu there’s a button which opens the preset menu:
Try renaming a preset and turn the knob. These changes would be lost if you removed the plugin and inserted it again. To save them, click “Export VST patch/bank file (.fxp/.fxb)…” and save the file test.fxb to your desktop. Remove the plugin, insert it again and import test.fxb to restore your changes.
VST plugins use the FXP format to store a single preset, and the FXB format to store a bank of them.
Run the AU target (you may have to Edit Scheme first to make it run in Reaper). Make sure you actually insert the AU plugin and not the VST. Note how Reaper defaults to “No preset”, but all presets are there in the dropdown menu and everything works as expected. Saving presets is a little different: You can’t import or export banks. For more details on preset saving see this post by Oli Larkin.
Now let’s add a better GUI!