Okay... starting to get a feel for this system now....
One thing I ran into today was trying to decide whether my menus should have their saveInPreset bool enabled or not. My menus have a callback associated with them that controls the loading of an effect and the binding of parameter knobs.
But because I am eventually going to be aiming at an effect chain preset format.... I figured saveInPreset should be disabled, and I should track the effect data manually.
I got there in there, but it did require a bit of thought. Because loading the effect networks seems to be asynchronous, so you cannot rely on the parameter knobs to be properly flushed at the right time when calling updateSaveInPresetComponents().
So after a lot of trial and error, I just decided to call it twice!!
inline function onPresetLoad(obj) {
local data = obj.presetData;
if (!isDefined(data)) return;
if (isDefined(data.ui)) {
UserPresetHandler.updateSaveInPresetComponents(data.ui);
}
local engIds = ["Engine1", "Engine2", "Engine3"];
for (i = 0; i < engIds.length; i++) {
local engineIdx = i + 1;
local smKey = "engine" + engineIdx + "SampleMap";
local wtKey = "engine" + engineIdx + "Wavetable";
if (isDefined(data[smKey]))
UISoundSelector.syncSamplerMenu(engineIdx, data[smKey]);
if (isDefined(data[wtKey]))
UISoundSelector.syncSynthMenu(engineIdx, data[wtKey]);
}
if (isDefined(data.fxSelections)) {
for (k in data.fxSelections) {
local fxName = data.fxSelections[k];
UIEffectDropDownMenu.syncEffectMenu(k, fxName);
}
}
if (isDefined(data.ui)) {
UserPresetHandler.updateSaveInPresetComponents(data.ui);
}
}
inline function onPresetSave() {
return {
"version": "1.0.0",
"presetAuthor": "",
"presetDescription": "User Preset",
"presetTags": [],
"presetData": {
"ui": UserPresetHandler.createObjectForSaveInPresetComponents(),
"engine1SampleMap": PluginSharedData.engineSounds["Engine1"].sampler,
"engine2SampleMap": PluginSharedData.engineSounds["Engine2"].sampler,
"engine3SampleMap": PluginSharedData.engineSounds["Engine3"].sampler,
"engine1Wavetable": PluginSharedData.engineSounds["Engine1"].synth,
"engine2Wavetable": PluginSharedData.engineSounds["Engine2"].synth,
"engine3Wavetable": PluginSharedData.engineSounds["Engine3"].synth,
"fxSelections": captureFXSelections()
}
};
}
This works well, if a little wasteful perhaps.
Part of the reason I wanted to do this is because the menu values are obviously floats, not the text value of the menu. And I knew that in the future if I wanted to add an effect type, and change the order of effects in the menu list, that this would break backwards compatibility. So I basically have a shim that will take a string and convert it to the right integer for the menu as it is in that moment, and then set the menu to the appropriate value .... which then triggers the callback to load the right effect network...
and then that last updateSaveInPresetComponents() call makes sure the parameters match what the preset has stored.