diff --git a/Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate b/Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate index ef0620e..8bfa044 100644 Binary files a/Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate and b/Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Source/PluginData.cpp b/Source/PluginData.cpp index 035922f..841df50 100644 --- a/Source/PluginData.cpp +++ b/Source/PluginData.cpp @@ -217,16 +217,6 @@ void DexedAudioProcessor::loadBuiltin(int idx) { 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) { // 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 - 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); - memcpy(state.program, data, 161); - state.cutoff = fx.uiCutoff; - state.reso = fx.uiReso; - state.programNum = currentProgram; + NamedValueSet blobSet; + blobSet.set("sysex", var((void *) &sysex_blob, 4104)); + blobSet.set("program", var((void *) &data, 161)); - destData.insert(&state, sizeof(PluginState), 0); + blobSet.copyToXmlAttributes(*dexedBlob); + copyXmlToBinary(dexedState, destData); } 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. // used to LOAD plugin state + ScopedPointer root(getXmlFromBinary(source, sizeInBytes)); - PluginState state; - - if ( sizeInBytes < sizeof(PluginState) ) { - TRACE("too small plugin state size %d", sizeInBytes); + if (root == nullptr) { + TRACE("unkown state format"); return; } - if ( sizeInBytes > sizeof(PluginState) ) { - TRACE("too big plugin state size %d", sizeInBytes); - sizeInBytes = sizeof(PluginState); + fx.uiCutoff = root->getDoubleAttribute("cutoff"); + fx.uiReso = root->getDoubleAttribute("reso"); + 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 ) { - TRACE("version of VST chunk is not compatible, bailing out"); + var sysex_blob = blobSet["sysex"]; + var program = blobSet["program"]; + + if ( sysex_blob.isVoid() || program.isVoid() ) { + TRACE("unkown serialized blob data"); return; } - importSysex((char *) state.sysex); - memcpy(data, state.program, 161); - - fx.uiCutoff = state.cutoff; - fx.uiReso = state.reso; - currentProgram = state.programNum; + importSysex((char *) sysex_blob.getBinaryData()->getData()); + memcpy(data, program.getBinaryData()->getData(), 161); lastStateSave = (long) time(NULL); TRACE("setting VST STATE"); @@ -311,7 +310,7 @@ CartridgeManager::CartridgeManager() { void CartridgeManager::getSysex(int idx, char *dest) { InputStream *is = builtin_pgm->createStreamForEntry(idx); - + if ( is == NULL ) { TRACE("ENTRY IN ZIP NOT FOUND"); return; @@ -320,3 +319,4 @@ void CartridgeManager::getSysex(int idx, char *dest) { is->read(dest, 4104); delete is; } + diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 9060b61..7b81cc6 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -89,7 +89,7 @@ void DexedAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) keyboardState.reset(); - nextMidi= new MidiMessage(0xF0); + nextMidi = new MidiMessage(0xF0); midiMsg = new MidiMessage(0xF0); } @@ -108,6 +108,9 @@ void DexedAudioProcessor::releaseResources() { } keyboardState.reset(); + + delete nextMidi; + delete midiMsg; } void DexedAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages) {