- 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
+31 -27
View File
@@ -2126,26 +2126,26 @@ JaySynthAudioProcessorEditor::JaySynthAudioProcessorEditor (JaySynthAudioProcess
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Buttons // Buttons
// -------------------------------------------------------------------- // --------------------------------------------------------------------
m_btn_osc0_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_OSC_0_ENABLE)); m_btn_osc0_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_OSC_0_ENABLE));
m_btn_osc1_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_OSC_1_ENABLE)); m_btn_osc1_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_OSC_1_ENABLE));
m_btn_noise_enable_led->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_NOISE_ENABLE)); m_btn_noise_enable_led->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_NOISE_ENABLE));
m_button_humanize_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_HUMANIZE_ENABLE)); m_button_humanize_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_HUMANIZE_ENABLE));
m_button_mono_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_MONOPHONIC_ENABLE)); m_button_mono_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_MONOPHONIC_ENABLE));
m_button_mono_retrigger->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_MONOPHONIC_RETRIGGER_ENABLE)); m_button_mono_retrigger->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_MONOPHONIC_RETRIGGER_ENABLE));
m_button_unisono_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_UNISONO_ENABLE)); m_button_unisono_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_UNISONO_ENABLE));
m_button_osc0_restart_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_OSC_0_RESTART_ON_TRIGGER)); m_button_osc0_restart_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_OSC_0_RESTART_ON_TRIGGER));
m_button_osc1_restart_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_OSC_1_RESTART_ON_TRIGGER)); m_button_osc1_restart_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_OSC_1_RESTART_ON_TRIGGER));
m_button_lfo0_restart_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_LFO_0_SYNC)); m_button_lfo0_restart_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_LFO_0_SYNC));
m_button_lfo1_restart_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_LFO_1_SYNC)); m_button_lfo1_restart_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_LFO_1_SYNC));
m_button_lfo2_restart_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_LFO_2_SYNC)); m_button_lfo2_restart_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_LFO_2_SYNC));
m_button_lfo3_restart_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_LFO_3_SYNC)); m_button_lfo3_restart_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_LFO_3_SYNC));
m_button_lfo0_individual_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_LFO_0_MODE)); m_button_lfo0_individual_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_LFO_0_MODE));
m_button_lfo1_individual_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_LFO_1_MODE)); m_button_lfo1_individual_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_LFO_1_MODE));
m_button_lfo2_individual_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_LFO_2_MODE)); m_button_lfo2_individual_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_LFO_2_MODE));
m_button_lfo3_individual_enable->setComponentID(String("BUTTON ") + String(SYNTH_PARAM_LFO_3_MODE)); m_button_lfo3_individual_enable->setComponentID(String("PARAM_BUTTON ") + String(SYNTH_PARAM_LFO_3_MODE));
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Sliders // Sliders
@@ -4933,7 +4933,7 @@ void JaySynthAudioProcessorEditor::buttonClicked (Button* buttonThatWasClicked)
if (buttonThatWasClicked == m_button_bank_load) if (buttonThatWasClicked == m_button_bank_load)
{ {
String filePatterns("*.fxb;*.xml"); String filePatterns("*.fxb;*.xmb");
FileChooser fc("Load bank", m_fileChooserDirectory, filePatterns, false); FileChooser fc("Load bank", m_fileChooserDirectory, filePatterns, false);
if (fc.browseForFileToOpen()) if (fc.browseForFileToOpen())
{ {
@@ -4944,7 +4944,7 @@ void JaySynthAudioProcessorEditor::buttonClicked (Button* buttonThatWasClicked)
} }
else if (buttonThatWasClicked == m_button_bank_save) else if (buttonThatWasClicked == m_button_bank_save)
{ {
String filePatterns("*.fxb;*.xml"); String filePatterns("*.fxb;*.xmb");
FileChooser fc("Save bank", m_fileChooserDirectory, filePatterns, false); FileChooser fc("Save bank", m_fileChooserDirectory, filePatterns, false);
if (fc.browseForFileToSave(true)) if (fc.browseForFileToSave(true))
{ {
@@ -4955,7 +4955,7 @@ void JaySynthAudioProcessorEditor::buttonClicked (Button* buttonThatWasClicked)
} }
else if (buttonThatWasClicked == m_button_patch_load) else if (buttonThatWasClicked == m_button_patch_load)
{ {
String filePatterns("*.fxp;*.xml"); String filePatterns("*.fxp;*.xmp");
FileChooser fc("Load patch", m_fileChooserDirectory, filePatterns, false); FileChooser fc("Load patch", m_fileChooserDirectory, filePatterns, false);
if (fc.browseForFileToOpen()) if (fc.browseForFileToOpen())
{ {
@@ -4966,7 +4966,7 @@ void JaySynthAudioProcessorEditor::buttonClicked (Button* buttonThatWasClicked)
} }
else if (buttonThatWasClicked == m_button_patch_save) else if (buttonThatWasClicked == m_button_patch_save)
{ {
String filePatterns("*.fxp;*.xml"); String filePatterns("*.fxp;*.xmp");
FileChooser fc("Save patch", m_fileChooserDirectory, filePatterns, false); FileChooser fc("Save patch", m_fileChooserDirectory, filePatterns, false);
if (fc.browseForFileToSave(true)) if (fc.browseForFileToSave(true))
{ {
@@ -4986,12 +4986,6 @@ void JaySynthAudioProcessorEditor::buttonClicked (Button* buttonThatWasClicked)
return; return;
} }
paramID = (int)(buttonThatWasClicked->getComponentID()).getTrailingIntValue();
value = (float)buttonThatWasClicked->getToggleState();
pParamInfo = getParamInfo(paramID);
if (pParamInfo)
getProcessor()->setParam(paramID, toParam(pParamInfo, (synth_float_t)value), true, true);
if (buttonThatWasClicked == m_button_humanize_enable) if (buttonThatWasClicked == m_button_humanize_enable)
{ {
getProcessor()->humanizeModeChanged(); getProcessor()->humanizeModeChanged();
@@ -5007,6 +5001,16 @@ void JaySynthAudioProcessorEditor::buttonClicked (Button* buttonThatWasClicked)
getProcessor()->unisonoModeChanged(); getProcessor()->unisonoModeChanged();
} }
if (buttonThatWasClicked->getComponentID().startsWith("PARAM"))
{
paramID = (int)(buttonThatWasClicked->getComponentID()).getTrailingIntValue();
value = (float)buttonThatWasClicked->getToggleState();
pParamInfo = getParamInfo(paramID);
if (pParamInfo)
{
getProcessor()->setParam(paramID, toParam(pParamInfo, (synth_float_t)value), true, true);
}
}
} }
void JaySynthAudioProcessorEditor::mouseDown (const MouseEvent &m) void JaySynthAudioProcessorEditor::mouseDown (const MouseEvent &m)
+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++) for (int i=0; i < SYNTH_NUM_PARAMS; i++)
{ {
synth_float_t value = patch->getParameter(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.. // 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++) 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 (i==SYNTH_PARAM_TUNE)
{ {
if (value > 400.0) if (value > 400.0)
@@ -732,49 +733,41 @@ void JaySynthAudioProcessor::xml2patch(const XmlElement& xml, JaySynthSound *pat
} }
patch->setParameter(i, value); 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++) 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]; JaySynthSound *pPatch = &patches[i];
pXml->setAttribute ("ID", i); xml_program->setAttribute ("ID", i);
patch2xml(*pXml, pPatch); 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.. while(xml)
XmlElement *pXML = (XmlElement*)&xml;
while(pXML)
{ {
int progID = pXML->getIntAttribute("ID"); // Read ID
int progID = xml->getIntAttribute("ID");
if (progID >= NUM_PROGRAMS) if (progID >= NUM_PROGRAMS)
{
break; break;
}
JaySynthSound *pPatch = &patches[progID]; JaySynthSound *pPatch = &patches[progID];
// ok, now pull out our parameters.. ScopedPointer<XmlElement> xml_patch = xml->getFirstChildElement();
pPatch->setName(pXML->getStringAttribute("NAME")); if (xml_patch->hasTagName ("Patch"))
for (int i=0; i < SYNTH_NUM_PARAMS; i++)
{ {
synth_float_t value = (synth_float_t) pXML->getDoubleAttribute (getParameterNameXML(i), pPatch->getParameter(i)); // Read patch
if (i==SYNTH_PARAM_TUNE) xml2patch(xml_patch, pPatch);
{
if (value > 400.0)
{
value = 1200*log(value/440)/log(2.0);
}
}
pPatch->setParameter(i, value);
} }
((JaySynthMidiCC*)pPatch->getMidiCC())->importXML(pXML); xml = xml->getNextElement();
pXML = pXML->getNextElement();
} }
} }
@@ -783,9 +776,9 @@ void JaySynthAudioProcessor::getStateInformation (MemoryBlock& destData)
commitEditBuffer(); commitEditBuffer();
// Create an outer XML element.. // Create an outer XML element..
ScopedPointer<XmlElement>xml = new XmlElement("JSYNTH_BANK"); XmlElement *xml = new XmlElement("JSynth");
bank2xml(xml);
bank2xml(*xml);
setCurrentProgram(getCurrentProgram()); setCurrentProgram(getCurrentProgram());
MemoryOutputStream outputStream(destData, false); MemoryOutputStream outputStream(destData, false);
@@ -800,36 +793,32 @@ void JaySynthAudioProcessor::getStateInformation (MemoryBlock& destData)
void JaySynthAudioProcessor::setStateInformation (const void* data, int sizeInBytes) void JaySynthAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{ {
int uncompressedSize; ScopedPointer<char> pUncompressedData = new char[8192*1024];
String lastError;
ScopedPointer<XmlElement> xmlState = NULL;
void* pData;
int size;
ScopedPointer<char> pUncompressedData;
pUncompressedData = new char[8192*1024];
MemoryInputStream inputStream(data, sizeInBytes, false); MemoryInputStream inputStream(data, sizeInBytes, false);
GZIPDecompressorInputStream GZIPDec(inputStream); GZIPDecompressorInputStream GZIPDec(inputStream);
uncompressedSize = GZIPDec.read(pUncompressedData, 8192*1024); int uncompressedSize = GZIPDec.read(pUncompressedData, 8192*1024);
pData = (void *)data; void* pData = (void *)data;
size = sizeInBytes; int size = sizeInBytes;
if (uncompressedSize) if (uncompressedSize)
{ {
pData = (void *)pUncompressedData; pData = (void *)pUncompressedData;
size = uncompressedSize; 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 (xml->hasTagName ("JSynth"))
if (xmlState->hasTagName ("JSYNTH_BANK")) {
{ xml = xml->getFirstChildElement();
XmlElement *pXML = xmlState->getFirstChildElement(); if (xml->hasTagName ("Bank"))
xml2bank(*pXML); {
} xml = xml->getFirstChildElement();
xml2bank(xml);
}
}
setCurrentProgram(getCurrentProgram()); setCurrentProgram(getCurrentProgram());
} }
} }
@@ -849,9 +838,9 @@ void JaySynthAudioProcessor::getCurrentProgramStateInformation (MemoryBlock& des
GZIPCompressorOutputStream GZIPEnc(&outputStream, /*compressionLevel*/0, /*deleteDestStreamWhenDestroyed*/false, /*windowBits*/0); GZIPCompressorOutputStream GZIPEnc(&outputStream, /*compressionLevel*/0, /*deleteDestStreamWhenDestroyed*/false, /*windowBits*/0);
// Create an outer XML element.. // 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()); setCurrentProgram(getCurrentProgram());
// then use this helper function to stuff it into the binary blob and return it.. // 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) if (xmlState != 0)
{ {
// make sure that it's actually our type of XML object.. xml2patch(xmlState, currpatch);
if (xmlState->hasTagName ("JSYNTH_PATCH")) 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) 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> //#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) 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*/"");
}
} }
//============================================================================== //==============================================================================
+4 -4
View File
@@ -207,11 +207,11 @@ public:
XmlElement* getXmlFromBinary (const void* data, const int sizeInBytes); XmlElement* getXmlFromBinary (const void* data, const int sizeInBytes);
const String getParameterNameXML (int index); const String getParameterNameXML (int index);
void patch2xml(XmlElement& xml, JaySynthSound const *patch); void patch2xml(XmlElement *xml, JaySynthSound const *patch);
void xml2patch(const XmlElement& xml, JaySynthSound *patch); void xml2patch(const XmlElement *xml, JaySynthSound *patch);
void bank2xml(XmlElement& xml); void bank2xml(XmlElement *xml);
void xml2bank(const XmlElement& xml); void xml2bank(const XmlElement *xml);
void getCurrentProgramStateInformation (MemoryBlock& destData); void getCurrentProgramStateInformation (MemoryBlock& destData);
void setCurrentProgramStateInformation (const void* data, int sizeInBytes); void setCurrentProgramStateInformation (const void* data, int sizeInBytes);