New callback: onLoaded
-
I think this would be useful - very useful. I need to do some value checking of widgets when my plug starts up, and I cant do this in the onInit, as these values are not initalised until the onInit completes.
So right now I have to do this in the onControl call back - it works but its a fiddly mess, and clogs the onControl call back with stuff that has nothing to do with widget values being changed by the end-user - a sure sign I think that this code is in the wrong place.
So I'd like (and I'm pretty sure others would too) an onLoaded callback that executes once after the onInit has finished and all the widgets are loaded and set up.
-
@Lindon add a panel, call it postInit or some other suitable name. Use it's callback function for all your postInit needs, don't use the generic onConrol callback for it.
-
@d-healey Dave that sounds ideal - so if I say;
inline function onPostInitControl(component, value) { //this executes AFTER eveyone is loaded... }; Content.getComponent("PostInit").setControlCallback(onPostInitControl);
I cna put all my post -init logic in here? and every widget will have its initalised value?
How do I fire this function?
or maybe its setLoadingCallback ?
But in any case...I'm very very confused.
I want my plugin to recall the values I entered in it - and its not doing that....
I start my plug in and it shows me 4 labels, holding these values:
11111,22222,33333,44444
I over type these with 99,88,77,66
and close my plugin.
I delete the plugin from my DAW, I reload it and the numbers are back at:
11111,22222,33333,44444
SO my plugin is NOT saving its internal state....
-
I cna put all my post -init logic in here? and every widget will have its initalised value?
Yes
How do I fire this function?
It's just a callback function like any other so will fire automatically after
on init
completes as long as itssaveInPreset
property is true.SO my plugin is NOT saving its internal state.
You have to save the default preset in order for it to load with a different initial state. This is the same with Kontakt's widgets too (except Kontakt instruments only have 1 preset), you always get the last saved state when adding a new instance of the plugin.
-
@d-healey OK great.....
"You have to save the default preset in order for it to load with a different initial state. This is the same with Kontakt's widgets too (except Kontakt instruments only have 1 preset), you always get the last saved state when adding a new instance of the plugin."
BUT:
I've tried to do this and it doesnt do it, I overwrite the labels wiht 99,88,77,66 and press a button - and in the buttons callback I say this;
Engine.saveUserPreset("Factory/Xylophone/Init");
-- I am assuming here that I am saving the preset? is this not right? Beacuase when I delete my plugin from the DAW and reload it the numbers are back at 1111,2222,3333,444
When you say "You have to save the default preset " can you show me how you would do that in a script?
-
@Lindon The savePreset function doesn't work - it has been mentioned a few times to @Christoph-Hart - currently it only works via the preset browser. However you can still use the
storeAllControlsAsPreset
function. -
@d-healey Great!
Whats the actual format of this call? (whats all this Automation stuff?)
Is it:
Content.storeAllControlsAsPreset("default",""); <-- well its not this cause I just tried and no change
or perhaps:
Content.storeAllControlsAsPreset("Factory/Xylophone/Init","");
or something I've missed off - the in-line documentation is not at all clear(as usual)
-
Content.storeAllControlsAsPreset("A", false)
Content.restoreAllControlsFromPreset("A")
This is what I used in my A/B comparison attempt.
-
@d-healey Okaaaay...
these look like asynchronous calls? Are they? and if so how do i know when they are complete?
-
@Lindon As far as I can tell they work the same was as the regular save/load presets (I think these functions exist for creating custom preset browsers). So once the load is completed the onControl callbacks are triggered.
-
A simple solution is this:
inline function onLoaded() { // Whatever you do here, it is guaranteed that every control // is initialised correctly. Console.print("onLoaded"); } // Grab a reference to the panel const var onLoadedPanel = Content.getComponent("onLoadedPanel"); // Makes it fire its control callback at user preset loading et al. onLoadedPanel.set("saveInPreset", true); // Nothing to see, move on... onLoadedPanel.set("visible", false); inline function ononLoadedPanelControl(component, value) { // If this control is not the last one in the list, // make sure to leave enough room by deferring the execution. component.startTimer(500); }; onLoadedPanel.setControlCallback(ononLoadedPanelControl); // We use the inbuilt timer functionality for asynchronous execution onLoadedPanel.setTimerCallback(function() { onLoaded(); this.stopTimer(); });
But again, all your problems are coming from hacking the user preset system for your authorisation method, which will have all kinds of weird side effects (eg. if people share your user presets, they bake their authorisation code into the user preset etc). The only proper solution is to use the upcoming and infamous
Engine.saveAppDataFile(jsonObject, "MyFile.js")
andEngine.loadAppDataFile("MyFile.js")
, which I am going to implement now so that you don't have to fish in the dark any longer :) -
please please please make at least the loadAppDataFile return a success/failure code....
-
Your wishes have been heard:
https://github.com/christophhart/HISE/commit/4c8930b123ad49d9a4df697fa7fbf9348789b70e
BTW, I am working on a full example of implementing a copy protection scheme like you described. I'll put it into the tutorial repo in a few minutes.