While debugging I regularly need to figure out information about a particular ValueTree instance, and where it belongs on its hierarchy. toXmlString()
tells you about a ValueTree’s children, but not its parents, which what you need to know if you’re trying to locate it.
I’ve probably accumulated and wasted several hours on this over the last few months, so I thought I’d invest some time into this problem, and came up with this quick and dirty solution:
void printVT(ValueTree& vtToPrint)
{
auto identifyMe = Identifier("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
vtToPrint.setProperty(identifyMe, var(), nullptr);
DBG(vtToPrint.getRoot().toXmlString());
vtToPrint.removeProperty(identifyMe, nullptr);
}
As you can see, this function prints out the entire hierarchy, with the identifier “xxxxxxxxxxxx” attached to the one you’re trying to find. Very useful!
Of course this might have unintended consequences if it notifies listeners to the change in properties. I guess you could exclude them, but in any case this is only intended for quick debugging scenarios.
Does anyone have any other tips for interrogating ValueTrees?