When Value object of ValueTree property is changed after setStateInformation call, property Value does not trigger changes to its referred Value object

I have a Value in the editor that refers to a property Value in the processor’s AudioProcessorValueTreeState’s ValueTree (state). So any changes made to one Value is made to the other, which works fine in every case except when a new property Value has just been loaded into the ValueTree from setStateInformation. So the issue is that I’m not sure why the Value in the editor does not get updated only when the property Value of the ValueTree has been updated after setStateInformation is called.

In my processor class I have:

AudioProcessorValueTreeState parameters;
Identifier Processor::propertyType (name of property); //a static Identifier

ProcessorConstructor()
{
    //.....
    parameters.state = ValueTree(Identifier(name)); //initialized after adding all parameters
    parameters.state.setProperty(propertyType, 0, nullptr );
}

getStateInformation (MemoryBlock& destData)
{
    //just like the tutorial
    auto state = parameters.copyState();
    std::unique_ptr<XmlElement> xml (state.createXml());
    copyXmlToBinary (*xml, destData);
}

setStateInformation (const void* data, int sizeInBytes)
{
    std::unique_ptr<XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));
    if (xmlState.get() != nullptr)
        if (xmlState->hasTagName (parameters.state.getType()))
            parameters.replaceState (ValueTree::fromXml (*xmlState));
}

In the editor, I use the Value provided by the ComboBox. I tried using ComboBoxAttachment and it didn’t work (even though it worked when I used it in a non-editor/non-component class for the same processor class). I also tried it with a separate Value member from the Editor and still got the same result.

This is what I have for it:

Processor& processor;
std::unique_ptr<ComboBox> dropDown;

editorConstructor()
{
    //.....
    dropDown->getSelectedIdAsValue().referTo(processor.parameters.state.getPropertyAsValue(processor.propertyType, nullptr));
}

Here

dropDown->getSelectedIdAsValue().referTo(processor.parameters.state.getPropertyAsValue(processor.propertyType, nullptr));

you are referring to a value stored the the parameters.state ValueTree. This ValueTree then gets replaced in setStateInformation,

void setStateInformation (const void* data, int sizeInBytes)
{
    std::unique_ptr<XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));
    if (xmlState.get() != nullptr)
        if (xmlState->hasTagName (parameters.state.getType()))
            parameters.replaceState (ValueTree::fromXml (*xmlState));
}

so the link between the ValueTree and the Value is broken.

You could do something like have an additional Value in your processor which is attached to the ValueTree, but is then re-attached after each setStateInformation call. Your editors can then all refer to this additional Value.

1 Like

Problem solved.

Thanks t0m!