diff --git a/source/libs/distrho/DistrhoPlugin.hpp b/source/libs/distrho/DistrhoPlugin.hpp index a7eef7ea1..f4f8b26b6 100644 --- a/source/libs/distrho/DistrhoPlugin.hpp +++ b/source/libs/distrho/DistrhoPlugin.hpp @@ -222,7 +222,7 @@ protected: // Callbacks (optional) virtual void d_bufferSizeChanged(uint32_t newBufferSize); - virtual void d_sampleRateChanged(double newSampleRate); + virtual void d_sampleRateChanged(double newSampleRate); // --------------------------------------------- diff --git a/source/libs/distrho/src/DistrhoPluginInternal.hpp b/source/libs/distrho/src/DistrhoPluginInternal.hpp index 690976ae1..3d1d9816b 100644 --- a/source/libs/distrho/src/DistrhoPluginInternal.hpp +++ b/source/libs/distrho/src/DistrhoPluginInternal.hpp @@ -186,8 +186,7 @@ public: bool parameterIsOutput(uint32_t index) const { - uint32_t hints = parameterHints(index); - return (hints & PARAMETER_IS_OUTPUT); + return (parameterHints(index) & PARAMETER_IS_OUTPUT); } const d_string& parameterName(uint32_t index) const @@ -265,9 +264,9 @@ public: void setState(const char* key, const char* value) { - assert(kPlugin && key && value); + assert(kPlugin != nullptr && key != nullptr && value != nullptr); - if (kPlugin && key && value) + if (kPlugin != nullptr && key != nullptr && value != nullptr) kPlugin->d_setState(key, value); } #endif @@ -302,7 +301,7 @@ public: void setBufferSize(uint32_t bufferSize, bool doCallback = false) { - assert(kData != nullptr && kPlugin && bufferSize >= 2); + assert(kData != nullptr && kPlugin != nullptr && bufferSize >= 2); if (kData != nullptr) { diff --git a/source/libs/distrho/src/DistrhoPluginLADSPA+DSSI.cpp b/source/libs/distrho/src/DistrhoPluginLADSPA+DSSI.cpp index d5c90ebf4..5a11cff97 100644 --- a/source/libs/distrho/src/DistrhoPluginLADSPA+DSSI.cpp +++ b/source/libs/distrho/src/DistrhoPluginLADSPA+DSSI.cpp @@ -14,8 +14,6 @@ * For a full copy of the license see the LGPL.txt file */ -#if defined(DISTRHO_PLUGIN_TARGET_LADSPA) || defined(DISTRHO_PLUGIN_TARGET_DSSI) - #include "DistrhoPluginInternal.hpp" #ifdef DISTRHO_PLUGIN_TARGET_DSSI @@ -30,6 +28,10 @@ # endif #endif +#if defined(DISTRHO_PLUGIN_TARGET_DSSI) && DISTRHO_PLUGIN_HAS_UI +# define DISTRHO_PLUGIN_WANT_SAMPLE_RATE 1 +#endif + #include typedef LADSPA_Data* LADSPA_DataPtr; @@ -57,7 +59,7 @@ public: #if DISTRHO_PLUGIN_WANT_LATENCY portLatency = nullptr; #endif -#if defined(DISTRHO_PLUGIN_TARGET_DSSI) && DISTRHO_PLUGIN_HAS_UI +#if DISTRHO_PLUGIN_WANT_SAMPLE_RATE portSampleRate = nullptr; #endif } @@ -430,7 +432,7 @@ static void dssi_run_synth(LADSPA_Handle instance, unsigned long sampleCount, sn // ------------------------------------------------- -static LADSPA_Descriptor ldescriptor = { +static LADSPA_Descriptor sLadspaDescriptor = { /* UniqueID */ 0, /* Label */ nullptr, /* Properties */ LADSPA_PROPERTY_REALTIME | LADSPA_PROPERTY_HARD_RT_CAPABLE, @@ -453,9 +455,9 @@ static LADSPA_Descriptor ldescriptor = { }; #ifdef DISTRHO_PLUGIN_TARGET_DSSI -static DSSI_Descriptor descriptor = { +static DSSI_Descriptor sDssiDescriptor = { 1, - &ldescriptor, + &sLadspaDescriptor, # if DISTRHO_PLUGIN_WANT_STATE dssi_configure, # else @@ -501,8 +503,8 @@ public: #if DISTRHO_PLUGIN_WANT_LATENCY portCount += 1; #endif -#if defined(DISTRHO_PLUGIN_TARGET_DSSI) && DISTRHO_PLUGIN_HAS_UI - portCount += 1; // sample-rate +#if DISTRHO_PLUGIN_WANT_SAMPLE_RATE + portCount += 1; #endif const char** const portNames = new const char* [portCount]; LADSPA_PortDescriptor* portDescriptors = new LADSPA_PortDescriptor [portCount]; @@ -511,7 +513,7 @@ public: // Set ports for (i=0; i < DISTRHO_PLUGIN_NUM_INPUTS; ++i, ++port) { - char portName[24] = { 0 }; + char portName[24] = { '\0' }; sprintf(portName, "Audio Input %lu", i+1); portNames[port] = strdup(portName); @@ -524,7 +526,7 @@ public: for (i=0; i < DISTRHO_PLUGIN_NUM_OUTPUTS; ++i, ++port) { - char portName[24] = { 0 }; + char portName[24] = { '\0' }; sprintf(portName, "Audio Output %lu", i+1); portNames[port] = strdup(portName); @@ -542,17 +544,17 @@ public: portRangeHints[port].HintDescriptor = LADSPA_HINT_SAMPLE_RATE; portRangeHints[port].LowerBound = 0.0f; portRangeHints[port].UpperBound = 1.0f; - port++; + ++port; #endif -#if defined(DISTRHO_PLUGIN_TARGET_DSSI) && DISTRHO_PLUGIN_HAS_UI +#if DISTRHO_PLUGIN_WANT_SAMPLE_RATE // Set sample-rate port portNames[port] = strdup("_sample-rate"); portDescriptors[port] = LADSPA_PORT_CONTROL | LADSPA_PORT_OUTPUT; portRangeHints[port].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE; portRangeHints[port].LowerBound = 0.0f; portRangeHints[port].UpperBound = 512000.0f; - port++; + ++port; #endif for (i=0; i < plugin.parameterCount(); ++i, ++port) @@ -566,7 +568,7 @@ public: portDescriptors[port] |= LADSPA_PORT_INPUT; { - const ParameterRanges& ranges = plugin.parameterRanges(i); + const ParameterRanges& ranges(plugin.parameterRanges(i)); const float defValue = ranges.def; portRangeHints[port].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE; @@ -601,7 +603,7 @@ public: } { - const uint32_t hints = plugin.parameterHints(i); + const uint32_t hints(plugin.parameterHints(i)); if (hints & PARAMETER_IS_BOOLEAN) portRangeHints[port].HintDescriptor |= LADSPA_HINT_TOGGLED; @@ -613,51 +615,51 @@ public: } // Set data - ldescriptor.UniqueID = plugin.uniqueId(); - ldescriptor.Label = strdup(plugin.label()); - ldescriptor.Name = strdup(plugin.name()); - ldescriptor.Maker = strdup(plugin.maker()); - ldescriptor.Copyright = strdup(plugin.license()); - ldescriptor.PortCount = portCount; - ldescriptor.PortNames = portNames; - ldescriptor.PortDescriptors = portDescriptors; - ldescriptor.PortRangeHints = portRangeHints; + sLadspaDescriptor.UniqueID = plugin.uniqueId(); + sLadspaDescriptor.Label = strdup(plugin.label()); + sLadspaDescriptor.Name = strdup(plugin.name()); + sLadspaDescriptor.Maker = strdup(plugin.maker()); + sLadspaDescriptor.Copyright = strdup(plugin.license()); + sLadspaDescriptor.PortCount = portCount; + sLadspaDescriptor.PortNames = portNames; + sLadspaDescriptor.PortDescriptors = portDescriptors; + sLadspaDescriptor.PortRangeHints = portRangeHints; } ~DescriptorInitializer() { - if (ldescriptor.Label != nullptr) - free((void*)ldescriptor.Label); + if (sLadspaDescriptor.Label != nullptr) + free((void*)sLadspaDescriptor.Label); - if (ldescriptor.Name != nullptr) - free((void*)ldescriptor.Name); + if (sLadspaDescriptor.Name != nullptr) + free((void*)sLadspaDescriptor.Name); - if (ldescriptor.Maker != nullptr) - free((void*)ldescriptor.Maker); + if (sLadspaDescriptor.Maker != nullptr) + free((void*)sLadspaDescriptor.Maker); - if (ldescriptor.Copyright != nullptr) - free((void*)ldescriptor.Copyright); + if (sLadspaDescriptor.Copyright != nullptr) + free((void*)sLadspaDescriptor.Copyright); - if (ldescriptor.PortDescriptors != nullptr) - delete[] ldescriptor.PortDescriptors; + if (sLadspaDescriptor.PortDescriptors != nullptr) + delete[] sLadspaDescriptor.PortDescriptors; - if (ldescriptor.PortRangeHints != nullptr) - delete[] ldescriptor.PortRangeHints; + if (sLadspaDescriptor.PortRangeHints != nullptr) + delete[] sLadspaDescriptor.PortRangeHints; - if (ldescriptor.PortNames != nullptr) + if (sLadspaDescriptor.PortNames != nullptr) { - for (unsigned long i=0; i < ldescriptor.PortCount; ++i) + for (unsigned long i=0; i < sLadspaDescriptor.PortCount; ++i) { - if (ldescriptor.PortNames[i] != nullptr) - free((void*)ldescriptor.PortNames[i]); + if (sLadspaDescriptor.PortNames[i] != nullptr) + free((void*)sLadspaDescriptor.PortNames[i]); } - delete[] ldescriptor.PortNames; + delete[] sLadspaDescriptor.PortNames; } } }; -static DescriptorInitializer init; +static DescriptorInitializer sInit; END_NAMESPACE_DISTRHO @@ -667,7 +669,7 @@ DISTRHO_PLUGIN_EXPORT const LADSPA_Descriptor* ladspa_descriptor(unsigned long index) { USE_NAMESPACE_DISTRHO - return (index == 0) ? &ldescriptor : nullptr; + return (index == 0) ? &sLadspaDescriptor : nullptr; } #ifdef DISTRHO_PLUGIN_TARGET_DSSI @@ -675,10 +677,6 @@ DISTRHO_PLUGIN_EXPORT const DSSI_Descriptor* dssi_descriptor(unsigned long index) { USE_NAMESPACE_DISTRHO - return (index == 0) ? &descriptor : nullptr; + return (index == 0) ? &sDssiDescriptor : nullptr; } #endif - -// ------------------------------------------------- - -#endif // DISTRHO_PLUGIN_TARGET_LADSPA || DISTRHO_PLUGIN_TARGET_DSSI diff --git a/source/libs/distrho/src/DistrhoUI.cpp b/source/libs/distrho/src/DistrhoUI.cpp index 2d4dea20e..175c13ea0 100644 --- a/source/libs/distrho/src/DistrhoUI.cpp +++ b/source/libs/distrho/src/DistrhoUI.cpp @@ -29,13 +29,6 @@ double d_lastUiSampleRate = 0.0; UI::UI() : pData(new PrivateData()) { -#if (defined(DISTRHO_PLUGIN_TARGET_DSSI) || defined(DISTRHO_PLUGIN_TARGET_LV2)) - pData->parameterOffset = DISTRHO_PLUGIN_NUM_INPUTS + DISTRHO_PLUGIN_NUM_OUTPUTS; -# if DISTRHO_PLUGIN_WANT_LATENCY - pData->parameterOffset += 1; // latency -# endif - pData->parameterOffset += 1; // sample-rate -#endif } UI::~UI() diff --git a/source/libs/distrho/src/DistrhoUIInternal.hpp b/source/libs/distrho/src/DistrhoUIInternal.hpp index da6bc7af7..4106d41a9 100644 --- a/source/libs/distrho/src/DistrhoUIInternal.hpp +++ b/source/libs/distrho/src/DistrhoUIInternal.hpp @@ -20,8 +20,7 @@ #include "DistrhoDefines.h" #if defined(DISTRHO_UI_EXTERNAL) -# include "../DistrhoUI.hpp" -// TODO +# include "../DistrhoUIExternal.hpp" #elif defined(DISTRHO_UI_OPENGL) # include "../DistrhoUIOpenGL.hpp" # include "../dgl/App.hpp" @@ -70,6 +69,14 @@ struct UI::PrivateData { ptr(nullptr) { assert(sampleRate != 0.0); + +#if defined(DISTRHO_PLUGIN_TARGET_DSSI) || defined(DISTRHO_PLUGIN_TARGET_LV2) + parameterOffset += DISTRHO_PLUGIN_NUM_INPUTS + DISTRHO_PLUGIN_NUM_OUTPUTS; +# if DISTRHO_PLUGIN_WANT_LATENCY + parameterOffset += 1; // latency +# endif + parameterOffset += 1; // sample-rate +#endif } ~PrivateData() @@ -116,10 +123,10 @@ public: #ifdef DISTRHO_UI_OPENGL : glApp(), glWindow(&glApp, winId), + kUi(createUI()), #else - : + : kUi(createUI()), #endif - kUi(createUI()), kData((kUi != nullptr) ? kUi->pData : nullptr) { assert(kUi != nullptr); @@ -161,13 +168,13 @@ public: return (kUi != nullptr) ? kUi->d_name() : ""; } - unsigned int width() + unsigned int width() const { assert(kUi != nullptr); return (kUi != nullptr) ? kUi->d_width() : 0; } - unsigned int height() + unsigned int height() const { assert(kUi != nullptr); return (kUi != nullptr) ? kUi->d_height() : 0; @@ -218,7 +225,7 @@ public: void idle() { #if defined(DISTRHO_UI_EXTERNAL) - // TODO - idle OSC + // needed? #elif defined(DISTRHO_UI_OPENGL) glApp.idle(); #else