diff --git a/distrho/DistrhoPlugin.hpp b/distrho/DistrhoPlugin.hpp index 79f4c2df..64f3beab 100644 --- a/distrho/DistrhoPlugin.hpp +++ b/distrho/DistrhoPlugin.hpp @@ -69,34 +69,74 @@ struct ParameterRanges { max = 1.0f; } + /*! + * Fix default value within range. + */ + void fixDefault() noexcept + { + fixValue(def); + } + + /*! + * Fix a value within range. + */ void fixValue(float& value) const noexcept { - if (value < min) + if (value <= min) value = min; else if (value > max) value = max; } + /*! + * Get a fixed value within range. + */ float getFixedValue(const float& value) const noexcept { - if (value < min) + if (value <= min) return min; - else if (value > max) + if (value >= max) return max; return value; } + /*! + * Get a value normalized to 0.0<->1.0. + */ float getNormalizedValue(const float& value) const noexcept { - const float newValue((value - min) / (max - min)); + const float normValue((value - min) / (max - min)); - if (newValue <= 0.0f) + if (normValue <= 0.0f) return 0.0f; - if (newValue >= 1.0f) + if (normValue >= 1.0f) return 1.0f; - return newValue; + return normValue; } + /*! + * Get a value normalized to 0.0<->1.0, fixed within range. + */ + float getFixedAndNormalizedValue(const float& value) const noexcept + { + if (value <= min) + return 0.0f; + if (value >= max) + return 1.0f; + + const float normValue((value - min) / (max - min)); + + if (normValue <= 0.0f) + return 0.0f; + if (normValue >= 1.0f) + return 1.0f; + + return normValue; + } + + /*! + * Get a proper value previously normalized to 0.0<->1.0. + */ float getUnnormalizedValue(const float& value) const noexcept { return value * (max - min) + min; @@ -113,7 +153,7 @@ struct Parameter { d_string unit; ParameterRanges ranges; - Parameter() + Parameter() noexcept : hints(0x0) {} void clear() noexcept @@ -261,6 +301,8 @@ private: struct PrivateData; PrivateData* const pData; friend class PluginExporter; + + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Plugin) }; // ----------------------------------------------------------------------- diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp index bb8b334b..d61b67d5 100644 --- a/distrho/DistrhoUI.hpp +++ b/distrho/DistrhoUI.hpp @@ -87,6 +87,8 @@ private: struct PrivateData; PrivateData* const pData; friend class UIExporter; + + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Plugin) }; // ----------------------------------------------------------------------- diff --git a/distrho/DistrhoUtils.hpp b/distrho/DistrhoUtils.hpp index 8dd5d511..46e3f258 100644 --- a/distrho/DistrhoUtils.hpp +++ b/distrho/DistrhoUtils.hpp @@ -163,6 +163,11 @@ void d_msleep(const uint msecs) } DISTRHO_SAFE_EXCEPTION("carla_msleep"); } +// ----------------------------------------------------------------------- +// we always need this class + +#include "extra/d_string.hpp" + // ----------------------------------------------------------------------- #endif // DISTRHO_UTILS_HPP_INCLUDED diff --git a/distrho/extra/d_string.hpp b/distrho/extra/d_string.hpp index 41b36fdc..3020d901 100644 --- a/distrho/extra/d_string.hpp +++ b/distrho/extra/d_string.hpp @@ -17,7 +17,7 @@ #ifndef DISTRHO_STRING_HPP_INCLUDED #define DISTRHO_STRING_HPP_INCLUDED -#include "../DistrhoUtils.hpp" +#include "d_leakdetector.hpp" // ----------------------------------------------------------------------- // d_string class @@ -709,7 +709,7 @@ private: } } - //DISTRHO_LEAK_DETECTOR(d_string) + DISTRHO_LEAK_DETECTOR(d_string) DISTRHO_PREVENT_HEAP_ALLOCATION };