Browse Source

APVTS: Fix apvts parameter update recursion

tags/2021-05-28
reuk ed 6 years ago
parent
commit
84849f8808
2 changed files with 15 additions and 4 deletions
  1. +6
    -1
      modules/juce_audio_processors/utilities/juce_AudioProcessorValueTreeState.cpp
  2. +9
    -3
      modules/juce_audio_processors/utilities/juce_AudioProcessorValueTreeState.h

+ 6
- 1
modules/juce_audio_processors/utilities/juce_AudioProcessorValueTreeState.cpp View File

@@ -71,7 +71,9 @@ void AudioProcessorValueTreeState::Parameter::valueChanged (float newValue)
return; return;
lastValue = newValue; lastValue = newValue;
sendValueChangedMessageToListeners (newValue);
if (onValueChanged != nullptr)
onValueChanged();
} }
//============================================================================== //==============================================================================
@@ -87,6 +89,9 @@ public:
unnormalisedValue (getRange().convertFrom0to1 (parameter.getDefaultValue())) unnormalisedValue (getRange().convertFrom0to1 (parameter.getDefaultValue()))
{ {
parameter.addListener (this); parameter.addListener (this);
if (auto* ptr = dynamic_cast<Parameter*> (&parameter))
ptr->onValueChanged = [this] { parameterValueChanged ({}, {}); };
} }
~ParameterAdapter() override { parameter.removeListener (this); } ~ParameterAdapter() override { parameter.removeListener (this); }


+ 9
- 3
modules/juce_audio_processors/utilities/juce_AudioProcessorValueTreeState.h View File

@@ -362,6 +362,10 @@ public:
UndoManager* const undoManager; UndoManager* const undoManager;
//============================================================================== //==============================================================================
private:
class ParameterAdapter;
public:
/** A parameter class that maintains backwards compatibility with deprecated /** A parameter class that maintains backwards compatibility with deprecated
AudioProcessorValueTreeState functionality. AudioProcessorValueTreeState functionality.
@@ -416,9 +420,13 @@ public:
private: private:
void valueChanged (float) override; void valueChanged (float) override;
std::function<void()> onValueChanged;
const float unsnappedDefault; const float unsnappedDefault;
const bool metaParameter, automatable, discrete, boolean; const bool metaParameter, automatable, discrete, boolean;
float lastValue = 0.0f;
float lastValue = -1.0f;
friend class AudioProcessorValueTreeState::ParameterAdapter;
}; };
//============================================================================== //==============================================================================
@@ -523,8 +531,6 @@ private:
bool, bool, bool, AudioProcessorParameter::Category, bool)); bool, bool, bool, AudioProcessorParameter::Category, bool));
//============================================================================== //==============================================================================
class ParameterAdapter;
#if JUCE_UNIT_TESTS #if JUCE_UNIT_TESTS
friend struct ParameterAdapterTests; friend struct ParameterAdapterTests;
#endif #endif


Loading…
Cancel
Save