Global variable confusion

Home Forums General Using Ctrlr Global variable confusion

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #46134
    beely
    Participant
      • Topics: 2
      • Replies: 1
      • Total: 3

      (Mac OSX 10.9.5, Ctrlr 5.3.85)

      I’ve been having a lot of global variable confusion lately.

      So I was using 5.2.x initially, and modulators linked to global variables was working fine – for instance, I had a knob that would select between four values, and that global variable it was linked to was used in other sysex messages for other knobs, so one filter cutoff knob could be targeted to the filter cutoff of Tones 1 to 4 on a Roland module. Great, worked well.

      And as I tweaked the modulator, the global variables would update in the panel settings in real time, so I could watch it change, both in the settings for the knob, and in the global variables list in the overall panel settings.

      Now I updated to 5.3, and was trying to do something else and having problems with global variables not seeming to react or even behave as I thought they did. And on loading my previous attempts, I can see now that changing knobs linked to modulators is not updating the global variable at all, whereas it previously did.

      Is this broken in 5.3.85 on OSX? Or did something internally change and I need to update something in my settings/panels?

      Edit: And now if I go back to 5.2.139, create a new panel, add a new slider and link it to global variable 0, as I move the slider, the global variable doesn’t change either. In fact, as I change the slider, the modulator value itself stays 0. I’m ?Confuzzled?

      Is there something conceptual I am missing about modulator and global variables?

      • This topic was modified 8 years, 11 months ago by beely.
      • This topic was modified 8 years, 11 months ago by beely. Reason: Added info
      #46236
      Puppeteer
      Participant
        • Topics: 16
        • Replies: 185
        • Total: 201
        • ★★

        I haven’t had much luck with the global variables in the right pane.

        Any variable declared in LUA appears to be global to the panel anyway, so I’m just using them and building the messages in LUA.

        The Puppeteer
        http://godlike.com.au

        #46286
        zeoka
        Participant
          • Topics: 73
          • Replies: 466
          • Total: 539
          • ★★★

          Hi
          Had trouble using glb var as i used it

          mod changeCallbak -> setGlobal
          other mod changeCallbak -> getGlobal

          As I said before to Puppeteer there is global(panel) Callback for glb var change
          That’s working fine

          Attach mod to glb var and apply what you want in this panel script Callback

          You can put complex expressions in it

          --
          -- Called when a global variable has changed it's value
          --
          
          MyVariables = function( index,  value)
          
          MySndGens = panel:getComponent("SoundGens")
          MyFilter = panel:getComponent("Filter")
          MyBufList = panel:getComponent("BufferList")
          vwEdtTab = panel:getModulatorByName("EditTab")
          
                if index == 5 
              then panel:getCanvas():repaint()                              
          --repaint all the panel
            elseif index == 0 and value == 0
              then panel:setGlobalVariable(2,panel:getGlobalVariable(2)%4)  
          -- return to the start 
              else   if index == 2 
                   then local a = BigInteger(panel:getGlobalVariable(0))
                              a:setBitRangeAsInt(1,4,value)
                        local b = BigInteger(1)          
                              b:setBitRangeAsInt(1,4,value)
                        local c = a:getBitRangeAsInt(0,7)
                        local d = b:getBitRangeAsInt(0,7)
                        local e = (23 + c)%128                
                        local f = (23 + d)%128
                                 if c ~= d 
                               then panel:sendMidiMessageNow(CtrlrMidiMessage{0xF0,0x3E,0x10,0x00,0x17,d,f,0xF7})
                                end
                              panel:sendMidiMessageNow(CtrlrMidiMessage{0xF0,0x3E,0x10,0x00,0x17,c,e,0xF7})
                    end    
                     if vwEdtTab ~= nil  
                   then CurrentSound() 
                    end
                     if BufferToGet == nil 
                   then vwEdtTab:setModulatorValue(0,false,false,false)
                   else vwEdtTab:setModulatorValue(1,false,false,false)
                    end
                     if MySndGens ~= nil then MySndGens:repaint() end
                     if MyBufList ~= nil then MyBufList:repaint() end
                     if MyFilter ~= nil  then MyFilter:repaint()  end
                end     
          end

          Apparently you can even set a global var in it :
          “if index == 0 then panel:setGlobalVariable(2,MODEA)”

          currentsound() is a sub script with complex glb var expressions, it is not in the main scritp because I use it elsewhere for panel startup (important step)

          function CurrentSound()
                 local a0 = panel:getGlobalVariable(0)
                 local a1 = panel:getGlobalVariable(1)
                 local a2 = panel:getGlobalVariable(2) + 1        
                 local a3 = panel:getGlobalVariable(3) + 1
                 local a4 = panel:getGlobalVariable(4) 
                 local a67 = panel:getGlobalVariable(6 +a0 ) 
                    if a1 == 1
                  then    if a67 ~= a2
                        then BufferToGet = MyBuffers[a0+1].FDAT[a2]             
                             SBufIdx =  a2                       
                      elseif a67 == a2    
                        then     if a4 == 0 
                               then BufferToGet = nil
                                    SBufIdx =  nil 
                             elseif a4 == 1
                               then    if MyBuffers[a0+1].FDAT[a3] ~= nil  
                                     then BufferToGet = MyBuffers[a0+1].FDAT[a3] 
                                     else BufferToGet = nil
                                      end
                                    SBufIdx =  a3 
                                end
                          end
                  else BufferToGet = nil
                       SBufIdx =  nil
                   end
                       MultiMode = a0
                return BufferToGet , SBufIdx , MultiMode   
          end

          in brief
          if index ~= GlobalVariable(5) then
          the script create 3 LUA variables I can use after elsewhere
          if index == 2 I send one or two midi messages
          if index == 0 then I set GlobalVariable(2) then the script restart ( a kind of loop)
          then I send one or two midi messages !
          That way the LUA variables created are always refreshed when you turn any knobs attached to glb var .you can still use panel:getGlobalVariable(index) if don’t want to use LUA variable to call the glob var value

          If that can help

          #46462
          beely
          Participant
            • Topics: 2
            • Replies: 1
            • Total: 3

            Hmm, ok then, not just me! 😉
            Glad to know I’m not completely on the wrong page.

            Thanks for the suggestions – some of which are a bit over my head initially as I’ve only really spent a few hours in Ctrlr doing pretty straightforward things, but i will go through and see whether it helps as I try to figure out this thing and make it do what I want 🙂

          Viewing 4 posts - 1 through 4 (of 4 total)
          • The forum ‘Using Ctrlr’ is closed to new topics and replies.
          There is currently 0 users and 76 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