Best way to get XML into memory

I have an audio plugin that needs to load some XML into memory to construct memory-based factory presets, and also to write them out as VST preset files. What is the best way to get these into memory (on both Mac and Windows, since on Windows there is no bundle where they can be stored internally).

I thought I’d store them as Xcode resources, so that I can simply copy them to the desired location for the AAX version (at least on Mac), and also as binary resources, so that other plugin types can read and convert them.

But I’m not seeing how to load binary resources into an XmlDocument. It appears I need to use either a String or a File to do this, but again, I don’t see how to specify a binary resource to do that. I do it all the time with bitmap resources, but is there something similar to getFromMemory() for String or File objects (or directly for XmlDocuments)?

Since XML is a text format, it is safe to use String here. And String has a constructor that takes a const char*: String (const char*)
You don’t even need to supply the maxChars, since it is zero terminated, and it’s in your binary, so nobody can trigger a buffer overflow vulnerability (but for safety, you could use it.

auto xml = XmlDocument::parse (String (BinaryData::foo_xml, BinaryData::foo_xmlSize));

N.B. not sure if this applies to your use case as well:

To create strings with extended characters from UTF-8, you should explicitly call String (CharPointer_UTF8 (“my utf8 string…”)). It’s highly recommended that you use UTF-8 with escape characters in your source code to represent extended characters, because there’s no other way to represent unicode strings in a way that isn’t dependent on the compiler, source code editor and platform.

3 Likes

Nice! Thanks!
It just occurred to me, though… is there a unified way to handle factory presets using JUCE? What I’m trying to do with the above code is handle them the way we did before JUCE, with AAX and VST2 being files and VST3 (and what was “wrapped” AU) being ProgramList members. Is there a better JUCE way?

Ok, I have AAX and AU working, but not sure how to handle VST3. Nothing shows up in Cubase ir Studio One (as VST3) just implementing the getProgramName / getNumPrograms / getCurrentProgram / setCurrentProgram functions.

In my pre-JUCE code, I used the VST3 function addProgramList() to add items to a ProgramList object. How do I do that in JUCE?

Looks like I have to do something with IUnitInfo, but not sure what exactly. Anyone have info on this, or example code anywhere?

Starting a separate topic for this, since it’s not really the issue given in the topic.