Skip to content

Commit c152cfb

Browse files
committed
Fix LADSPA hint calculation for logarithmic parameters
For parameters from 1 to 65535 with defaults of 4096 and 128, the old logic picked “low” and “low”, resulting in default values of 16 for both, whereas this new logic picks “high” and “middle”, resulting in defaults of 4096 and 256.
1 parent 4238e1c commit c152cfb

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

distrho/src/DistrhoPluginLADSPA+DSSI.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "DistrhoPluginInternal.hpp"
1818

19+
#include <cmath>
20+
1921
#if DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST
2022
# error Cannot use parameter value change request with LADSPA or DSSI
2123
#endif
@@ -646,9 +648,21 @@ static const struct DescriptorInitializer
646648
portRangeHints[port].HintDescriptor |= LADSPA_HINT_DEFAULT_MAXIMUM;
647649
else
648650
{
649-
const float middleValue = ranges.min/2.0f + ranges.max/2.0f;
650-
const float middleLow = (ranges.min/2.0f + middleValue/2.0f)/2.0f + middleValue/2.0f;
651-
const float middleHigh = (ranges.max/2.0f + middleValue/2.0f)/2.0f + middleValue/2.0f;
651+
float middleValue;
652+
float middleLow;
653+
float middleHigh;
654+
if (hints & kParameterIsLogarithmic)
655+
{
656+
middleValue = std::sqrt(ranges.min * ranges.max);
657+
middleLow = std::sqrt(std::sqrt(ranges.min * middleValue) * middleValue);
658+
middleHigh = std::sqrt(std::sqrt(ranges.max * middleValue) * middleValue);
659+
}
660+
else
661+
{
662+
middleValue = ranges.min/2.0f + ranges.max/2.0f;
663+
middleLow = (ranges.min/2.0f + middleValue/2.0f)/2.0f + middleValue/2.0f;
664+
middleHigh = (ranges.max/2.0f + middleValue/2.0f)/2.0f + middleValue/2.0f;
665+
}
652666

653667
/**/ if (defValue < middleLow)
654668
portRangeHints[port].HintDescriptor |= LADSPA_HINT_DEFAULT_LOW;

0 commit comments

Comments
 (0)