Using dynamic values inside within or whenT

Hello,

I would like to use dynamic data for some values. But I do not succeed for some operations.
For instance, If I would like to replace the value 0.5 of the following lines:

d1 $ sometimesBy 0.5 (fast 2) $ sound "bd*8"
d1 $ within (0, 0.5) (fast 2) $ sound "bd*8"
d1 $ whenT ((< 0.5).(flip Data.Fixed.mod' 2)) (fast 2) $ sound "bd*8"

I can do it and it works in the case of everything, but how to change arguments of within or whenT dynamically with "test" ? The last two generate an error:

setF "test" (cF 0.5 "test")
d1 $ sometimesBy "^test" (fast 2) $ sound "bd*8"
d1 $ within (0, "^test") (fast 2) $ sound "bd*8" -- how to replace the second argument of within dynamically ?
d1 $ whenT ((< "^test").(flip Data.Fixed.mod' 2)) (fast 2) $ sound "bd*8"

Thanks for the help,

Christophe

Yes unfortunately those parameters of within and whenT don't accept patterns.

You can promote make them patternable but it's a bit fiddly:

tidal> toPerc tpat f pat = innerJoin $ fmap (\t -> within (0, t) f pat) tpat
tidal> drawLine $ toPerc "<0 0.5>" (fast 2) $ "a b c d"

[11 cycles]
|abcd|abcdc-d-|abcd|abcdc-d-|abcd|abcdc-d-|abcd|abcdc-d-|abcd|abcdc-d-|abcd
1 Like

fiddly maybe, but it works!
Thank you so much!

Christophe