home/ atoms/ tidal-every-conditional

every applies a transformation to a pattern on every nth cycle, leaving other cycles unchanged

every n f p takes a cycle count n, a function f, and a pattern p, applying f to p once every n cycles (cycles 0, n, 2n, …) and playing p unmodified in between — the primary conditional operator for introducing periodic variation without breaking the underlying pattern. If f takes its own argument (e.g. fast 2), it must be wrapped in parentheses, every 3 (fast 2) p; a bare every 3 $ fast 2 $ ... fails because that structure applies fast before every sees it. Variants extend this: every' n offset f p fires the transform on cycles offset, offset+n, offset+2n (so every' 3 0 equals every 3, but every' 3 1 fires on 1, 4, 7, …); foldEvery [3,5] f p applies f on any cycle that is a multiple of 3 or 5, and applies it twice on multiples of both (15).

Examples

d1 $ every 4 (rev) $ sound "bd*2 [bd [sn sn*2 sn] sn]"   -- reverse every 4th cycle
d1 $ every 3 (fast 2) $ n "0 1 [~ 2] 3" # sound "arpy"   -- double speed every 3rd cycle
d1 $ every 8 (const $ sound "arpy*4") $ sound "bd sn"    -- swap in a fill every 8th
d1 $ foldEvery [5,3] (|+ n 1) $ s "moog" # legato 1

Assessment

What does every 4 (fast 2) $ s "bd sn" produce over 8 cycles? Write an expression that reverses a pattern every 3 cycles and doubles its speed every 5 cycles. Explain the difference between every 3 rev and every' 3 1 rev, and why the transform must be parenthesized.

“`every` is function that allows you to apply another function conditionally. It takes three inputs: how often the function should be applied (e.g. `3` to apply it every `3` cycles), the function to be applied, and the pattern you are applying it to.”
corpus · tidalcycles-conditions-reference-every-whenmod-mask-euclidin · chunk 1
“every takes three parameters: a number, a function and a pattern to apply the function to. The number specifies how often the function is applied to the pattern.”
corpus · tidalcycles-userbase-tutorial-community-function-by-function · chunk 3