Module Initialization...

Post Reply
terrymcg
Posts: 85
Joined: Mon Apr 08, 2019 12:35 am

Module Initialization...

Post by terrymcg »

Hi Folks...

I'm trying to use a group of hidden Editable Labels to store some persistent state information for a module I'm building - 'quick recall' slots that store sub-preset level information for the module. Each label is tied to a ToggleButton (in radio group), and the overlay text color of the ToggleButton varies (or should) depending on the contents of the associated label. My goal is to make a group of buttons have persistent but variable behaviors that are saved/restored with the default module state, similar to the behavior of "regular" GUI elements (eg. knobs, buttons, and switches).

I've got the mechanics worked out, but the module initialization sequence is kicking my butt...

Initialize() seems to get called fairly early, GUI elements may not have their final (restored by default) values yet.
SetStateInformation() doesn't seem to get called if no preset is loaded (and therefor never from within VMD).
Notify() seems to be called for each GUI element, but the ordering is indeterminate, and I need multiple elements to be available before I'm "ready to go". Keeping track of them all by hand is a giant pain, as is then trying to distinguish initialization related events from actual user input.

I've found a couple of other posts that touch on this, but nothing directly applicable:
SetStateInformation not firing when no custom info in preset
Debugging issues that happen when presets loaded

At the moment, I'm checking a flag in ProcessSample(), but since in VMD ProcessSample() may start early, even that's unreliable.

Could a notification event (Module_Initialized maybe?) be added to Notify() that was guaranteed to be fired *after* the module has been fully initialized from VM/VMD's viewpoint? Or an additional callback member function ala SetStateInformation that would *always* be called after module initialization?

Maybe I'm missing something and/or overcomplicating things (wouldn't be the first time! ;) ), but what are others doing to decided when initialization is complete?

Cheers,
--
Terry McG
Cherry Dan
Site Admin
Posts: 256
Joined: Fri Jul 27, 2018 5:36 pm

Re: Module Initialization...

Post by Cherry Dan »

terrymcg wrote: Mon Apr 22, 2019 1:19 am I'm trying to use a group of hidden Editable Labels to store some persistent state information for a module I'm building - 'quick recall' slots that store sub-preset level information for the module.
Hi Terry,

Why not use GetStateInformation() and SetStateInformation for these purposes? That's what they're intended for - to store and recall persistent state information for a module.

The process of loading a module proceeds this way:

1) Initialize() is called on the module
2) If a save state is being recalled (loading a preset, loading a DAW project, etc.):
a) Preset_Loading_Start notification is sent
b) SetStateInformation() is called with binary block of state information, IF GetStateInformation() returned any data.
c) Any knobs, sliders, buttons, labels, etc. that were saved with a project or preset (if any) get restored
d) Preset_Loading_Finish notification is sent

As a result, you can consider using the Preset_Loading_Finish notification to respond to the loading of save data. By the time it gets called, all of your hidden label data should be available. Just make sure your default state is initialized properly in your Initialize() function, in case this is a new module being created, and there is no save state data available yet.

Again, however, I recommend you take advantage of the GetStateInformation() and SetStateInformation() functions. These are designed precisely so that you can save your module's state data that extends beyond knob/slider positions, such as modes, colors, etc.

Does that help?

Thanks,
Dan
terrymcg
Posts: 85
Joined: Mon Apr 08, 2019 12:35 am

Re: Module Initialization...

Post by terrymcg »

Hi Dan...

Thanks for the suggestion, I appreciate your insights.

I'll experiment with Set/GetStateInformaiton, but I'm not sure they're quite what I need...

As I understand it, the preset support routines aren't ever called in VMD (since it doesn't support presets), but somehow knob/slider info *is* restored. That's the behavior I' was trying to replicate. I'll do some tests, maybe I'm over-complicating things again ;)

FWIW, I did get my hidden labels to work - watching for the notifications and rearranging some logic did the trick (I'm converting the stuff I want to store into hex strings that get stuffed into the labels). <thumb up>

Oh, and since I've rolled back to 1.3.5, I don't seem to have access to the Preset_Loading_* notifications... yet. ;)

Thanks again!

Cheers,
--
Terry McG
Post Reply

Return to “Module Designer”