Reply To: Radio button in a modulator group needs a default setting

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

#118970
dnaldoog
Participant
  • Topics: 4
  • Replies: 480
  • Total: 484
  • ★★

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

screenshot of lua radio group panel

Attachments:
You must be logged in to view attached files.
Do NOT follow this link or you will be banned from the site!