so you have a block of 7 rows of 8 buttons each. P.I indicates the current column. on each step you want to trigger the scripts that have the corresponding buttons latched. this does require a loop, because on each step you need to check each of the 7 rows. since there are 7 scripts we can trigger, this leaves one script that can be used for this task.
add this line to the metro script before you advance to the next step:
L 1 7: SCRIPT 8
in script 8 we now need to do this: check the button located in the row specified by variable I (which gets passed from the calling loop) and the column specified by P.I and fire a corresponding script if it’s latched. to check a button state we can use G.BTN.V index op, where index is the button index. when you use G.BTX to create a block of buttons, the first parameter is the starting index, and buttons are given consecutive numbers, arranged left to right first, then top to bottom. so in case of your block the indexes are:
01 02 03 04 05 06 07 08
09 10 11 12 13 14 15 16
... and so on
to get the index of the button we want we can use this formula:
J - + P.I * I 8 7
since there are 8 buttons in each row, we multiple the row number (I) by 8 and add the current horizontal position (P.I). we then need to shift it by 7 so that the leftmost button in row 1 gives us index 1, which is the starting index in your button block definition (you can change it to start with 8 instead of 1, then you don’t need to subtract 7 here).
with the button index now determined it’s easy to do the rest:
IF G.BTN.V J: SCRIPT I
another suggestion - instead of using G.LED and a separate row to indicate the current step you can do this:
G.CLR
G.REC P.I 1 1 7 -2 -2
G.CLR removes all previously drawn LEDs - but this doesn’t affect buttons and faders. then we draw a 1 column wide rectangle using the special brightness level of -2 - it makes everything underneath it a little brighter. this way you can see the current step in the sequencer itself.
now, could we expand this to all 8 scripts and 8 rows? yes! define the button block like this:
G.BTX 8 0 0 1 1 1 0 0 8 8
and change metro to this:
G.CLR
G.REC P.I 0 1 8 -2 -2
J P.I
L 1 8: $ * I G.BTN.V + J * I 8
P.NEXT
here is what happens here: we use a similar formula to calculate the button index and we get that button’s state. it can only be 1 (if it’s pressed/latched) or 0. so when we multiply it by I we either get the script number (since we just multiple by 1) or 0. SCRIPT 0 does nothing, since there is no script 9 which is exactly the effect we want and allows us to combine this all in one loop without using IF.
this line has the max number of characters, so if you want to use this with grid 128 this won’t fit:
L 1 8: $ * I G.BTN.V + T * I 16
instead, store 16 in a variable: Z 16 and use it instead:
L 1 8: $ * I G.BTN.V + T * I Z