Any examples of using AudioProcessorValueTreeState for handling parameter changes?

Here is a simple example. Not perfect, but it works here.

In processor.h —
UndoManager undoManager; AudioProcessorValueTreeState params;

//Define the parameter's id and name
#define P_ID_OSC1_KYTRKD "KYTRKD"
#define P_NM_OSC1_KYTRKD "Key Tracked"

In processor.cpp —
//Instantiate the AudioProcessorValueTreeState and UndoManager
TestAudioProcessor::TestAudioProcessor()
: undoManager(3000, 30), params(*this, &undoManager)

//make a range
NormalisableRange<float> rngZeroToOne (0.0f, 1.0f, 0.0001f);

//create the parameter in the constructor with the name, id, and range
params.createAndAddParameter (P_ID_OSC1_KYTRKD, P_NM_OSC1_KYTRKD, P_NM_OSC1_KYTRKD, rngZeroToOne, rngZeroToOne.snapToLegalValue(0.0f), nullptr, nullptr);

in Editor.h —
ScopedPointer<AudioProcessorValueTreeState::ButtonAttachment> keyTrackToggleAttachment;
ScopedPointer<ToggleButton> keyTrackToggle;

In Editor.cpp —
//in constructor
keyTrackToggleAttachment = new AudioProcessorValueTreeState::ButtonAttachment (*p.getParamValueTree(), P_ID_OSC1_KYTRKD, *keyTrackToggle);

Good luck!

1 Like