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!
