HISE Logo Forum
    • Categories
    • Register
    • Login

    How do you avoid creating 16 callback functions for an array of 16 buttons?

    Scheduled Pinned Locked Moved Scripting
    5 Posts 3 Posters 1.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      elanhickler
      last edited by elanhickler

      Let's say I have 16 buttons in an array for an arpeggiator. I want button 0 to turn on/off step 0. I want button 1 to turn on/off step 1. How do you do that without doing:

      switch(control)
      {
          case(ButtonArray[0]): 
              setStepOnOff[0] = value;
              break;
          case(ButtonArray[1]): 
              setStepOnOff[1] = value;
              break;
          case(ButtonArray[2]): 
              setStepOnOff[2] = value;
              break;
      
      etc...
      
      }
      
      1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey
        last edited by

        I do it with a loop that goes through each index in the array

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        1 Reply Last reply Reply Quote 0
        • E
          elanhickler
          last edited by elanhickler

          ...that loop would have to happen for every control movement, not good.

          1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart
            last edited by

            local i = ButtonRow.indexOf(control);
            setStepOnOff[i] = value;
            
            1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey
              last edited by d.healey

              Not every control, you can do a check to see if the control is in the array before looping, which now that I think of it would give you the array index of the control so you wouldn't need a loop after all.

              I just realised that's what Christoph has suggested.

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              27

              Online

              1.8k

              Users

              12.1k

              Topics

              105.4k

              Posts