| 998 | } |
| 999 | |
| 1000 | void FireAudioProcessor::setStateInformation(const void* data, int sizeInBytes) |
| 1001 | { |
| 1002 | // You should use this method to restore your parameters from this memory block, |
| 1003 | // whose contents will have been created by the getStateInformation() call. |
| 1004 | |
| 1005 | std::unique_ptr<juce::XmlElement> xmlState(getXmlFromBinary(data, sizeInBytes)); |
| 1006 | if (xmlState.get() != nullptr && xmlState->hasTagName("state")) |
| 1007 | { |
| 1008 | int xmlIndex = 0; |
| 1009 | // 1. set treestate |
| 1010 | const auto xmlTreeState = xmlState->getChildElement(xmlIndex++); |
| 1011 | if (xmlTreeState != nullptr) |
| 1012 | { |
| 1013 | // Convert the XML to a ValueTree so we can inspect and modify it before loading. |
| 1014 | auto treeToLoad = juce::ValueTree::fromXml(*xmlTreeState); |
| 1015 | |
| 1016 | // This is the backward-compatibility logic. |
| 1017 | // We loop through each band to check if the SHAPE_BYPASS_ID exists. |
| 1018 | for (int i = 0; i < 4; ++i) |
| 1019 | { |
| 1020 | auto shapeBypassParamID = ParameterIDAndName::getIDString(SHAPE_BYPASS_ID, i); |
| 1021 | |
| 1022 | // If the ValueTree from the preset file does NOT have this property... |
| 1023 | if (! treeToLoad.hasProperty(shapeBypassParamID)) |
| 1024 | { |
| 1025 | // ...it means we are loading an old preset. |
| 1026 | // To maintain the old sound, we must manually add the property |
| 1027 | // and set its value to 'true' (enabled). |
| 1028 | treeToLoad.setProperty(shapeBypassParamID, 1.0, nullptr); |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | treeState.replaceState(juce::ValueTree::fromXml(*xmlTreeState)); |
| 1033 | } |
| 1034 | |
| 1035 | // 2. set current preset ID |
| 1036 | const auto xmlCurrentState = xmlState->getChildElement(xmlIndex++); |
| 1037 | if (xmlCurrentState != nullptr) |
| 1038 | { |
| 1039 | // load preset |
| 1040 | presetId = xmlCurrentState->getIntAttribute("currentPresetID", 0); |
| 1041 | statePresets.setCurrentPresetId(presetId); // only set preset id not value |
| 1042 | // so it won't override the value you changed from the preset |
| 1043 | |
| 1044 | editorWidth = xmlCurrentState->getIntAttribute("editorWidth", INIT_WIDTH); |
| 1045 | editorHeight = xmlCurrentState->getIntAttribute("editorHeight", INIT_HEIGHT); |
| 1046 | } |
| 1047 | |
| 1048 | // 3. Load LFO Shapes |
| 1049 | if (auto* lfoState = xmlState->getChildByName("LFO_STATE")) |
| 1050 | { |
| 1051 | // First, clear all existing LFO data in a thread-safe way. |
| 1052 | lfoManager->clearAllLfoData(); |
| 1053 | |
| 1054 | for (auto* lfoXml : lfoState->getChildIterator()) |
| 1055 | { |
| 1056 | const int index = lfoXml->getIntAttribute("index", -1); |
| 1057 | if (juce::isPositiveAndBelow(index, 4)) // Use a fixed size for safety |
nothing calls this directly
no test coverage detected