Classes
Pattern
Defined in classes/Pattern.ts
Patterns are the building blocks of Zen. They are used to generate patterns of values in interesting, concise ways. Pattern methods can be chained together. Pattern methods can be prefixed with a $ to create a new pattern; for example, $add. The results of each pattern are combined together.
s0.p.amp.range(0,1)
s0.px.drive.sine(0,1)
s0.py.modi.range(0,10).mul((t%q)/q)
s0.e.every(3).$and.every(4)
aliases
Defined in classes/Pattern.ts
Shorthand aliases for pattern methods.
a: 'add',
an: 'and',
b: 'bin',
bm: 'btms',
bs: 'bts',
cl: 'clamp',
c: 'coin',
cc: 'midicc',
co: 'cosine',
cu: 'curve',
d: 'div',
dr: 'divr',
e: 'else',
eq: 'eq',
ev: 'every',
i: 'if',
intrp: 'interpolate',
inv: 'inversion',
in: 'invert',
la: 'layer',
mo: 'mod',
m: 'mul',
n: 'not',
no: 'noise',
nb: 'ntbin',
o: 'or',
of: 'often',
pu: 'pulse',
rd: 'random',
ra: 'range',
r: 'rarely',
sa: 'saw',
se: 'seq',
v: 'set',
si: 'sine',
sq: 'square',
st: 'step',
so: 'sometimes',
s: 'sub',
sr: 'subr',
t: 'toggle',
tr: 'tri',
trig: 'trigger',
tu: 'tune',
u: 'use',
x: 'xor'
_
Defined in classes/Pattern.ts
Return to parent Pattern or Stream Useful when using any of the dollar methods, which spawn new Patterns, allowing you to return to this original pattern. Or, use as shorthand to access the underlying stream
s1.set({inst: 'synth', cut: 1})
s1.p.n.coin()
.$if.set(57)._
.$else.set('Ddor..*16')
s1.e.every(1)
s0.x.set(8)._.y.set(8)
add
Defined in classes/Pattern.ts
Add a value to the previous value in the pattern chain.
s0.p.n.noise(60,72,1).add(12)
s0.p.n.noise(60,72,1).add('0?12*16')
- value: a value, instance of Pattern, or Zen pattern string
and
Defined in classes/Pattern.ts
Compare the previous value in the pattern chain with a value.
s0.e.every(3).add(t%2)
Or, use $and to create a new pattern and compare it with the previous pattern in the chain.
s0.e.every(3).$and.every(2)
- value: a value, instance of Pattern, or Zen pattern string
at
Defined in classes/Pattern.ts
Get a value from the previous value in the pattern chain, at index n Expects the previous value to be an array
s0.p.n.set('Ddor%16').at(t%16)
- n: index of value to retrieve
atan2
Defined in classes/Pattern.ts
Get the arctangent of the previous value in the pattern chain
- y: value to divide by
bin
Defined in classes/Pattern.ts
Generate truthy or falsy values from a binary string.
s0.p.n.bin('1111') // output depends on the number of division per cycle / canvas. If 16, returns 1 every 4 divisions, 0 otherwise
- n: binary string
- rest:
btms
Defined in classes/Pattern.ts
Convert the previous value from beats to milliseconds, scaling by bpm
s0.p.dur(1).btms()
bts
Defined in classes/Pattern.ts
Convert the previous value from beats to seconds, scaling by bpm
s0.p.dur(1).bts().mul(1000)
cosine
Defined in classes/Pattern.ts
Generate a cosine wave between lo and hi. Use as the first call in a pattern chain.
s0.p.modi.cosine(0, 10)
- args:
curve
Defined in classes/Pattern.ts
Generate a curve between lo and hi. Use as the first call in a pattern chain.
- lo: lowest value in range
- hi: highest value in range
- curve: curve of the pattern. Default is 0.5, which means a linear curve.
- freq: number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.
div
Defined in classes/Pattern.ts
Divide the previous value in the pattern chain by a value.
s0.p.n.noise(60,72,1).div(2)
Or, use $div to create a new pattern and divide it by the previous pattern in the chain.
s0.p.n.noise(60,72,1).$div.noise(0,12,1)
- value: a value, instance of Pattern, or Zen pattern string
divr
Defined in classes/Pattern.ts
Reverse divide the previous value in the pattern chain by a value.
s0.p.modi.noise(1,2).divr(2)
Or, use $divr to create a new pattern and divide it by the previous pattern in the chain.
s0.p.n.noise(0,12,1).$divr.noise(60,72,1)
- value: a value, instance of Pattern, or Zen pattern string
else
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is a truthy or falsy value If false return new value, if true, simply pass on the previous value
- value: a value, instance of Pattern, or Zen pattern string
eq
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is equal to a value using ==.
- args:
even
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is an even number
- args:
every
Defined in classes/Pattern.ts
Generate truthy or falsy values every n divisions.
s0.e.every(4) // return 1 every 4 divisions, 0 otherwise
s0.p.n.every(2, 60, 72) // return 60 every 2 divisions, 72 otherwise
- args:
fn
Defined in classes/Pattern.ts
Provide a callback function to the previous value in the pattern chain
s0.p.modi.seq([0,1,2,3]).fn(x => x * 2)
- cb: callback function
gt
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is greater than a value.
s0.p.n.noise(0,1).gt(0.3, 60, 72)
- args:
gte
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is greater than or equal to a value.
s0.p.n.noise(0,1).gte(0.3, 60, 72)
- args:
if
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is a truthy or falsy value If true return new value, if false, simply pass on the previous value
- value: a value, instance of Pattern, or Zen pattern string
interpolate
Defined in classes/Pattern.ts
Interpolate between a value and the previous value in the pattern chain
s0.y.sine(0,15,1).$intrp.sine(15,0,1,0.5)
- val: value to interpolate to
inversion
Defined in classes/Pattern.ts
Invert the previous chord in the pattern chain
s0.p.n.set('Cmi7').inversion(1)
s0.p.n.set('Cmi7').$inversion.range(0,8,1)
- n: inversion
invert
Defined in classes/Pattern.ts
Invert the previous value in the pattern chain - like a bitwise NOT. Returns a 0 if true, and a 1 if false.
io
Defined in classes/Pattern.ts
On/off. Returns 1 when on, 0 when off. True values passed to the first argument will turn the pattern on, false values are ignored. True values passed to the second argument will turn the pattern off, false values are ignored.
s0.e.io(s1.e, s2.e)
- i:
- o:
layer
Defined in classes/Pattern.ts
Layer a value on top of the previous value in the pattern chain, forming an array of values
s0.p.n.set('Ddor%16..*16').layer(62)
- n:
lt
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is less than a value.
- args:
lte
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is less than or equal to a value.
- args:
max
Defined in classes/Pattern.ts
Get the maximum of the previous value in the pattern chain and a given value
- compare: value to compare to
midicc
Defined in classes/Pattern.ts
Use a midi cc on the selected device
s0.p.vol.midicc(1,0.5,0)
- cc: control change number
- device: midi device index (default is 0)
- value: initial value (default is 1)
midinote
Defined in classes/Pattern.ts
Use the currently pressed key(s) on the selected device
s0.p.n.midinote()
- device: midi device index (default is 0)
min
Defined in classes/Pattern.ts
Get the minimum of the previous value in the pattern chain and a given value
- compare: value to compare to
mod
Defined in classes/Pattern.ts
Modulo the previous value in the pattern chain by a value. Or, use $mod to pass the outcome of a pattern to the function
s0.n.set(t).mod(12).add(36)
s0.n.set(t).$mod.set(12)
- value: a value, instance of Pattern, or Zen pattern string
mtr
Defined in classes/Pattern.ts
Map the preceding value in the chain to a new range.
- outMin: the new minimum value
- outMax: the new maximum value
- inMin:
- inMax:
mul
Defined in classes/Pattern.ts
Multiply the previous value in the pattern chain by a value.
s0.p.n.noise(60,72,1).mul(2)
- value: a value, instance of Pattern, or Zen pattern string
neq
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is not equal to a value using !=.
- args:
noise
Defined in classes/Pattern.ts
Generate a number between lo and hi, using a simplex noise function.
s0.p.pan.noise(0, 1)
- args:
not
Defined in classes/Pattern.ts
Negate the value passed as the first argument
s0.e.every(3)
s1.e.not(s0.e)
s2.e.not(!(t%3))
s3.e.not('1?0*16')
- x: a value, instance of Pattern, or Zen pattern string
ntbin
Defined in classes/Pattern.ts
Convert a number to binary string, then passes it to .bin().
s0.p.n.ntbin(9, 8) // 9 in binary is 1001, padded out to 8 digits. Passes 00001001 to .bin()
- n: a number
- q: the length of the binary string
- freq: number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.
- a: value to return when true
- b: value to return when false
odd
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is an odd number
- args:
once
Defined in classes/Pattern.ts
Returns a 1 the first time it is called, and 0 thereafter
ts
s0.e.once()
or
Defined in classes/Pattern.ts
Compare the previous value in the pattern chain with a value.
s0.e.every(3).or(t%2)
- value: a value, instance of Pattern, or Zen pattern string
pow
Defined in classes/Pattern.ts
Multiply the previous value in the pattern chain to the power of a given value
- exponent: value to multiply by
pulse
Defined in classes/Pattern.ts
Generate a pulse wave between lo and hi. Use as the first call in a pattern chain.
s0.p.modi.pulse(0, 10, 0.25)
- args:
random
Defined in classes/Pattern.ts
Generate a random number between lo and hi.
s0.p.n.random(60,72,1)
- args:
range
Defined in classes/Pattern.ts
Generate a range of values between lo and hi. Use as the first call in a pattern chain.
s0.p.modi.range(0, 10, 1, 2)
- args:
saw
Defined in classes/Pattern.ts
Generate a saw wave between lo and hi. Alias of range. Use as the first call in a pattern chain.
s0.p.modi.saw(0, 10)
- args:
seq
Defined in classes/Pattern.ts
Choose from a sequence of values. Use as the first call in a pattern chain.
s0.p.n.seq([60,72,74,76])
- values: an array of values
- freq: number of iterations of the sequence, either per cycle or per canvas. Default is 1, which means once per cycle.
set
Defined in classes/Pattern.ts
Set a single value
s0.p.amp.set(1)
ts
s1.e.set(s0.e)
s0.e.set('1?0*16')
s0.x.set(t => t) // run a function, with the first argument being the current time
- value: a single string or number or array of strings or numbers, or a Pattern, or a Zen pattern string
sine
Defined in classes/Pattern.ts
Generate a sine wave between lo and hi. Use as the first call in a pattern chain.
s0.p.modi.sine(0, 10)
- args:
sometimes
Defined in classes/Pattern.ts
50/50 chance of returning 1 or 0. Also, use coin().
s0.e.sometimes()
- args:
square
Defined in classes/Pattern.ts
Generate a square wave between lo and hi. Use as the first call in a pattern chain. See also pulse.
s0.p.modi.square(0, 10)
- lo: lowest value in range
- hi: highest value in range
- freq: number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.
step
Defined in classes/Pattern.ts
Round the previous value in the pattern chain to the step value.
- value: value to round to
sub
Defined in classes/Pattern.ts
Subtract a value from the previous value in the pattern chain.
s0.p.n.noise(60,72,1).sub(12)
- value: a value, instance of Pattern, or Zen pattern string
subr
Defined in classes/Pattern.ts
Reverse subtract. Subtract the previous value in the pattern chain from a value.
s0.p.amp.noise(0.5,0.25).subr(1)
- value: a value, instance of Pattern, or Zen pattern string
toggle
Defined in classes/Pattern.ts
Toggle on or off using the value passed as the first argument A true value will toggle the pattern on, a false value will toggle it off
s0.e.every(3)
s1.e.toggle(s0.e)
s2.e.toggle(!(t%3))
s3.e.toggle('1?0*16')
- x: a value, instance of Pattern, or Zen pattern string
tri
Defined in classes/Pattern.ts
Generate a triangle wave between lo and hi. Use as the first call in a pattern chain.
s0.p.harm.tri(0, 4, 0.25)
- args:
ttms
Defined in classes/Pattern.ts
Convert the previous value from divisions of a bar to seconds, scaling by bpm
s0.p.set(q).ttms()
tune
Defined in classes/Pattern.ts
Round the previous value in the pattern chain to the nearest value in an array.
s0.p.n.noise(0,12).tune([0,2,4,5,7,9,11,12]).add(36)
- array: array of values to round to
use
Defined in classes/Pattern.ts
Inset another pattern's stack into the current pattern's stack
s0.p.amp.sine()
s1.p.pan.use(s0.p.amp);
- pattern: an instance of another pattern
xor
Defined in classes/Pattern.ts
Compare the previous value in the pattern chain with a value.
s0.e.every(3).xor(t%2)
- value: a value, instance of Pattern, or Zen pattern string
Stream
Defined in classes/Stream.ts
A stream is a musical layer. You can use a stream to map musical parameters across time and space.
When a stream triggers an event, musical parameters are determined by the stream's position in time and space.
When a stream triggers a mutation, all active events are mutated based on the stream's position in time and space.
Streams are available within Zen as s0, s1, s2, s3, s4, s5, s6, s7.
s0.set({inst: 'synth', n: 60}) // set the stream's default parameters
s0.p.lag.set(1).btms()
s0.px._modi.saw(1,10) // map the synth's modulation index across the x axis
s0.py._harm.range(0,10,1) // map the synth's harmonic series across the y axis
s0.x.range(0,16,1) // move the stream across the x axis of the canvas
s0.y.noise(0,16,1,0.5) // move the stream across the y axis of the canvas
s0.e.every(4) // trigger an event every 4 divisions
s0.m.not(s0.e)
_aliases
Defined in classes/Stream.ts
Shorthand aliases for pattern methods
{
add: 'a',
and: 'an',
}
map
Defined in classes/Stream.ts
An object used to map parameter names to different keys. Useful for mapping to MIDI controllers
s0.map = {amp: 'cc1', cutoff: 'cc74'}
p
Defined in classes/Stream.ts
Patterns to be mapped across time
s0.p.amp.range(0,1) // ramp amp from 0 to 1 across the cycle
px
Defined in classes/Stream.ts
Patterns to be mapped across the x axis
s0.px.amp.range(0,1) // ramp amp from 0 to 1 across the x axis of the canvas
py
Defined in classes/Stream.ts
Patterns to be mapped across the y axis
s0.py.amp.range(0,1) // ramp amp from 0 to 1 across the y axis of the canvas
pz
Defined in classes/Stream.ts
Patterns to be mapped across the z axis
s0.pz.amp.range(0,1) // ramp amp from 0 to 1 across the z axis of the canvas
e
Defined in classes/Stream.ts
A Pattern for determining whether the stream should trigger an event
s0.e.set(1) // trigger an event every division
s0.e.every(4) // trigger an event every 4 divisions
s0.e.bin('1000 1001') // use a binary pattern to trigger events
m
Defined in classes/Stream.ts
A Pattern for determining whether to mutate all active events in the stream. Only mutates parameters prefixed with _, e.g. _amp
s0.m.set(1) // mutate all active events every division
s0.m.every(4) // mutate all active events every 4 divisions
mute
Defined in classes/Stream.ts
A Pattern for determining whether to mute the stream
s0.mute.set(1) // mute the stream every division
s0.mute.every(4) // mute the stream every 4 divisions
solo
Defined in classes/Stream.ts
A Pattern for determining whether to solo the stream. If true, mutes all other streams
s0.solo.set(1) // solo the stream every division
s0.solo.every(4) // solo the stream every 4 divisions
t
Defined in classes/Stream.ts
A Pattern for setting the stream's position in time
s0.t.sine(0,16,1) // override the global t with a sine wave between 0 and 16
x
Defined in classes/Stream.ts
A Pattern for setting the stream's position in space
s0.x.saw(0,16,1) // move the stream across the x axis of the canvas with a saw wave between 0 and 16
xyz
Defined in classes/Stream.ts
A Pattern for setting all axes of the stream's position at the same time. Expects an array of values
s0.xyz.set([t,8,0])
y
Defined in classes/Stream.ts
A Pattern for setting the stream's position in space
s0.y.saw(0,16,1) // move the stream across the y axis of the canvas with a saw wave between 0 and 16
z
Defined in classes/Stream.ts
A Pattern for setting the stream's position in space
s0.z.saw(0,16,1) // move the stream across the z axis of the canvas with a saw wave between 0 and 16
set
Defined in classes/Stream.ts
Set multiple stream parameter using key/value pairs
s0.set({amp: 1, n: 60, reverb: 0.5})
- ps: key/value pairs
Zen
Defined in classes/Zen.ts
The Zen class allows you to set global parameters. It is available within Zen as z.
z.t.range(0, 16, 1) // pattern time
z.bpm.range(60, 120, 1) // pattern bpm
z.s = 16 // size of canvas
z.q = 16 // frames per cycle
z.update = 1 // when to update the executed code, 1 is on the next division, q is on the next cycle etc.
z.set({reverb: 1, rsize: 0.5}) // set global parameters for all streams. Can be overwritten by stream parameters
z.p.n.scales('d-dorian', 16) // set global time parameters using z.p
z.px._modi.range(0, 1, 0.25) // set global stream parameters using z.px
etc.
_aliases
Defined in classes/Stream.ts
Shorthand aliases for pattern methods
{
add: 'a',
and: 'an',
}
map
Defined in classes/Stream.ts
An object used to map parameter names to different keys. Useful for mapping to MIDI controllers
s0.map = {amp: 'cc1', cutoff: 'cc74'}
p
Defined in classes/Stream.ts
Patterns to be mapped across time
s0.p.amp.range(0,1) // ramp amp from 0 to 1 across the cycle
px
Defined in classes/Stream.ts
Patterns to be mapped across the x axis
s0.px.amp.range(0,1) // ramp amp from 0 to 1 across the x axis of the canvas
py
Defined in classes/Stream.ts
Patterns to be mapped across the y axis
s0.py.amp.range(0,1) // ramp amp from 0 to 1 across the y axis of the canvas
pz
Defined in classes/Stream.ts
Patterns to be mapped across the z axis
s0.pz.amp.range(0,1) // ramp amp from 0 to 1 across the z axis of the canvas
bpm
Defined in classes/Zen.ts
A Pattern for setting the global bpm
z.bpm.saw(60,120,0.5) // set the global bpm with a saw wave between 60 and 120, over 2 cycles
c
Defined in classes/Zen.ts
Get the current cycle. This is available within your code as c.
s0.e.every(c%2 ? 1 : 4) // every 1 frame on odd cycles, every 4 frames on even cycles
e
Defined in classes/Stream.ts
A Pattern for determining whether the stream should trigger an event
s0.e.set(1) // trigger an event every division
s0.e.every(4) // trigger an event every 4 divisions
s0.e.bin('1000 1001') // use a binary pattern to trigger events
latency
Defined in classes/Zen.ts
A Pattern for setting the global latency
z.latency.set(500) // set the global latency to 500ms
m
Defined in classes/Stream.ts
A Pattern for determining whether to mutate all active events in the stream. Only mutates parameters prefixed with _, e.g. _amp
s0.m.set(1) // mutate all active events every division
s0.m.every(4) // mutate all active events every 4 divisions
mute
Defined in classes/Stream.ts
A Pattern for determining whether to mute the stream
s0.mute.set(1) // mute the stream every division
s0.mute.every(4) // mute the stream every 4 divisions
q
Defined in classes/Zen.ts
Set the number of divisions per cycle. Changing this value updates the variable q within your code.
z.q = 16 // set the number of divisions per cycle to 16
s
Defined in classes/Zen.ts
Set the size of the canvas. Changing this value updates the variable s within your code.
z.s = 16 // set the size of the canvas to 16
seed
Defined in classes/Zen.ts
A Pattern for setting the global seeding
z.seed.saw(0,1,0.5) // set the global seed with a saw wave between 0 and 1, over 2 cycles
solo
Defined in classes/Stream.ts
A Pattern for determining whether to solo the stream. If true, mutes all other streams
s0.solo.set(1) // solo the stream every division
s0.solo.every(4) // solo the stream every 4 divisions
t
Defined in classes/Zen.ts
A Pattern for setting the global time. The outcome of the pattern updates the variable t within your code.
z.t.sine(0,16,1) // set the global t with a sine wave between 0 and 16
update
Defined in classes/Zen.ts
Set when to update the executed code
z.update = 1 // update on every frame
z.update = 4 // update on every 4th frame
z.update = q // update on the next cycle
x
Defined in classes/Stream.ts
A Pattern for setting the stream's position in space
s0.x.saw(0,16,1) // move the stream across the x axis of the canvas with a saw wave between 0 and 16
xyz
Defined in classes/Stream.ts
A Pattern for setting all axes of the stream's position at the same time. Expects an array of values
s0.xyz.set([t,8,0])
y
Defined in classes/Stream.ts
A Pattern for setting the stream's position in space
s0.y.saw(0,16,1) // move the stream across the y axis of the canvas with a saw wave between 0 and 16
z
Defined in classes/Stream.ts
A Pattern for setting the stream's position in space
s0.z.saw(0,16,1) // move the stream across the z axis of the canvas with a saw wave between 0 and 16
set
Defined in classes/Stream.ts
Set multiple stream parameter using key/value pairs
s0.set({amp: 1, n: 60, reverb: 0.5})
- ps: key/value pairs