Hi, I have the same problem and It doesn’t store states Can anybody please have a look at it ? I did everything i found in tutorials and docs . There are so many post about this topic but everything is mixed and i don’t know which one is the right way to save and load these states .
PluginEditor.h
Slider mVolumeSlider{ Slider::RotaryHorizontalVerticalDrag, Slider::TextBoxBelow };
AudioProcessorValueTreeState::SliderAttachment mVolumeAttachment{ processor.getValueTreeState(),
TestAudioProcessor::paramVolume,
mVolumeSlider };
PluginProcessor.h :
AudioProcessorValueTreeState& getValueTreeState();
static String paramVolume;
Atomic<float> mVolume{ 0.0f };
UndoManager mUndoManager;
AudioProcessorValueTreeState mState;
PluginProcessor.cpp
#include "PluginProcessor.h"
#include "PluginEditor.h"
String TestAudioProcessor::paramVolume("volume");
TestAudioProcessor::TestAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor(BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput("Input", AudioChannelSet::stereo(), true)
#endif
.withOutput("Output", AudioChannelSet::stereo(), true)
#endif
), mState(*this, &mUndoManager, "Test Plugin",
{
std::make_unique<AudioParameterFloat>(paramVolume,
TRANS("Volume"),
NormalisableRange<float>(0.0f,1.0f,1.0f),
mVolume.get()," ",
AudioProcessorParameter::genericParameter,
[](float v, int) {return String(v,2) + " "; },
[](const String& t) {return t.dropLastCharacters(2).getFloatValue(); }),
#endif
{
mState.addParameterListener(paramVolume, this);
}
const String TestAudioProcessor::getName() const
{
return "Test Plugin";
}
void TestAudioProcessor::parameterChanged(const String& parameterID, float newValue)
{
if (parameterID == paramVolume) {
mVolume = newValue;
}
}
AudioProcessorValueTreeState& TestAudioProcessor::getValueTreeState()
{
return mState;
}
//===================================================================
bool TestAudioProcessor::hasEditor() const
{
return true; // (change this to false if you choose to not supply an editor)
}
AudioProcessorEditor* TestAudioProcessor::createEditor()
{
return new TestAudioProcessor(*this);
}
void TestAudioProcessor::getStateInformation(MemoryBlock& destData)
{
mState.state = ValueTree(Identifier(JucePlugin_Name));
auto state = mState.copyState();
std::unique_ptr<XmlElement> xml(state.createXml());
copyXmlToBinary(*xml, destData);
}
void TestAudioProcessor::setStateInformation(const void* data, int sizeInBytes)
{
std::unique_ptr<XmlElement> xmlState(getXmlFromBinary(data, sizeInBytes));
if (xmlState.get() != nullptr)
if (xmlState->hasTagName(mState.state.getType()))
mState.replaceState(ValueTree::fromXml(*xmlState));
}