- refactored XML structure

- new XML structure not compatible to old structure
This commit is contained in:
2023-04-29 00:05:13 +02:00
parent 08b70cb57b
commit ca353251f4
3 changed files with 142 additions and 96 deletions
+107 -65
View File
@@ -705,24 +705,25 @@ void JaySynthAudioProcessor::commitEditBuffer()
}
}
void JaySynthAudioProcessor::patch2xml(XmlElement& xml, JaySynthSound const *patch)
void JaySynthAudioProcessor::patch2xml(XmlElement *xml, JaySynthSound const *patch)
{
xml.setAttribute ("NAME", patch->getName());
ScopedPointer<XmlElement> xml_patch = xml->createNewChildElement("Patch");
xml_patch->setAttribute ("NAME", patch->getName());
for (int i=0; i < SYNTH_NUM_PARAMS; i++)
{
synth_float_t value = patch->getParameter(i);
xml.setAttribute (getParameterNameXML(i), String(value, 10));
xml_patch->setAttribute (getParameterNameXML(i), String(value, 10));
}
patch->getMidiCC()->exportXML(&xml);
patch->getMidiCC()->exportXML(xml_patch);
}
void JaySynthAudioProcessor::xml2patch(const XmlElement& xml, JaySynthSound *patch)
void JaySynthAudioProcessor::xml2patch(const XmlElement *xml, JaySynthSound *patch)
{
// ok, now pull out our parameters..
patch->setName(xml.getStringAttribute("NAME"));
patch->setName(xml->getStringAttribute("NAME"));
for (int i=0; i < SYNTH_NUM_PARAMS; i++)
{
synth_float_t value = (synth_float_t) xml.getDoubleAttribute (getParameterNameXML(i), patch->getParameter(i));
synth_float_t value = (synth_float_t) xml->getDoubleAttribute (getParameterNameXML(i), patch->getParameter(i));
if (i==SYNTH_PARAM_TUNE)
{
if (value > 400.0)
@@ -732,49 +733,41 @@ void JaySynthAudioProcessor::xml2patch(const XmlElement& xml, JaySynthSound *pat
}
patch->setParameter(i, value);
}
((JaySynthMidiCC*)patch->getMidiCC())->importXML(&xml);
((JaySynthMidiCC*)patch->getMidiCC())->importXML(xml);
}
void JaySynthAudioProcessor::bank2xml(XmlElement& xml)
void JaySynthAudioProcessor::bank2xml(XmlElement *xml)
{
ScopedPointer<XmlElement> xml_bank = xml->createNewChildElement("Bank");
for (int i=0; i < NUM_PROGRAMS; i++)
{
XmlElement *pXml = xml.createNewChildElement (String("PATCH_") + String(i));
ScopedPointer<XmlElement> xml_program = xml_bank->createNewChildElement (String("Program_") + String(i));
JaySynthSound *pPatch = &patches[i];
pXml->setAttribute ("ID", i);
patch2xml(*pXml, pPatch);
xml_program->setAttribute ("ID", i);
patch2xml(xml_program, pPatch);
}
}
void JaySynthAudioProcessor::xml2bank(const XmlElement& xml)
void JaySynthAudioProcessor::xml2bank(const XmlElement *xml)
{
// make sure that it's actually our type of XML object..
XmlElement *pXML = (XmlElement*)&xml;
while(pXML)
while(xml)
{
int progID = pXML->getIntAttribute("ID");
// Read ID
int progID = xml->getIntAttribute("ID");
if (progID >= NUM_PROGRAMS)
{
break;
}
JaySynthSound *pPatch = &patches[progID];
// ok, now pull out our parameters..
pPatch->setName(pXML->getStringAttribute("NAME"));
for (int i=0; i < SYNTH_NUM_PARAMS; i++)
ScopedPointer<XmlElement> xml_patch = xml->getFirstChildElement();
if (xml_patch->hasTagName ("Patch"))
{
synth_float_t value = (synth_float_t) pXML->getDoubleAttribute (getParameterNameXML(i), pPatch->getParameter(i));
if (i==SYNTH_PARAM_TUNE)
{
if (value > 400.0)
{
value = 1200*log(value/440)/log(2.0);
}
}
pPatch->setParameter(i, value);
// Read patch
xml2patch(xml_patch, pPatch);
}
((JaySynthMidiCC*)pPatch->getMidiCC())->importXML(pXML);
pXML = pXML->getNextElement();
xml = xml->getNextElement();
}
}
@@ -783,9 +776,9 @@ void JaySynthAudioProcessor::getStateInformation (MemoryBlock& destData)
commitEditBuffer();
// Create an outer XML element..
ScopedPointer<XmlElement>xml = new XmlElement("JSYNTH_BANK");
bank2xml(*xml);
XmlElement *xml = new XmlElement("JSynth");
bank2xml(xml);
setCurrentProgram(getCurrentProgram());
MemoryOutputStream outputStream(destData, false);
@@ -800,36 +793,32 @@ void JaySynthAudioProcessor::getStateInformation (MemoryBlock& destData)
void JaySynthAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
int uncompressedSize;
String lastError;
ScopedPointer<XmlElement> xmlState = NULL;
void* pData;
int size;
ScopedPointer<char> pUncompressedData;
pUncompressedData = new char[8192*1024];
ScopedPointer<char> pUncompressedData = new char[8192*1024];
MemoryInputStream inputStream(data, sizeInBytes, false);
GZIPDecompressorInputStream GZIPDec(inputStream);
uncompressedSize = GZIPDec.read(pUncompressedData, 8192*1024);
int uncompressedSize = GZIPDec.read(pUncompressedData, 8192*1024);
pData = (void *)data;
size = sizeInBytes;
void* pData = (void *)data;
int size = sizeInBytes;
if (uncompressedSize)
{
pData = (void *)pUncompressedData;
size = uncompressedSize;
}
xmlState = getXmlFromBinary(pData, size);
ScopedPointer<XmlElement> xml = getXmlFromBinary(pData, size);
if (xmlState != 0)
if (xml != 0)
{
// make sure that it's actually our type of XML object..
if (xmlState->hasTagName ("JSYNTH_BANK"))
{
XmlElement *pXML = xmlState->getFirstChildElement();
xml2bank(*pXML);
}
if (xml->hasTagName ("JSynth"))
{
xml = xml->getFirstChildElement();
if (xml->hasTagName ("Bank"))
{
xml = xml->getFirstChildElement();
xml2bank(xml);
}
}
setCurrentProgram(getCurrentProgram());
}
}
@@ -849,9 +838,9 @@ void JaySynthAudioProcessor::getCurrentProgramStateInformation (MemoryBlock& des
GZIPCompressorOutputStream GZIPEnc(&outputStream, /*compressionLevel*/0, /*deleteDestStreamWhenDestroyed*/false, /*windowBits*/0);
// Create an outer XML element..
ScopedPointer<XmlElement>xml = new XmlElement("JSYNTH_PATCH");
ScopedPointer<XmlElement> xml = new XmlElement("JSynth");
patch2xml(xml, currpatch);
patch2xml(*xml, currpatch);
setCurrentProgram(getCurrentProgram());
// then use this helper function to stuff it into the binary blob and return it..
@@ -887,12 +876,8 @@ void JaySynthAudioProcessor::setCurrentProgramStateInformation (const void* data
if (xmlState != 0)
{
// make sure that it's actually our type of XML object..
if (xmlState->hasTagName ("JSYNTH_PATCH"))
{
xml2patch(*xmlState, currpatch);
setCurrentProgram(getCurrentProgram());
}
xml2patch(xmlState, currpatch);
setCurrentProgram(getCurrentProgram());
}
}
@@ -915,11 +900,39 @@ void JaySynthAudioProcessor::loadPatch (const File &file, int index)
}
}
}
else if (String(".xmp") == ext)
{
XmlElement *xml = XmlDocument::parse(file);
if (xml->hasTagName ("JSynth"))
{
ScopedPointer<XmlElement> xml2 = xml->getFirstChildElement();
if (xml2->hasTagName ("Patch"))
{
xml2patch(xml2, currpatch);
setCurrentProgram(getCurrentProgram());
}
}
}
}
void JaySynthAudioProcessor::savePatch (const File &file, int index)
{
String filename(file.getFullPathName());
String ext = file.getFileExtension();
if (String(".fxp") == ext)
{
// ToDo: implement fxp save
}
else if (String(".xmp") == ext)
{
commitEditBuffer();
// Create an outer XML element..
ScopedPointer<XmlElement> xml = new XmlElement("JSynth");
patch2xml(xml, currpatch);
// Write XML to file
xml->writeToFile (/*const File &destinationFile*/file, /*dtdToUse*/"");
}
}
//#include <juce_ByteOrder.h>
@@ -942,11 +955,40 @@ void JaySynthAudioProcessor::loadBank (const File &file)
}
}
}
else if (String(".xmb") == ext)
{
XmlElement *xml = XmlDocument::parse(file);
if (xml->hasTagName ("JSynth"))
{
XmlElement *xml2 = xml->getFirstChildElement();
if (xml2->hasTagName ("Bank"))
{
XmlElement *xml3 = xml2->getFirstChildElement();
xml2bank(xml3);
setCurrentProgram(getCurrentProgram());
}
}
}
}
void JaySynthAudioProcessor::saveBank (const File &file)
{
String filename(file.getFullPathName());
String ext = file.getFileExtension();
if (String(".fxb") == ext)
{
// ToDo: implement fxp save
}
else if (String(".xmb") == ext)
{
commitEditBuffer();
// Create an outer XML element..
ScopedPointer<XmlElement> xml = new XmlElement("JSynth");
bank2xml(xml);
// Write XML to file
xml->writeToFile (/*const File &destinationFile*/file, /*dtdToUse*/"");
}
}
//==============================================================================