Preset Component Callbacks Triggering Twice on Startup
-
@clevername27 do you call changed() in the onInit script?
Something is definitely weird with your initialisation routine…
-
@Christoph-Hart said in Preset Component Callbacks Triggering Twice on Startup:
do you call changed() in the onInit script?
Doesn't this get ignored by default? HISE even tells you it's ignoring the call.
He might be calling the function itself, though.
-
@Christoph-Hart Thanks, I'll double-check.
-
This post is deleted! -
@Christoph-Hart I'm not. (I placed a Console.print before each onChanged in my code, to double-check.)
-
@Christoph-Hart (or anyone) Could you pls tell me -
-
Is there is variable persistence within HISE after programme execution stops?
-
Is there a difference between code literally being in Interface.js, and being inside an included file (assuming it's in the right sequence)?
-
What does "setEnableUserPresetPreprocessing" do?
-
How does HISE define when onInit is complete, so the default preset can be loaded?
Thank you.
-
-
@clevername27 Alright, T-Shirt time for the big guy, if you have set a default preset it does in fact load the preset that is stored in the xml first, then load the default preset afterwards, so you actually end up with it being executed twice.
Usually it's not a critical issue though, it's just like a angry user smashing the load preset button twice (and most heavyweight operations like samplemap loading are skipped if the value doesn't change).
Is there a real issue that this behaviour creates on your end or were you just curious?
-
@Christoph-Hart Thank you for your reply and info. I worked around it, and my code is better for it. The console appeared to log the sequence of events differently, seemingly randomly. With your info, plus @ustk's comment in this thread, I sorted things out.
For those here by search, looking for a work-around: Declare a global JSON object (at the top of onInit UI) with a flags for when onInit UI is done, and the pre/post callbacks run. Increment callback flags inside the callback (first checking if they're defined), and at the bottom of onInit UI. Then, define a function called something like IsComponentCallbackSafe(component) that returns true or false if OnInit UI is done and the callback cycle has run twice (but no more). (Remember to use IsDefined there as well.) Then, at the top of the callback for each component stored in a preset, do
if (IsComponentCallbackSafe(component))
then function body. There's probably a more elegant way to do that, but I like it, because it means I can set other criteria when it's not safe for those callbacks to run. You can also iterate the function through an array of your components, etc. -
@Christoph-Hart is it too much trouble to add an engine.isInitFinished method that we can call and check and never worry about counting flags again?
It would switch to true after everything has been loaded or triggered once, twice or however many times.
There's a real use case for post init scenarios where all the controls have their values loaded and the control callback did their thing and the engine starts running.
Could be niche and for some complex cases but it's definitely there.
-
Maybe…but what if the plugin interface could expand up, instead of just down.? Think about it.
I'm just kidding. I don't even understand what you wrote. Is 'callback' even a real word? How is there a tiny picture of me next to my name? This all raises too many questions.
-