How to get a grouped representation xml with an audio processor value tree state

Hi folks,

I’m currently using an audioprocessorvaluetreestate to manage several effect parameters.
I would like to export my effect settings from the value tree to a xml file.
We all know that the effects are stored like this:

<Identifier>
  <PARAM id="CompressorAttack" value="1.0"/>
  <PARAM id="CompressorRatio" value="50.0"/>
  <PARAM id="FilterCuttOff" value="0.5"/>
  <PARAM id="FilterQ" value="0.8"/>
</Identifier>

But would it be possible to use AudioProcessorParameterGroups and get a representation like this:

<ParameterGroups>
          <Group name="Compressor">
            <Parameter id="CompressorAttack" value="1.0"/>
            <Parameter id="CompressorRatio" value="50.0"/>
          </Group>
          <Group name="Filter">
            <Parameter id="FilterCuttOff" value="0.5"/>
            <Parameter id="FilterQ" value="0.8"/>
          </Group>
</ParameterGroups>

So far I found that this representation was possible with a value tree using this method:
ValueTree (const Identifier& type, std::initializer_list<NamedValueSet::NamedValue> properties, std::initializer_list<ValueTree> subTrees = {});

But then I cannot use audioprocessorvaluetreestate.
If I init audioprocessorvaluetreestate with AudioProcessorParameterGroups I still don’t get the desired representation and the juce source code seems to indicate that the group feature is not used by the internal value tree.

I’m looking for getting the desired representation with this kind of call:
audioprocessorvaluetreestate.state.toXmlString()

Would you have an idea to get this representation?

I’m still trying to resolve this. Nobody already encountered this kind of issue?

What do you want to use the XML for?

You can iterate over the parameter tree to do this:

std::function<void(const AudioProcessorParameterGroup&, XmlElement&)> createGroups;
createGroups = [&createGroups](const AudioProcessorParameterGroup& apGroup, XmlElement& xmlGroup)
{
    for (auto node : apGroup)
    {
        if (auto group = node->getGroup())
        {
            auto element = xmlGroup.createNewChildElement ("GROUP");
            element->setAttribute ("name", group->getName());
            createGroups (*group, *element);
        }
        else if (auto parameter = node->getParameter())
        {
            auto element = xmlGroup.createNewChildElement ("PARAMETER");
            element->setAttribute ("name", parameter->getName (256));
            element->setAttribute ("value", parameter->getValue());
        }
    }
};

XmlElement root ("ROOT");
createGroups (getParameterTree(), root);
std::cout << root.toString();

Thanks for your reply. I’m really sorry for replying to you only now but the project was kind of abandoned and I’ve been away from JUCE dev this last weeks.

The goal of this is to export parameters data as a XML or JSON in a formatted architecture that will be parsed by an external service.
That’s the reason I cannot use the simple representation I mentioned first.

Thanks for your exemple I will try it when the project will come back to life in few weeks I guess.