JuceDemoPlugin ParameterSlider update bug


#1

Hi all,

I’ve noticed a little bug in the JuceDemoPlugin in ParameterSlider class in PluginEditor.cpp that might confuse new gyus using JUCE. When you update the slider value by entering the value in the entry box (and hitting enter) the host is not notified. The reason is because of the condition in its valueChanged method:

void valueChanged() override
{
    if (isMouseButtonDown())
        param.setValueNotifyingHost ((float) Slider::getValue());
    else
        param.setValue ((float) Slider::getValue());
}

Also, when the host updates the value, there’s a redundant call of the param.setValue(...) because of this method:

void updateSliderPos()
{
    const float newValue = param.getValue();

    if (newValue != (float) Slider::getValue() && ! isMouseButtonDown())
        Slider::setValue (newValue);
}

The storyline is:
Host updates parameter (automation)
Timer calls updateSliderPos
Slider calls setValue on self
Slider calls valueChanged on self
Slider calls param.setValue - this call is redundant, the old and new value equals

Here’s my suggestion on how it should look like:

void valueChanged() override
{
     param.setValueNotifyingHost ((float) Slider::getValue());
}

void updateSliderPos()
{
    const float newValue = param.getValue();

    if (newValue != (float) Slider::getValue() && ! isMouseButtonDown())
        Slider::setValue (newValue, NotificationType::dontSendNotification);
}

#2

Yes, that looks sensible. I’ll add it to the develop branch shortly.

Thanks.