Hard coded presets - how to store in code?

Hello,
it’s probably stupid and easy question, but I’ve just spent about 4 hours to find the solution.

I want to prepare my presets in Logic Pro X, and store them as regular aupreset.
But then, when I already prepare all presets, I want to import all of them to code to have them hard coded in my plugin.

I tried to store the data as a String, and then make some conversions with Base64 converters, some String methods, MemoryBlock etc. But nothing works for me.

The only solution I’ve found is to copy text from my aupreset file, then on some website online converter convert it to base64, and then the result also with online converter to hex, and then I copy that hex code as a array in
static const unsigned char temp_binary_data_nn[] = { 0x56, 0x43, 0x32 .... };

And then I assing that array to:
const void* myBinary = temp_binary_data_nn;

and after then I can create:
std::unique_ptr<XmlElement> theParams (getXmlFromBinary(dupa, sizeOfmyBinary));

And it works for me, but I supose there is some much easier method to solve such issue. But I can’t find it.

For any help thanks in advance.

Have you tried adding the files to your project via the File Explorer in the Projucer?

Once added you can right-click to make sure they are being added to the project as a binary resource, then access in your code via the BinaryData namespace.

For example, if the files are all XML text you could access them in the code by writing something like:

auto text = String::createStringFromData (BinaryData::PresetFileName_aupreset, BinaryData::PresetFileName_aupresetSize);
auto xml = parseXML (text);
1 Like

Hey, it sounds great. Thanks.

auto text = String::createStringFromData (BinaryData::PresetFileName_aupreset, BinaryData::PresetFileName_aupresetSize);
auto xml = parseXML (text);

OK, that’s great but if I do like you showed then I get always false when:
if( xml->hasTagName("jucePluginState"))

So the ValueTree::fromXml(*xml); needs to get as parameter not the whole *.aupreset but some part of it with tag name "jucePluginState"
But I have no idea how to dig deeper inside xml to get XmlElement which is needed in ValueTree::fromXml(*xml);

Your approach to creating presets does sound super complicated! There are definitely easier ways.

Are you managing parameters in your plug-in with the APVTS class? (As shown in this tutorial.)

Hello,
yes I managing parameters as it is shown in linked tutorial.
The problem is: I don’t want to have presets in separated files, but instead I want it to be hard coded in my AU component file, or in *.vst3 file.

So as I understand I should store somewere in code something like that:
const XmlElement myPreset01 = ???;

And then use it to call:
myAPVTS.replaceState (ValueTree::fromXml (myPreset01));

So the question is how to define const XmlElement myPreset01 = ???;
According to documentation, it should be created by ValueTree::createXml()
but it gives me std::unique_ptr<XmlElement> instead const XmlElement
But even it would give me const XmlElement I still need to have stored in some way const ValueTree myState01.

Oh! I feel lost :slight_smile:

Here’s a JUCE PIP (you can load it in the Projucer) for a command-line application that will try to extract the ValueTree state as XML from an .aupreset file.

You could use this to convert any .aupreset files you save to .xml files. You could then add those XML files to your jucer project and they should load into ValueTree::fromXml.

The PIP is just an example, I haven’t thoroughly tested it and with a bit of modification it could be made to convert an enitre folder.

1 Like

Hello, great thanks for your help. In the end it works for me.
I use that:
std::unique_ptr<XmlElement> xml(myParams.state.createXml());

Then I write it to file. And then such file I put in projucer to get binary version.
And then your instruction works:

auto text = String::createStringFromData (BinaryData::PresetFileName_aupreset, BinaryData::PresetFileName_aupresetSize);
auto xml = parseXML (text);

Great thanks for help

You all keep quoting this code:

…but it’s over-complicating things - all you need to write is this:

auto xml = parseXML (BinaryData::PresetFileName_aupreset);

!

4 Likes

Yes, this sounds more on track for a sane workflow! What you described about saving presets as aupreset files and then extracting the data sounded about 100x more complicated than needed.

For my “hard coded” factory presets I use the same basic idea, but after saving a temp XML file for each preset, I then copy/paste that data into a single factory presets XML file in the project’s source tree. (Then Projucer handles converting that to a binary object.) I also take that opportunity to add some meta-data to each preset, like the preset name.