Skip to content

Commit

Permalink
Add plugin-side parameters to cairoui example
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Oct 11, 2023
1 parent 26373f3 commit 77bd69e
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 185 deletions.
3 changes: 1 addition & 2 deletions examples/CairoUI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
# ------------------------------ #

dpf_add_plugin(d_cairoui
TARGETS jack dssi lv2 vst2
TARGETS clap dssi jack lv2_sep vst2 vst3
UI_TYPE cairo
FILES_DSP
CairoExamplePlugin.cpp
FILES_UI
Artwork.cpp
DemoWidgetBanner.cpp
CairoExampleUI.cpp)

target_include_directories(
Expand Down
135 changes: 113 additions & 22 deletions examples/CairoUI/CairoExamplePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,62 @@ START_NAMESPACE_DISTRHO

class CairoExamplePlugin : public Plugin
{
float fParameters[kParameterCount];

public:
CairoExamplePlugin()
: Plugin(0, 0, 0)
: Plugin(kParameterCount, 0, 0)
{
std::memset(fParameters, 0, sizeof(fParameters));
}

const char* getLabel() const
/**
Get the plugin label.@n
This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
*/
const char* getLabel() const override
{
return "cairo_ui";
}

/**
Get an extensive comment/description about the plugin.
*/
const char* getDescription() const override
{
return "Cairo DPF Example";
}

const char* getMaker() const
/**
Get the plugin author/maker.
*/
const char* getMaker() const override
{
return "Jean Pierre Cimalando";
return "DISTRHO";
}

const char* getLicense() const
/**
Get the plugin license (a single line of text or a URL).@n
For commercial plugins this should return some short copyright information.
*/
const char* getLicense() const override
{
return "ISC";
}

uint32_t getVersion() const
/**
Get the plugin version, in hexadecimal.
*/
uint32_t getVersion() const override
{
return d_version(1, 0, 0);
}

int64_t getUniqueId() const
/**
Get the plugin unique Id.@n
This value is used by LADSPA, DSSI, VST2 and VST3 plugin formats.
*/
int64_t getUniqueId() const override
{
return d_cconst('d', 'C', 'a', 'i');
}
Expand All @@ -58,7 +87,7 @@ class CairoExamplePlugin : public Plugin
Initialize the audio port @a index.@n
This function will be called once, shortly after the plugin is created.
*/
void initAudioPort(bool input, uint32_t index, AudioPort& port) override
void initAudioPort(const bool input, const uint32_t index, AudioPort& port) override
{
// treat meter audio ports as stereo
port.groupId = kPortGroupMono;
Expand All @@ -67,29 +96,91 @@ class CairoExamplePlugin : public Plugin
Plugin::initAudioPort(input, index, port);
}

void initParameter(uint32_t index, Parameter& parameter)
/**
Initialize the parameter @a index.@n
This function will be called once, shortly after the plugin is created.
*/
void initParameter(const uint32_t index, Parameter& parameter) override
{
// unused
(void)index;
(void)parameter;
/**
All parameters in this plugin have the same ranges.
*/
switch (index)
{
case kParameterKnob:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Knob";
parameter.symbol = "knob";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f;
parameter.ranges.def = 0.0f;
break;
case kParameterTriState:
parameter.hints = kParameterIsAutomatable|kParameterIsInteger;
parameter.name = "Color";
parameter.symbol = "color";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 2.0f;
parameter.ranges.def = 0.0f;
parameter.enumValues.count = 3;
parameter.enumValues.restrictedMode = true;
{
ParameterEnumerationValue* const values = new ParameterEnumerationValue[3];
parameter.enumValues.values = values;
values[0].label = "Red";
values[0].value = 0;
values[1].label = "Green";
values[1].value = 1;
values[2].label = "Blue";
values[2].value = 2;
}
break;
case kParameterButton:
parameter.hints = kParameterIsAutomatable|kParameterIsBoolean;
parameter.name = "Button";
parameter.symbol = "button";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f;
parameter.ranges.def = 0.0f;
parameter.enumValues.count = 2;
parameter.enumValues.restrictedMode = true;
{
ParameterEnumerationValue* const values = new ParameterEnumerationValue[2];
parameter.enumValues.values = values;
values[0].label = "Off";
values[0].value = 0;
values[1].label = "On";
values[1].value = 1;
}
break;
}
}

float getParameterValue(uint32_t index) const
/**
Get the current value of a parameter.@n
The host may call this function from any context, including realtime processing.
*/
float getParameterValue(const uint32_t index) const override
{
return 0;

// unused
(void)index;
return fParameters[index];
}

void setParameterValue(uint32_t index, float value)
/**
Change a parameter value.@n
The host may call this function from any context, including realtime processing.@n
When a parameter is marked as automatable, you must ensure no non-realtime operations are performed.
@note This function will only be called for parameter inputs.
*/
void setParameterValue(const uint32_t index, const float value) override
{
// unused
(void)index;
(void)value;
fParameters[index] = value;
}

void run(const float** inputs, float** outputs, uint32_t frames)
/**
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** const inputs, float** const outputs, const uint32_t frames) override
{
/**
This plugin does nothing, it just demonstrates cairo UI usage.
Expand Down
92 changes: 67 additions & 25 deletions examples/CairoUI/CairoExampleUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,56 @@

START_NAMESPACE_DISTRHO

/**
We need a few classes from DGL.
*/
// We need a few classes from DGL.
using DGL_NAMESPACE::CairoGraphicsContext;
using DGL_NAMESPACE::CairoImage;
using DGL_NAMESPACE::CairoImageButton;
using DGL_NAMESPACE::CairoImageKnob;
using DGL_NAMESPACE::CairoImageSwitch;

// And from ourselves
using DGL_NAMESPACE::DemoWidgetBanner;

class CairoExampleUI : public UI
class CairoExampleUI : public UI,
public CairoImageKnob::Callback,
public CairoImageSwitch::Callback,
public DemoWidgetClickable::Callback
{
ScopedPointer<CairoImageKnob> fKnob;
ScopedPointer<CairoImageSwitch> fButton;
ScopedPointer<DemoWidgetBanner> fWidgetBanner;
ScopedPointer<DemoWidgetClickable> fWidgetClickable;

public:
CairoExampleUI()
: UI(200, 200)
{
fWidgetClickable = new DemoWidgetClickable(this);
fWidgetClickable->setSize(50, 50);
fWidgetClickable->setAbsolutePos(100, 100);
CairoImage knobSkin;
knobSkin.loadFromPNG(Artwork::knobData, Artwork::knobDataSize);

fWidgetBanner = new DemoWidgetBanner(this);
fWidgetBanner->setSize(180, 80);
fWidgetBanner->setAbsolutePos(10, 10);
fWidgetBanner->setSize(180, 80);

CairoImage knobSkin;
knobSkin.loadFromPNG(Artwork::knobData, Artwork::knobDataSize);
fWidgetClickable = new DemoWidgetClickable(this);
fWidgetClickable->setAbsolutePos(100, 100);
fWidgetClickable->setSize(50, 50);
fWidgetClickable->setCallback(this);
fWidgetClickable->setId(kParameterTriState);

fKnob = new CairoImageKnob(this, knobSkin);
fKnob->setSize(80, 80);
fKnob->setAbsolutePos(10, 100);
fKnob->setSize(80, 80);
fKnob->setCallback(this);
fKnob->setId(kParameterKnob);

CairoImage buttonOn, buttonOff;
buttonOn.loadFromPNG(Artwork::buttonOnData, Artwork::buttonOnDataSize);
buttonOff.loadFromPNG(Artwork::buttonOffData, Artwork::buttonOffDataSize);

fButton = new CairoImageButton(this, buttonOff, buttonOn);
fButton->setSize(60, 35);
fButton = new CairoImageSwitch(this, buttonOff, buttonOn);
fButton->setAbsolutePos(100, 160);
fButton->setSize(60, 35);
fButton->setCallback(this);
fButton->setId(kParameterButton);

#if 0
// we can use this if/when our resources are scalable, for now they are PNGs
Expand All @@ -67,7 +81,7 @@ class CairoExampleUI : public UI
setSize(200 * scaleFactor, 200 * scaleFactor);
#else
// without scalable resources, let DPF handle the scaling internally
setGeometryConstraints(200, 200, true, true);
setGeometryConstraints(DISTRHO_UI_DEFAULT_WIDTH, DISTRHO_UI_DEFAULT_HEIGHT, true, true);
#endif
}

Expand Down Expand Up @@ -101,18 +115,46 @@ class CairoExampleUI : public UI
}
#endif

void parameterChanged(uint32_t index, float value) override
void parameterChanged(const uint32_t index, const float value) override
{
// unused
(void)index;
(void)value;
switch (index)
{
case kParameterKnob:
fKnob->setValue(value);
break;
case kParameterTriState:
fWidgetClickable->setColorId(static_cast<int>(value + 0.5f));
break;
case kParameterButton:
fButton->setDown(value > 0.5f);
break;
}
}

private:
ScopedPointer<DemoWidgetClickable> fWidgetClickable;
ScopedPointer<DemoWidgetBanner> fWidgetBanner;
ScopedPointer<CairoImageKnob> fKnob;
ScopedPointer<CairoImageButton> fButton;
void demoWidgetClicked(DemoWidgetClickable*, const uint8_t colorId) override
{
setParameterValue(kParameterTriState, colorId);
}

void imageKnobDragStarted(CairoImageKnob*) override
{
editParameter(kParameterKnob, true);
}

void imageKnobDragFinished(CairoImageKnob*) override
{
editParameter(kParameterKnob, false);
}

void imageKnobValueChanged(CairoImageKnob*, const float value) override
{
setParameterValue(kParameterKnob, value);
}

void imageSwitchClicked(CairoImageSwitch*, bool down) override
{
setParameterValue(kParameterButton, down ? 1.f : 0.f);
}
};

UI* createUI()
Expand Down
Loading

0 comments on commit 77bd69e

Please sign in to comment.