home/ atoms/ tidal-when-whenmod-cycle-predicates

TidalCycles when and whenmod apply transforms based on a predicate or modular arithmetic test on the cycle number

when test f p applies f to pattern p only when the test function returns True for the current cycle number. The test is any Haskell function Int -> Bool, giving full flexibility: when ((elem '4').show) transforms on any cycle whose number contains the digit 4 (cycle 4, 14, 24, 34, 40…). whenmod m n f p tests whether currentCycle mod m >= n: whenmod 8 4 (fast 2) doubles speed on cycles 4,5,6,7, then 12,13,14,15, etc. This is effectively ‘every other block of m cycles, start the transform at position n.’ ifp extends this to two-branch if-else: apply f1 when True, f2 when False.

Examples

d1 $ when ((elem '4').show) (striate 4) $ sound "hh hc"
d1 $ whenmod 8 4 (fast 2) (sound "bd sn kurt")
d1 $ ifp ((== 0).(flip mod 2)) (striate 4) (# coarse "24 48") $ sound "hh hc"

Assessment

Describe the cycle-number pattern on which whenmod 6 3 (rev) applies its transformation. Write a when expression that doubles speed only on prime-numbered cycles. When would ifp be more useful than two separate when expressions?

“`whenmod` has a similar form and behavior to `every`, but requires an additional number. It applies the function to the pattern, when the remainder of the current loop number divided by the first parameter, is greater or equal than the second parameter.”
corpus · tidalcycles-conditions-reference-every-whenmod-mask-euclidin · chunk 1