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



  • 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...
    
    }
    


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



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



  • local i = ButtonRow.indexOf(control);
    setStepOnOff[i] = value;
    


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


 

0
Online

353
Users

1.1k
Topics

7.5k
Posts