Home › Forums › General › Programming › button array method?
Tagged: button array
- This topic has 38 replies, 3 voices, and was last updated 6 years, 3 months ago by human fly.
-
AuthorPosts
-
December 12, 2017 at 1:16 am #73771
length of the
string that determines order?No, it’s not the length of the string – the reason why gets pretty technical, but Lua probably doesn’t order hash arrays/tables for speed reasons at a guess.
December 12, 2017 at 8:44 am #73778great – i looked in your jd990 panel, and found:
‘myActiveSelect’
which has the same headerlocal sName=L(mod:getName())
some little weirdnesses with this: crashes on startup,
which is fixed with:-- This variable stops index issues during panel bootup if panel:getRestoreState() == true or panel:getProgramState() == true then return end
(seems best to do this with all buttons having associated methods so they
don’t trigger/scan on startup)second weirdness is the actual button values: check ‘current value’,
it keeps incrementing. maybe this is what happens with buttons-with-no-
value? no: not in my mini-panel: have a momentary 1 and then it goes
back to 0.don’t understand why ‘custom’ is needed, what it’s for.
here’s my current file – the method doesn’t run – see what happens
with the buttons here. startup with all grey; should go red as they
go high, then back to grey. but crash/fail happens, and it latches
‘high’. then look at the ‘current value’ – compare this to how
yours keeps incrementing (apparently in 2s?/per button?)was trying to get LEDs associated with buttons; that isn’t doing
anything – can’t yet visualize how a led value would ‘latch’,
while the button value would be momentary .. nb: led is not needed,
really, and could more easily depend on what appears selected in
the selection window.>>panel
Attachments:
You must be logged in to view attached files.December 12, 2017 at 5:24 pm #73780How about this?
pattSelect = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source) local sName= L(mod:getName()) local sub=tonumber(string.sub(sName,-1)) for i=1,4 do if i ~= sub then panel:getModulatorByName("ledtext"..i):getComponent():setPropertyString("uiLabelTextColour", "FF0E2B01") panel:getModulatorByName("pattern"..i):getComponent():setValue(0,false) end end if value == 1 then panel:getModulatorByName("ledtext"..sub):getComponent():setPropertyString("uiLabelTextColour","FF67EF00") end end
- This reply was modified 6 years, 3 months ago by dnaldoog.
Attachments:
You must be logged in to view attached files.December 12, 2017 at 5:33 pm #73783….or this code to toggle the selected button and LED off
-- -- Called when a modulator value changes -- @mod http://ctrlr.org/api/class_ctrlr_modulator.html -- @value new numeric value of the modulator -- myPattSelect = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source) local sName= L(mod:getName()) local sub=tonumber(string.sub(sName,-1)) for i=1,4 do if i ~= sub then panel:getModulatorByName("ledtext"..i):getComponent():setPropertyString("uiLabelTextColour", "FF0E2B01") panel:getModulatorByName("pattern"..i):getComponent():setValue(0,false) end end if value == 1 then panel:getModulatorByName("ledtext"..sub):getComponent():setPropertyString("uiLabelTextColour","FF67EF00") else panel:getModulatorByName("ledtext"..sub):getComponent():setPropertyString("uiLabelTextColour", "FF0E2B01") panel:getModulatorByName("pattern"..sub):getComponent():setValue(0,false) end end
Attachments:
You must be logged in to view attached files.December 12, 2017 at 7:17 pm #73785tried those – i like the first bit 🙂
i’ve amended it with a bodgey thing i’ve done before,
to get the led colour/state to output a result.have also removed the values from the buttons – it is
only a (displayed name) now, and they aren’t ‘toggle’.
led still works, and it makes the selection on the
output display.
also disabled the line that sets ~= items to 0, still
seems to work.(still getting my head round your first 2 lines)but: this is still onValueChange. won’t work at onMouseDown,
gives error at line 7. and if i then change it back and
recompile, it crashes again – until i reload the file.
??what’s that all about??
my code for the 2nd bit is a bit unwieldy. want to loop that,
of course, if i can (imagine 48 buttons…)myPattSelect = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source) local sName= L(mod:getName()) local sub=tonumber(string.sub(sName,-1)) for i=1,4 do if i ~= sub then panel:getModulatorByName("ledtext"..i):getComponent():setPropertyString("uiLabelTextColour", "FF0E2B01") --panel:getModulatorByName("pattern"..i):getComponent():setValue(0,false) else panel:getModulatorByName("ledtext"..sub):getComponent():setPropertyString("uiLabelTextColour","FF67EF00") end end for i=1,4 do local s=L(panel:getComponent("ledtext"..i):getProperty("uiLabelTextColour")) if s == "FF67EF00" then if i == 1 then panel:getComponent("labl_pattern"):setPropertyString("uiLabelText",""..i) elseif i == 2 then panel:getComponent("labl_pattern"):setPropertyString("uiLabelText",""..i) elseif i == 3 then panel:getComponent("labl_pattern"):setPropertyString("uiLabelText",""..i) elseif i == 4 then panel:getComponent("labl_pattern"):setPropertyString("uiLabelText",""..i) end end end end
Attachments:
You must be logged in to view attached files.December 12, 2017 at 8:11 pm #73787ok…how’s this?
myPattSelect = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source) local sName= L(mod:getName()) local sub=tonumber(string.sub(sName,-1)) for i=1,4 do if i ~= sub then panel:getModulatorByName("ledtext"..i):getComponent():setPropertyString("uiLabelTextColour", "FF0E2B01") --panel:getModulatorByName("pattern"..i):getComponent():setValue(0,false) else panel:getModulatorByName("ledtext"..sub):getComponent():setPropertyString("uiLabelTextColour","FF67EF00") end end local display=nil for i=1,4 do local s=L(panel:getComponent("ledtext"..i):getProperty("uiLabelTextColour")) if s == "FF67EF00" then display = i for i= 1,4 do panel:getComponent("labl_pattern"):setPropertyString("uiLabelText",""..display) end end end end
December 12, 2017 at 10:25 pm #73788with some more buttons, condensed a bit ( could go more perhaps
with some logic )btw… noticed the ‘twist’ you do in that first argument !
if not sub, ledtext..*i* is blabla1
else ledtext..*sub* is blabla2>>panel
Attachments:
You must be logged in to view attached files.December 13, 2017 at 1:12 am #73790-- -- Called when a modulator value changes -- @mod http://ctrlr.org/api/class_ctrlr_modulator.html -- @value new numeric value of the modulator -- ledtext={} -- initialise to improve scalability for i=1,16 do ledtext=panel:getModulatorByName("ledtext"..i) end -------------------------------------------------------------- myPattSelect = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source) local sName= L(mod:getName()) local sub=tonumber(string.sub(sName,-2)) local display=nil for i,v in ipairs(ledtext) do if i ~= sub then v:getComponent():setPropertyString("uiLabelTextColour", "FF0E2B01") else ledtext[ sub ]:getComponent():setPropertyString("uiLabelTextColour","FF67EF00") end end panel:getModulatorByName("labl_pattern"):getComponent():setPropertyString("uiLabelText",tostring(sub)) end
December 13, 2017 at 3:23 am #73799local
display=nil
for i=1,4 do local s=L(panel:getComponent(“ledtext”..i):getProperty(“uiLabelTextColour”)) if s == “FF67EF00” then display = i
for i= 1,4 do panel:getComponent(“labl_pattern”):setPropertyString(“uiLabelText”,””..display) end end end endYou can achieve this in the first loop. Also I think you are running a loop within another loop but using the same iterator variable ‘i’ which could have unexpected results to say the least! Also
""..display
can also be written astostring(display)
but all of this is unnecessary as I see it and as I said can be achieved with one line of code in the previous loop:
panel:getModulatorByName("labl_pattern"):getComponent():setPropertyString("uiLabelText",tostring(sub))
December 13, 2017 at 6:44 am #73800ah, something new to me there:
what isledtext sub
? (not getting square brackets today !)
i’m still not sure what square brackets do.
table items .. does it denote a ‘field’?/array? etc. ?ok: tried that code, got this:
At line [-1]: [C] What: C Namewhat: global Name: ipairs Error message: [string "myPattSelect"]:20: bad argument #1 to 'ipairs' (table expected, got userdata)
December 13, 2017 at 6:54 am #738010k, so .. ledtext square brackets is the table, and sub
represents/is the number obtained where it is declared.
got it.… going to try to see if i can fix the error.
this resembles more the original assumption i had of
building a table to reference.December 13, 2017 at 7:03 am #73802hehe, ok, sorted. nice one :tu: it needs table.insert :
(nb: noticing simpler way of declaring ledtext there, without L()
or _G() )this works 🙂
*edit*: momentous! haha. added the startup exclusion thing, because
it was making it run through the table so it displayed ’16’/last item
in the display box instead of the selected button. better now.
(don’t put it right at the top, or Ctrlr hangs, and you have to
delete Roaming/Ctrlr/ctrlr.settings, because even editing the file
in notepad doesn’t stop it loading the last autosaved version, as
opposed to the ‘hard-saved’ named version – why i don’t like to
use versioning..)-- -- Called when a modulator value changes -- @mod http://ctrlr.org/api/class_ctrlr_modulator.html -- @value new numeric value of the modulator -- tabl_ledtext={} -- initialise to improve scalability for i=1,16 do ledtext=panel:getModulatorByName("ledtext"..i) table.insert(tabl_ledtext,ledtext) end -------------------------------------------------------------- myPattSelect = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source) -- This variable stops index issues during panel bootup if panel:getRestoreState() == true or panel:getProgramState() == true then return end local sName= L(mod:getName()) local sub=tonumber(string.sub(sName,-2)) local display=nil for i,v in ipairs(tabl_ledtext) do if i ~= sub then v:getComponent():setPropertyString("uiLabelTextColour", "FF0E2B01") else tabl_ledtext[ sub ]:getComponent():setPropertyString("uiLabelTextColour","FF67EF00") end end panel:getModulatorByName("labl_pattern"):getComponent():setPropertyString("uiLabelText",tostring(sub)) end
December 13, 2017 at 7:24 am #73803oh … lol… now it doesn’t work with the leds…
but the buttons do the selection .. (still viable, then)
off to figure that out …December 13, 2017 at 7:37 am #73804last post for now… findings:
in fact, it doesn’t change leds on startup like this:
it needs to be recompiled in order to run that.the startup ‘exclusion’ doesn’t make any difference,
so i’ve put it back in for now, to stop it jumping
to end of list/table.wonder why the leds need it to be recompiled?
back later …December 13, 2017 at 7:53 am #73805Have you noticed that this forum doesn’t accept square brackets plus a character end square brackets? – you need to place a space between? [ sub ].
Square brackets indicate an array/table element.
December 13, 2017 at 12:47 pm #73822aah, so that’s how it’s done..
December 13, 2017 at 1:25 pm #73823solved: it likes it more with the ‘table initialize’ bit
inside the function. now it’s working as it should (famous
last words..)question: why did you have it before the function?
i tried putting that in a panelLoaded method called
at startup, and it didn’t work/make any difference.ps: *really like this* – perfect for assigning
snapshots/presets, or little sub-preset things,
like pre-configured envelopes, with names,
ie: percussive/piano/etc etc.pps: also, of course, for calling tabs. it avoids
having to have 2-state radio buttons, and button values,
and the button changes shade anyway. a bit tricky finding
space for the ‘leds’ but they aren’t even needed anyway.
(these are like your hidden ‘ghost’ parameters?)December 13, 2017 at 1:44 pm #73824in fact, kicking out the leds, the short form that works
appears to be:selectShort = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source) -- -- This variable stops index issues during panel bootup if panel:getRestoreState() == true or panel:getProgramState() == true then return end local sName= L(mod:getName()) local sub=tonumber(string.sub(sName,-2)) panel:getModulatorByName("labl_pattern"):getComponent():setPropertyString("uiLabelText",tostring(sub)) end
December 13, 2017 at 6:47 pm #73825so here’s a concluding file for this (panel below)
(includes ‘short’ version, with no LEDs action)
looks pretty sweet 🙂
nice one, dnaldoog (again) !am integrating this into the ‘simple sequencer’ now,
to fetch… pattern strings, i suppose, or arrays, or
something.edit: back over here now > table/array seems to be a good way atm:
Attachments:
You must be logged in to view attached files. -
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.