Chapter 9

Mixing & routing

Levels and panning in the code, buses between tracks, sidechains, and the mixer.

The channel strip

These take numbers, patterns or signals, like everything else.

WriteDoes
.gain(v)level going into the chain; lower drives the effects less. 1 is unity
.postgain(v)level after the chain: the fader. 1 is unity
.pan(v)−1 left to 1 right
.width(v)stereo width: 0 mono, 1 unchanged, up to 4
.bassmono(hz)mono below hz, stereo above
.o(n)output pair: .o(2) is channels 3/4 (raise output channels in settings)

Several .gain() or .postgain() calls multiply, so .gain(0.5).gain(env()) is a level times an envelope.

pad: note("<[c3,eb3,g3] [bb2,d3,f3]>").synth("Wavetable").fx("Chorus")
  .width(2).bassmono(200).postgain(0.35)
bell: s("pt_keys:1").note("<g4 bb4 c5 d5>*2").pan("-0.6 0.6").postgain(0.3)

Buses

.bus("name", amount) sends a track to a named bus, and audio("name") plays that bus on another track. .dry(0) silences the track's own output; .bsend() does both at once. Both arguments pattern, so .bus("<verb delay>") re-routes as it goes.

The send leaves the chain where it is written. After the last device it is the track's output. Before a device it taps the signal at that point, so what follows stays out of the send: a delay feeding back on itself can keep its reverb out of the loop.

delay: audio("delay").fx("Delay").bus("feedback", 0.4).fx("Reverb")
feedback: audio("feedback").bsend("delay")
pad: note("c3 e3 g3").synth("Wavetable")
  .width(0.6)
  .pan("<-0.5 0.5>")
  .bus("space", 0.3).postgain(0.5)

verb: audio("space").fx("Reverb").param("Mix", 1).postgain(0.8)

A function as the Delay's second argument is a chain inside its feedback loop: every repeat goes through it once more, so a highpass thins each echo further. Its devices are on the track like any other. The way round is taken off the delay time, so the repeats stay on the beat; a time shorter than the way round is held at it.

dub: s("~ cp ~ ~").postgain(0.4)
  .fx("Delay", (x) => x.fx("Filter").param("Mode", "highpass").param("Cutoff", 0.4))
  .param("Feedback", 0.75)

Sources and sidechains

midi() and audio() do two things, depending on where they are written. At the head of a track they are its source:

midi("KeyStep").synth("Wavetable")   // play from a MIDI device
audio("drums").fx("Reverb")         // another track through a reverb
input(1).fx("Overdrive")            // a microphone or interface input

After an .fx() they feed that effect: .midi("kick") replays kick's notes into it, and .audio("kick") feeds kick's audio into its sidechain.

kick: s("bd*4").postgain(0.3)
// the ducker dips on each of kick's notes
bass: note("c2*8").synth("Wavetable").fx("Ducker").midi("kick").postgain(0.3)
// the compressor listens to kick's audio
pad: note("[c3,eb3,g3]").synth("Wavetable").fx("Compressor").audio("kick").postgain(0.3)

A name means a track first, then any device whose name contains it. Force one with "track:kick" or "dev:KeyStep". For a trigger with no track of its own, make a muted one (_trig: note("c5 ~ c5 ~")) and point at it.

The browser asks for permission the first time a pattern uses input() or a MIDI device. Web MIDI is in Chrome, Edge and Firefox, not Safari. Inputs picked in settings are numbered across in the order you picked them; input("USB", 1) names whose channel you mean.

Audio input needs a device with inputs, picked in settings. To use several interfaces, tick them under extra inputs; input("Scarlett", 1) then names whose channel you mean.

The mixer

The mixer: a strip per track with meters, faders and pan, beside a spectrum and a stereo image.

{app+g} opens a strip per track (meter, fader, pan, width, mute, solo, and ▽ mono for bass mono) beside a spectrum and a stereo image. Anything in the outer ø wedges is lost in mono.

The mixer writes code. A fader rewrites the track's .postgain(), mute and solo write _ and S, and clicking a strip's name renames the track everywhere. The mix lives in the song.

Groups show as one strip that unfolds. The plots analyze up to eight strips, then only the master; folding groups keeps a big song under that.