Home › Forums › General › Programming › Getting crazy with variables… Thx for help!
Tagged: global variable
- This topic has 3 replies, 2 voices, and was last updated 8 years, 4 months ago by dasfaker.
-
AuthorPosts
-
December 5, 2015 at 11:51 am #64894
Hi,
after lots of try-out, I’m now requesting you some help to understand and solve my problem with variables.I have a function LoadPreset where I set a boolean (also tried with Int – same stuff) to true when I’m loading a preset. So, bLoadPreset=true.
In that function, I’m reading the preset dump and setting modulator values accordingly.
Classical stuff…
Each modulator has a a “OnValueChange” function that is adapting text strings on an LCD screen.
Obviously, when loading a preset, I don’t want to change the LCD for all the parameters so I’m testing the bLoadPreset variable to check if it is true or not. If true, I’m not updating the LCD panel.
After all reading of the parameters in the preset dump, I reset the bLoadPreset boolean to false in the LoadPreset function.Here comes the issues:
1. I’m displaying the bLoadPreset variable before changing a parameter value (thus from the LoadPreset function) and in the modulator “OnValueChange” function and it is true before and false after… Don’t understand what is causing the change2. I thought that the modulator’s “OnValueChange” methods needs some time to react and that the end of the LoadPreset function is reached before the modulator’s “OnValueChange” methods are processed. So I have set a timer at the end of the parameters read and before resetting the bLoadPreset to false
timer:setCallback (1, timerCallback) timer:startTimer(1, 200)
and in the callback I have
function timerCallback(timerId) timer:stopTimer(timerId) end
This doesn’t help.
3. I then tried to use Ctrlr global variables. In LoadPreset I set a global variable to 1 as
panel:setGlobalVariable(1, 1)
that I get in the modulator’s “OnValueChange” method asAmpEgVelAmt = function(modulator, modValue) bLoadingPreset = panel:getGlobalVariable(1) utils.infoWindow("AmpEgVelAmt","bLoadingPreset="..tostring(panel:getGlobalVariable(1))) if isPanelReady() then if bLoadingPreset==0 then ....
There it is showing 0 instead of 1…
If for testing purpose I’m setting it to 1 in the modulator’s method then it displays 1 which is correct.So, don’t understand at all how come that this variable is changing…
Thx in advance for any help!!!
December 5, 2015 at 10:14 pm #64932If I understand correctly, I think I had this problem too. I think the issue is that a single method is executed entirely before another method is called. So if you set this variable to true at the beginning of LoadPreset ,change some modulator values and finally set the variable to false at the end of LoadPreset, when those modulators that change value execute it’s OnValueChange method, loadPreset has been executed till the end, and your variable is set to false.
About the timer, where did you set the variable to false? It should be here
function timerCallback(timerId) bLoadPreset = false timer:stopTimer(timerId) end
If this doesn’t work, try to set the variable to false on the method of the last modulator that change it’s value.
December 5, 2015 at 10:27 pm #64933Thx a lot dasfaker! It works now.
It is exactly as you said. As I left the reset of bLoadingPreset in the main function, it was set back to 0 before the OnValueChange functions were triggered.
By putting it in the timer callback it gives the time of all modulators to perform their OnValueChange function.Btw, I figured out the wave morphing function. Was pretty straightforward in fact. I’ll make it scalable next week (I have a long train trip so will have time to play with it).
December 5, 2015 at 10:40 pm #64935Cool.
About the morphing function, yeah, it’s all about comparing table values and calculate an average point for each value.
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.