Switch to XML storage format

pull/1/head
asb2m10 11 years ago
parent ced347bb37
commit f83a12b08a
  1. BIN
      Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate
  2. 70
      Source/PluginData.cpp
  3. 5
      Source/PluginProcessor.cpp

@ -217,16 +217,6 @@ void DexedAudioProcessor::loadBuiltin(int idx) {
importSysex((char *) &syx_data); importSysex((char *) &syx_data);
} }
#define CURRENT_PLUGINSTATE_VERSION 2
struct PluginState {
int version;
uint8_t sysex[4104];
uint8_t program[161];
float cutoff;
float reso;
int programNum;
};
//============================================================================== //==============================================================================
void DexedAudioProcessor::getStateInformation(MemoryBlock& destData) { void DexedAudioProcessor::getStateInformation(MemoryBlock& destData) {
// You should use this method to store your parameters in the memory block. // You should use this method to store your parameters in the memory block.
@ -235,17 +225,22 @@ void DexedAudioProcessor::getStateInformation(MemoryBlock& destData) {
// used to SAVE plugin state // used to SAVE plugin state
PluginState state; XmlElement dexedState("dexedState");
XmlElement *dexedBlob = dexedState.createNewChildElement("dexedBlob");
state.version = CURRENT_PLUGINSTATE_VERSION; dexedState.setAttribute("cutoff", fx.uiCutoff);
dexedState.setAttribute("reso", fx.uiReso);
dexedState.setAttribute("currentProgram", currentProgram);
char sysex_blob[4104];
exportSysex((char *) &sysex_blob, (char *) sysex);
exportSysex((char *)(&state.sysex), (char *) sysex); NamedValueSet blobSet;
memcpy(state.program, data, 161); blobSet.set("sysex", var((void *) &sysex_blob, 4104));
state.cutoff = fx.uiCutoff; blobSet.set("program", var((void *) &data, 161));
state.reso = fx.uiReso;
state.programNum = currentProgram;
destData.insert(&state, sizeof(PluginState), 0); blobSet.copyToXmlAttributes(*dexedBlob);
copyXmlToBinary(dexedState, destData);
} }
void DexedAudioProcessor::setStateInformation(const void* source, int sizeInBytes) { void DexedAudioProcessor::setStateInformation(const void* source, int sizeInBytes) {
@ -253,32 +248,36 @@ void DexedAudioProcessor::setStateInformation(const void* source, int sizeInByte
// whose contents will have been created by the getStateInformation() call. // whose contents will have been created by the getStateInformation() call.
// used to LOAD plugin state // used to LOAD plugin state
ScopedPointer<XmlElement> root(getXmlFromBinary(source, sizeInBytes));
PluginState state; if (root == nullptr) {
TRACE("unkown state format");
if ( sizeInBytes < sizeof(PluginState) ) {
TRACE("too small plugin state size %d", sizeInBytes);
return; return;
} }
if ( sizeInBytes > sizeof(PluginState) ) { fx.uiCutoff = root->getDoubleAttribute("cutoff");
TRACE("too big plugin state size %d", sizeInBytes); fx.uiReso = root->getDoubleAttribute("reso");
sizeInBytes = sizeof(PluginState); currentProgram = root->getIntAttribute("currentProgram");
XmlElement *dexedBlob = root->getChildByName("dexedBlob");
if ( dexedBlob == NULL ) {
TRACE("dexedBlob element not found");
return;
} }
memcpy((void *) &state, source, sizeInBytes); NamedValueSet blobSet;
blobSet.setFromXmlAttributes(*dexedBlob);
if ( state.version != CURRENT_PLUGINSTATE_VERSION ) { var sysex_blob = blobSet["sysex"];
TRACE("version of VST chunk is not compatible, bailing out"); var program = blobSet["program"];
if ( sysex_blob.isVoid() || program.isVoid() ) {
TRACE("unkown serialized blob data");
return; return;
} }
importSysex((char *) state.sysex); importSysex((char *) sysex_blob.getBinaryData()->getData());
memcpy(data, state.program, 161); memcpy(data, program.getBinaryData()->getData(), 161);
fx.uiCutoff = state.cutoff;
fx.uiReso = state.reso;
currentProgram = state.programNum;
lastStateSave = (long) time(NULL); lastStateSave = (long) time(NULL);
TRACE("setting VST STATE"); TRACE("setting VST STATE");
@ -311,7 +310,7 @@ CartridgeManager::CartridgeManager() {
void CartridgeManager::getSysex(int idx, char *dest) { void CartridgeManager::getSysex(int idx, char *dest) {
InputStream *is = builtin_pgm->createStreamForEntry(idx); InputStream *is = builtin_pgm->createStreamForEntry(idx);
if ( is == NULL ) { if ( is == NULL ) {
TRACE("ENTRY IN ZIP NOT FOUND"); TRACE("ENTRY IN ZIP NOT FOUND");
return; return;
@ -320,3 +319,4 @@ void CartridgeManager::getSysex(int idx, char *dest) {
is->read(dest, 4104); is->read(dest, 4104);
delete is; delete is;
} }

@ -89,7 +89,7 @@ void DexedAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
keyboardState.reset(); keyboardState.reset();
nextMidi= new MidiMessage(0xF0); nextMidi = new MidiMessage(0xF0);
midiMsg = new MidiMessage(0xF0); midiMsg = new MidiMessage(0xF0);
} }
@ -108,6 +108,9 @@ void DexedAudioProcessor::releaseResources() {
} }
keyboardState.reset(); keyboardState.reset();
delete nextMidi;
delete midiMsg;
} }
void DexedAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { void DexedAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages) {

Loading…
Cancel
Save