- constify
- refactored MidiCC - JaySynthSound is not MidiCC, but has MidiCC - refactored xml import export for patches and banks
This commit is contained in:
+111
-89
@@ -13,6 +13,8 @@
|
||||
#include "JaySynthAudioProcessorEditor.h"
|
||||
#include "synth/vector_utils.h"
|
||||
|
||||
using namespace juce;
|
||||
|
||||
JaySynthAudioProcessorEditor* getEditor(JaySynthAudioProcessor *pThis)
|
||||
{
|
||||
return dynamic_cast<JaySynthAudioProcessorEditor*>(pThis->getActiveEditor());
|
||||
@@ -473,7 +475,7 @@ void JaySynthAudioProcessor::setCurrentProgram (int index)
|
||||
// Set SYNTH_PARAM_TOTAL_NUM_VOICES first
|
||||
setParam(SYNTH_PARAM_TOTAL_NUM_VOICES, currpatch->getParameter(SYNTH_PARAM_TOTAL_NUM_VOICES), false, false);
|
||||
|
||||
midCC_editBuffer = *currpatch->getMidiCC();
|
||||
midCC_editBuffer = *((JaySynthMidiCC*)currpatch->getMidiCC());
|
||||
|
||||
pSynth->setMidiCC_editBuffer(&midCC_editBuffer);
|
||||
pSynth->ClearControls();
|
||||
@@ -689,52 +691,113 @@ const String JaySynthAudioProcessor::getParameterNameXML (int index)
|
||||
return name;
|
||||
}
|
||||
|
||||
void JaySynthAudioProcessor::commitEditBuffer()
|
||||
{
|
||||
if (isPatchModified() || midCC_editBuffer.isMidiCCmodified())
|
||||
{
|
||||
for (int i=0; i < SYNTH_NUM_PARAMS; i++)
|
||||
{
|
||||
synth_float_t value = getParam(i);
|
||||
currpatch->setParameter(i, value); // Copy synth param to current program
|
||||
}
|
||||
JaySynthMidiCC *midiCC = (JaySynthMidiCC*)currpatch->getMidiCC();
|
||||
midiCC->copyMidiCC(&midCC_editBuffer); // Copy MidiCC edit buffer to patch
|
||||
}
|
||||
}
|
||||
|
||||
void JaySynthAudioProcessor::patch2xml(XmlElement& xml, JaySynthSound const *patch)
|
||||
{
|
||||
xml.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));
|
||||
}
|
||||
patch->getMidiCC()->exportXML(&xml);
|
||||
}
|
||||
|
||||
void JaySynthAudioProcessor::xml2patch(const XmlElement& xml, JaySynthSound *patch)
|
||||
{
|
||||
// ok, now pull out our parameters..
|
||||
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));
|
||||
if (i==SYNTH_PARAM_TUNE)
|
||||
{
|
||||
if (value > 400.0)
|
||||
{
|
||||
value = 1200*log(value/440)/log(2.0);
|
||||
}
|
||||
}
|
||||
patch->setParameter(i, value);
|
||||
}
|
||||
((JaySynthMidiCC*)patch->getMidiCC())->importXML(&xml);
|
||||
}
|
||||
|
||||
void JaySynthAudioProcessor::bank2xml(XmlElement& xml)
|
||||
{
|
||||
for (int i=0; i < NUM_PROGRAMS; i++)
|
||||
{
|
||||
XmlElement *pXml = xml.createNewChildElement (String("PATCH_") + String(i));
|
||||
JaySynthSound *pPatch = &patches[i];
|
||||
pXml->setAttribute ("ID", i);
|
||||
patch2xml(*pXml, pPatch);
|
||||
}
|
||||
}
|
||||
|
||||
void JaySynthAudioProcessor::xml2bank(const XmlElement& xml)
|
||||
{
|
||||
// make sure that it's actually our type of XML object..
|
||||
XmlElement *pXML = (XmlElement*)&xml;
|
||||
|
||||
while(pXML)
|
||||
{
|
||||
int progID = pXML->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++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
((JaySynthMidiCC*)pPatch->getMidiCC())->importXML(pXML);
|
||||
pXML = pXML->getNextElement();
|
||||
}
|
||||
}
|
||||
|
||||
void JaySynthAudioProcessor::getStateInformation (MemoryBlock& destData)
|
||||
{
|
||||
int i, progID;
|
||||
synth_float_t value;
|
||||
JaySynthSound *pPatch;
|
||||
XmlElement *pXML;
|
||||
|
||||
commitEditBuffer();
|
||||
|
||||
// Create an outer XML element..
|
||||
ScopedPointer<XmlElement>xml = new XmlElement("JSYNTH_BANK");
|
||||
|
||||
bank2xml(*xml);
|
||||
setCurrentProgram(getCurrentProgram());
|
||||
|
||||
MemoryOutputStream outputStream(destData, false);
|
||||
MemoryBlock tmpBlock(destData.getSize(), /*initialiseToZero*/true);
|
||||
GZIPCompressorOutputStream GZIPEnc(&outputStream, /*compressionLevel*/0, /*deleteDestStreamWhenDestroyed*/false, /*windowBits*/0);
|
||||
|
||||
if (isPatchModified() || midCC_editBuffer.isMidiCCmodified())
|
||||
{
|
||||
for (i=0; i < SYNTH_NUM_PARAMS; i++)
|
||||
{
|
||||
value = getParam(i);
|
||||
currpatch->setParameter(i, value); // Copy synth param to current program
|
||||
}
|
||||
currpatch->getMidiCC()->copyMidiCC(&midCC_editBuffer); // Copy MidiCC edit buffer to patch
|
||||
}
|
||||
|
||||
for (progID=0; progID < NUM_PROGRAMS; progID++)
|
||||
{
|
||||
pXML = xml->createNewChildElement (String("PATCH_") + String(progID));
|
||||
pPatch = &patches[progID];
|
||||
pXML->setAttribute ("ID", progID);
|
||||
pXML->setAttribute ("NAME", pPatch->getName());
|
||||
for (i=0; i < SYNTH_NUM_PARAMS; i++)
|
||||
{
|
||||
value = pPatch->getParameter(i);
|
||||
pXML->setAttribute (getParameterNameXML(i), String(value, 10));
|
||||
}
|
||||
pPatch->getMidiCC()->exportXML(pXML);
|
||||
|
||||
}
|
||||
setCurrentProgram(getCurrentProgram());
|
||||
|
||||
// then use this helper function to stuff it into the binary blob and return it..
|
||||
copyXmlToBinary (*xml, tmpBlock);
|
||||
GZIPEnc.write(tmpBlock.getData(), tmpBlock.getSize());
|
||||
outputStream.flush();
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
{
|
||||
File pluginfile = File::getSpecialLocation (File::currentExecutableFile).getParentDirectory();
|
||||
File file(pluginfile.getFullPathName() + String("/bank.xml"));
|
||||
@@ -746,10 +809,7 @@ void JaySynthAudioProcessor::getStateInformation (MemoryBlock& destData)
|
||||
|
||||
void JaySynthAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
|
||||
{
|
||||
int i, progID, uncompressedSize;
|
||||
synth_float_t value;
|
||||
JaySynthSound *pPatch;
|
||||
XmlElement *pXML;
|
||||
int uncompressedSize;
|
||||
String lastError;
|
||||
ScopedPointer<XmlElement> xmlState = NULL;
|
||||
void* pData;
|
||||
@@ -773,38 +833,11 @@ void JaySynthAudioProcessor::setStateInformation (const void* data, int sizeInBy
|
||||
|
||||
if (xmlState != 0)
|
||||
{
|
||||
|
||||
// make sure that it's actually our type of XML object..
|
||||
if (xmlState->hasTagName ("JSYNTH_BANK"))
|
||||
{
|
||||
pXML = xmlState->getFirstChildElement();
|
||||
|
||||
while(pXML)
|
||||
{
|
||||
progID = pXML->getIntAttribute("ID");
|
||||
if (progID >= NUM_PROGRAMS)
|
||||
break;
|
||||
|
||||
pPatch = &patches[progID];
|
||||
|
||||
// ok, now pull out our parameters..
|
||||
pPatch->setName(pXML->getStringAttribute("NAME"));
|
||||
for (i=0; i < SYNTH_NUM_PARAMS; i++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
pPatch->getMidiCC()->importXML(pXML);
|
||||
pXML = pXML->getNextElement();
|
||||
|
||||
}
|
||||
XmlElement *pXML = xmlState->getFirstChildElement();
|
||||
xml2bank(*pXML);
|
||||
}
|
||||
setCurrentProgram(getCurrentProgram());
|
||||
}
|
||||
@@ -818,8 +851,8 @@ void JaySynthAudioProcessor::getCurrentProgramStateInformation (MemoryBlock& des
|
||||
// You should use this method to store your parameters in the memory block.
|
||||
// Here's an example of how you can use XML to make it easy and more robust:
|
||||
|
||||
int i;
|
||||
synth_float_t value;
|
||||
commitEditBuffer();
|
||||
|
||||
MemoryOutputStream outputStream (destData, false);
|
||||
MemoryBlock tmpBlock(2*65536, /*initialiseToZero*/true);
|
||||
GZIPCompressorOutputStream GZIPEnc(&outputStream, /*compressionLevel*/0, /*deleteDestStreamWhenDestroyed*/false, /*windowBits*/0);
|
||||
@@ -827,23 +860,7 @@ void JaySynthAudioProcessor::getCurrentProgramStateInformation (MemoryBlock& des
|
||||
// Create an outer XML element..
|
||||
ScopedPointer<XmlElement>xml = new XmlElement("JSYNTH_PATCH");
|
||||
|
||||
if (isPatchModified() || midCC_editBuffer.isMidiCCmodified())
|
||||
{
|
||||
for (i=0; i < SYNTH_NUM_PARAMS; i++)
|
||||
{
|
||||
value = getParam(i);
|
||||
currpatch->setParameter(i, value); // Copy synth param to current program
|
||||
}
|
||||
currpatch->getMidiCC()->copyMidiCC(&midCC_editBuffer); // Copy MidiCC edit buffer to patch
|
||||
}
|
||||
|
||||
xml->setAttribute ("NAME", currpatch->getName());
|
||||
for (i=0; i < SYNTH_NUM_PARAMS; i++)
|
||||
{
|
||||
value = currpatch->getParameter(i);
|
||||
xml->setAttribute (getParameterNameXML(i), String(value, 10));
|
||||
}
|
||||
currpatch->getMidiCC()->exportXML(xml);
|
||||
patch2xml(*xml, currpatch);
|
||||
setCurrentProgram(getCurrentProgram());
|
||||
|
||||
// then use this helper function to stuff it into the binary blob and return it..
|
||||
@@ -891,6 +908,9 @@ void JaySynthAudioProcessor::setCurrentProgramStateInformation (const void* data
|
||||
// make sure that it's actually our type of XML object..
|
||||
if (xmlState->hasTagName ("JSYNTH_PATCH"))
|
||||
{
|
||||
xml2patch(*xmlState, currpatch);
|
||||
|
||||
#if 0
|
||||
// ok, now pull out our parameters..
|
||||
currpatch->setName(xmlState->getStringAttribute("NAME"));
|
||||
for (i=0; i < SYNTH_NUM_PARAMS; i++)
|
||||
@@ -905,18 +925,20 @@ void JaySynthAudioProcessor::setCurrentProgramStateInformation (const void* data
|
||||
}
|
||||
currpatch->setParameter(i, value);
|
||||
}
|
||||
}
|
||||
currpatch->getMidiCC()->importXML(xmlState);
|
||||
((JaySynthMidiCC*)currpatch->getMidiCC())->importXML(xmlState);
|
||||
#endif
|
||||
setCurrentProgram(getCurrentProgram());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void JaySynthAudioProcessor::loadPatch (int index, const File &file)
|
||||
void JaySynthAudioProcessor::loadPatch (const File &file, int index)
|
||||
{
|
||||
String filename(file.getFullPathName());
|
||||
}
|
||||
|
||||
void JaySynthAudioProcessor::savePatch (int index, const File &file)
|
||||
void JaySynthAudioProcessor::savePatch (const File &file, int index)
|
||||
{
|
||||
String filename(file.getFullPathName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user