zen

    Patterns are the building blocks of Zen. They are used to generate patterns of values in interesting, concise ways.

    Implements

    • Dictionary
    Index

    Properties

    aliases: {
        qm: string;
        qms: string;
        qpb: string;
        qpbs: string;
        qph: string;
        qphs: string;
        qr: string;
    } = ...

    Shorthand aliases for pattern methods.

    qm: 'qmeasurement',
    qms: 'qmeasurements',
    qpb: 'qprobability',
    qpbs: 'qprobabilities',
    qph: 'qphase',
    qphs: 'qphases',
    qr: 'qresult',

    Methods

    • Add a value to the previous value in the pattern chain.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.n.noise(1,60,72).add(12)
      
      s0.n.noise(1,60,72).add('0?12*16')
      
    • Compare the previous value in the pattern chain with a value.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.e.every(3).and(t().mod(5))
      
    • Get a value, or values, from the previous value in the pattern chain It is assumed that the previous value is an array

      Parameters

      • i: patternable[]

        index of value to retrieve, or array of indexes to retrieve. Negative numbers are counted from the end of the array.

      Returns Pattern

      s0.set({inst:0, cut:0})
      s0.n.set('Ddor%16').at('0..8?*16')
      s0.e.every(1)
    • At, but reversed. Given an array of values, it returns the value at the index provided by the previous value in the pattern chain.

      Parameters

      • array: patternable

        array of values

      Returns Pattern

      s0.x.t().atr([0,1,5,4]).div(16)
      
    • Generate truthy or falsy values from a binary string.

      Parameters

      • n: string = '10000000'

        binary string

      • freq: patternable = 1

        number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.

      Returns Pattern

      s0.e.bin('1111') // output depends on the number of division per cycle / canvas. If 16, returns 1 every 4 divisions, 0 otherwise
      
    • Convert the previous value from beats to milliseconds, scaling by bpm. Or, if a value is passed, convert that value from beats to milliseconds, scaling by bpm.

      Parameters

      • Optionalvalue: patternable

      Returns Pattern

      s0.dur(1).btms() // this is equivalent
      
      s0.dur(btms(1)) // ...to this
      
    • Convert the previous value from beats to seconds, scaling by bpm. Or, if a value is passed, convert that value from beats to seconds, scaling by bpm.

      Parameters

      • Optionalvalue: patternable

      Returns Pattern

      s0.dur(1).bts().mul(1000)
      
      s0.dur(bts(1)).mul(1000) // this is equivalent
      
    • Return the current cycle

      Parameters

      • wrap: number = -1

        optional number to wrap the cycle count at

      Returns Pattern

      s0.test.c(4).print('Cycle')
      s0.e.set(1)
    • Cache the value. Set how many values to cache and how many times to repeat the cache before it clears

      Parameters

      • size: patternable = 16

        number of values to cache

      • repeats: patternable = 4

        number of times to repeat the cache before it clears. Default is 1.

      Returns Pattern

      s0.e.random(0,1).step(1).cache(16,4)
      
    • Clamp the previous value in the pattern chain to a range.

      Parameters

      • min: patternable

        minimum value

      • max: patternable

        maximum value

      Returns Pattern

    • Generate a cosine wave between lo and hi. Use as the first call in a pattern chain.

      Parameters

      • freq: patternable = 1

        number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.

      • lo: patternable = 0

        lowest value in range

      • hi: patternable = 1

        highest value in range

      Returns Pattern

      s0.modi.cosine().mul(10)
      
    • Parameters

      • event: patternable = 1

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.x.count(s0.e).div(16)
      s0.e.every('0?1*4|*2')
    • Count up from 0 to n-1 or Infinity if n is 0. Restarts the counter each time reset is true.

      Parameters

      • n: patternable = 0

        the number to count up to, default is 0

      • reset: patternable

        a value, instance of Pattern, or Zen pattern string that resets the counter

      Returns Pattern

      s0.set({inst: 1, bank: 'bd'})
      s0.x.counter(16, s0.e).div(q())
      s0.e.set('3:8')
    • Generate a curve between lo and hi. Use as the first call in a pattern chain.

      Parameters

      • freq: patternable = 1

        number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.

      • lo: patternable = 0

        lowest value in range

      • curve: patternable = 0.5

        curve of the pattern. Default is 0.5, which means a linear curve.

      • hi: patternable = 1

        highest value in range

      Returns Pattern

    • Degrade the pattern, replacing values with 0 based on a probability

      Parameters

      • amt: patternable = 0.5

        amount to degrade by. 1 is fully degraded (all 0s), 0 is not degraded at all

      Returns Pattern

    • Divide the previous value in the pattern chain by a value.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.n.noise(1,60,72).div(2)
      
    • Reverse divide the previous value in the pattern chain by a value.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.modi.noise().mul(2)
      
    • If the previous value in the pattern chain is falsy, return a new value, otherwise return previous value.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      • use ifelse() instead, kept for backwards compatibility
    • Test if the previous value in the pattern chain is equal to a value using ==.

      Parameters

      • value: patternable

        value to test against

      Returns Pattern

    • Generate truthy or falsy values every n divisions.

      Parameters

      • n: patternable

        number of divisions

      Returns Pattern

      s0.e.every(4) // return 1 every 4 divisions, 0 otherwise
      
    • Expand the previous value in the pattern chain to to an array of length n.

      Parameters

      • n: patternable

        length of the array

      • Optionalcallback: (value: number, index: number, array: number[]) => number

        optional callback to modify each value in the array

      Returns Pattern

    • Filter - filter the previous value in the pattern chain

      Parameters

      • cb: (x: patternValue) => boolean

        callback function to apply to each value

      Returns Pattern

    • Provide a callback function to the previous value in the pattern chain

      Parameters

      • cb: (x: patternValue) => patternValue

        callback function

      Returns Pattern

      s0.modi.seq([0,1,2,3]).fn(x => x * 2)
      
    • Test if the previous value in the pattern chain is greater than a value.

      Parameters

      • value: patternable

        value to test against

      Returns Pattern

      s0.n.noise(1).gt(0.3).ifelse(60, 72)
      
    • Test if the previous value in the pattern chain is greater than or equal to a value.

      Parameters

      • value: patternable

        value to test against

      Returns Pattern

      s0.n.noise().gte(0.3).ifelse(60, 72)
      
    • When trigger is true, samples the value returned by the previous pattern in the chain, and holds it until the next trigger.

      Parameters

      • trigger: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.e.every(5)
      s0.x.noise().hold(s0.e)
    • Alias for ifelse

      Parameters

      • ifValue: patternable = 1

        a value, instance of Pattern, or Zen pattern string

      • elseValue: patternable = 0

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

    • If the previous value in the pattern chain is truthy, return a new value, otherwise return previous value.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      • use ifelse() instead, kept for backwards compatibility
    • 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

      Parameters

      • ifValue: patternable = 1

        a value, instance of Pattern, or Zen pattern string

      • elseValue: patternable = 0

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

    • Interpolate between a value and the previous value in the pattern chain

      Parameters

      • val: patternable

        value to interpolate to

      Returns Pattern

      s0.y.sine().intrp(sine(0.5))
      
    • Invert the previous chord in the pattern chain

      Parameters

      • n: patternable

        inversion

      Returns Pattern

      s0.n.set('Cmi7').inversion(1)
      
    • 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.

      Parameters

      • i: patternable

        a value, instance of Pattern, or Zen pattern string

      • o: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.e.io(s1.e, s2.e)
      
    • Layer a value on top of the previous value in the pattern chain, forming an array of values

      Parameters

      • n: patternable

      Returns Pattern

      s0.n.set('Ddor%16..*16').layer(62)
      
    • Test if the previous value in the pattern chain is less than a value.

      Parameters

      • value: patternable = 1

        value to test against

      Returns Pattern

    • Test if the previous value in the pattern chain is less than or equal to a value.

      Parameters

      • value: patternable

        value to test against

      Returns Pattern

    • Map - apply a function to each value in the previous value in the pattern chain

      Parameters

      • cb: (x: patternValue) => patternValue

        callback function to apply to each value

      Returns Pattern

    • Markov pattern generator

      Parameters

      • matrix: number[][]

        transition matrix

      • states: patternable = 0

        number of states to generate in the pattern. If 0, uses z.q. Default is 0.

      • frequency: patternable = 1

        frequency - number of patterns to generate per cycle. Default is 1.

      Returns Pattern

      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)
    • Get the maximum of the previous value in the pattern chain and a given value

      Parameters

      • compare: patternable = 0

        value to compare to

      Returns Pattern

    • Use a midi cc on the selected device

      Parameters

      • cc: patternable

        control change number

      • device: patternable = 0

        midi device index (default is 0)

      • value: patternable = 1

        initial value (default is 1)

      Returns Pattern

      s0.vol.midicc(1,0.5,0)
      
    • Use the notes from a midi file

      Parameters

      • path: string

        url path to midi file, must be available to the browser

      • param: string = 'n'

        e | n | dur. Default n.

      Returns Pattern

      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')
      
    • Use the currently pressed key(s) on the selected device

      Parameters

      • device: patternable

        midi device index (default is 0)

      Returns Pattern

      s0.n.midinote()
      
    • Get the minimum of the previous value in the pattern chain and a given value

      Parameters

      • compare: patternable = 0

        value to compare to

      Returns Pattern

    • Modulo the previous value in the pattern chain by a value.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.n.set(t).mod(12).add(36)
      
    • Map the preceding value in the chain to a new range.

      Parameters

      • outMin: patternable

        the new minimum value

      • outMax: patternable

        the new maximum value

      • inMin: patternable = 0

        the minimum value of the input range. Default is 0.

      • inMax: patternable = 1

        the maximum value of the input range. Default is 1.

      Returns Pattern

    • Multiply the previous value in the pattern chain by a value.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.n.noise(1,60,72).mul(2)
      
    • Test if the previous value in the pattern chain is not equal to a value using !=.

      Parameters

      • value: patternable

        value to test against

      Returns Pattern

    • Generate a number between lo and hi, using a simplex noise function.

      Parameters

      • freq: patternable = 1

        Speed of the noise function.

      • lo: patternable = 0

        lowest value in range

      • hi: patternable = 1

        highest value in range

      Returns Pattern

      s0.pan.noise()
      
    • Negate the value passed as the first argument

      Parameters

      • x: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.e.every(3)
      s1.e.not(s0.e)
      s3.e.every(1).and(not(s0.e)).and(not(s1.e))
    • Convert a number to binary string, then passes it to .bin().

      Parameters

      • n: patternable = 0

        a number

      • q: number = 8

        the length of the binary string

      • freq: patternable = 1

        number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.

      Returns Pattern

      s0.n.ntbin(9, 8) // 9 in binary is 1001, padded out to 8 digits. Passes 00001001 to .bin()
      
    • Compare the previous value in the pattern chain with a value.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.e.every(3).or(t().mod(2))
      
    • 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

      Parameters

      • ...args: patternable[]

      Returns Pattern

      s0.x.sine()
      s0.y.noise()
      s0.pack(s0.x, s0.y).print().fn(([x, y]) => ...)
    • Modify the value returned by a previous iteration of the pattern

      Parameters

      • fn: Function

      Returns Pattern

      z.grid.persist((t, prev) => prev ? [...prev, Math.random()] : [])
      
    • Post the current value to the console

      Parameters

      • prefix: string = ''

        optional prefix to the message

      Returns Pattern

      s0.n.set('Cmi7').print('s0.n')
      
    • Generate a pulse wave between lo and hi. Use as the first call in a pattern chain.

      Parameters

      • freq: patternable = 1

        number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.

      • width: patternable = 0.5

        width of the pulse. Default is 0.5, which means a square wave.

      • lo: patternable = 0

        lowest value in range

      • hi: patternable = 1

        highest value in range

      Returns Pattern

      s0.modi.pulse(0.25, 1, 10)
      
    • Return the value of the measured qubit

      Parameters

      • qubit: patternable = 0

        qubit to measure

      Returns Pattern

      s0.e.measurement(0)
      
    • Returns the phase of a given state of the quantum system. Assuming that this value is between -PI and +PI, the result is normalised

      Parameters

      • state: patternable

        state to get phase of, as an integer

      Returns Pattern

      s0.phase.qphase(0).print()
      
    • Returns an array of probabilities (squared amplitude coefficients) for all possible states of the quantum system

      Returns Pattern

      s0.probs.qprobabilities().print()
      
    • Return the probability (squared amplitude coefficient) for a given state of the quantum system

      Parameters

      • state: patternable

        state to get probability of, as an integer

      Returns Pattern

      s0.amp.qprobability(0).print()
      
    • Returns the measured state as an integer - ie. in a 2-qubit system, 00 = 0, 01 = 1, 10 = 2, 11 = 3

      Returns Pattern

      s0.res.qresult().print()
      
    • Generate a random number between lo and hi.

      Parameters

      • lo: patternable = 0

        lowest value in range

      • hi: patternable = 1

        highest value in range

      Returns Pattern

      s0.n.random(60,72).step(1)
      
    • Generate a range of values between lo and hi. Use as the first call in a pattern chain.

      Parameters

      • freq: patternable = 1

        number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.

      • lo: patternable = 0

        lowest value in range

      • hi: patternable = 1

        highest value in range

      Returns Pattern

      s0.modi.range(0, 10, 1, 2)
      
    • Reduce - reduce the previous value in the pattern chain to a single value

      Parameters

      • cb: (acc: patternValue, x: patternValue) => patternValue

        callback function to apply to each value

      • initial: patternValue = 0

        initial value to start the reduction

      Returns Pattern

    • Generate a saw wave between lo and hi. Alias of range. Use as the first call in a pattern chain.

      Parameters

      • freq: patternable = 1

        number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.

      • lo: patternable = 0

        lowest value in range

      • hi: patternable = 1

        highest value in range

      Returns Pattern

      s0.modi.saw().mul(10)
      
    • Choose from a sequence of values. Use as the first call in a pattern chain.

      Parameters

      • values: number[] = []

        an array of values

      • freq: patternable = 1

        number of iterations of the sequence, either per cycle or per canvas. Default is 1, which means once per cycle.

      Returns Pattern

      s0.n.seq([60,72,74,76])
      
    • Set a single value

      Parameters

      • value: patternable

        a single string or number or array of strings or numbers, or a Pattern, or a Zen pattern string

      Returns Pattern

      s0.amp.set(1)
      
      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
      
    • Generate a sine wave between lo and hi. Use as the first call in a pattern chain.

      Parameters

      • freq: patternable = 1

        number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.

      • lo: patternable = 0

        lowest value in range

      • hi: patternable = 1

        highest value in range

      Returns Pattern

      s0.modi.sine().mul(10)
      
    • Size - number of values in the previous value in the pattern chain

      Returns Pattern

      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
      
    • Slice - slice the previous value in the pattern chain

      Parameters

      • start: patternable = 0

        start index of the slice

      • end: patternable = Infinity

        end index of the slice

      Returns Pattern

    • Snap the previous value in the pattern chain to the nearest value in an array.

      Parameters

      • array: patternable

        array of values to snap to

      Returns Pattern

      s0.x.random(0,1).snap([0,0.25,0.5,0.75])
      s0.e.set(1)
    • Some - test if some values in the previous value in the pattern chain pass a test

      Parameters

      • cb: (x: patternValue) => boolean

        callback function to apply to each value

      Returns Pattern

    • Generate a square wave between lo and hi. Use as the first call in a pattern chain. See also pulse.

      Parameters

      • freq: patternable = 1

        number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.

      • lo: patternable = 0

        lowest value in range

      • hi: patternable = 1

        highest value in range

      Returns Pattern

      s0.modi.square(1,0,10)
      
    • Subtract a value from the previous value in the pattern chain.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.n.noise(1,60,72).sub(12)
      
    • Reverse subtract. Subtract the previous value in the pattern chain from a value.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.amp.noise(1,0.5,0.25).subr(1)
      
    • Convert text to normalised values between 0 and 1.

      Parameters

      • text: string

      Returns Pattern

      s0.n.textToNormal('hello world!')
      
    • 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

      Parameters

      • x: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.e.every(8)
      s1.e.toggle(s0.e)
      s1.y.set(0.5)
    • Generate a triangle wave between lo and hi. Use as the first call in a pattern chain.

      Parameters

      • freq: patternable = 1

        number of iterations of the pattern, either per cycle or per canvas. Default is 1, which means once per cycle.

      • lo: patternable = 0

        lowest value in range

      • hi: patternable = 1

        highest value in range

      Returns Pattern

      s0.harm.tri(0.25).mul(4)
      
    • Round the previous value in the pattern chain to the nearest value in an array.

      Parameters

      • array: patternable

        array of values to round to

      Returns Pattern

      s0.n.noise(1,0,12).tune([0,2,4,5,7,9,11,12]).add(36)
      
    • Compare the previous value in the pattern chain with a value.

      Parameters

      • value: patternable

        a value, instance of Pattern, or Zen pattern string

      Returns Pattern

      s0.e.every(3).xor(t().mod(2))
      
    MMNEPVFCICPMFPCPTTAAATR