Home › Forums › General › Programming › Radio button in a modulator group needs a default setting › Reply To: Radio button in a modulator group needs a default setting
June 30, 2020 at 2:03 am
#118970
Well it becomes difficult when you need to use these buttons as toggle buttons sending MIDI 0/1 or 0/127.
Here is a more developed version:
First I have an some initialising code in a function that runs when the panel loads.
--
-- Called when the panel has finished loading
--
-- @type the type of instance beeing started, types available in the CtrlrPanel
-- class as enum
--
-- InstanceSingle
-- InstanceMulti
-- InstanceSingleRestriced
-- InstanceSingleEngine
-- InstanceMultiEngine
-- InstanceSingleRestrictedEngine
--
init = function(--[[ CtrlrInstance --]] type)
dontBlock=false
panel:getModulatorByName("ButtonA"):setValue(1,false)
panel:getModulatorByName("ButtonB"):setValue(0,false)
panel:getModulatorByName("ButtonC"):setValue(0,false)
myGlobal="ButtonA"
globalValue=127
end
then a common mouse down function attached to each button:
--
-- Called when a mouse is down on this component
--
myRadio = function(--[[ CtrlrComponent --]] comp, --[[ MouseEvent --]] event)
local modName=L(comp:getOwner():getName())
dontBlock=true
if dontBlock then
local t={ButtonA=75,ButtonB=76,ButtonC=77}
for k,v in pairs(t)do
panel:getModulatorByName(k):getComponent():setValue(0,false)--set all other modulators to false
if k==modName then
if myGlobal==tostring(k) and globalValue==127 then
globalValue=0
else
globalValue=127
end
-- do something
panel:sendMidiMessageNow(CtrlrMidiMessage(string.format("B6 %.2x %.2x",v,globalValue)))
panel:getLabel("debug"):setText(k.."\nsending "..string.format("%.2X",globalValue))
myGlobal=tostring(k)
end
end
end -- dontBlock
end --f
Note the change in the t{} table to a hash table:
Regards,
JG