Page 1 of 1

How to store digital counter values in VM setup

Posted: Fri Aug 30, 2019 6:59 am
by seal58
Hello,

during JAVA programming every symbol's value has to be set once before using. Independent of that Voltage Modular stores last state of any value of switches, toggle buttons, knobs.

Unfortunately it seems not to be done for digital counters. Everytime when I load a saved user setup in VM, all counters of my modules are reset to initial values instead of last set values. Is there a way to fix this?

I'd like to check, if a value is stored. If it is, it could be used, if not, initial value should be set.

Re: How to store digital counter values in VM setup

Posted: Fri Aug 30, 2019 8:49 am
by Captain
This is explained in the Programmer’s Manual, check the chapter about SetStateInformation and GetStateInformation. Another way, which might be a little kludge-y, but I have tried it a few times and it seems to work OK: use an invisible knob or slider to store the value.

Re: How to store digital counter values in VM setup

Posted: Fri Aug 30, 2019 4:06 pm
by seal58
Hi Captain,

the idea with a hidden knob is great and seems to be realised rather easy. Thank you very much!

In Initialize() I readout the knob value to set the counter.
In Process() I set the knob value everytime, when the counter value is changed.
That should it be. Unfortunately this does not work. After loading the preset, the default value of the knob overrides formerly set value.

The VMD manual gives rather little information about GetStateInformation() and SetStateInformation(). Without any example I do not understand the use of these functions.
First I tried to use these methods as "myCounter.SetStateInformation(value)". That leads to "cannot find symbol SetStateInformation()".

Then I used these methods as regular statements and got error messages, because byte[] cannot converted to any other format.

Could you please bring me to the right way.

Re: How to store digital counter values in VM setup

Posted: Sun Sep 01, 2019 12:04 pm
by Captain
I have not used the Get/SetStateInformation system myself (yet), so can't help with that (yet). But the invisible knob method is easy, you don't have to put anything in Initialize() (other than hiding the knob) or ProcessSample(). Just add this inside the Notify() method:

Code: Select all

case Knob_Changed: 
{
	if ( component == knob1 ) {
		counter1.SetValue( doubleValue );
	}
}
The counter variable name is counter1 and the hidden knob is knob1. The trick is to ignore the counter, and think of it only as a visual representation of the number. Then set the knob value to whatever you wish anywhere in the code, and treat that as the "master" value. The counter always follows it automatically, and the value is saved between sessions. It seems like the Knob_Changed notification is called once when you run the module, so it's not even necessary to set the counter value in Initialize(). Just remember to set suitable Min & Max values for the knob.

Re: How to store digital counter values in VM setup

Posted: Sun Sep 01, 2019 4:16 pm
by seal58
Hi,
now I understood the idea. I changed my modules and the setups save and restore all setups. :)
Thanks a lot!