@@ -25,6 +25,9 @@ | |||
#if DISTRHO_UI_USE_NANOVG | |||
# include "../dgl/NanoVG.hpp" | |||
typedef DGL::NanoWidget UIWidget; | |||
#elif DISTRHO_UI_USE_NTK | |||
# include "FL/Fl_Double_Window.H" | |||
typedef Fl_Double_Window UIWidget; | |||
#else | |||
typedef DGL::Widget UIWidget; | |||
#endif | |||
@@ -44,19 +47,19 @@ public: | |||
// Host DSP State | |||
double d_getSampleRate() const noexcept; | |||
void d_editParameter(uint32_t index, bool started); | |||
void d_setParameterValue(uint32_t index, float value); | |||
void d_editParameter(const uint32_t index, const bool started); | |||
void d_setParameterValue(const uint32_t index, const float value); | |||
#if DISTRHO_PLUGIN_WANT_STATE | |||
void d_setState(const char* key, const char* value); | |||
void d_setState(const char* const key, const char* const value); | |||
#endif | |||
#if DISTRHO_PLUGIN_IS_SYNTH | |||
void d_sendNote(uint8_t channel, uint8_t note, uint8_t velocity); | |||
void d_sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity); | |||
#endif | |||
// ------------------------------------------------------------------- | |||
// Host UI State | |||
void d_setSize(uint width, uint height); | |||
void d_setSize(const uint width, const uint height); | |||
#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS | |||
// ------------------------------------------------------------------- | |||
@@ -33,7 +33,7 @@ const ParameterRanges PluginExporter::sFallbackRanges; | |||
// ----------------------------------------------------------------------- | |||
// Plugin | |||
Plugin::Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount) | |||
Plugin::Plugin(const uint32_t parameterCount, const uint32_t programCount, const uint32_t stateCount) | |||
: pData(new PrivateData()) | |||
{ | |||
if (parameterCount > 0) | |||
@@ -42,21 +42,25 @@ Plugin::Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCou | |||
pData->parameters = new Parameter[parameterCount]; | |||
} | |||
#if DISTRHO_PLUGIN_WANT_PROGRAMS | |||
if (programCount > 0) | |||
{ | |||
#if DISTRHO_PLUGIN_WANT_PROGRAMS | |||
pData->programCount = programCount; | |||
pData->programNames = new d_string[programCount]; | |||
#endif | |||
} | |||
#else | |||
DISTRHO_SAFE_ASSERT(programCount == 0); | |||
#endif | |||
#if DISTRHO_PLUGIN_WANT_STATE | |||
if (stateCount > 0) | |||
{ | |||
#if DISTRHO_PLUGIN_WANT_STATE | |||
pData->stateCount = stateCount; | |||
pData->stateKeys = new d_string[stateCount]; | |||
#endif | |||
} | |||
#else | |||
DISTRHO_SAFE_ASSERT(stateCount == 0); | |||
#endif | |||
} | |||
Plugin::~Plugin() | |||
@@ -88,22 +92,25 @@ const TimePos& Plugin::d_getTimePos() const noexcept | |||
#endif | |||
#if DISTRHO_PLUGIN_WANT_LATENCY | |||
void Plugin::d_setLatency(uint32_t frames) noexcept | |||
void Plugin::d_setLatency(const uint32_t frames) noexcept | |||
{ | |||
pData->latency = frames; | |||
} | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
// Callbacks (optional) | |||
void Plugin::d_bufferSizeChanged(uint32_t) | |||
#if DISTRHO_PLUGIN_HAS_MIDI_OUTPUT | |||
bool Plugin::d_writeMidiEvent(const MidiEvent& /*midiEvent*/) noexcept | |||
{ | |||
// TODO | |||
return false; | |||
} | |||
#endif | |||
void Plugin::d_sampleRateChanged(double) | |||
{ | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Callbacks (optional) | |||
void Plugin::d_bufferSizeChanged(uint32_t) {} | |||
void Plugin::d_sampleRateChanged(double) {} | |||
// ----------------------------------------------------------------------- | |||
@@ -93,6 +93,10 @@ | |||
# define DISTRHO_UI_USE_NANOVG 0 | |||
#endif | |||
#ifndef DISTRHO_UI_USE_NTK | |||
# define DISTRHO_UI_USE_NTK 0 | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
// Define DISTRHO_UI_URI if needed | |||
@@ -393,7 +393,7 @@ public: | |||
return fData->sampleRate; | |||
} | |||
void setBufferSize(const uint32_t bufferSize, bool doCallback = false) | |||
void setBufferSize(const uint32_t bufferSize, const bool doCallback = false) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,); | |||
@@ -412,7 +412,7 @@ public: | |||
} | |||
} | |||
void setSampleRate(const double sampleRate, bool doCallback = false) | |||
void setSampleRate(const double sampleRate, const bool doCallback = false) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr,); | |||
@@ -48,25 +48,25 @@ double UI::d_getSampleRate() const noexcept | |||
return pData->sampleRate; | |||
} | |||
void UI::d_editParameter(uint32_t index, bool started) | |||
void UI::d_editParameter(const uint32_t index, const bool started) | |||
{ | |||
pData->editParamCallback(index + pData->parameterOffset, started); | |||
} | |||
void UI::d_setParameterValue(uint32_t index, float value) | |||
void UI::d_setParameterValue(const uint32_t index, const float value) | |||
{ | |||
pData->setParamCallback(index + pData->parameterOffset, value); | |||
} | |||
#if DISTRHO_PLUGIN_WANT_STATE | |||
void UI::d_setState(const char* key, const char* value) | |||
void UI::d_setState(const char* const key, const char* const value) | |||
{ | |||
pData->setStateCallback(key, value); | |||
} | |||
#endif | |||
#if DISTRHO_PLUGIN_IS_SYNTH | |||
void UI::d_sendNote(uint8_t channel, uint8_t note, uint8_t velocity) | |||
void UI::d_sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity) | |||
{ | |||
pData->sendNoteCallback(channel, note, velocity); | |||
} | |||
@@ -75,7 +75,7 @@ void UI::d_sendNote(uint8_t channel, uint8_t note, uint8_t velocity) | |||
// ----------------------------------------------------------------------- | |||
// Host UI State | |||
void UI::d_setSize(uint width, uint height) | |||
void UI::d_setSize(const uint width, const uint height) | |||
{ | |||
pData->setSizeCallback(width, height); | |||
} | |||
@@ -93,9 +93,7 @@ void* UI::d_getPluginInstancePointer() const noexcept | |||
// ----------------------------------------------------------------------- | |||
// DSP Callbacks (optional) | |||
void UI::d_sampleRateChanged(double) | |||
{ | |||
} | |||
void UI::d_sampleRateChanged(double) {} | |||
// ----------------------------------------------------------------------- | |||
// UI Callbacks (optional) | |||
@@ -140,6 +140,11 @@ public: | |||
} | |||
#endif | |||
void dssiui_samplerate(const double sampleRate) | |||
{ | |||
fUI.setSampleRate(sampleRate, true); | |||
} | |||
void dssiui_show() | |||
{ | |||
fUI.setVisible(true); | |||
@@ -322,6 +327,9 @@ int osc_sample_rate_handler(const char*, const char*, lo_arg** argv, int, lo_mes | |||
d_lastUiSampleRate = sampleRate; | |||
if (globalUI != nullptr) | |||
globalUI->dssiui_samplerate(sampleRate); | |||
return 0; | |||
} | |||
@@ -19,12 +19,16 @@ | |||
#include "../DistrhoUI.hpp" | |||
#include "../../dgl/App.hpp" | |||
#include "../../dgl/Window.hpp" | |||
#if DISTRHO_UI_USE_NTK | |||
# include "FL/Fl_Double_Window.H" | |||
typedef Fl_Double_Window Window; | |||
#else | |||
# include "../../dgl/App.hpp" | |||
# include "../../dgl/Window.hpp" | |||
using DGL::App; | |||
using DGL::IdleCallback; | |||
using DGL::Window; | |||
#endif | |||
START_NAMESPACE_DISTRHO | |||
@@ -145,15 +149,15 @@ class UIExporterWindow : public Window | |||
public: | |||
UIExporterWindow(App& app, const intptr_t winId, void* const dspPtr) | |||
: Window(app, winId), | |||
fUi(createUiWrapper(dspPtr, this)), | |||
fUI(createUiWrapper(dspPtr, this)), | |||
fIsReady(false) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
const int width = fUi->d_getWidth(); | |||
const int height = fUi->d_getHeight(); | |||
const int width = fUI->d_getWidth(); | |||
const int height = fUI->d_getHeight(); | |||
fUi->setSize(width, height); | |||
fUI->setSize(width, height); | |||
setResizable(false); | |||
setSize(width, height); | |||
@@ -161,12 +165,12 @@ public: | |||
~UIExporterWindow() | |||
{ | |||
delete fUi; | |||
delete fUI; | |||
} | |||
UI* getUI() const noexcept | |||
{ | |||
return fUi; | |||
return fUI; | |||
} | |||
bool isReady() const noexcept | |||
@@ -177,16 +181,16 @@ public: | |||
protected: | |||
void onReshape(int width, int height) override | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
fUi->setSize(width, height); | |||
fUi->d_uiReshape(width, height); | |||
fUI->setSize(width, height); | |||
fUI->d_uiReshape(width, height); | |||
fIsReady = true; | |||
} | |||
private: | |||
UI* const fUi; | |||
UI* const fUI; | |||
bool fIsReady; | |||
}; | |||
@@ -201,10 +205,10 @@ public: | |||
void* const dspPtr = nullptr) | |||
: glApp(), | |||
glWindow(glApp, winId, dspPtr), | |||
fUi(glWindow.getUI()), | |||
fData((fUi != nullptr) ? fUi->pData : nullptr) | |||
fUI(glWindow.getUI()), | |||
fData((fUI != nullptr) ? fUI->pData : nullptr) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,); | |||
fData->ptr = ptr; | |||
@@ -219,23 +223,23 @@ public: | |||
const char* getName() const noexcept | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr, ""); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, ""); | |||
return fUi->d_getName(); | |||
return fUI->d_getName(); | |||
} | |||
uint getWidth() const noexcept | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr, 0); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, 0); | |||
return fUi->d_getWidth(); | |||
return fUI->d_getWidth(); | |||
} | |||
uint getHeight() const noexcept | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr, 0); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, 0); | |||
return fUi->d_getHeight(); | |||
return fUI->d_getHeight(); | |||
} | |||
// ------------------------------------------------------------------- | |||
@@ -251,28 +255,28 @@ public: | |||
void parameterChanged(const uint32_t index, const float value) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
fUi->d_parameterChanged(index, value); | |||
fUI->d_parameterChanged(index, value); | |||
} | |||
#if DISTRHO_PLUGIN_WANT_PROGRAMS | |||
void programChanged(const uint32_t index) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
fUi->d_programChanged(index); | |||
fUI->d_programChanged(index); | |||
} | |||
#endif | |||
#if DISTRHO_PLUGIN_WANT_STATE | |||
void stateChanged(const char* const key, const char* const value) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',); | |||
DISTRHO_SAFE_ASSERT_RETURN(value != nullptr,); | |||
fUi->d_stateChanged(key, value); | |||
fUI->d_stateChanged(key, value); | |||
} | |||
#endif | |||
@@ -281,7 +285,7 @@ public: | |||
void exec(IdleCallback* const cb) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(cb != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
glWindow.addIdleCallback(cb); | |||
glWindow.setVisible(true); | |||
@@ -291,17 +295,17 @@ public: | |||
void exec_idle() | |||
{ | |||
if (glWindow.isReady()) | |||
fUi->d_uiIdle(); | |||
fUI->d_uiIdle(); | |||
} | |||
bool idle() | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr, false); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr, false); | |||
glApp.idle(); | |||
if (glWindow.isReady()) | |||
fUi->d_uiIdle(); | |||
fUI->d_uiIdle(); | |||
return ! glApp.isQuiting(); | |||
} | |||
@@ -339,6 +343,21 @@ public: | |||
return ! glApp.isQuiting(); | |||
} | |||
void setSampleRate(const double sampleRate, const bool doCallback = false) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,); | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
DISTRHO_SAFE_ASSERT(sampleRate > 0.0); | |||
if (fData->sampleRate == sampleRate) | |||
return; | |||
fData->sampleRate = sampleRate; | |||
if (doCallback) | |||
fUI->d_sampleRateChanged(sampleRate); | |||
} | |||
private: | |||
// ------------------------------------------------------------------- | |||
// DGL Application and Window for this widget | |||
@@ -349,7 +368,7 @@ private: | |||
// ------------------------------------------------------------------- | |||
// Widget and DistrhoUI data | |||
UI* const fUi; | |||
UI* const fUI; | |||
UI::PrivateData* const fData; | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UIExporter) | |||