# Detect long button press # Red Heron Music, Nov 6, 2022
# Notes # delays do not work in MDP2 version of SB # see post on problems with delays below 150 ms in SB on Mac
# Example uses # Cc 01 on Ch1 is monitored button # i0 to store button state # i1 to store delay time # F0 58 10 - synthetic SysEx message for time tick
If Load Ass i0 = 0 # initialize button to off Ass i1 = $200 # Default delay time in ms End
If M0 == B0 01 # Detected button action If M2 > 0 # Button is on Ass i0 = 1 Snd F0 58 10 F7 +I +Di1 # Any non-delayed button on actions here (optional) Else # Button is off Ass i0 = 0 # Any button off actions here (optional) End End
If M0 == F0 58 10 If i0 == 0 # Button now off, no action # No Action Else # Button still on, take delayed action # Example action Snd B1 20 20 End Block # Block synthetic message End
There is no way to cancel a delayed send, but we can avoid sending multiple delays downstream.
When we detect the button is on, check first if I0 == 0, only then send the delayed message. If i0 == 1, then the message has already been send
But this does point out this logic could be improved - this approach presumed a fairly benign button use. It is not going to work if there is a lot of quick button tapping, then on the last of a sequence you hold the button.
There may be a better solution paring the delay with a timer - will ponder.