momentary button lua ?

Home Forums General Programming momentary button lua ?

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #72544
    human fly
    Participant
      • Topics: 124
      • Replies: 1070
      • Total: 1194
      • ★★★★

      hi folks, early question on this while i try to figure it out:

      i have a row of 4 buttons, momentary action/non-latching.
      each one calls a tab, with its own lua. that means 4 methods,
      and i would like to combine them into a single function.

      basically, i’m cheating at the moment. i have 4 versions of
      this:

      function pt1P1_Tab0()
      
      	-- This stops issues during panel bootup
      	if panel:getRestoreState() or panel:getProgramState() then return end
      
      --show tab
      	local tab = 	panel:getComponent ("tabs_Main_pt1"):setPropertyInt("uiTabsCurrentTab", 0)
      	local tabUI = 	panel:getComponent ("tabs_UIGraphic_pt1"):setPropertyInt("uiTabsCurrentTab", 0)
      
      	local ledtxt9  = panel:getModulatorByName("ledText9")
      	local ledtxt10 = panel:getModulatorByName("ledText10")
      	local ledtxt11 = panel:getModulatorByName("ledText11")
      	local ledtxt12 = panel:getModulatorByName("ledText12")
      
      	ledtxt9	:getComponent():setProperty("uiLabelTextColour","FFD28008", false)
      	ledtxt10:getComponent():setProperty("uiLabelTextColour","FF523000", false)
      	ledtxt11:getComponent():setProperty("uiLabelTextColour","FF523000", false)
      	ledtxt12:getComponent():setProperty("uiLabelTextColour","FF523000", false)
      end

      what i want to do is combine the 4 methods into 1. the button will
      temporarily have an ‘on’ state, that triggers the state of the tab
      selection, from ie: 4 options: 0,1,2,3.

      luckily this works with tabs, and i only have to specify the new tab
      number. if i just wanted 4 leds.. oh yeah, i just have to mention
      all 4 and specify them by modulator name…
      (lol bears no relation to what happens in a discrete circuit.. )

      i have a good little prefab/panel to illustrate this if anyone’s
      interested, need to upload.

      #72552
      goodweather
      Participant
        • Topics: 45
        • Replies: 550
        • Total: 595
        • ★★★

        Hi, you can have a look at my Pro2 panel and look at OscOn_OnChange method under Oscillators method group.

        Basically:
        – you have your method adapted with one argument being a string (button name) or a number (1 to 4) and doing different things based on the button name or the number
        – each momentary button has a name (either button1 to button4 or completely different ones)
        – they all call the same on value change method
        – the structure of that method should be like:

        --
        -- Called when a modulator value changes
        -- @mod   http://ctrlr.org/api/class_ctrlr_modulator.html
        -- @value    new numeric value of the modulator
        --
        Button_OnChange = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source)
        
        -- No action while loading a program or if the panel is in bootstrap or program states
        if bLoadingProgram or not isPanelReady() then
        	return
        end
        
        sName= L(mod:getName())
        
        if sName == "button1" then 
        	your_method("button1")
        elseif sName == "button2" then 
        	your_method("button2")
        elseif sName == "button3" then 
        	your_method("button3")
        elseif sName == "button4" then 
        	your_method("button4")
        end
        
        end
        #72555
        human fly
        Participant
          • Topics: 124
          • Replies: 1070
          • Total: 1194
          • ★★★★

          here it is as a bpanelz:
          https://app.box.com/s/5s2t3pqsj806chg7ucbflnwk8vs9pogg

          (60kb)

          i hope the initial values are ok: should be all levels at 100,
          all buttons on. the partials buttons are just navigation in
          the main project.

          when one partial is off, the other one (they are pairs) doubles
          to take its place.

          the same thing happens with level: when at zero, it is the same
          as off – but this is indicated now with an orange led 🙂

          atm, these are separate methods.
          of course, what needs to happen is that when toggling buttons,
          leds resume appropriate states/colour.

          lol, i’m being lazy: i will get back round to this – hacking through
          some other stuff in the meantime. (please note my ‘native leds’, made
          from label modulators, with ‘-‘ … *rather nice*, though i say so
          myself, cough cough..)

        Viewing 3 posts - 1 through 3 (of 3 total)
        • The forum ‘Programming’ is closed to new topics and replies.
        There is currently 0 users and 57 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