Any way to view a value tree?

Hi, is there a way to easily print out a value tree to see all of its contents?
It is practically impossible to click through the variabes section of visual studio.

There is a great tool for this in the juce-toys, GitHub - jcredland/juce-toys: Debugging utilities in a JUCE Module, plus NatVis and LLDB customizations. Follow the instructions to install the juce.natvis file, and you will have a much better view of ValueTrees, and a number of other JUCE containters.

3 Likes

Thanks, this is really useful!

The juce-toys thing is great, though I think I remember having to modify the files a bit before I could get it to work.

If you’re looking for something simpler, then you can use valueTree.toXmlString() to print ValueTrees as XML.

Personally, I have set up a global function like this:

void printVT(ValueTree toPrint)
{
    static const Identifier printTest("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

    toPrint.setProperty(printTest, "x", nullptr);

    DBG(toPrint.getRoot().toXmlString());

    toPrint.removeProperty(printTest, nullptr);
}

This prints the whole tree and puts a marker on the node that you’re looking at. It’s pretty crude, but very useful for debugging.

1 Like

@LiamG I actually updated the juce-toys a while back and submitted a PR which fixed them (along with other changes to juce containers). But, you are also right, in that there are instances where dumping the whole thing makes sense.

Do you know if this kind of tool exist for Xcode? juce-toys seems to be made for Visual Studio only.

I think the juce-toys has one for xcode as well, juce_lldb_xcode.py., but I did not update it as I did the VS one. Hopefully Jim will update it, but if not, I suspect I eventually do it to, as I do cross platform work, and I always bemoan this missing in xcode.

Thanks! I’m sorry I didn’t see this file :sweat_smile:

I was never able to get this working in XCode, or didn’t understand what it was supposed to add and how to access it properly.

I need to take a swing at it. if I do I will post an update here, with any extra info on getting it setup.

2 Likes

Hey @cpr2323(/all), can you help me get the .natvis for juce-toys to stay registered in my jucer file?

Apologies if this is a dumb question, but it just won’t save the solution after I add it. I have a clone of juce-toys in my user modules folder. I add the module to the projucer file with a local copy. It copies the files into JUCE Library Code/modules/jcf_debug, as expected.

I then copy over the juce.natvis file into the jcf_debug. Right click on my solution, add existing item, it seems to load properly (according to the docs, this happens automatically in VS2022).

But there are no changes I can commit and when I close/reopen VS2022, the natvis file is deleted natvis file is only saved if I add it to the global jfc_debug folder (makes sense as juce.natvis is at the repo level, one directory above the module itself).

How do we add solution-level files in projucer? I only have “Fonts” and “Source” directories in the File Explorer tab, and no relevant options in the Modules tab.

Cheers! :smiley:


edit: I got this working by including the .natvis in my VS2022 installation folder. For me, the file goes in Microsoft Visual Studio\2022\Community\Common7\Packages\Debugger\Visualizers. This is the 5th location identified under “Natvis file locations” in the docs I linked.

After that I had to set
JUCE_MODAL_LOOPS_PERMITTED 1
in the file juce_PlatformDefs.h (for my overall Juce installation; hopefully this doesn’t cause any problems later) to get the example code running. Now that it is proven I’ll be able to incorporate juce-toys in my project!