Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created February 2, 2019 11:28
Show Gist options
  • Save Xenakios/084ea2eaa7f2cb04bc6d262d15f2f878 to your computer and use it in GitHub Desktop.
Save Xenakios/084ea2eaa7f2cb04bc6d262d15f2f878 to your computer and use it in GitHub Desktop.
void saveToXml(File dest, std::vector<std::vector<int>> src)
{
if (dest.exists())
dest.deleteFile();
XmlElement chordselem("chords");
for (int i=0;i<src.size();++i)
{
XmlElement* chordelem = chordselem.createNewChildElement("chord_"+String(i));
for (int j = 0; j < src[i].size(); ++j)
{
chordelem->setAttribute("note_"+String(j), src[i][j]);
}
}
chordselem.writeToFile(dest, "");
}
std::vector<std::vector<int>> readFromXml(File src)
{
std::vector<std::vector<int>> result;
auto xml = juce::parseXML(src);
int numchildren = xml->getNumChildElements();
result.resize(numchildren);
for (int i = 0; i < numchildren; ++i)
{
auto chordelem = xml->getChildElement(i);
int numnotes = chordelem->getNumAttributes();
result[i].resize(numnotes);
for (int j = 0; j < chordelem->getNumAttributes(); ++j)
{
result[i][j] = chordelem->getAttributeValue(j).getIntValue();
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment