GenericAudioProcessorEditor Suggestions w/ Code


#1

Improved display of the parameter on the slider, as well as using the plugin's range.


class ProcessorParameterPropertyComp   : public PropertyComponent,
                                         private AudioProcessorListener,
                                         private Timer
{
public:
    ProcessorParameterPropertyComp (const String& name, AudioProcessor& p, const int index_)
        : PropertyComponent (name),
          owner (p),
          index (index_),
          paramHasChanged (false),
          slider (p, index_)
    {
        startTimer (100);
        addAndMakeVisible (slider);
        owner.addListener (this);
    }
    ~ProcessorParameterPropertyComp()
    {
        owner.removeListener (this);
    }
    void refresh() override
    {
        paramHasChanged = false;
        slider.setValue (owner.getParameter (index), dontSendNotification);
        slider.updateText();
    }
    void audioProcessorChanged (AudioProcessor*) override  {}
    void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float) override
    {
        if (parameterIndex == index)
            paramHasChanged = true;
    }
    void timerCallback() override
    {
        if (paramHasChanged)
        {
            refresh();
            startTimer (20);
        }
        else
        {
            startTimer (jmin (250, getTimerInterval() + 10));
        }
    }
private:
    //==============================================================================
    class ParamSlider  : public Slider
    {
    public:
        ParamSlider (AudioProcessor& p, const int index_)
          : owner (p),
            index (index_)
        {
            const int steps = owner.getParameterNumSteps (index);
            if (steps <= 0 || steps == 0x7fffffff)
                setRange (0.0, 1.0);
            else
                setRange (0.0, 1.0, (100.0 / (double) steps) * 0.01);
            setSliderStyle (Slider::LinearBar);
            setTextBoxIsEditable (false);
            setScrollWheelEnabled (true);
        }
        void valueChanged() override
        {
            const float newVal = (float) getValue();
            if (owner.getParameter (index) != newVal)
            {
                owner.setParameterNotifyingHost (index, newVal);
                updateText();
            }
        }
        String getTextFromValue (double /*value*/) override
        {
            return owner.getParameterText (index) + " " + owner.getParameterLabel (index);
        }
    private:
        //==============================================================================
        AudioProcessor& owner;
        const int index;
        JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParamSlider)
    };
    AudioProcessor& owner;
    const int index;
    bool volatile paramHasChanged;
    ParamSlider slider;
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProcessorParameterPropertyComp)
};

#2

Cheers! I'll take a look right away..


#3

As for the setRange() of the slider in case of a discrete parameter, the interval to use should be

1.0 / (steps - 1)

For a 2 positions parameter (min/max) this yields an interval = 1.0 which spans the whole range of the slider (as expected)

For a 3 positions parameter (min/half/max) this yields an interval = 0.5 that means that the valid values are 0.0, 0.5 and 1.0, as expected, and so on.

Jules, this should also be changed in the code you commited for this (the "- 1" part is missing) and, obviously, this makes sense only if the parameter has at least 2 steps.

 


#4

Yes, good point, thanks. I should have spent a little longer sanity-checking that code!


#5

whilst you're at it this is still a problem...

http://www.juce.com/forum/topic/genericaudioprocessoreditor-issue-jumping-sliders-parameters-displaying-enumerated-lists