Home › Forums › General › Programming › button array method?
Tagged: button array
- This topic has 38 replies, 3 voices, and was last updated 6 years, 4 months ago by human fly.
-
AuthorPosts
-
September 17, 2017 at 9:41 am #72948
anyone have some ideas for a button array method?
i want to have an array of 8 buttons, each selecting one of
8 tabs on a uiTabs.so far, i’ve used individual methods for each button, with
mouseDown (could be valueChange..) – this doesn’t seem
efficient. i suppose if they all use the same method, then
i would just have to go:
if button1 ~= nil then…etc. elseif button2 ~=nil then…
and so on.wondering if there are problems i’ll encounter with this.
seems this is a fundamental button logic thing, but like
this, it is much more simple than an exclusive array thing,
as i don’t have to specify what the other states are (because
uiTabs can only show one tab at a time)nb: these will be non-latching momentaries. i can have a
led that lights to show which is selected, or put text on
the button and change its text colour.September 17, 2017 at 10:31 am #72951so why doesn’t this work? (i’ve tried plain ‘getValue’, and have tried
getComponent) – all buttons call the same method with mouseDown.function partViewSelect() -- This stops issues during panel bootup if panel:getRestoreState() or panel:getProgramState() then return end --uiTab tabs_timbreParams = panel:getModulatorByName("tabs_timbreParams") --buttons partSel1 = panel:getModulatorByName("partSel1"):getModulatorValue() partSel2 = panel:getModulatorByName("partSel2"):getModulatorValue() partSel3 = panel:getModulatorByName("partSel3"):getModulatorValue() partSel4 = panel:getModulatorByName("partSel4"):getModulatorValue() partSel5 = panel:getModulatorByName("partSel5"):getModulatorValue() partSel6 = panel:getModulatorByName("partSel6"):getModulatorValue() partSel7 = panel:getModulatorByName("partSel7"):getModulatorValue() partSel8 = panel:getModulatorByName("partSel8"):getModulatorValue() if partSel1 ~= nil then tabs_timbreParams:setPropertyInt("uiTabsCurrentTab", 0) elseif partSel2 ~= nil then tabs_timbreParams:setPropertyInt("uiTabsCurrentTab", 1) elseif partSel3 ~= nil then tabs_timbreParams:setPropertyInt("uiTabsCurrentTab", 2) elseif partSel4 ~= nil then tabs_timbreParams:setPropertyInt("uiTabsCurrentTab", 3) elseif partSel5 ~= nil then tabs_timbreParams:setPropertyInt("uiTabsCurrentTab", 4) elseif partSel6 ~= nil then tabs_timbreParams:setPropertyInt("uiTabsCurrentTab", 5) elseif partSel7 ~= nil then tabs_timbreParams:setPropertyInt("uiTabsCurrentTab", 6) elseif partSel8 ~= nil then tabs_timbreParams:setPropertyInt("uiTabsCurrentTab", 7) end end
September 17, 2017 at 2:04 pm #72953I did this in a Moog Sub37 panel proto…
You need to put all buttons in the same Radio Group.
A radio group is simply a number…
This will make the button highlighted and switch off the other ones in the same group.Then you attach the same OnChange method to all buttons and track the one which is = 1
Don’t use OnMouse Down because it is not the same!
OnMouseDown doesn’t mean you change the value…
If you have an uiImageSlider with a label and the button image, OnMouseDOwn can react when you click on the label and this doesn’t change the On/Off state.
Clicking on the button will change the On/Off state.
So, OnMouseDown is not the same as OnChange!September 17, 2017 at 2:19 pm #72955(oh i did already start a topic on this..)
ok: i’ve used mouseDown in the same way for some buttons,
it didn’t seem to make a lot of difference, the way i was
using it.i avoided using the Radio buttons thing because i was curious
to see if i could get a method to do it instead, as i have my
own highlighting going on (maybe it’s a bit laborious, too..)
oh yes: it’s because i want my buttons to appear to have a
momentary action, rather than staying latched down when selected,
and instead change the text colour on the button – in this case,
it appears as if a backlight comes on for the text.(i change
the ‘off’state text colour. i like the look.. 🙂 ) (same as
a led coming on above the selected item)so i thought if i check the value of all buttons when the
onChange is called, with getValue, and then go as in the
code i showed above, it would select my tab number, but it
doesn’t seem to do anything.i’ve tried it with individual methods/functions called, and
it changes the tab normally, so …? curious as to how to
do it with a single method.
(i’m going to be sending several changes with this button down,
it actually selects the Part, in a multitimbral setup – aaargh,
do i want to go there? …)September 17, 2017 at 5:43 pm #72956It is the same principle without Radio group. The difference is that you need to switch the buttons on/off yourself.
You can do that very quickly with a loop 1-8 (for 8 buttons) and by choosing the button names accordingly (button1-button8).
You should do all that within a single OnChange method called by all buttons.
First switch everything to OFF then switch the one that changed to ON (you know which one it is as it is in the “mod” variable of the method).September 17, 2017 at 6:09 pm #72957right, time for me to commit to memory how to do a loop, huh.
so i’m going to start with ?button1 == 0
button2 == 0
etc.
or should that be ‘nil’?and then.. ok, i’ll go and read up on loops again 😉
September 17, 2017 at 6:36 pm #72958ok, not ‘==’ but ‘=’
lol i can tell there’s some perverse expectation of my torment
here, as i struggle to figure this out. thanks ! hahaSeptember 17, 2017 at 8:05 pm #72959i understand what you want me to do here: scan the states of
all the buttons with one click, and find the one that isn’t
at ‘0’/nil.September 17, 2017 at 9:35 pm #72960nope.
can’t get my head round it at the moment ! another day.
i’ll use the single little methods for now. reason being,
i’m not even sure i’m going to use this bit right now,
and i want to focus on the layout, and move on with that.
(rather than taking a detour for a few days, when i’ve
been doing quite a bit of that)December 9, 2017 at 11:15 am #73740It is the same principle without Radio group. The difference is that you need to switch the buttons on/off yourself.
You can do that very quickly with a loop 1-8 (for 8 buttons) and by choosing the button names accordingly (button1-button8).
You should do all that within a single OnChange method called by all buttons.
First switch everything to OFF then switch the one that changed to ON (you know which one it is as it is in the “mod” variable of the method).hi,
i’m having another go at this. i’ve got 4 buttons in a radio group (1),
set to toggle, named ‘pattern1’, 2, 3, 4.the following code isn’t doing it, but it’s the kind of thing
i’m trying out. “_G[]” is ‘getting’ the modulators’ values.
it is returning the last one every time, because it is running
all the way through. if i put the ‘conclusion’ outside the loop,
i get a nil. realise i don’t know how to ‘get’ the result from
the loop out to the rest of it (as a variable i can concatenate).
also some issues with the onChange happening twice (with other
ways i’ve tried it, lots). little panel attached, below>>function pattSelect() local patt=0 for i=1,4 do _G["pattern"..i]= panel:getModulatorByName("pattern"..i):getModulatorValue() if _G["pattern"..i]==1 then patt = i end end console(String("pattern = "..patt)) panel:getComponent("labl_pattern"):setPropertyString("uiLabelText",""..patt) end
Attachments:
You must be logged in to view attached files.December 9, 2017 at 4:21 pm #73743still clueless on this.. 🙁
i’m doing a loop to get all my buttons into a table, and
then trying with another loop to see which one has value==1,
trying to return that to the console. no success yet.also: Radio Button do not quite have the right behaviour:
if you click a 2nd time on the ‘on’ button, it goes ‘off’,
leaving all 4 buttons off – there should always be just 1
button ‘on’, never more, and never all ‘off’.
maybe some other configuration of properties allows this,
haven’t found it yet.i quite liked my ‘momentary’ click, that sets a LED high,
and then finding out which one is high, to determine the
selection. might try that again (or something that sets
a value representing which button has been clicked)December 10, 2017 at 12:56 pm #73751edit—
December 11, 2017 at 10:37 am #73761if i put the ‘conclusion’ outside the loop,
i get a nil. realise i don’t know how to ‘get’ the result from
the loop out to the rest of it (as a variable i can concatenate).Hi Human Fly,
Did you find a solution for this? – I looked at the panel and can’t quite get the jist of the quote above and couldn’t understand what you are trying to do.
December 11, 2017 at 11:28 am #73762morning ! 🙂 rainy day, so …
let me start again because it was a bit muddled.
i’ve got a clearer idea now:i’m going to ‘get’ the ‘LED’ state in order to make the
selection (my current idea – but i can maybe ‘get’ the
mouseclick as well – don’t know about that yet).so this works so far: – the easy bit –
(but i’m not changing LED state with buttons yet. led1 is on
because i copied it in that way) – i don’t really need the
table yet, but maybe it will be useful later. just checking
i’m doing it right.(remember that i’m doing leds with colour
change text symbol..4 buttons, 4 leds, and there’s a ‘lcd’
output to show the selection – not done yet here, still using
console)function pattSelect() tbl_leds={} for i=1,4 do local s=L(panel:getComponent("ledText"..i):getProperty("uiLabelTextColour")) table.insert(tbl_leds,s) if s == "FFD28008" then selection = i console(String("pattSelect= "..selection)) end end --[temp:check table data, print table method]-- for index, data in ipairs(tbl_leds) do --console(String(index.." "..data)) end end
December 11, 2017 at 11:37 am #73763nb: i’m not 100% in the difference between
‘ipairs’ and ‘pairs’ ..eg: first answer here:
https://stackoverflow.com/questions/41942289/display-contents-of-tables-in-lua
note that i’m using textual variable names, like in the example,
not just letters 🙂
makes it easier to get a handle on..December 11, 2017 at 1:00 pm #73764–if you have an associative (hash) table like
a={
blue=”blue”,
green=”green”,
red=”red”,}
print(“…………………..”)
for i,v in pairs (a) do
print(i,v)
end–it will output
–green green
–blue blue
–red red
–note that the order is not the same as the declaration order
–ipairs won’t work for this hash arrayb={
“blue”,”green”,”red”,
}for i,v in pairs (b) do
print(i,v)
end
for i,v in ipairs (b) do
print(i,v)
end
–both pairs and ipairs print in the correct orderc={
[1]=”blue”,
[2]=”green”,
[3]=”red”,
}for i,v in ipairs (c) do
print(i,v)
end–both pairs and ipairs print in the correct order (blue,green,red)
–so they are both similar for indexed arraysI read that “… ipairs, functions the same for the most part as pairs except that it will stop the loop once it runs into a non-existent (nil) value. …
December 11, 2017 at 4:19 pm #73765great, thanks – with that first one: is it the length of the
string that determines order? that’s what it looks like.next thing i’m trying: to ‘get’ the button click, on one of
the four buttons, “pattern1” ..2,3,4 – using the _G[ ] thing
(this appears to be creating a ‘field’? ie: a table/array?),
but instead of returning just one clicked item, it lists all 4:for i=1,4 do G["pattern"..i]= panel:getModulatorByName("pattern"..i):getModulatorValue() if _G["pattern"..i]~=0 then selected = i console(String("selected = "..selected)) end end
the trouble here, possibly is with the buttons i have: currently there
are no values on them – this is a mouseDown method, rather than
onValueChange, and they are not set to toggle. normally this triggers
a method, and with past methods, i have one method per button, so that
was simple, it just executed the instruction. now, i want it to scan
which button has been clicked and use that to determine which option
if carried out. (the leds wouldn’t matter if i could get that to
happen)goodweather says clearly ‘declare them all nil’ to start with.
can i do that with a loop? not yet, with _G[ ], that i can see.
i’m using that afterwards to getValue, but it doesn’t seem to be
getting anything from the button modulators (because they don’t
have a value? surely they do? 0/1?)i mean, i can see what he’s getting at now – his version requires
the Radio button property, but i’m trying to avoid that for now.
(if you look, they still toggle off when it’s an exclusive array,
when there should always be at least one, and no more than one, ‘on’.)December 11, 2017 at 4:51 pm #73766ok, so: looking at the buttons set up like this for click-only
operation, with the properties pane, they do not change value
like this.before, i was getting the button (led) to change, doing this:
panel:getModulatorByName("ledTextExt1"):getComponent():setProperty("uiLabelTextColour","FFD28008", false) panel:getModulatorByName("ledTextExt2"):getComponent():setProperty("uiLabelTextColour","FF0E2B01", false) panel:getModulatorByName("ledTextExt3"):getComponent():setProperty("uiLabelTextColour","FF0E2B01", false) panel:getModulatorByName("ledTextExt4"):getComponent():setProperty("uiLabelTextColour","FF0E2B01", false)
with a separate method for each button. i just need to have one method for all.
(think i’ve seen dasfaker do something like this, gonna have a look..)December 11, 2017 at 8:51 pm #73768duuuh … how can i just get the name of the last
selected modulator?i’ve noticed that if you don’t put a 2nd value in
the button box, mouse click gives no value change.
to get a ‘momentary’ action, you have to have a 2nd
entry, and then set it to ‘trigger on mouse down’.
and it sometimes gets stuck triggering in the wrong
direction, ie: 1 to 0 instead of 0 to 1. all kinda trouble…so what i want is just to, dunno, how about getProperty(“name”)
on last clicked modulator. then somehow use that. tying myself
in knots here…December 12, 2017 at 12:37 am #73769In that function all you need is to get a variable from 1-4 – you could use the name of the button, maybe returning a substring value of the end character as I have done below, or maybe use modulatorCustomIndex etc: Obviously each button shares the same function.
function a(mod,value) local sName=L(mod:getName()) local cIndexName=mod:getProperty("modulatorCustomName") local selected = string.sub(sName,-1) console(String("selected = "..selected)) console(String("cIndexName= "..cIndexName)) end -- function
Regards,
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.