Parameter Listener for AudioProcessorValueTreeState?


Can someone make me an example of Parameter Listener for AudioProfeccorValueTreeState?
I have:

parameters.createAndAddParameter("pitchLAVal", "Pitch Left A Value", String(), NormalisableRange<float> (-1.0, 1.0), 1.0, nullptr, nullptr);

And I assume that I can add a listener in this way:

parameters.addParameterListener("pitchLAVal", ??? );

I don’t know what is ???..


If you look at the header file you can see the definition of the function:

void addParameterListener (StringRef parameterID, Listener* listener);

Just above it you can see how a Listener is defined:

struct JUCE_API  Listener
    virtual ~Listener();

    /** This callback method is called by the AudioProcessorValueTreeState when a parameter changes. */
    virtual void parameterChanged (const String& parameterID, float newValue) = 0;

So, the second parameter needs to be a pointer to a class that inherits from Listener (and thus implements the parameterChanged method). This class will have its parameterChanged method called on parameter changes.


Ok but in the header I have to derive from the Listener as SliderListener?
Something like:

class IntellifexAudioProcessorEditor  : public AudioProcessorEditor,
                                    private SliderListener,
                                    private ButtonListener,
                                    private Timer

Or I have to build a custom class?


Neither of those:

class IntellifexAudioProcessorEditor  : private AudioProcessorValueTreeState::Listener
    : parameters (*this, nullptr)
    IntellifexAudioProcessorEditor() {
        parameters.addParameterListener ("yourParamId", this);
    void parameterChanged (const String& parameterID, float newValue) override
        // Called when parameter "yourParamId" is changed.

I would suggest that you do a lot of reading about C++ to learn about how these things work before continuing to use JUCE.


Thank you very much…
Your are right… Even friends of mine said that… But is more funny learning C++ by using JUCE…:wink:

Bitwise I didn’t know only the string for the listener in the constructor…


You don’t have to add a parameter listener in the constructor - I was just putting it there as an example.

Go and find a good C++ book!