Browse Source

Info example: Show if host supports parameter changes

Signed-off-by: falkTX <falktx@falktx.com>
pull/277/head
falkTX 4 years ago
parent
commit
87d4cac0fe
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 46 additions and 17 deletions
  1. +5
    -1
      examples/Info/DistrhoPluginInfo.h
  2. +10
    -5
      examples/Info/InfoExamplePlugin.cpp
  3. +31
    -11
      examples/Info/InfoExampleUI.cpp

+ 5
- 1
examples/Info/DistrhoPluginInfo.h View File

@@ -1,6 +1,6 @@
/* /*
* DISTRHO Plugin Framework (DPF) * 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 * 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 * 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_USER_RESIZABLE 1
#define DISTRHO_UI_USE_NANOVG 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__ #ifdef __MOD_DEVICES__
#define DISTRHO_PLUGIN_USES_MODGUI 1 #define DISTRHO_PLUGIN_USES_MODGUI 1
#endif #endif


enum Parameters { enum Parameters {
kParameterBufferSize = 0, kParameterBufferSize = 0,
kParameterCanRequestParameterValueChanges,
kParameterTimePlaying, kParameterTimePlaying,
kParameterTimeFrame, kParameterTimeFrame,
kParameterTimeValidBBT, kParameterTimeValidBBT,


+ 10
- 5
examples/Info/InfoExamplePlugin.cpp View File

@@ -32,8 +32,9 @@ public:
// clear all parameters // clear all parameters
std::memset(fParameters, 0, sizeof(float)*kParameterCount); 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[kParameterBufferSize] = getBufferSize();
fParameters[kParameterCanRequestParameterValueChanges] = canRequestParameterValueChanges();
} }
protected: protected:
@@ -119,11 +120,16 @@ protected:
parameter.name = "BufferSize"; parameter.name = "BufferSize";
parameter.symbol = "buffer_size"; parameter.symbol = "buffer_size";
break; break;
case kParameterTimePlaying:
case kParameterCanRequestParameterValueChanges:
parameter.name = "Parameter Changes";
parameter.symbol = "parameter_changes";
parameter.hints |= kParameterIsBoolean; parameter.hints |= kParameterIsBoolean;
parameter.ranges.max = 1.0f;
break;
case kParameterTimePlaying:
parameter.name = "TimePlaying"; parameter.name = "TimePlaying";
parameter.symbol = "time_playing"; parameter.symbol = "time_playing";
parameter.ranges.min = 0.0f;
parameter.hints |= kParameterIsBoolean;
parameter.ranges.max = 1.0f; parameter.ranges.max = 1.0f;
break; break;
case kParameterTimeFrame: case kParameterTimeFrame:
@@ -131,10 +137,9 @@ protected:
parameter.symbol = "time_frame"; parameter.symbol = "time_frame";
break; break;
case kParameterTimeValidBBT: case kParameterTimeValidBBT:
parameter.hints |= kParameterIsBoolean;
parameter.name = "TimeValidBBT"; parameter.name = "TimeValidBBT";
parameter.symbol = "time_validbbt"; parameter.symbol = "time_validbbt";
parameter.ranges.min = 0.0f;
parameter.hints |= kParameterIsBoolean;
parameter.ranges.max = 1.0f; parameter.ranges.max = 1.0f;
break; break;
case kParameterTimeBar: case kParameterTimeBar:


+ 31
- 11
examples/Info/InfoExampleUI.cpp View File

@@ -26,23 +26,25 @@ START_NAMESPACE_DISTRHO


class InfoExampleUI : public UI class InfoExampleUI : public UI
{ {
static const uint kInitialWidth = 405;
static const uint kInitialHeight = 256;

public: public:
InfoExampleUI() InfoExampleUI()
: UI(405, 256),
: UI(kInitialWidth, kInitialHeight),
fSampleRate(getSampleRate()),
fScale(1.0f) fScale(1.0f)
{ {
std::memset(fParameters, 0, sizeof(float)*kParameterCount); std::memset(fParameters, 0, sizeof(float)*kParameterCount);
std::memset(fStrBuf, 0, sizeof(char)*(0xff+1)); std::memset(fStrBuf, 0, sizeof(char)*(0xff+1));


fSampleRate = getSampleRate();

#ifdef DGL_NO_SHARED_RESOURCES #ifdef DGL_NO_SHARED_RESOURCES
createFontFromFile("sans", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"); createFontFromFile("sans", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf");
#else #else
loadSharedResources(); loadSharedResources();
#endif #endif


setGeometryConstraints(405, 256, true);
setGeometryConstraints(kInitialWidth, kInitialHeight, true);
} }


protected: protected:
@@ -97,7 +99,7 @@ protected:
drawRight(x, y, getTextBufFloat(fSampleRate)); drawRight(x, y, getTextBufFloat(fSampleRate));
y+=lineHeight; y+=lineHeight;


// nothing
// separator
y+=lineHeight; y+=lineHeight;


// time stuff // time stuff
@@ -113,6 +115,14 @@ protected:
drawRight(x, y, getTextBufTime(fParameters[kParameterTimeFrame])); drawRight(x, y, getTextBufTime(fParameters[kParameterTimeFrame]));
y+=lineHeight; 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 // BBT
x = 200.0f * fScale; x = 200.0f * fScale;
y = 15.0f * fScale; y = 15.0f * fScale;
@@ -134,7 +144,7 @@ protected:
y+=lineHeight; y+=lineHeight;


drawLeft(x, y, "Tick:"); drawLeft(x, y, "Tick:");
drawRight(x, y, getTextBufInt(fParameters[kParameterTimeTick]));
drawRight(x, y, getTextBufFloatExtra(fParameters[kParameterTimeTick]));
y+=lineHeight; y+=lineHeight;


drawLeft(x, y, "Bar Start Tick:"); drawLeft(x, y, "Bar Start Tick:");
@@ -161,7 +171,7 @@ protected:


void onResize(const ResizeEvent& ev) override 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); UI::onResize(ev);
} }
@@ -192,6 +202,12 @@ private:
return fStrBuf; 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 char* getTextBufTime(const uint64_t frame)
{ {
const uint32_t time = frame / uint64_t(fSampleRate); const uint32_t time = frame / uint64_t(fSampleRate);
@@ -203,21 +219,25 @@ private:
} }


// helpers for drawing text // 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(); beginPath();
fillColor(200, 200, 200); fillColor(200, 200, 200);
textAlign(ALIGN_RIGHT|ALIGN_TOP); textAlign(ALIGN_RIGHT|ALIGN_TOP);
textBox(x, y, 100 * fScale, text);
textBox(x, y, width, text);
closePath(); 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(); beginPath();
fillColor(255, 255, 255); fillColor(255, 255, 255);
textAlign(ALIGN_LEFT|ALIGN_TOP); textAlign(ALIGN_LEFT|ALIGN_TOP);
textBox(x + (105 * fScale), y, 100 * fScale, text);
textBox(x + (105 * fScale), y, width, text);
closePath(); closePath();
} }




Loading…
Cancel
Save