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:

do
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:

Cool idea!
Did you manage to find another syntax that works for you?
I'm not in front of tidalCycles right now, but I wonder, if somethingl ike this works:

d1 
$ fast (|+ 1 (cF 1 "44"))
$ "bd*4" # gain (range 0.2 0.8 "^78")

By the way, is the caret ^ operator a shorthand vor cF _ _ in a way? I can't find it in the docs, but it looks really handy.

select chooses between a list of patterns:

select "^44" ["0", "2"]

selectF chooses between a list of functions:

selectF "^44" [fast 2, iter 4, rev] $ s "bd sd"

If you just want to switch a function on/off, you can use id to stand for doing nothing

selectF "^44" [id, fast 2] $ s "bd sd"

E.g. this would apply the speed to the sd:

selectF "0 1 0 0" [id, (# speed 2)] $ s "bd sd cp cp"
1 Like

Yes that's right!