I think I must be misunderstanding something about ValueTree handling. I cant seem to get data saved to a file back into my ValueTree.
I have a method that saves the some settings in a ValueTree:
void DrumController::setFileForActivePad(const File file )
{
synthAudioSource->setSampleForSound(lastSelectedPad - 1, file);
String nodeName;
nodeName << "pad" << lastSelectedPad;
Identifier nodeIdentifier(nodeName);
ValueTree padParameters = drumSettings.getOrCreateChildWithName(nodeIdentifier, nullptr);
padParameters.setProperty("audioFilePath", file.getFullPathName(), nullptr);
saveDefaultSettings();
}
this calls saveDefaultSettings which writes the ValueTree to a binary file:
void DrumController::saveSettings(File &settingsFile)
{
std::cout << drumSettings.toXmlString();
FileOutputStream os(settingsFile);
drumSettings.writeToStream(os);
}
the console is showing me the contents of my ValueTree before writing to the file. For example:
<?xml version="1.0" encoding="UTF-8"?>
<drumSettings>
<pad1 audioFilePath="/Users/alexgustafson/Music/newSample/perc/kick2.wav"/>
<pad2 audioFilePath="/Users/alexgustafson/Music/newSample/perc/snare2.wav"/>
<pad3 audioFilePath="/Users/alexgustafson/Music/newSample/perc/hihat_01.wav"/>
</drumSettings>
I can see the file size increasing as I write new data.
However when I import the file back to ValueTree I only see the first 2 nodes:
<?xml version="1.0" encoding="UTF-8"?>
<drumSettings>
<pad1 audioFilePath="/Users/alexgustafson/Music/newSample/perc/kick2.wav"/>
</drumSettings>
This is the code for reading the data back into a ValueTree:
void DrumController::loadSettings(File &settingsFile)
{
if (!settingsFile.exists()) {
return;
}
FileInputStream is(settingsFile);
drumSettings = ValueTree::readFromStream(is);
std::cout << drumSettings.toXmlString();
}
On my console I see:
<?xml version="1.0" encoding="UTF-8"?>
<drumSettings>
<pad1 audioFilePath="/Users/alexgustafson/Music/newSample/perc/kick2.wav"/>
</drumSettings>
only the first child node exists. The others are missing.
Can anyone tell my what I’m doing wrong? Any tips would be greatly appreciated.
Thanks in advance!