This helps #387, but rule is defined by the plugin. Later on the user must be able to choose the scale mode (among other things)tags/1.9.7
@@ -20,6 +20,8 @@ | |||||
#include "CarlaDefines.h" | #include "CarlaDefines.h" | ||||
#include <cmath> | |||||
#ifdef CARLA_PROPER_CPP11_SUPPORT | #ifdef CARLA_PROPER_CPP11_SUPPORT | ||||
# include <cstdint> | # include <cstdint> | ||||
#else | #else | ||||
@@ -1384,6 +1386,19 @@ typedef struct { | |||||
return value * (max - min) + min; | return value * (max - min) + min; | ||||
} | } | ||||
/*! | |||||
* Get a logarithmic value previously normalized to 0.0<->1.0. | |||||
*/ | |||||
float getUnnormalizedLogValue(const float& value) const noexcept | |||||
{ | |||||
if (value <= 0.0f) | |||||
return min; | |||||
if (value >= 1.0f) | |||||
return max; | |||||
return min * std::pow(max/min, value); | |||||
} | |||||
#endif /* __cplusplus */ | #endif /* __cplusplus */ | ||||
} ParameterRanges; | } ParameterRanges; | ||||
@@ -1533,7 +1533,10 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_LOGARITHMIC) | |||||
value = pData->param.ranges[k].getUnnormalizedLogValue(ctrlEvent.value); | |||||
else | |||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | ||||
value = std::rint(value); | value = std::rint(value); | ||||
@@ -1192,7 +1192,10 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_LOGARITHMIC) | |||||
value = pData->param.ranges[k].getUnnormalizedLogValue(ctrlEvent.value); | |||||
else | |||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | ||||
value = std::rint(value); | value = std::rint(value); | ||||
@@ -824,7 +824,10 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_LOGARITHMIC) | |||||
value = pData->param.ranges[k].getUnnormalizedLogValue(ctrlEvent.value); | |||||
else | |||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | ||||
value = std::rint(value); | value = std::rint(value); | ||||
@@ -1026,7 +1026,10 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_LOGARITHMIC) | |||||
value = pData->param.ranges[k].getUnnormalizedLogValue(ctrlEvent.value); | |||||
else | |||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | ||||
value = std::rint(value); | value = std::rint(value); | ||||
@@ -3168,7 +3168,10 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_LOGARITHMIC) | |||||
value = pData->param.ranges[k].getUnnormalizedLogValue(ctrlEvent.value); | |||||
else | |||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | ||||
value = std::rint(value); | value = std::rint(value); | ||||
@@ -1560,7 +1560,10 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_LOGARITHMIC) | |||||
value = pData->param.ranges[k].getUnnormalizedLogValue(ctrlEvent.value); | |||||
else | |||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | ||||
value = std::rint(value); | value = std::rint(value); | ||||
@@ -1279,7 +1279,10 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_LOGARITHMIC) | |||||
value = pData->param.ranges[k].getUnnormalizedLogValue(ctrlEvent.value); | |||||
else | |||||
value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); | |||||
if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) | ||||
value = std::rint(value); | value = std::rint(value); | ||||