All Control Callbacks Get Triggered On Init?
-
Just need an all-clear.
I have a few scriptPanels that act as buttons to switch between different GUI panels/boards. I have a simple function which is called in each of their callbacks resets all of them to 0, and switches the one calling it to 1, then executes that control's things.
Hitting F5 (so load up) executes this in order for all these buttons, as init executes all control callbacks.
Now, I can easily get around this since I'm using the panel and can simply move the function to the panel's mouse click callback.
But what about other controls? How would you handle this using the standard button?
Is there any way to prevent the onControlCallback from being executed on init?
-
@aaronventure Turn off saveInPreset and the callback won't be triggered (and the value won't be saved in the preset).
If you have controls you do want to save in preset and they call some function that you don't want to be called on load, then the simplest solution is to have a flag that you set at the end of on init.
-
@d-healey said in All Control Callbacks Get Triggered On Init?:
Turn off saveInPreset and the callback won't be triggered (and the value won't be saved in the preset).
Ah, this is the information that I was looking for.
Thanks, David.
-
@d-healey said in All Control Callbacks Get Triggered On Init?:
If you have controls you do want to save in preset and they call some function that you don't want to be called on load, then the simplest solution is to have a flag that you set at the end of on init.
Alright, tried both with .data and a var, and it doesn't work. Looks like the entirety of the script gets executed, and then the control callbacks get executed in declaration order.
The solution is to add a check in the function (or the callback)
if (flag) callback; else flag++;
then, the flag gets ticked on the first execution. A bit dirty but it is what it is. Even dirtier for non-panel widgets as they don't have .data storage.
Another one would be using the PersistentData panel trick and storing which of the panels should be active, disabling saveInPreset for the buttons, then recalling that saved persistent data on init and calling its function.
-
A post init callback would be useful - https://forum.hise.audio/topic/4933/post-init-callback?_=1695290221334
Another solution is to put a button at the end of your component tree and put your code in its callback, this will be called after all the other components. Or instead of adding a dummy button, use the actual last component in your tree if suitable.
-
@d-healey said in All Control Callbacks Get Triggered On Init?:
Another solution is to put a button at the end of your component tree and put your code in its callback, this will be called after all the other components. Or instead of adding a dummy button, use the actual last component in your tree if suitable.
That's a good one. Kontakt has on persistence_changed which executes after on init, meaning that on init has to pass first, which does not happen if the track is muted in the DAW or the VEPro instance isn't connected. So my instruments there always load up with the "loading" image which says exactly that, and all the UI controls get their visibility set only in persistence_changed.
But if in HISE the controls get executed after the init callback passes, then simply adding a dummy control at the end is not a big deal. Much like the PersistentData thing, or the colorPalette, or my dummy DAW automation controls. or my dummy switcheroo volume sliders. Hey, we need a dummy component list!