Getting crazy with variables… Thx for help!

Home Forums General Programming Getting crazy with variables… Thx for help!

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #64894
    goodweather
    Participant
      • Topics: 45
      • Replies: 550
      • Total: 595
      • ★★★

      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 change

      2. 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 as

      AmpEgVelAmt = 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!!!

      #64932
      dasfaker
      Keymaster
        • Topics: 80
        • Replies: 793
        • Total: 873
        • ★★★

        If 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.

        #64933
        goodweather
        Participant
          • Topics: 45
          • Replies: 550
          • Total: 595
          • ★★★

          Thx 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).

          #64935
          dasfaker
          Keymaster
            • Topics: 80
            • Replies: 793
            • Total: 873
            • ★★★

            Cool.

            About the morphing function, yeah, it’s all about comparing table values and calculate an average point for each value.

          Viewing 4 posts - 1 through 4 (of 4 total)
          • The forum ‘Programming’ is closed to new topics and replies.
          There is currently 0 users and 133 guests online
          No users are currently active
          Forum Statistics
          Threads: 2,495, Posts: 17,374, Members: 77,605
          Most users ever online was 12 on January 22, 2019 3:47 pm
          Ctrlr