good question, it helped me discover a minor bug (“transparent” brightness level
-3 is not supported for grid controls, only LEDs), thanks! will fix this in the next version. we can work around it for now though.
now, in general, if you want to track hold+press you would use momentary buttons as their state reflects whether the button is pressed, so you could simply use
IF G.BTN.V .. to check that. for your scenario it’s a bit more complicated as we don’t want to be checking all 16 buttons in a row. let’s use a variable and set it to
X coordinate of the last pressed button. when a button is released we’ll set it to -1 to indicate nothing is currently pressed. let’s use
Z for this, execute
Z -1 and add it to the
now create your buttons (i’m using 1 row as an example here):
G.BTX 0 0 0 1 1 0 0 1 16 1
this creates a row of 16 momentary buttons that trigger script 1 when pressed. and here is our script 1:
I G.BTNX; T G.BTNV
IF && ! T EQ I Z: Z -1; BREAK
IF ! T: BREAK
IF EQ Z -1: Z I; BREAK
A MIN Z I; B MAX Z I
I stores the
X coordinate of the button,
T stores the state: 1 is pressed, 0 is released (have to store these in variables so the rest of the script fits). 2nd line means: if a button is released, and this is the button that was pressed last (so
Z has its
X coordinate), reset
Z back to -1 and exit. this is so that we properly clear
Z for single presses.
3rd line compares
G.BTNV (which is stored in
T) to zero, if it’s true it’s a release and there is nothing to do, so we break. finally, we know it’s a press, so we check if there is a previously pressed button (
Z is not -1). if not, we just set
Z and break.
at this point
Z contains the previously pressed button, and
I contains the currently pressed button (or, more accurately, their
X coordinates), and using
MAX we can get our start and end points (which i store in variables
one problem here is that we can’t use these momentary buttons for the actual sequencer. so here is a trick: just add latching buttons on top of the momentary ones - but make sure to give them ids that are higher than the ones used for the momentary buttons (controls get rendered in the order of their ids, so you don’t want your momentary buttons hiding your latching ones).
one more trick: to display the currently selected loop the easiest option is to draw a rectangle using the special brightness level of -2 (“brighten”).
so, typing all this is a good way to feel the pain and it’s just not a very elegant solution to something that would be a fairly common scenario. i’ll think of some better mechanism to handle this, maybe a couple of ops to check if there is a previously pressed button in a group.