On/Off button: 1 goes on, the other goes off

Home Forums General Programming On/Off button: 1 goes on, the other goes off

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #119356
    BAUS
    Participant
      • Topics: 2
      • Replies: 22
      • Total: 24

      Hi there,

      I am a new user of Ctrlr (in the programming sense) and I am looking for a few different things and how to program them.

      The first thing is:

      I have two ON/OFF buttons. When Button 1 is ON, Button 2 is OFF. If Button 2 is ON, Button 1 is OFF.

      Could anybody be so kind to show me in the right direction.

      I have looked at different panels that have what I need (Pro2 and Korg X5RW) and it’s a lot of code that I would like to understand.

      Thanks in advance,

      Robin Bausewein

      Updating a 25 year old Editor

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

        Hi BAUS,

        It’s not trivial in my opinion and you need lua.

        Here are two panels that emulate radio button functionality. (see attached)

        One uses the onMouseDown listener and the other onValueChange:

        Note that both panels have an init() function that sets the default radio button on panel load.

        Regards,

        • This reply was modified 3 years, 7 months ago by dnaldoog. Reason: added extra comment
        • This reply was modified 3 years, 7 months ago by dnaldoog. Reason: removed buggy onValueChange panel
        • This reply was modified 3 years, 7 months ago by dnaldoog. Reason: re uploaded onValueChange panel
        Attachments:
        You must be logged in to view attached files.
        #119389
        dnaldoog
        Participant
          • Topics: 4
          • Replies: 480
          • Total: 484
          • ★★

          See this post for a fuller explanation:


          ctrlr.org/forums/topic/radio-button-in-a-modulator-group-needs-a-default-setting/page/2/#post-119393

          #119588
          BAUS
          Participant
            • Topics: 2
            • Replies: 22
            • Total: 24

            Thanks dndaldoog,

            I finished my Panel with all the sysex codes now. I thought that would be the first thing to do.

            So, I am back at the issue with the buttons. I took a look at the things you posted about that. Also I copied the code of the Radio2 onValueChange into my panel, adjusted the names according to my panel but the script is not giving any output in the Console.

            I think I am missing 1 or 3 points here 😀

            Like others here I am new to Lua (or even programming/scripting) and have some trouble interpreting the scripts that I am reading…but that will come with time, if I keep at it.

            My two functions to fix in this Panel are basically the same:

            * If OSC Pair 1 is on, OSC Pair 2 should be off and vice versa
            * If Program 01 is selected (led is on) then Program 02 through 32 should be off (led off).

            I see how that scripts works in your example panel but can’t get it to work in mine.

            Thanks,

            Robin.

            Attachments:
            You must be logged in to view attached files.

            Updating a 25 year old Editor

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

              Hi Robin,

              I think for me to offer an answer I would have to see your work so far.

              If you don’t want to make it public, send me a private message and I’ll send you my email address then you can send it as an attachment.

              Regards,

              John

              #119609
              BAUS
              Participant
                • Topics: 2
                • Replies: 22
                • Total: 24

                John….I sent you a PM….but I think I figured it out how to do it just now. 😀

                I added a 5th button on the panel so I added “button5” to the table and changed the last line to:
                (user clicked on a button – not lua generated – that would be 6 or 7)

                Also I understand that setting the INIT value made the difference.

                Let me test some more!

                Robin.

                Updating a 25 year old Editor

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

                  Hi Robin,

                  All you should have to do is add the 32 button names to the local table in the init function, but don’t change the if source == 4 part. That’s crucial that it be left in there otherwise you’ll get an infinite loop and crash Ctrlr.

                  You would then need to add 32 modulator names to the initial script.

                  There is a more elegant way to do this. In the init script each button is assigned to a variable, which is then accessed instead of panel:getModulatorByName() in the function loop. See attached panel

                  Regards,

                  ?

                  Attachments:
                  You must be logged in to view attached files.
                  #119748
                  BAUS
                  Participant
                    • Topics: 2
                    • Replies: 22
                    • Total: 24

                    Okay….. I used Dnalgood’s unelegant way of putting all the buttons in the local list….and it works…partially.

                    What works is that only 1 button led is ON and the other 31 are off. Good!

                    What’s not working is that each button that I press now outputs Program Change 32 except for button 32….that one outputs Program Change 31. I am still looking into this.

                    Any ideas?

                    Thanks,

                    Robin Bausewein.

                    Updating a 25 year old Editor

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

                      Hi BAUS,

                      You would need to remove all the sysex code from Ctrlr MIDI message type field – set to None and send the sysex all from lua.

                      
                      ProgramSelect = function(--[[ CtrlrModulator --]] mod --[[ number --]], value --[[ number --]], source)
                          if source == 4 then
                              local sName = L(mod:getName())
                      
                              local t = {"PROGRAM01", "PROGRAM02", "PROGRAM03", "PROGRAM04", "PROGRAM05", "PROGRAM06", "PROGRAM07", "PROGRAM08", "PROGRAM09", "PROGRAM10", "PROGRAM11", "PROGRAM12", "PROGRAM13", "PROGRAM14", "PROGRAM15", "PROGRAM16", "PROGRAM17", "PROGRAM18", "PROGRAM19", "PROGRAM20", "PROGRAM21", "PROGRAM22", "PROGRAM23", "PROGRAM24", "PROGRAM25", "PROGRAM26", "PROGRAM27", "PROGRAM28", "PROGRAM29", "PROGRAM30", "PROGRAM31", "PROGRAM32"} -- local table of buttons in radio
                      
                              for i, v in pairs(t) do
                                  if sName == v then
                      				local sysMess=string.format("F0 00 00 23 01 43 C1 00 %.2X F7",i-1)
                      				panel:sendMidiMessageNow(CtrlrMidiMessage(sysMess))
                                  else
                                      _G[v]:setValue(0, true)
                                  end -- fi
                              end -- for
                          end -- source == 4 (user clicked on a button - not lua generated - that would be 5 or 6)
                      end
                      

                      Regards,

                      #119823
                      BAUS
                      Participant
                        • Topics: 2
                        • Replies: 22
                        • Total: 24

                        Dnaldoog!!!! Thanks so much!

                        This is working great.

                        I am now getting deeper into the Lua programming language too. I have some more ideas for the Panel
                        with regards to requesting Patch Settings so the Panel reflects the Patch in the Mirage and possibly
                        also the Program Settings.

                        Let’s see how far I can get with that.

                        Again….thank you so much for your help.

                        Updating a 25 year old Editor

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