How to prevent VM to save/restore the states of knobs, buttons, etc.?

Post Reply
User avatar
AndreasFranke
Posts: 24
Joined: Fri Apr 16, 2021 10:27 am
Location: Germany
Contact:

How to prevent VM to save/restore the states of knobs, buttons, etc.?

Post by AndreasFranke »

Code: Select all

//  public byte[] GetStateInformation()

	//  Gets called when the module's state gets saved, typically when the user saves a preset with
	//  this module in it. Voltage Modular will automatically save the states of knobs, sliders, etc.,
	//  but if you have any custom state information you need to save, return it from this function.
//
I'm working on a module that has 3 Toggle Buttons (Stop, Start, Pause) and I wanted them to have a fixed state every time the module is started:
  • Stop = ON (127)
  • Start = OFF (0)
  • Pause = OFF (0)
These three buttons each set an internal variable to 0 or 127.
These variables are checked inside the GUI_Update_Timer and turn the related buttons on/off by setting the Toggle Buttons value to 1 or 0.
Inside SetStateInformation, I restore all my variables from previous sessions and there I set the variables to the state I want them:
Stop = 127, Play = 0 and Pause = 0. Of course, I checked inside the Debugger if the right values are restored here, btw.
Because of this the next time the GUI_Update_Timer runs, the Stop, Start, and Pause buttons should be updated to the state I wanted them. BUT they don't they always will be overwritten by VM's automatically saved states! It drives me a little crazy.

Please do not tell me, that VM restores automatically stored values AFTER SetStateInformation, this wouldn't be logical in any way to me. How can I overwrite the autosaved states of knobs & buttons?

Any hints, what I could do?
Andreas
ColinP
Posts: 1000
Joined: Mon Aug 03, 2020 7:46 pm

Re: How to prevent VM to save/restore the states of knobs, buttons, etc.?

Post by ColinP »

Unfortunately there is no documentation on method call or event ordering available. You have to just test things yourself and sometimes things aren't what one might expect.

As you have already figured, what is probably happening here is that Notify() is receiving automated state restoring Button_Changed events after SetStateInformation() has been called and your Notify() code is overwriting the values you previously set.

You'll find quite a few strange things in VM as you delve deeper. It's evolved over time and some mods seem to be rather ad hoc rather than thought through, Still this is the case with most software systems. Developer's time is limited and sh*t happens.

You should be able to fix the problem using a flag.
User avatar
AndreasFranke
Posts: 24
Joined: Fri Apr 16, 2021 10:27 am
Location: Germany
Contact:

Re: How to prevent VM to save/restore the states of knobs, buttons, etc.?

Post by AndreasFranke »

ColinP wrote: Sun Jun 13, 2021 9:04 pm Unfortunately there is no documentation on method call or event ordering available. You have to just test things yourself and sometimes things aren't what one might expect.

As you have already figured, what is probably happening here is that Notify() is receiving automated state restoring Button_Changed events after SetStateInformation() has been called and your Notify() code is overwriting the values you previously set.

You'll find quite a few strange things in VM as you delve deeper. It's evolved over time and some mods seem to be rather ad hoc rather than thought through, Still this is the case with most software systems. Developer's time is limited and sh*t happens.

You should be able to fix the problem using a flag.
Good morning ColinP,
later after I posted my question I found the solution in another thread in this forum (viewtopic.php?f=9&t=501). If I don't set my saved values directly inside SetStateInformation and do it later in the Preset_Loading_Finish notification it works as I wanted it to do. And you are right these are essential things that should be better documented in the manual.

Andreas
Post Reply

Return to “Module Designer”