Home › Forums › General › Programming › Radio button in a modulator group needs a default setting
- This topic has 21 replies, 3 voices, and was last updated 3 years, 8 months ago by dnaldoog.
-
AuthorPosts
-
August 11, 2020 at 10:54 pm #119383
Hi Dnaldoog,
Hope everything is alright on your side.
I’ll check the new script you fixed during the next weekend and yes it makes more sense.
I’m stuck with my DP4 panel since I’m still waiting for a DSP to be delivered. One got fried and it’s more than a month I’m waiting it to arrive. COVID20 makes parcels very slow to be delivered.
Once I install and set up my unit I’ll get back to work and finish the panel once and for all 🙂
I go a Yamaha SPX990 and a Quadraverb2 this summer for a good price. I’ll program panels for them as well in september, the sysex implementation for alesis and yamaha are way more easier than ensoniq’s.
take care
DamienAugust 12, 2020 at 3:07 pm #119393Hi Damien,
Great to hear from you! Those SPX990s seem to going up in price. I have a Yamaha REV500 (that I hope to write a panel for someday). Hope the DSP arrives soon!
I think I finally got this whole radio button problem sorted out. Below is a summary of my findings so far, for people trying to find a solution in future.
- GOAL: Create a set of uiImageButton as radio buttons (ie you click on one button and the others in the set switch off)
- PROBLEM: If you attach a callback function Called when the modulator value changes to each button you will end up with an infinite loop (and crash Ctrlr). This is because when you set all non clicked buttons to 0,true (false doesn’t update the image) the function is fired again and an infinite loop is created.
Note:: The clicked on button will always be set to ‘1’.
- SOLUTION: The third parameter in the callback function ‘source’ returns 4 when a user clicks on a button, otherwise if lua or the program changes the button, you get ‘5’,or’6′ returned.
In the callback function we can block the code from running when not clicked on by checking for:
if source == 4 then end
Put each button name in a table in the function:
local t={"button1","button2","button3"}
At the beginning of the function, determine the name of the button you clicked on:
local sName=L(mod:getName())
Loop through each button and run code for the clicked on button and switch other buttons to OFF!
if source == 4 then -- this code is only run by the button you clicked on for _,v in ipairs (t) do if v == sName then -- do something, send MIDI etc else panel:getModulatorByName(v):setValue(0, true) -- this sets the other buttons to off -- they in turn will fire this function but send 5 or 6 as 'source' so the infinite loop is avoided end
- EXTRA:
In an init function which runs when the program is loaded Called when the program has finished loading, you can set the radio buttons to a default (on panel load) setting:panel:getModulatorByName("button1"):setValue(1,true) panel:getModulatorByName("button2"):setValue(0,true) panel:getModulatorByName("button3"):setValue(0,true)
- But wait, there’s more!
It is better to initialise all modulators by assigning them to lua variables. This will optimise and speed up the panel:
in an init function, which runs when the program is loaded Called when the program has finished loading
button1=panel:getModulatorByName("button1") -- global lua variable button2=panel:getModulatorByName("button2") -- can be now used to refer button3=panel:getModulatorByName("button3") -- to the object anywhere in your program button1:setValue(1,true) button2:setValue(0,true) button3:setValue(0,true)
In the callback function you can now access the global lua variable directly using _G[].
if source == 4 then -- this code is only run by the button you clicked on for _,v in ipairs (t) do if v == sName then -- do something, send MIDI etc else _G[v]:setValue(0, true) -- this sets the other buttons to off -- they in turn will fire this function but send 5 or 6 as 'source' so the infinite loop is avoided end
Attachments:
You must be logged in to view attached files. -
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.