@@ -90,48 +90,48 @@ static const uint32_t kParameterIsOutput = 0x10; | |||
When changing this struct values you must ensure maximum > minimum and default is within range. | |||
*/ | |||
struct ParameterRanges { | |||
/** | |||
Default value. | |||
*/ | |||
/** | |||
Default value. | |||
*/ | |||
float def; | |||
/** | |||
Minimum value. | |||
*/ | |||
/** | |||
Minimum value. | |||
*/ | |||
float min; | |||
/** | |||
Maximum value. | |||
*/ | |||
/** | |||
Maximum value. | |||
*/ | |||
float max; | |||
/** | |||
Default constructor. | |||
*/ | |||
/** | |||
Default constructor. | |||
*/ | |||
ParameterRanges() noexcept | |||
: def(0.0f), | |||
min(0.0f), | |||
max(1.0f) {} | |||
/** | |||
Constructor using custom values. | |||
*/ | |||
/** | |||
Constructor using custom values. | |||
*/ | |||
ParameterRanges(const float df, const float mn, const float mx) noexcept | |||
: def(df), | |||
min(mn), | |||
max(mx) {} | |||
/** | |||
Fix the default value within range. | |||
*/ | |||
/** | |||
Fix the default value within range. | |||
*/ | |||
void fixDefault() noexcept | |||
{ | |||
fixValue(def); | |||
} | |||
/** | |||
Fix a value within range. | |||
*/ | |||
/** | |||
Fix a value within range. | |||
*/ | |||
void fixValue(float& value) const noexcept | |||
{ | |||
if (value < min) | |||
@@ -140,9 +140,9 @@ struct ParameterRanges { | |||
value = max; | |||
} | |||
/** | |||
Get a fixed value within range. | |||
*/ | |||
/** | |||
Get a fixed value within range. | |||
*/ | |||
const float& getFixedValue(const float& value) const noexcept | |||
{ | |||
if (value <= min) | |||
@@ -152,9 +152,9 @@ struct ParameterRanges { | |||
return value; | |||
} | |||
/** | |||
Get a value normalized to 0.0<->1.0. | |||
*/ | |||
/** | |||
Get a value normalized to 0.0<->1.0. | |||
*/ | |||
float getNormalizedValue(const float& value) const noexcept | |||
{ | |||
const float normValue((value - min) / (max - min)); | |||
@@ -166,9 +166,9 @@ struct ParameterRanges { | |||
return normValue; | |||
} | |||
/** | |||
Get a value normalized to 0.0<->1.0, fixed within range. | |||
*/ | |||
/** | |||
Get a value normalized to 0.0<->1.0, fixed within range. | |||
*/ | |||
float getFixedAndNormalizedValue(const float& value) const noexcept | |||
{ | |||
if (value <= min) | |||
@@ -186,9 +186,9 @@ struct ParameterRanges { | |||
return normValue; | |||
} | |||
/** | |||
Get a proper value previously normalized to 0.0<->1.0. | |||
*/ | |||
/** | |||
Get a proper value previously normalized to 0.0<->1.0. | |||
*/ | |||
float getUnnormalizedValue(const float& value) const noexcept | |||
{ | |||
if (value <= 0.0f) | |||
@@ -204,43 +204,43 @@ struct ParameterRanges { | |||
Parameter. | |||
*/ | |||
struct Parameter { | |||
/** | |||
Hints describing this parameter. | |||
@see ParameterHints | |||
*/ | |||
/** | |||
Hints describing this parameter. | |||
@see ParameterHints | |||
*/ | |||
uint32_t hints; | |||
/** | |||
The name of this parameter. | |||
A parameter name can contain any character, but hosts might have a hard time with non-ascii ones. | |||
The name doesn't have to be unique within a plugin instance, but it's recommended. | |||
*/ | |||
/** | |||
The name of this parameter. | |||
A parameter name can contain any character, but hosts might have a hard time with non-ascii ones. | |||
The name doesn't have to be unique within a plugin instance, but it's recommended. | |||
*/ | |||
d_string name; | |||
/** | |||
The symbol of this parameter. | |||
A parameter symbol is a short restricted name used as a machine and human readable identifier. | |||
The first character must be one of _, a-z or A-Z and subsequent characters can be from _, a-z, A-Z and 0-9. | |||
@note: Parameter symbols MUST be unique within a plugin instance. | |||
*/ | |||
/** | |||
The symbol of this parameter. | |||
A parameter symbol is a short restricted name used as a machine and human readable identifier. | |||
The first character must be one of _, a-z or A-Z and subsequent characters can be from _, a-z, A-Z and 0-9. | |||
@note: Parameter symbols MUST be unique within a plugin instance. | |||
*/ | |||
d_string symbol; | |||
/** | |||
The unit of this parameter. | |||
This means something like "dB", "kHz" and "ms". | |||
Can be left blank if units do not apply to this parameter. | |||
*/ | |||
/** | |||
The unit of this parameter. | |||
This means something like "dB", "kHz" and "ms". | |||
Can be left blank if units do not apply to this parameter. | |||
*/ | |||
d_string unit; | |||
/** | |||
Ranges of this parameter. | |||
The ranges describe the default, minimum and maximum values. | |||
*/ | |||
/** | |||
Ranges of this parameter. | |||
The ranges describe the default, minimum and maximum values. | |||
*/ | |||
ParameterRanges ranges; | |||
/** | |||
Default constructor for a null parameter. | |||
*/ | |||
/** | |||
Default constructor for a null parameter. | |||
*/ | |||
Parameter() noexcept | |||
: hints(0x0), | |||
name(), | |||
@@ -253,25 +253,25 @@ struct Parameter { | |||
MIDI event. | |||
*/ | |||
struct MidiEvent { | |||
/** | |||
Size of internal data. | |||
*/ | |||
/** | |||
Size of internal data. | |||
*/ | |||
static const uint32_t kDataSize = 4; | |||
/** | |||
Time offset in frames. | |||
*/ | |||
/** | |||
Time offset in frames. | |||
*/ | |||
uint32_t frame; | |||
/** | |||
Number of bytes used. | |||
*/ | |||
/** | |||
Number of bytes used. | |||
*/ | |||
uint32_t size; | |||
/** | |||
MIDI data. | |||
If size > kDataSize, dataExt is used (otherwise null). | |||
*/ | |||
/** | |||
MIDI data. | |||
If size > kDataSize, dataExt is used (otherwise null). | |||
*/ | |||
uint8_t data[kDataSize]; | |||
const uint8_t* dataExt; | |||
}; | |||
@@ -366,9 +366,9 @@ struct TimePosition { | |||
beatsPerMinute(0.0) {} | |||
} bbt; | |||
/** | |||
Default constructor for a time position. | |||
*/ | |||
/** | |||
Default constructor for a time position. | |||
*/ | |||
TimePosition() noexcept | |||
: playing(false), | |||
frame(0), | |||
@@ -627,7 +627,7 @@ private: | |||
*/ | |||
extern Plugin* createPlugin(); | |||
// ----------------------------------------------------------------------- | |||
// ----------------------------------------------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO | |||
@@ -41,9 +41,7 @@ START_NAMESPACE_DISTRHO | |||
TODO. | |||
you should not have to call setSize during construction, | |||
that is handled by d_initSize | |||
if you want to change size later on you should use setSize and then d_setSize to report to host | |||
must call setSize during construction, | |||
*/ | |||
class UI : public UIWidget | |||
{ | |||
@@ -59,7 +57,7 @@ public: | |||
virtual ~UI(); | |||
/* -------------------------------------------------------------------------------------------------------- | |||
* Host DSP state */ | |||
* Host state */ | |||
/** | |||
Get the current sample rate used in plugin processing. | |||
@@ -91,15 +89,6 @@ public: | |||
void d_sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity); | |||
#endif | |||
/* -------------------------------------------------------------------------------------------------------- | |||
* Host UI state */ | |||
/** | |||
TODO: Document this. | |||
never call this from the constructor | |||
*/ | |||
void d_setSize(const uint width, const uint height); | |||
#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS | |||
/* -------------------------------------------------------------------------------------------------------- | |||
* Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */ | |||
@@ -111,16 +100,6 @@ public: | |||
#endif | |||
protected: | |||
/* -------------------------------------------------------------------------------------------------------- | |||
* Init */ | |||
/** | |||
Set the initial UI size. | |||
This function will be called once, shortly after the UI is created. | |||
@see d_setSize(uint,uint) | |||
*/ | |||
virtual void d_initSize(uint& width, uint& height) = 0; | |||
/* -------------------------------------------------------------------------------------------------------- | |||
* DSP/Plugin Callbacks */ | |||
@@ -165,13 +144,31 @@ protected: | |||
#if ! DISTRHO_UI_USE_NTK | |||
/** | |||
OpenGL reshape function, called when the host window is resized. | |||
OpenGL window reshape function, called when parent window is resized. | |||
You can reimplement this function for a custom OpenGL state. | |||
@see Window::onReshape(uint,uint) | |||
*/ | |||
virtual void d_uiReshape(uint width, uint height); | |||
#endif | |||
/* -------------------------------------------------------------------------------------------------------- | |||
* UI Resize Handling, internal */ | |||
#if DISTRHO_UI_USE_NTK | |||
/** | |||
NTK widget resize function, called when the widget is resized. | |||
This is overriden here so the host knows when the UI is resized by you. | |||
*/ | |||
void resize(int x, int y, int w, int h) override; | |||
#else | |||
/** | |||
OpenGL widget resize function, called when the widget is resized. | |||
This is overriden here so the host knows when the UI is resized by you. | |||
@see Widget::onResize(const ResizeEvent&) | |||
*/ | |||
void onResize(const ResizeEvent& ev) override; | |||
#endif | |||
// ------------------------------------------------------------------------------------------------------- | |||
private: | |||
@@ -51,7 +51,7 @@ inline float | |||
// misc functions | |||
static inline | |||
long d_cconst(const int a, const int b, const int c, const int d) noexcept | |||
int64_t d_cconst(const int a, const int b, const int c, const int d) noexcept | |||
{ | |||
return (a << 24) | (b << 16) | (c << 8) | (d << 0); | |||
} | |||
@@ -18,20 +18,20 @@ | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
// Static data, see DistrhoPluginInternal.hpp | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* Static data, see DistrhoPluginInternal.hpp */ | |||
uint32_t d_lastBufferSize = 0; | |||
double d_lastSampleRate = 0.0; | |||
// ----------------------------------------------------------------------- | |||
// Static fallback data, see DistrhoPluginInternal.hpp | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* Static fallback data, see DistrhoPluginInternal.hpp */ | |||
const d_string PluginExporter::sFallbackString; | |||
const ParameterRanges PluginExporter::sFallbackRanges; | |||
// ----------------------------------------------------------------------- | |||
// Plugin | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* Plugin */ | |||
Plugin::Plugin(const uint32_t parameterCount, const uint32_t programCount, const uint32_t stateCount) | |||
: pData(new PrivateData()) | |||
@@ -68,8 +68,8 @@ Plugin::~Plugin() | |||
delete pData; | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Host state | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* Host state */ | |||
uint32_t Plugin::d_getBufferSize() const noexcept | |||
{ | |||
@@ -84,9 +84,6 @@ double Plugin::d_getSampleRate() const noexcept | |||
#if DISTRHO_PLUGIN_WANT_TIMEPOS | |||
const TimePos& Plugin::d_getTimePos() const noexcept | |||
{ | |||
// timePos outside run() may not be valid | |||
DISTRHO_SAFE_ASSERT(pData->isProcessing); | |||
return pData->timePos; | |||
} | |||
#endif | |||
@@ -106,12 +103,12 @@ bool Plugin::d_writeMidiEvent(const MidiEvent& /*midiEvent*/) noexcept | |||
} | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
// Callbacks (optional) | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* Callbacks (optional) */ | |||
void Plugin::d_bufferSizeChanged(uint32_t) {} | |||
void Plugin::d_sampleRateChanged(double) {} | |||
// ----------------------------------------------------------------------- | |||
// ----------------------------------------------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -105,9 +105,9 @@ public: | |||
jack_activate(fClient); | |||
if (const char* const name = jack_get_client_name(fClient)) | |||
fUI.setTitle(name); | |||
fUI.setWindowTitle(name); | |||
else | |||
fUI.setTitle(fPlugin.getName()); | |||
fUI.setWindowTitle(fPlugin.getName()); | |||
fUI.exec(this); | |||
} | |||
@@ -295,7 +295,7 @@ protected: | |||
void setSize(const uint width, const uint height) | |||
{ | |||
fUI.setSize(width, height); | |||
fUI.setWindowSize(width, height); | |||
} | |||
// ------------------------------------------------------------------- | |||
@@ -217,7 +217,7 @@ protected: | |||
void setSize(const uint width, const uint height) | |||
{ | |||
fUI.setSize(width, height); | |||
fUI.setWindowSize(width, height); | |||
hostCallback(audioMasterSizeWindow, width, height, nullptr, 0.0f); | |||
} | |||
@@ -18,15 +18,15 @@ | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
// Static data, see DistrhoUIInternal.hpp | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* Static data, see DistrhoUIInternal.hpp */ | |||
double d_lastUiSampleRate = 0.0; | |||
void* d_lastUiDspPtr = nullptr; | |||
UIWindow* d_lastUiWindow = nullptr; | |||
// ----------------------------------------------------------------------- | |||
// UI | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* UI */ | |||
UI::UI() | |||
: UIWidget(*d_lastUiWindow), | |||
@@ -40,8 +40,8 @@ UI::~UI() | |||
delete pData; | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Host DSP State | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* Host state */ | |||
double UI::d_getSampleRate() const noexcept | |||
{ | |||
@@ -72,17 +72,9 @@ void UI::d_sendNote(const uint8_t channel, const uint8_t note, const uint8_t vel | |||
} | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
// Host UI State | |||
void UI::d_setSize(const uint width, const uint height) | |||
{ | |||
pData->setSizeCallback(width, height); | |||
} | |||
#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS | |||
// ----------------------------------------------------------------------- | |||
// Direct DSP access | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* Direct DSP access */ | |||
void* UI::d_getPluginInstancePointer() const noexcept | |||
{ | |||
@@ -90,13 +82,13 @@ void* UI::d_getPluginInstancePointer() const noexcept | |||
} | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
// DSP Callbacks (optional) | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* DSP/Plugin Callbacks (optional) */ | |||
void UI::d_sampleRateChanged(double) {} | |||
// ----------------------------------------------------------------------- | |||
// UI Callbacks (optional) | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* UI Callbacks (optional) */ | |||
#if ! DISTRHO_UI_USE_NTK | |||
void UI::d_uiReshape(uint width, uint height) | |||
@@ -112,6 +104,22 @@ void UI::d_uiReshape(uint width, uint height) | |||
} | |||
#endif | |||
// ----------------------------------------------------------------------- | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* UI Resize Handling, internal */ | |||
#if DISTRHO_UI_USE_NTK | |||
void UI::resize(int x, int y, int w, int h) | |||
{ | |||
UIWidget::resize(x, y w, h); | |||
pData->setSizeCallback(w, h); | |||
} | |||
#else | |||
void UI::onResize(const ResizeEvent& ev) | |||
{ | |||
pData->setSizeCallback(ev.size.getWidth(), ev.size.getHeight()); | |||
} | |||
#endif | |||
// ----------------------------------------------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -97,7 +97,7 @@ public: | |||
fHostClosed(false), | |||
fOscData(oscData) | |||
{ | |||
fUI.setTitle(uiTitle); | |||
fUI.setWindowTitle(uiTitle); | |||
} | |||
~UIDssi() | |||
@@ -147,12 +147,12 @@ public: | |||
void dssiui_show() | |||
{ | |||
fUI.setVisible(true); | |||
fUI.setWindowVisible(true); | |||
} | |||
void dssiui_hide() | |||
{ | |||
fUI.setVisible(false); | |||
fUI.setWindowVisible(false); | |||
} | |||
void dssiui_quit() | |||
@@ -195,7 +195,7 @@ protected: | |||
void setSize(const uint width, const uint height) | |||
{ | |||
fUI.setSize(width, height); | |||
fUI.setWindowSize(width, height); | |||
} | |||
private: | |||
@@ -62,10 +62,6 @@ struct UI::PrivateData { | |||
void* dspPtr; | |||
#endif | |||
// UI | |||
uint initialWidth; | |||
uint initialHeight; | |||
// Callbacks | |||
editParamFunc editParamCallbackFunc; | |||
setParamFunc setParamCallbackFunc; | |||
@@ -80,8 +76,6 @@ struct UI::PrivateData { | |||
#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS | |||
dspPtr(d_lastUiDspPtr), | |||
#endif | |||
initialWidth(0), | |||
initialHeight(0), | |||
editParamCallbackFunc(nullptr), | |||
setParamCallbackFunc(nullptr), | |||
setStateCallbackFunc(nullptr), | |||
@@ -134,9 +128,6 @@ struct UI::PrivateData { | |||
void setSizeCallback(const uint width, const uint height) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(initialWidth != 0,); | |||
DISTRHO_SAFE_ASSERT_RETURN(initialHeight != 0,); | |||
if (setSizeCallbackFunc != nullptr) | |||
setSizeCallbackFunc(ptr, width, height); | |||
} | |||
@@ -166,15 +157,9 @@ public: | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
uint width = 0, height = 0; | |||
fUI->d_initSize(width, height); | |||
// set widget size | |||
fUI->setSize(width, height); | |||
// set window size | |||
setResizable(false); | |||
setSize(width, height); | |||
setSize(fUI->getWidth(), fUI->getHeight()); | |||
} | |||
~UIExporterWindow() | |||
@@ -205,9 +190,10 @@ protected: | |||
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,); | |||
// report size change to plugin UI | |||
fUI->setSize(width, height); | |||
// TESTING is this needed? | |||
//fUI->setSize(width, height); | |||
// update openGL state | |||
// custom window reshape | |||
fUI->d_uiReshape(width, height); | |||
fIsReady = true; | |||
@@ -256,6 +242,11 @@ public: | |||
return glWindow.getHeight(); | |||
} | |||
bool isVisible() const noexcept | |||
{ | |||
return glWindow.isVisible(); | |||
} | |||
// ------------------------------------------------------------------- | |||
uint32_t getParameterOffset() const noexcept | |||
@@ -324,39 +315,38 @@ public: | |||
return ! glApp.isQuiting(); | |||
} | |||
bool isVisible() const noexcept | |||
{ | |||
return glWindow.isVisible(); | |||
} | |||
void quit() | |||
{ | |||
glWindow.close(); | |||
glApp.quit(); | |||
} | |||
void setSize(const uint width, const uint height) | |||
// ------------------------------------------------------------------- | |||
void setWindowSize(const uint width, const uint height) | |||
{ | |||
glWindow.setSize(width, height); | |||
} | |||
void setTitle(const char* const uiTitle) | |||
void setWindowTitle(const char* const uiTitle) | |||
{ | |||
glWindow.setTitle(uiTitle); | |||
} | |||
void setTransientWinId(const intptr_t winId) | |||
void setWindowTransientWinId(const intptr_t winId) | |||
{ | |||
glWindow.setTransientWinId(winId); | |||
} | |||
bool setVisible(const bool yesNo) | |||
bool setWindowVisible(const bool yesNo) | |||
{ | |||
glWindow.setVisible(yesNo); | |||
return ! glApp.isQuiting(); | |||
} | |||
// ------------------------------------------------------------------- | |||
void setSampleRate(const double sampleRate, const bool doCallback = false) | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,); | |||
@@ -70,7 +70,7 @@ public: | |||
if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Long)) | |||
{ | |||
if (const int64_t frontendWinId = *(const int64_t*)options[i].value) | |||
fUI.setTransientWinId(static_cast<intptr_t>(frontendWinId)); | |||
fUI.setWindowTransientWinId(static_cast<intptr_t>(frontendWinId)); | |||
} | |||
else | |||
d_stderr("Host provides frontendWinId but has wrong value type"); | |||
@@ -82,7 +82,7 @@ public: | |||
if (const char* const windowTitle = (const char*)options[i].value) | |||
{ | |||
hasTitle = true; | |||
fUI.setTitle(windowTitle); | |||
fUI.setWindowTitle(windowTitle); | |||
} | |||
} | |||
else | |||
@@ -91,7 +91,7 @@ public: | |||
} | |||
if (! hasTitle) | |||
fUI.setTitle(DISTRHO_PLUGIN_NAME); | |||
fUI.setWindowTitle(DISTRHO_PLUGIN_NAME); | |||
} | |||
// ------------------------------------------------------------------- | |||
@@ -138,12 +138,12 @@ public: | |||
int lv2ui_show() | |||
{ | |||
return fUI.setVisible(true) ? 0 : 1; | |||
return fUI.setWindowVisible(true) ? 0 : 1; | |||
} | |||
int lv2ui_hide() | |||
{ | |||
return fUI.setVisible(false) ? 0 : 1; | |||
return fUI.setWindowVisible(false) ? 0 : 1; | |||
} | |||
// ------------------------------------------------------------------- | |||
@@ -211,7 +211,7 @@ protected: | |||
void setSize(const uint width, const uint height) | |||
{ | |||
fUI.setSize(width, height); | |||
fUI.setWindowSize(width, height); | |||
if (fUiResize != nullptr && ! fWinIdWasNull) | |||
fUiResize->ui_resize(fUiResize->handle, width, height); | |||