Save/Load JSON
-
Here I have a minimal where I can print the current value of a knob in a format that allows me to copy and paste it directly into a callback - using it for buttons, knobs, panel data etc so it's very useful
const var PRINT_REVERB = Content.getComponent("PRINT_REVERB"); const var btn_ApplyReverb = Content.getComponent("btn_ApplyReverb"); inline function onPRINT_REVERBControl(component, value) { if (value) { local outputText = ""; outputText += "knb_OSC1_Reverb_Width.setValue(" + knb_OSC1_Reverb_Width.getValue() + "); knb_OSC1_Reverb_Width.changed();\n"; Console.print(outputText); } }; Content.getComponent("PRINT_REVERB").setControlCallback(onPRINT_REVERBControl); //-------------------------------------------------------------------------------------------------------------- inline function onbtn_ApplyReverbControl(component, value) { knb_OSC1_Reverb_Width.setValue(0.1500000059604645); knb_OSC1_Reverb_Width.changed(); }; Content.getComponent("btn_ApplyReverb").setControlCallback(onbtn_ApplyReverbControl); const var SAVE = Content.getComponent("SAVE"); const var LOAD = Content.getComponent("LOAD");
I'm trying to wrap my head around JSON objects now so that I could save current values of buttons, knobs, panel data etc from the UI as a JSON file in a format that would make it then loadable as a function applied by a load button - similar to my PRINT button. This is a simplified version of what I want, but understanding this would get me on the right path if anyone has any wise nuggets on this. I did think about adding an addButton with some kind of incrementing name as well as the callback text required directly in the printout too, but thought JSON might be a better way to go and would prevent the user from just adding millions of buttons just because they could - Edit, I can't print buttons haha, I'm tripping, been a while since I slept lol. But the JSON question still stands
-
@rglides Solved!
const var SAVE = Content.getComponent("SAVE"); const var LOAD = Content.getComponent("LOAD"); inline function onSAVEControl(component, value) { if (value) { local reverbData = { "OSC1_Reverb_Width": knb_OSC1_Reverb_Width.getValue() }; Engine.dumpAsJSON(reverbData, "reverb_settings.json"); } }; Content.getComponent("SAVE").setControlCallback(onSAVEControl); inline function onLOADControl(component, value) { if (value) { local loadReverb = Engine.loadFromJSON("reverb_settings.json"); if (loadedData != undefined) { if (loadReverb.OSC1_Reverb_Width != undefined) { knb_OSC1_Reverb_Width.setValue(loadReverb.OSC1_Reverb_Width); knb_OSC1_Reverb_Width.changed(); } } } }; Content.getComponent("LOAD").setControlCallback(onLOADControl);