Write arrays of floats into XML

Is there a demo or walkthrough somewhere on how to write an array of floats into XML?

…or does someone just wanna drop a hint on the best way to do that?

I am storing float array data as Base64 string. It isn’t human readable tough:

float data[129];
MemoryBlock b(data, sizeof(float) * 129);
String dataString = b.toBase64Encoding();

Reading it back:

MemoryBlock b2;
b2.fromBase64Encoding(dataString);
FloatVectorOperations::copy(data, b2.getData(), 129); // add some safe checks in real code

Yep, there are probably 10 different ways you could do it, but it depends entirely on what the use-case is…

i want to save and load arrays of midi note info.

in my Sequence class, i have a struct like:

struct Parameters
{
    bool noteExists;
    int midiNumber;
    float lengthInSteps;
    uint8 velocity;
    int cc1;
    int cc2;
};

and my sequence reads and writes from an array of those structs.
I also have getter and setter functions for each parameter in my Sequence class.

max number of steps is 128, if that is important.

Directly you could:

auto root = new XmlElement("root"); 
for (...) {
auto child = new XmlElement("note");
child->setAttribute("midiNumber", note->midiNumber); 
// ...
root.addChildElement(child); 
}
1 Like