tur/temporal

stdlib/temporal.tur
defn

slow

(slow [factor p])

play a pattern slower by a given factor.

factorslowdown factor (> 1 = slower)
ppattern to slow down
Pattern<T> that plays at 1/factor speed.

  ((slow 2 my-pat) 1.0)  ; same as (my-pat 0.5)
defn

fast

(fast [factor p])

play a pattern faster by a given factor.

factorspeedup factor (> 1 = faster)
ppattern to speed up
Pattern<T> that plays factor times faster.

  ((fast 2 my-pat) 1.0)  ; same as (my-pat 2.0)
defn

stretch

(stretch [factor p])

stretch time within a cycle (alias for slow).

factorstretch factor
ppattern to stretch

Pattern<T> with stretched time.

defn

compress

(compress [factor p])

compress time within a cycle (alias for fast).

factorcompression factor
ppattern to compress

Pattern<T> with compressed time.

defn

shift

(shift [offset p])

shift a pattern forward or backward in time.

offsettime offset in beats (positive = later, negative = earlier)
ppattern to shift
Pattern<T> shifted in time.

  ((shift 0.5 my-pat) 1.0)  ; same as (my-pat 1.5)
defn

rot

(rot [amount p])

rotate a pattern's phase (alias for shift).

amountrotation amount in beats
ppattern to rotate

Pattern<T> with shifted phase.

defn

mirror

(mirror [p])

mirror a pattern within each 2-beat window.

ppattern to mirror
Pattern<T> that plays forward in [0,1) then backward in [1,2).

  ((mirror my-pat) 1.5)  ; reads from time 0.5
defn

rev

(rev [p])

reverse a pattern within each 1-beat cycle.

ppattern to reverse
Pattern<T> with reversed time within each cycle.

  ((rev my-pat) 0.25)  ; same as (my-pat 0.75)
defn

repeat

(repeat [n p])

repeat a pattern n times within its cycle.

nrepetition count
ppattern to repeat
Pattern<T> playing n times faster.

  ((repeat 4 my-pat) 0.0)
defn

once

(once [p & [zero 0])

play a pattern only during the first beat, then return zero.

ppattern to play
zerovalue after the first cycle (default: 0)

Pattern<T> that silences after time >= 1.0.

defn

for-beats

(for-beats [duration p & [zero 0])

play a pattern for a fixed number of beats, then return zero.

durationduration in beats
ppattern to play
zerovalue after duration (default: 0)

Pattern<T> active for duration beats.

defn

loop-cycles

(loop-cycles [cycles p & [zero 0])

loop a pattern for a fixed number of cycles then stop.

cyclesnumber of cycles to loop
ppattern to loop
zerovalue after looping ends (default: 0)

Pattern<T>.

defn

loop-range

(loop-range [start end p & [zero 0])

loop a pattern between two time points.

startstart time in beats
endend time in beats
ppattern to loop
zerovalue outside [start, end) (default: 0)

Pattern<T> looping within the window.

defn

warp

(warp [warp-fn p])

remap time using an arbitrary function.

warp-fnBeats -> Beats transformation applied to time before evaluation
ppattern to warp

Pattern<T> evaluated at warped time.

defn

warp-by

(warp-by [warp-pat p])

remap time by multiplying with values from another pattern.

warp-patNumPattern producing a time-scaling factor
ppattern to warp

Pattern<T> evaluated at time * warp-pat(time).

defn

quantize-beat

(quantize-beat [p])

snap pattern evaluation to the nearest beat boundary.

ppattern to quantize

Pattern<T> that only changes on whole-beat boundaries.

defn

quantize

(quantize [n p])

snap pattern evaluation to multiples of n beats.

nquantization grid size in beats
ppattern to quantize
Pattern<T> quantized to n-beat intervals.

  (quantize 0.25 my-pat)  ; 16th-note grid
defn

quantize-subdiv

(quantize-subdiv [subdivisions p])

snap pattern evaluation to a subdivision grid.

subdivisionsnumber of subdivisions per beat (e.g., 4 = 16th notes)
ppattern to quantize

Pattern<T> quantized to 1/subdivisions-beat steps.

defn

time-mod

(time-mod [period p])

wrap time into a [0, period) window before evaluation.

periodperiod in beats
ppattern to wrap

Pattern<T> evaluated with time mod period.

defn

time-switch

(time-switch [period & patterns])

cycle through a list of patterns, each lasting period beats.

periodduration per pattern in beats
patternspatterns to cycle through
Pattern<T> switching to the next pattern every period beats.

  ((time-switch 4 pat-a pat-b pat-c) 5.0)  ; uses pat-b
defn

transform-time

(transform-time [p & transformations])

apply a sequence of temporal transformations to a pattern.

pbase pattern
transformationslist of [transform-fn args...] pairs to apply in order
Pattern<T> with all transformations applied.

  (transform-time (cycle 1 2 3) [slow 2] [shift 0.5] [repeat 2])
defn

backwards

(backwards [p & [duration 1.0])

play a pattern in reverse within each cycle.

ppattern to reverse
durationcycle duration in beats (default: 1.0)

Pattern<T> playing backwards.

defn

palindrome

(palindrome [p & [duration 1.0])

play a pattern forwards then backwards (ping-pong).

ppattern to palindrome
durationhalf-period in beats (default: 1.0)
Pattern<T> playing forward then backward in a 2*duration window.

  ((palindrome my-pat) 1.5)  ; reads from time 0.5 (backwards half)
defn

stutter

(stutter [subdivisions p])

repeat each value of a pattern subdivisions times.

subdivisionshow many times to repeat each value
ppattern to stutter
Pattern<T> with stuttered output.

  ((stutter 4 my-pat) 0.5)  ; reads from floor(0.5/4) = 0
defn

time-window

(time-window [start end p & [zero 0])

gate a pattern to a specific time window.

startwindow start in beats
endwindow end in beats
ppattern to window
zerovalue outside the window (default: 0)

Pattern<T> active only in [start, end).

defn

fade-in

(fade-in [fade-duration p])

produce a linear ramp from 0 to 1 over fade-duration beats.

fade-durationduration of the fade in beats
ppattern (currently unused, ramp only)

NumPattern rising linearly to 1.0 then holding at 1.0.

defn

fade-out

(fade-out [fade-duration start-time p])

produce a linear ramp from 1 to 0 starting at start-time.

fade-durationduration of the fade in beats
start-timebeat at which the fade begins
ppattern (currently unused, ramp only)

NumPattern holding 1.0 before start-time, then falling to 0.0.