commit 87d4cac0fe404877fd34c5aeac51a833b065924a
parent f9ff394a950bafcdb5541d90ff965c48059af06a
Author: falkTX <falktx@falktx.com>
Date: Mon, 24 May 2021 12:54:44 +0100
Info example: Show if host supports parameter changes
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
3 files changed, 46 insertions(+), 17 deletions(-)
diff --git a/examples/Info/DistrhoPluginInfo.h b/examples/Info/DistrhoPluginInfo.h
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -29,12 +29,16 @@
#define DISTRHO_UI_USER_RESIZABLE 1
#define DISTRHO_UI_USE_NANOVG 1
+// only checking if supported, not actually used
+#define DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST 1
+
#ifdef __MOD_DEVICES__
#define DISTRHO_PLUGIN_USES_MODGUI 1
#endif
enum Parameters {
kParameterBufferSize = 0,
+ kParameterCanRequestParameterValueChanges,
kParameterTimePlaying,
kParameterTimeFrame,
kParameterTimeValidBBT,
diff --git a/examples/Info/InfoExamplePlugin.cpp b/examples/Info/InfoExamplePlugin.cpp
@@ -32,8 +32,9 @@ public:
// clear all parameters
std::memset(fParameters, 0, sizeof(float)*kParameterCount);
- // we can know buffer-size right at the start
+ // we can know some things right at the start
fParameters[kParameterBufferSize] = getBufferSize();
+ fParameters[kParameterCanRequestParameterValueChanges] = canRequestParameterValueChanges();
}
protected:
@@ -119,11 +120,16 @@ protected:
parameter.name = "BufferSize";
parameter.symbol = "buffer_size";
break;
- case kParameterTimePlaying:
+ case kParameterCanRequestParameterValueChanges:
+ parameter.name = "Parameter Changes";
+ parameter.symbol = "parameter_changes";
parameter.hints |= kParameterIsBoolean;
+ parameter.ranges.max = 1.0f;
+ break;
+ case kParameterTimePlaying:
parameter.name = "TimePlaying";
parameter.symbol = "time_playing";
- parameter.ranges.min = 0.0f;
+ parameter.hints |= kParameterIsBoolean;
parameter.ranges.max = 1.0f;
break;
case kParameterTimeFrame:
@@ -131,10 +137,9 @@ protected:
parameter.symbol = "time_frame";
break;
case kParameterTimeValidBBT:
- parameter.hints |= kParameterIsBoolean;
parameter.name = "TimeValidBBT";
parameter.symbol = "time_validbbt";
- parameter.ranges.min = 0.0f;
+ parameter.hints |= kParameterIsBoolean;
parameter.ranges.max = 1.0f;
break;
case kParameterTimeBar:
diff --git a/examples/Info/InfoExampleUI.cpp b/examples/Info/InfoExampleUI.cpp
@@ -26,23 +26,25 @@ START_NAMESPACE_DISTRHO
class InfoExampleUI : public UI
{
+ static const uint kInitialWidth = 405;
+ static const uint kInitialHeight = 256;
+
public:
InfoExampleUI()
- : UI(405, 256),
+ : UI(kInitialWidth, kInitialHeight),
+ fSampleRate(getSampleRate()),
fScale(1.0f)
{
std::memset(fParameters, 0, sizeof(float)*kParameterCount);
std::memset(fStrBuf, 0, sizeof(char)*(0xff+1));
- fSampleRate = getSampleRate();
-
#ifdef DGL_NO_SHARED_RESOURCES
createFontFromFile("sans", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf");
#else
loadSharedResources();
#endif
- setGeometryConstraints(405, 256, true);
+ setGeometryConstraints(kInitialWidth, kInitialHeight, true);
}
protected:
@@ -97,7 +99,7 @@ protected:
drawRight(x, y, getTextBufFloat(fSampleRate));
y+=lineHeight;
- // nothing
+ // separator
y+=lineHeight;
// time stuff
@@ -113,6 +115,14 @@ protected:
drawRight(x, y, getTextBufTime(fParameters[kParameterTimeFrame]));
y+=lineHeight;
+ // separator
+ y+=lineHeight;
+
+ // param changes
+ drawLeft(x, y, "Param Changes:", 20);
+ drawRight(x, y, (fParameters[kParameterCanRequestParameterValueChanges] > 0.5f) ? "Yes" : "No", 40);
+ y+=lineHeight;
+
// BBT
x = 200.0f * fScale;
y = 15.0f * fScale;
@@ -134,7 +144,7 @@ protected:
y+=lineHeight;
drawLeft(x, y, "Tick:");
- drawRight(x, y, getTextBufInt(fParameters[kParameterTimeTick]));
+ drawRight(x, y, getTextBufFloatExtra(fParameters[kParameterTimeTick]));
y+=lineHeight;
drawLeft(x, y, "Bar Start Tick:");
@@ -161,7 +171,7 @@ protected:
void onResize(const ResizeEvent& ev) override
{
- fScale = static_cast<float>(ev.size.getHeight())/256.0f;
+ fScale = static_cast<float>(ev.size.getHeight())/static_cast<float>(kInitialHeight);
UI::onResize(ev);
}
@@ -192,6 +202,12 @@ private:
return fStrBuf;
}
+ const char* getTextBufFloatExtra(const float value)
+ {
+ std::snprintf(fStrBuf, 0xff, "%.2f", value + 0.001f);
+ return fStrBuf;
+ }
+
const char* getTextBufTime(const uint64_t frame)
{
const uint32_t time = frame / uint64_t(fSampleRate);
@@ -203,21 +219,25 @@ private:
}
// helpers for drawing text
- void drawLeft(const float x, const float y, const char* const text)
+ void drawLeft(float x, const float y, const char* const text, const int offset = 0)
{
+ const float width = (100.0f + offset) * fScale;
+ x += offset * fScale;
beginPath();
fillColor(200, 200, 200);
textAlign(ALIGN_RIGHT|ALIGN_TOP);
- textBox(x, y, 100 * fScale, text);
+ textBox(x, y, width, text);
closePath();
}
- void drawRight(const float x, const float y, const char* const text)
+ void drawRight(float x, const float y, const char* const text, const int offset = 0)
{
+ const float width = (100.0f + offset) * fScale;
+ x += offset * fScale;
beginPath();
fillColor(255, 255, 255);
textAlign(ALIGN_LEFT|ALIGN_TOP);
- textBox(x + (105 * fScale), y, 100 * fScale, text);
+ textBox(x + (105 * fScale), y, width, text);
closePath();
}