Listen to parameters changes in Editor class

Hi Jucers,

Question regarding parameters changes.

Seems pretty straight forward to listen to parameters changes in the AudioProcessor but I need to do so in the PluginEditor class.

I have declared the APVTS as public member of the processor, added the parent AudioProcessorValueTreeState::Listener in the editor and added the editor itself as listener.

class MyProcessorEditor  : public juce::AudioProcessorEditor
                         , public juce::AudioProcessorValueTreeState::Listener
{
public:
    MyProcessorEditor (EpicNotesJuceAudioProcessor&);
    ~MyProcessorEditor() override;

    ...

    void parameterChanged(const juce::String& parameterID, float newValue) {
      // logging..
    }
MyAudioProcessorEditor::MyAudioProcessorEditor (MyAudioProcessor& p)
    : AudioProcessorEditor (&p)
    , audioProcessor (p)
{
    audioProcessor.parameters.addParameterListener(juce::String("customParam"), this);
    ...
}

The problem arises when the DAW changes a parameter, it fails randomly in either of this files
juce_VST3PluginFormat.cpp
juce_AudioProcessorValueTreeState.cpp

ERROR: JUCE Message Thread (1): EXC_BAD_ACCESS (code=1, address=0x10)

juce_VST3PlugiFormat.cpp

class EditControllerParameterDispatcher final : private Timer
{
public:
    ~EditControllerParameterDispatcher() override { stopTimer(); }

    void push (Steinberg::int32 index, float value)
    {
        if (controller == nullptr)
            return;

        if (MessageManager::getInstance()->isThisTheMessageThread())
            controller->setParamNormalized (cache.getParamID (index), value);
        else
            cache.set (index, value);
    }

specifically this line

controller->setParamNormalized (cache.getParamID (index), value);

juce_AudioProcessorValueTreeState.cpp

  void parameterValueChanged (int, float) override
  {
      const auto newValue = denormalise (parameter.getValue());

      if (! listenersNeedCalling && approximatelyEqual ((float) unnormalisedValue, newValue))
          return;

      unnormalisedValue = newValue;
      listeners.call ([this] (Listener& l) { l.parameterChanged (parameter.paramID, unnormalisedValue); });
      listenersNeedCalling = false;
      needsUpdate = true;
  }

specifically this line

listeners.call ([this] (Listener& l) { l.parameterChanged (parameter.paramID, unnormalisedValue); });

Is it even possible to listen for parameters changes in the Editor class?
Any comments/suggestions?

Thanks!

1 Like

Do you remove the listener in the destructor of the editor?

Yes! @zsliu98 this code is in place

MyAudioProcessorEditor::~MyAudioProcessorEditor() {
 audioProcessor.parameters.removeParameterListener(juce::String("customParam"), this);
}

The code looks correct to me. The stack trace may provide more information. You may also check whether that parameter exists in the APVTS.

I have used listeners in editors. No issues.

@zsliu98 ok yes, it was a typo in the param id declaration, this is embarrassing. Thanks for the replies