I have a plugin that uses AudioProcessorValueTreeState to manage its state, with a bunch of sliders in the UI.
I’d like to add something like an “INIT” button to reset all sliders to their initial position; each parameter has a default value which is set it in
createParameterLayout(), and can be easily recalled by double-clicking the sliders).
But how can I achieve the same result from my code?
Is there any built-in mechanism to do this? I took a look at the docs but couldn’t find what I was looking for.
I tried to manually access my parameters and then call something like
but I got an error saying that
AudioParameterFloat::setValue is inaccessible.
I got the feeling that I’m trying to reinvent the wheel here. Any thoughts?
From the documentation of
If you want to set the value of a parameter internally, e.g. from your
editor component, then don’t call this directly - instead, use the
setValueNotifyingHost() method, which will also send a message to
the host telling it about the change. If the message isn’t sent, the host
won’t be able to automate your parameters properly.
I hope this helps.
Right… I completely missed that - thanks!
For the records, after doing this,the next problem was that
getDefaultValue is also private so it can’t be accessed; I found some useful tips on this thread and managed to get it working.
How about this approach? In short: convert the APVTS to XML, manipulate the XML so all current values are set to their default values, then replace the APVTS with the modified XML.
// in this example, we have named the Processor's AudioProcessorValueTreeState object as "parameters"
ValueTree state = parameters.copyState(); // grab a copy of the current parameters Value Tree
std::unique_ptr<XmlElement> tempXml (state.createXml()); // convert parameters Value Tree to an XML object
// iterate through each "PARAM" element in XML, and overwrite values with their defaults
forEachXmlChildElementWithTagName (*tempXml, child, "PARAM")
float defaultValue = parameters.getParameter(child->getStringAttribute("id"))->getDefaultValue();
parameters.replaceState (ValueTree::fromXml (*tempXml));
to reset to default state, is this not correct?
Ik this is old but I was looking for the same solution as the guy who posted this thread and this worked perfectly for me, so thank you.
Cool, glad it was helpful. Note that the
forEachXmlChildElementWithTagName macro is now deprecated, and the comments note that:
New code should avoid this macro, and instead use getChildWithTagNameIterator directly.
Just something to be aware of, going forward.