Home › Forums › General › Using Ctrlr › Global variable confusion › Reply To: Global variable confusion
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