tur/structural
seq
(seq [& patterns])
sequence patterns end to end, each getting equal time per cycle.
| patterns | one or more patterns to sequence |
Pattern<T> cycling through patterns one beat at a time. ((seq pat-a pat-b pat-c) 1.5) ; evaluates pat-b at sub-time 0.5
seq-n
(seq-n [& pattern-lengths])
sequence patterns with custom durations per segment.
| pattern-lengths | list of [pattern length] tuples |
Pattern<T> proportionally allocating time to each segment.
stack
(stack [& patterns])
evaluate all patterns simultaneously and return their values as a vector.
| patterns | one or more patterns to stack |
Pattern<vec<T>> where each element is one pattern's value at the current time. ((stack kick-pat snare-pat hat-pat) 0.0)
stack-with
(stack-with [f & patterns])
stack patterns and fold results with a combiner function.
| f | function vec<T> -> U combining all pattern values | |
| patterns | patterns to stack |
Pattern<U>.
sum
(sum [& patterns])
pointwise sum of numeric patterns.
| patterns | one or more NumPattern to sum |
NumPattern returning the sum of all pattern values. ((sum bass-pat melody-pat) 0.5)
multiply
(multiply [& patterns])
pointwise product of numeric patterns.
| patterns | one or more NumPattern to multiply |
NumPattern returning the product of all pattern values.
average
(average [& patterns])
pointwise average of numeric patterns.
| patterns | one or more NumPattern to average |
NumPattern returning the arithmetic mean of all pattern values.
when
(when [cond p & [zero 0])
gate a pattern through a boolean condition.
| cond | BoolPattern controlling when p fires | |
| p | pattern to gate | |
| zero | value when condition is false (default: 0) |
Pattern<T>. (when (pattern/every-n 2) kick-pat 0)
if-pat
(if-pat [cond then-p else-p])
select between two patterns based on a boolean pattern.
| cond | BoolPattern | |
| then-p | pattern when condition is true | |
| else-p | pattern when condition is false |
Pattern<T>.
every
(every [n p & [zero 0])
trigger a pattern every n beats.
| n | beat interval | |
| p | pattern to trigger | |
| zero | value between triggers (default: 0) |
Pattern<T>. (every 4 fill-pat)
nth
(nth [n p & [offset 0 zero 0])
trigger a pattern when beat number mod n equals offset.
| n | modulo base | |
| p | pattern to trigger | |
| offset | target remainder (default: 0) | |
| zero | value when not triggered (default: 0) |
Pattern<T>.
euclid
(euclid [steps hits & [rotation 0])
Euclidean rhythm distributing hits as evenly as possible.
| steps | total number of steps in the pattern | |
| hits | number of active (hit) steps | |
| rotation | rotation offset (default: 0) |
NumPattern returning 1 for hits and 0 for rests. ((euclid 8 5) 0.0) ; classic 5-in-8 Euclidean rhythm
euclid-vals
(euclid-vals [steps hits & [on-value 1 off-value 0 rotation 0])
Euclidean rhythm with custom on/off values.
| steps | total steps | |
| hits | number of hit steps | |
| on-value | value for hits (default: 1) | |
| off-value | value for rests (default: 0) | |
| rotation | rotation offset (default: 0) |
Pattern<T> with custom on/off values.
select
(select [index & patterns])
choose among patterns using an index pattern.
| index | NumPattern producing indices into the pattern list | |
| patterns | patterns to select from |
Pattern<T> delegating to the selected sub-pattern. ((select (cycle 0 1 2) pat-a pat-b pat-c) 0.5)
first-nonzero
(first-nonzero [& [zero 0 patterns])
return the first non-zero value from a set of patterns.
| zero | zero sentinel value (default: 0) | |
| patterns | patterns to check in order |
Pattern<T> returning the first non-zero pattern value.
index
(index [& [cycle-length 1])
return the step index within a cycle.
| cycle-length | number of steps per cycle (default: 1) |
IntPattern returning the current step index.
first-beat
(first-beat [& [cycle-length 1])
true on the first step of each cycle.
| cycle-length | steps per cycle (default: 1) |
BoolPattern.
last-beat
(last-beat [& [cycle-length 1])
true on the last step of each cycle.
| cycle-length | steps per cycle (default: 1) |
BoolPattern.
chain
(chain [& [sentinel nil patterns])
concatenate patterns, advancing when a sentinel value is returned.
| sentinel | value indicating end of a pattern segment (default: nil) | |
| patterns | patterns to chain |
Pattern<T> advancing through patterns in order.
interleave
(interleave [& patterns])
alternate between patterns each beat.
| patterns | patterns to interleave |
Pattern<T> cycling through patterns one per beat, with each sub-pattern receiving compressed time equal to the number of patterns. ((interleave pat-a pat-b) 0.5) ; reads pat-a at time 1.0
interleave-n
(interleave-n [& pattern-lengths])
interleave patterns with custom durations (alias for seq-n).
| pattern-lengths | list of [pattern length] tuples |
Pattern<T>.
mask
(mask [source mask & [zero 0])
let signal pass only where a boolean mask is true.
| source | Pattern to read values from | |
| mask | BoolPattern: true = pass, false = block | |
| zero | value when masked (default: 0) |
Pattern<T>. (mask melody-pat (euclid 8 5))
invert
(invert [p])
invert a boolean pattern.
| p | BoolPattern to invert |
BoolPattern with negated values.
and-pat
(and-pat [a b])
logical AND of two boolean patterns.
| a | first BoolPattern | |
| b | second BoolPattern |
BoolPattern.
or-pat
(or-pat [a b])
logical OR of two boolean patterns.
| a | first BoolPattern | |
| b | second BoolPattern |
BoolPattern.
xor-pat
(xor-pat [a b])
logical XOR of two boolean patterns.
| a | first BoolPattern | |
| b | second BoolPattern |
BoolPattern.
group
(group [group-size group-pattern & patterns])
partition patterns into groups and apply a group combiner.
| group-size | number of patterns per group | |
| group-pattern | function (time, patterns) -> T applied to each group | |
| patterns | patterns to group |
Pattern<T> applying group-pattern to the current group.