Boolean midi controls for more efficient code?

Hi there! I'm having a blast controlling Tidal via MIDI, using the usual "^33" syntax and a Novation controller.

This works for both knobs sending [0-127], but also with 'on-off' buttons which send either 0 or 127.
However, using those ones for state variations to toggle patterns, I had to resort to somecyclesBy:

d1 $ somecyclesBy "^44" (fast 2) $ "bd*4" # gain (range 0.2 0.8 "^78")
d2 $ "~ cp" # gain (0.9 * "^79")
d3 $ "~ cp" # gain (0.9 * "^79")

At scale I have the impression this can quickly result in late messages, and I wonder if that could be because somecyclesBy evaluates some probabilities, not just boolean values, so there might be more computing under the hood than I need here!
At first I was using sometimesBy but it looked like using the latter one improved a bit my situation, which is why I suspect there's something fishy in my approach.

Anyone has a suggestion how to refactor the above, so that d1 would fast 2 depending on Midi CC ^44 being 0 or 127, without resorting to someXBy?

1 Like

How about

while "^44" (fast 2)

1 Like

Thanks @cleary for jumping in!

Tried these few ones and I'm not sure I get how while works, but it doesn't seem suited here:

d1 $ sometimesBy "^44" (fast 2) $ "bd" -- Works as expected
d1 $ someCyclesBy "^44" (fast 2) $ "bd" -- Works as expected

d1 $ while "^44" (fast 2) $ "bd" -- No sound

d1 $ while 1 (fast 2) $ "bd" -- No instance for (Num Bool) arising from the literal ‘1’

d1 $ while True (fast 2) $ "bd" -- Couldn't match expected type ‘Pattern Bool’ with actual type ‘Bool’

Yeah you're right, I had a brief play with it this morning to try and get something functional without success ...

I thought that it might require being segmented to discretize the events a bit but... no luck.

Sorry I couldn't be of more help :confused: