Defined in classes/Pattern.ts
Patterns are the building blocks of Zen. They are used to generate patterns of values in interesting, concise ways.
Defined in classes/Pattern.ts
Shorthand aliases for pattern methods.
qm: 'qmeasurement',
qms: 'qmeasurements',
qpb: 'qprobability',
qpbs: 'qprobabilities',
qph: 'qphase',
qphs: 'qphases',
qr: 'qresult',
Defined in classes/Pattern.ts
Add a value to the previous value in the pattern chain.
s0.n.noise(1,60,72).add(12)
s0.n.noise(1,60,72).add('0?12*16')
Defined in classes/Pattern.ts
Compare the previous value in the pattern chain with a value.
s0.e.every(3).and(t().mod(5))
Defined in classes/Pattern.ts
Get a value, or values, from the previous value in the pattern chain It is assumed that the previous value is an array
s0.set({inst:0, cut:0})
s0.n.set('Ddor%16').at('0..8?*16')
s0.e.every(1)
Defined in classes/Pattern.ts
Get the arctangent of the previous value in the pattern chain
Defined in classes/Pattern.ts
At, but reversed. Given an array of values, it returns the value at the index provided by the previous value in the pattern chain.
s0.x.t().atr([0,1,5,4]).div(16)
Defined in classes/Pattern.ts
Generate truthy or falsy values from a binary string.
s0.e.bin('1111') // output depends on the number of division per cycle / canvas. If 16, returns 1 every 4 divisions, 0 otherwise
Defined in classes/Pattern.ts
Convert the previous value from beats to milliseconds, scaling by bpm
s0.dur(1).btms()
Defined in classes/Pattern.ts
Convert the previous value from beats to seconds, scaling by bpm
s0.dur(1).bts().mul(1000)
Defined in classes/Pattern.ts
Cache the value. Set how many values to cache and how many times to repeat the cache before it clears
s0.e.random(0,1).step(1).cache(16,4)
Defined in classes/Pattern.ts
Clamp the previous value in the pattern chain to a range.
Defined in classes/Pattern.ts
Generate a cosine wave between lo and hi. Use as the first call in a pattern chain.
s0.modi.cosine().mul(10)
Defined in classes/Pattern.ts
s0.x.count(s0.e).div(16)
s0.e.every('0?1*4|*2')
Defined in classes/Pattern.ts
Count up from 0 to n-1 or Infinity if n is 0. Restarts the counter each time reset is true.
s0.set({inst: 1, bank: 'bd'})
s0.x.counter(16, s0.e).div(q())
s0.e.set('3:8')
Defined in classes/Pattern.ts
Generate a curve between lo and hi. Use as the first call in a pattern chain.
Defined in classes/Pattern.ts
Degrade the pattern, replacing values with 0 based on a probability
Defined in classes/Pattern.ts
Divide the previous value in the pattern chain by a value.
s0.n.noise(1,60,72).div(2)
Defined in classes/Pattern.ts
Reverse divide the previous value in the pattern chain by a value.
s0.modi.noise().mul(2)
Defined in classes/Pattern.ts
If the previous value in the pattern chain is falsy, return a new value, otherwise return previous value.
- use ifelse() instead, kept for backwards compatibilityDefined in classes/Pattern.ts
Test if the previous value in the pattern chain is equal to a value using ==.
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is an even number
Defined in classes/Pattern.ts
Generate truthy or falsy values every n divisions.
s0.e.every(4) // return 1 every 4 divisions, 0 otherwise
Defined in classes/Pattern.ts
Filter - filter the previous value in the pattern chain
Defined in classes/Pattern.ts
Provide a callback function to the previous value in the pattern chain
s0.modi.seq([0,1,2,3]).fn(x => x * 2)
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is greater than a value.
s0.n.noise(1).gt(0.3).ifelse(60, 72)
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is greater than or equal to a value.
s0.n.noise().gte(0.3).ifelse(60, 72)
Defined in classes/Pattern.ts
When trigger is true, samples the value returned by the previous pattern in the chain, and holds it until the next trigger.
s0.e.every(5)
s0.x.noise().hold(s0.e)
Defined in classes/Pattern.ts
If the previous value in the pattern chain is truthy, return a new value, otherwise return previous value.
- use ifelse() instead, kept for backwards compatibilityDefined 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
Defined in classes/Pattern.ts
Interpolate between a value and the previous value in the pattern chain
s0.y.sine().intrp(sine(0.5))
Defined in classes/Pattern.ts
Invert the previous chord in the pattern chain
s0.n.set('Cmi7').inversion(1)
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.
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)
Defined in classes/Pattern.ts
Layer a value on top of the previous value in the pattern chain, forming an array of values
s0.n.set('Ddor%16..*16').layer(62)
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is less than a value.
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is less than or equal to a value.
Defined in classes/Pattern.ts
Map - apply a function to each value in the previous value in the pattern chain
Defined in classes/Pattern.ts
Markov pattern generator
s0.set({inst: 1})
s0.bank.set(['bd', 'sd', 'hh']).at(
markov(
[[0,0.1,0.9], [0.25,0.1,0.9], [0.5,0.25,0.5]]),
64,
0.25
)
s0.e.set(1)
Defined in classes/Pattern.ts
Get the maximum of the previous value in the pattern chain and a given value
Defined in classes/Pattern.ts
Use a midi cc on the selected device
s0.vol.midicc(1,0.5,0)
Defined in classes/Pattern.ts
Use the notes from a midi file
s0.n.midifile('path/to/midi.mid', 'n')
s0.dur.midifile('path/to/midi.mid', 'dur').btms()
s0.e.midifile('path/to/midi.mid', 'e')
Defined in classes/Pattern.ts
Use the currently pressed key(s) on the selected device
s0.n.midinote()
Defined in classes/Pattern.ts
Get the minimum of the previous value in the pattern chain and a given value
Defined in classes/Pattern.ts
Modulo the previous value in the pattern chain by a value.
s0.n.set(t).mod(12).add(36)
Defined in classes/Pattern.ts
Map the preceding value in the chain to a new range.
Defined in classes/Pattern.ts
Multiply the previous value in the pattern chain by a value.
s0.n.noise(1,60,72).mul(2)
Defined in classes/Pattern.ts
Test if the previous value in the pattern chain is not equal to a value using !=.
Defined in classes/Pattern.ts
Generate a number between lo and hi, using a simplex noise function.
ts
s0.pan.noise()
Defined in classes/Pattern.ts
Negate the value passed as the first argument
s0.e.every(3)
s1.e.not(s0.e)
s3.e.every(1).and(not(s0.e)).and(not(s1.e))
Defined in classes/Pattern.ts
Convert a number to binary string, then passes it to .bin().
s0.n.ntbin(9, 8) // 9 in binary is 1001, padded out to 8 digits. Passes 00001001 to .bin()
Defined in classes/Pattern.ts
Returns a 1 the first time it is called, and 0 thereafter
ts
s0.e.once()
Defined in classes/Pattern.ts
Compare the previous value in the pattern chain with a value.
s0.e.every(3).or(t().mod(2))
Defined in classes/Pattern.ts
Pack all arguments into an array Arguments can be a value, instance of Pattern, or Zen pattern string Each will be evaluated and packed into an array
s0.x.sine()
s0.y.noise()
s0.pack(s0.x, s0.y).print().fn(([x, y]) => ...)
Defined in classes/Pattern.ts
Modify the value returned by a previous iteration of the pattern
z.grid.persist((t, prev) => prev ? [...prev, Math.random()] : [])
Defined in classes/Pattern.ts
The previous value in the pattern chain to the power of a given value
Defined in classes/Pattern.ts
Post the current value to the console
s0.n.set('Cmi7').print('s0.n')
Defined in classes/Pattern.ts
Generate a pulse wave between lo and hi. Use as the first call in a pattern chain.
s0.modi.pulse(0.25, 1, 10)
Defined in classes/Pattern.ts
Return the value of the measured qubit
s0.e.measurement(0)
Defined in classes/Pattern.ts
Return all measurements of the system as an array
s0.e.measurements()
Defined in classes/Pattern.ts
Returns the phase of a given state of the quantum system. Assuming that this value is between -PI and +PI, the result is normalised
s0.phase.qphase(0).print()
Defined in classes/Pattern.ts
Returns an array of phases for all basis states of the quantum system
s0.phases.qphases().print()
Defined in classes/Pattern.ts
Returns an array of probabilities (squared amplitude coefficients) for all possible states of the quantum system
s0.probs.qprobabilities().print()
Defined in classes/Pattern.ts
Return the probability (squared amplitude coefficient) for a given state of the quantum system
s0.amp.qprobability(0).print()
Defined in classes/Pattern.ts
Returns the measured state as an integer - ie. in a 2-qubit system, 00 = 0, 01 = 1, 10 = 2, 11 = 3
s0.res.qresult().print()
Defined in classes/Pattern.ts
Generate a random number between lo and hi.
s0.n.random(60,72).step(1)
Defined in classes/Pattern.ts
Generate a range of values between lo and hi. Use as the first call in a pattern chain.
s0.modi.range(0, 10, 1, 2)
Defined in classes/Pattern.ts
Reduce - reduce the previous value in the pattern chain to a single value
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.modi.saw().mul(10)
Defined in classes/Pattern.ts
Choose from a sequence of values. Use as the first call in a pattern chain.
s0.n.seq([60,72,74,76])
Defined in classes/Pattern.ts
Set a single value
ts
s0.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
Defined in classes/Pattern.ts
Generate a sine wave between lo and hi. Use as the first call in a pattern chain.
s0.modi.sine().mul(10)
Defined in classes/Pattern.ts
Size - number of values in the previous value in the pattern chain
s0.n.set([0,1,2,3]).size() // returns 4
s0.n.set('Cmaj7').size() // returns 4
s0.n.set('Cmaj7..*16').size() // returns 1
Defined in classes/Pattern.ts
Slice - slice the previous value in the pattern chain
Defined in classes/Pattern.ts
Snap the previous value in the pattern chain to the nearest value in an array.
s0.x.random(0,1).snap([0,0.25,0.5,0.75])
s0.e.set(1)
Defined in classes/Pattern.ts
Some - test if some values in the previous value in the pattern chain pass a test
Defined in classes/Pattern.ts
50/50 chance of returning 1 or 0. Also, use coin()
.
s0.e.sometimes()
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.modi.square(1,0,10)
Defined in classes/Pattern.ts
Round the previous value in the pattern chain to the step value.
Defined in classes/Pattern.ts
Subtract a value from the previous value in the pattern chain.
s0.n.noise(1,60,72).sub(12)
Defined in classes/Pattern.ts
Reverse subtract. Subtract the previous value in the pattern chain from a value.
s0.amp.noise(1,0.5,0.25).subr(1)
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(8)
s1.e.toggle(s0.e)
s1.y.set(0.5)
Defined in classes/Pattern.ts
Generate a triangle wave between lo and hi. Use as the first call in a pattern chain.
s0.harm.tri(0.25).mul(4)
Defined in classes/Pattern.ts
Convert the previous value from divisions of a bar to seconds, scaling by bpm
ts
s0.q().ttms()
Defined in classes/Pattern.ts
Round the previous value in the pattern chain to the nearest value in an array.
s0.n.noise(1,0,12).tune([0,2,4,5,7,9,11,12]).add(36)
Defined in classes/Pattern.ts
Inset another pattern's stack into the current pattern's stack
s0.amp.sine()
s1.pan.use(s0.amp);
Defined in classes/Pattern.ts
Compare the previous value in the pattern chain with a value.
s0.e.every(3).xor(t().mod(2))
Defined in classes/Stream.ts
A Stream is a musical layer. You can think of it as a track in a DAW, or a channel in a mixer.
It can be used to control multiple instruments, effects, and routing.
Streams are available within Zen as s0
, s1
, s2
, s3
, s4
, s5
, s6
, s7
.
s0.set({inst:0,cut:0,reverb:.5,delay:.25,vol:.5,modi:1.25,mods:0.1})
s0.n.set('Cpro%16..*16 | Cpro%16..?*16').sub(12),
s0.s.noise(.25,0.05,0.5)
s0.e.every(4).or(every(3))
Defined in classes/Stream.ts
Defined in classes/Stream.ts
Defined in classes/Stream.ts
Defined in classes/Wire.ts
The Wire class represents a single wire in a quantum circuit. They are represented in Zen as q0, q1, q2, etc. It uses the Quantum Circuit package to implement quantum gates. Some gates are documented here. See https://www.npmjs.com/package/quantum-circuit#implemented-gates for a list of all implemented gates.
ts
q0.h().cx([1])
Defined in classes/Wire.ts
Toffoli gate, or CCNOT gate
Defined in classes/Wire.ts
Controlled NOT gate, or CNOT gate
Defined in classes/Wire.ts
Use the last measure as the initial state of the qubit
Defined in classes/Wire.ts
Generate a random circuit
Defined in classes/Wire.ts
Rotation around the X-axis by given angle
Defined in classes/Wire.ts
Rotation around the Y-axis by given angle
Defined in classes/Wire.ts
Rotation around the Z-axis by given angle
Defined in classes/Wire.ts
Single qubit rotation with 3 Euler angles
Defined in classes/Wire.ts
Update a gate parameter outside of a gate method
q0.update('r2.2.0', $noise())
Defined in classes/Wire.ts
PI rotation over X-axis, also known as NOT gate