button array method?

Home Forums General Programming button array method?

Tagged: 

Viewing 19 posts - 21 through 39 (of 39 total)
  • Author
    Posts
  • #73771
    dnaldoog
    Participant
      • Topics: 4
      • Replies: 480
      • Total: 484
      • ★★

      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.

      https://en.wikipedia.org/wiki/Associative_array

      #73778
      human fly
      Participant
        • Topics: 124
        • Replies: 1070
        • Total: 1194
        • ★★★★

        great – i looked in your jd990 panel, and found:
        ‘myActiveSelect’
        which has the same header local 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.
        #73780
        dnaldoog
        Participant
          • Topics: 4
          • Replies: 480
          • Total: 484
          • ★★

          How 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.
          #73783
          dnaldoog
          Participant
            • Topics: 4
            • Replies: 480
            • Total: 484
            • ★★

            ….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.
            #73785
            human fly
            Participant
              • Topics: 124
              • Replies: 1070
              • Total: 1194
              • ★★★★

              tried 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.
              #73787
              human fly
              Participant
                • Topics: 124
                • Replies: 1070
                • Total: 1194
                • ★★★★

                ok…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
                
                #73788
                human fly
                Participant
                  • Topics: 124
                  • Replies: 1070
                  • Total: 1194
                  • ★★★★

                  with 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.
                  #73790
                  dnaldoog
                  Participant
                    • Topics: 4
                    • Replies: 480
                    • Total: 484
                    • ★★
                    
                    --
                    -- 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
                    
                    #73799
                    dnaldoog
                    Participant
                      • Topics: 4
                      • Replies: 480
                      • Total: 484
                      • ★★

                      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

                      You 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 as tostring(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))

                      #73800
                      human fly
                      Participant
                        • Topics: 124
                        • Replies: 1070
                        • Total: 1194
                        • ★★★★

                        ah, something new to me there:
                        what is ledtext 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)
                        #73801
                        human fly
                        Participant
                          • Topics: 124
                          • Replies: 1070
                          • Total: 1194
                          • ★★★★

                          0k, 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.

                          #73802
                          human fly
                          Participant
                            • Topics: 124
                            • Replies: 1070
                            • Total: 1194
                            • ★★★★

                            hehe, 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
                            #73803
                            human fly
                            Participant
                              • Topics: 124
                              • Replies: 1070
                              • Total: 1194
                              • ★★★★

                              oh … lol… now it doesn’t work with the leds…
                              but the buttons do the selection .. (still viable, then)
                              off to figure that out …

                              #73804
                              human fly
                              Participant
                                • Topics: 124
                                • Replies: 1070
                                • Total: 1194
                                • ★★★★

                                last 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 …

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

                                  Have 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.

                                  #73822
                                  human fly
                                  Participant
                                    • Topics: 124
                                    • Replies: 1070
                                    • Total: 1194
                                    • ★★★★

                                    aah, so that’s how it’s done..

                                    #73823
                                    human fly
                                    Participant
                                      • Topics: 124
                                      • Replies: 1070
                                      • Total: 1194
                                      • ★★★★

                                      solved: 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?)

                                      #73824
                                      human fly
                                      Participant
                                        • Topics: 124
                                        • Replies: 1070
                                        • Total: 1194
                                        • ★★★★

                                        in 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
                                        #73825
                                        human fly
                                        Participant
                                          • Topics: 124
                                          • Replies: 1070
                                          • Total: 1194
                                          • ★★★★

                                          so 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:

                                          simple sequencer

                                          Attachments:
                                          You must be logged in to view attached files.
                                        Viewing 19 posts - 21 through 39 (of 39 total)
                                        • The forum ‘Programming’ is closed to new topics and replies.
                                        There is currently 0 users and 66 guests online
                                        No users are currently active
                                        Forum Statistics
                                        Threads: 2,495, Posts: 17,374, Members: 77,605
                                        Most users ever online was 12 on January 22, 2019 3:47 pm
                                        Ctrlr