tur/pattern
pat-at
(pat-at [p time])
evaluate a pattern at a specific time.
| p | pattern to evaluate | |
| time | time in beats |
Pattern value at the given time. (pat-at (const 5) 2.3) ; => 5
pat-start
(pat-start [p])
evaluate a pattern at time 0.
| p | pattern to evaluate |
Pattern value at time 0. (pat-start (cycle 10 20 30)) ; => 10
const
(const [value])
constant pattern that always returns the same value.
| value | the value to return regardless of time |
Pattern<T> that always returns value. (const 0.5)
silence
(silence)
pattern that always returns none (for option types).
Pattern<option<T>> that always returns none.
cycle
(cycle [& values])
cycle through values one per beat.
| values | one or more values to cycle through |
Pattern<T> advancing to the next value each beat. ((cycle 1 2 3) 0.0) ; => 1 ((cycle 1 2 3) 1.0) ; => 2
fast-cycle
(fast-cycle [rate & values])
cycle through values at a faster rate.
| rate | cycles per whole (default: 1 = same as cycle) | |
| values | values to cycle through |
Pattern<T> cycling rate times faster than cycle. ((fast-cycle 2 1 2 3) 0.5) ; evaluates as if time=1.0
phase
(phase [& [cycle_length 1.0])
return the fractional phase within a cycle.
| cycle_length | length of the cycle in beats (default: 1.0) |
NumPattern returning phase in [0, cycle_length). ((phase 2.0) 1.5) ; => 1.5
P
(P [& exprs])
macro shorthand: (P x) => (const x), (P x y ...) => (cycle x y ...).
(P 1 2 3) ; same as (cycle 1 2 3) (P 5) ; same as (const 5)
rand-choice
(rand-choice [& values])
randomly pick a value from the supplied list on each evaluation.
| values | one or more values to choose from |
Pattern<T> returning a random element each time it is evaluated. ((rand-choice 1 2 3) 0.0) ; => 1, 2, or 3 at random
rand-int
(rand-int [min max])
pattern returning a random integer in [min, max) each evaluation.
| min | minimum value (inclusive) | |
| max | maximum value (exclusive) |
NumPattern of random integers.
rand-float
(rand-float)
pattern returning a random float in [0, 1) each evaluation.
NumPattern of random floats.
rand-range
(rand-range [min max])
pattern returning a random float in [min, max) each evaluation.
| min | minimum value (inclusive) | |
| max | maximum value (exclusive) |
NumPattern.
identity
(identity)
pattern that returns its time argument unchanged.
NumPattern returning the raw time value.
time-pat
(time-pat)
pattern returning the current time value.
NumPattern that is the identity function over time.
beat-number
(beat-number)
pattern returning the integer beat number.
NumPattern returning floor(time). ((beat-number) 2.7) ; => 2.0
beat-fraction
(beat-fraction)
pattern returning the fractional part of the current beat.
NumPattern returning time - floor(time). ((beat-fraction) 2.7) ; => 0.7
alt
(alt [a b])
alternate between two values on even/odd beats.
| a | value on even beats | |
| b | value on odd beats |
Pattern<T> alternating between a and b. ((alt 1 2) 0.0) ; => 1 ((alt 1 2) 1.0) ; => 2
if-pat
(if-pat [condition a b])
choose between two values based on a boolean pattern.
| condition | Boolean pattern or time -> bool function | |
| a | value when condition is true | |
| b | value when condition is false |
Pattern<T>.
every-n
(every-n [n])
true when the beat number is a multiple of n.
| n | modulo base |
BoolPattern that is true when floor(time) mod n == 0. ((every-n 4) 4.0) ; => true
when-mod
(when-mod [n & [offset 0])
true when beat number mod n equals a given offset.
| n | modulo base | |
| offset | target remainder (default: 0) |
BoolPattern.
when
(when [cond p & [zero 0])
gate a pattern through a boolean condition.
| cond | Boolean pattern controlling when p fires | |
| p | pattern to gate | |
| zero | value returned when cond is false (default: 0) |
Pattern<T>. (when (every-n 2) (const 1) 0)
every
(every [n p & [zero 0])
play a pattern only every n beats.
| n | beat interval | |
| p | pattern to play | |
| zero | value between triggers (default: 0) |
Pattern<T>. (every 4 my-pat)
pattern-length
(pattern-length [p])
attempt to determine the cycle length of a pattern.
nil (cannot be determined statically in general).
pattern-constant?
(pattern-constant? [p])
check whether a pattern is constant.
false (cannot be determined statically in general).
PatternWithMeta<T>
(defstruct PatternWithMeta<T> [])
pattern bundled with introspection metadata.
with-meta
(with-meta [pattern & [name "" description "" tags [])
attach metadata to a pattern.
| pattern | the underlying pattern | |
| name | human-readable name (default: "") | |
| description | description of the pattern (default: "") | |
| tags | categorisation tags (default: []) |
PatternWithMeta<T>.
pattern-of
(pattern-of [p])
extract the underlying pattern from a PatternWithMeta value.
| p | PatternWithMeta<T> |
Pattern<T>.