How to retrieve settings from ScriptFX in onInit when the plugin starts?
-
Hi everyone,
I've built an FX plugin with a “realtime” and a “long latency” option (Lookahead off/on), which means I can switch between them with a button, and depending on the setting, a different latency is sent to the DAW via
Engine.setLatencySamples. That works fine. The default setting is “realtime”.Now, if I change a few plugin parameters in the DAW and activate the “latency” mode, save the project, close it, and then reopen it, all plugin parameters load correctly (including the status of the latency button), BUT I can’t access the correct status of the button in the 'onInit' script to send the correct latency to the DAW when loading. This means the plugin always sends the “realtime” latency first, even though “long latency” mode is actually enabled. I’ve already tried using a timer to delay the query, but that doesn’t work either (though the query for the current sample rate does work there):
const var to = Engine.createTimerObject(); var timerStop = 0; to.setTimerCallback(function() { if (!timerStop) { getSamplerate(); //Samlplerate request function works if(ScriptFX.getAttribute(ScriptFX.Lookahead)>0) { // THIS DOESNT WORK, but why? Engine.setLatencySamples(lookaheadSmpl); } timerStop = timerStop+1; } else { to.stopTimer(); } }); to.startTimer(400);Has anyone an idea? :)
-
@jojojojonas If the controls are set to save in preset then anything you do in
on initwill be overwriten when the control callback triggers.Use the technique described here (in the snippet) for responding to a DAW session load.
https://docs.hise.dev/tutorials/all/index.html#dynamic-plugin-parameters
-
@David-Healey Ah very nice, thank you! I will give that a try!