Chapter 11
Controls & displays
Sliders, knobs and step grids drawn in the code; scopes, meters and punchcards beside it.
Some calls are drawn in the editor where they are written. A control is a value you move by hand: moving it rewrites the call in the code and is heard at once, without evaluating. A display shows what a track is doing while the song plays. Both appear once the code has been evaluated.
Controls
| Call | |
|---|---|
slider(value, min, max, step) | a box slider, dragged sideways; min and max are 0 and 1 unless given |
knob(value, min, max, step) | a knob, dragged up and down |
knob(880, 20, 20000, { curve: "exp" }) | a knob or slider that turns on a curve: exp sweeps a ratio, the way a frequency wants; pow and sym bend the range (with curveExp), from one end or from the middle |
toggle(1) | 1 or 0, switched by a click |
button() | 1 while held down, 0 otherwise |
xy(x, y) | a pad under the line; .x and .y are its two axes, 0 to 1 |
Shift-drag a slider or a knob for fine steps, or turn the mouse wheel over it. Each control is a
pattern, so it goes anywhere a value does: a gain, a device's control, an argument to
.range(). Typing a new number into the call moves the control to match.
setbpm(120)
keys: n("0 2 4 <7 9>").scale("C minor").synth("Wavetable")
.param("Osc 1 Position", knob(0.3))
.fx("Filter").param("Cutoff", slider(0.6, 0.2, 0.9))
.gain(toggle(1)).postgain(0.4)
kick: s("bd*4").postgain(button().range(0.4, 0))
const pad = xy(0.3, 0.6)
chords: note("<[c3,eb3,g3] [ab2,c3,eb3]>").synth("Wavetable")
.param("Osc 1 Position", pad.x)
.fx("Filter").param("Cutoff", pad.y)
.postgain(0.3)
A number already in the code becomes a control from the right-click menu: knob from
0.5 or slider from 0.5. The value of a .param() takes that
control's range and curve; any other number gets a range it fits in.
Recording a movement
.record({ cycles }) on a control records how you move it while the music plays. Let go, or leave a MIDI or
OSC controller still for a cycle, and the movement loops, cycles long, on the same
beats it was played on. The take is kept as a drawn shape: the call gains
take: "name", the shape opens in the shape editor, and touching the control again
punches in: the stretch from the grab to the release is overwritten and the rest of the loop
kept (a touch longer than the loop replaces it). While the take plays, the control is drawn
where the take has it, marked with the accent. It works the same on slider(), knob(),
toggle(), xy() (both axes),
midicc(), osc() and macro(); a
button() keeps its presses as cells instead (see
a button as a rhythm).
setbpm(120)
pad: note("<c3 eb3 g3 bb2>").synth("Wavetable")
.fx("Filter").param("Cutoff", knob(0.5, 0.2, 0.9).record({ cycles: 2 }))
.postgain(0.3)
A control without .record() keeps its movement for a while too, and so do
midicc(), osc() and macro(), and the knobs of a device's
window or a plugin's own window. capture,
in the header, writes in what was just moved as if .record() had been there all along:
every control that moved in the last phrase (everything since four cycles of stillness)
gains .record({ cycles, take }) and its take, and plays it from then on; a hardware
knob's take goes on each place in the code that reads it; a device knob moved in its window
becomes .param("Cutoff", knob(880, 20, 20000, { curve: "exp" }).record({ cycles, take })),
turning the way the window's knob does. The takes
are one length, the whole cycles the phrase covers. A take keeps that length in its
definition - _shape("lead-take", "…", { cycles: 3 }) - so changing
cycles in the call pads it with its last value, or cuts it, rather than stretching
it: cycles: 4 rounds a three-cycle take out to a bar. In the shape editor,
{mod+l} on a selected span loops just that stretch, and {mod+d} plays it twice; both
set the take's length and cycles to match. The open piano roll
captures what was just played on its track as well. In DJ mode each deck's takes land in its
own code, and capture can be learned onto a controller pad.
Steps, bars and grids
| Call | |
|---|---|
steps("x . x .") | a row of cells, one per step: . is a rest, x plays 1, a number or a word plays as itself |
sliders("0.2 0.8", min, max) | a bar per step, each its own value |
matrix({ bd: "x...", sd: "..x." }) | a grid with a row per name; a cell plays its row's name |
shiftreg("x . x x . . x .") | a row of cells read as a shift register: a value from 0 to 1 on every step (see below) |
acid(16) | bars with accents, long gates, slides and octaves (see below) |
steps(8) · sliders(8) · matrix({ bd: 8, sd: 8 }) | that many empty steps, bars halfway up, or empty rows, to click into |
These are drawn in place of their call: the cells stand where the text was, with a wider gap
every four steps in a row of fours, so the beats can be counted. Click a cell to
switch it, or drag across a row to paint; drag a bar up or down to set it. Each change rewrites the
text behind the cells, so undo, copy and paste carry it like any other code. The first click on a
count writes the cells out, so steps(8) becomes steps("x . . . . . . .").
A cell lights while it sounds, as the text under it would: through cat() only the
row that is playing lights, and through bite() the cells light in the order they
are played.
Written with nothing inside, steps() and sliders() draw eight cells. A
matrix() needs at least one row: without one it plays nothing, stays text and says so
in the console. A row the grid can't read is drawn empty and named in the console; a row written as
a variable stays text.
Right-click the cells for randomize: as many hits as the row has now, somewhere
else, spelled with the row's own tokens (half the row when it has none, or nothing but); every
bar of a sliders() at a new height in its range; every row of a matrix()
at once. coarser halves a row of cells: each pair of cells becomes one, a hit
if either was, so nothing played is lost and a hit moves earlier by at most a step.
finer doubles it: each cell followed by a rest, so it plays the same and has
room for more. Both work on steps(), shiftreg() and every row of a
matrix() at once. Edit as text opens the call to type into; with the caret in it,
show as cells (show as bars for sliders) draws it again.
setbpm(118)
drums: s(matrix({ bd: "x . . . x . . .", sd: ". . . . x . . .", hh: 8 })).postgain(0.4)
kick: s("bd").struct(steps(8)).postgain(0.3)
hats: s("hh*8").vel(sliders("1 0.4 0.7 0.4 1 0.4 0.7 0.4")).postgain(0.3)
A matrix row's name is what its cells play. Name the rows after drums and it is a drum grid; name them with numbers and it is a note grid, here scale degrees:
keys: n(matrix({ 0: "x . . . x . . .", 3: ". x . . . x . .", 7: ". . x . . . x .", 9: ". . . x . . . x" }))
.scale("C minor").synth("Wavetable").postgain(0.4)
bass: n(steps("0 . 3 . 5 . 7 3")).scale("C minor").sub(7).synth("Wavetable")
.fx("Filter").param("Cutoff", sliders("0.2 0.5 0.8 0.4"))
.postgain(0.4)
Rows that change
{ mutate } on steps(), sliders() or matrix() makes the
row change a little each time it comes round. At the end of every cycle, while the song plays,
each cell on its own changes with that chance: a cell switches between hit and rest, a bar is
thrown again in its range. The change is written into the call, so you watch the row move and
the next cycle plays it, without evaluating. These writes stay out of undo, which steps back
through your own edits only.
mutate | |
|---|---|
0 | the row stays as it is |
0.05 | about one cell in twenty changes each cycle: a pattern that drifts |
0.5 | every cell thrown again each cycle |
1 | every cell switches each cycle: the row and its inverse, one after the other |
The chance can be any signal or pattern instead of a number, read as each cycle begins: a
knob() (const amt = knob(0.05), then { mutate: amt }), a
MIDI controller ({ mutate: midicc("Twister")(12) }), an LFO, or "<0 0.2>" to
change every other cycle. On sliders(), { deviation } keeps a bar
thrown again near where it was: it moves by a bell curve with that standard deviation, in the
bars' own units, and stays in the range. deviation: 1 on bars from 0 to 12 moves
about two in three of them by 1 or less. randomize uses it too.
setbpm(120)
kick: s("bd").struct(steps("x . . . x . . x . . x . x . . .", { mutate: 0.05 })).postgain(0.4)
hats: s("hh*8").vel(sliders("1 0.4 0.7 0.4 1 0.4 0.7 0.4", 0, 1, { mutate: 0.2, deviation: 0.1 })).postgain(0.3)
lead: n(sliders("0 4 7 4 2 9 7 4", 0, 12, { mutate: 0.1, deviation: 1 }).floor()).scale("C minor")
.synth("Wavetable").postgain(0.3)
shiftreg() is a row of cells read as a looping shift register. Every step gets a
value from 0 to 1: that step and the seven before it, round the row, read as a binary number
with the step itself as the top bit. Each value is the one before it halved, with the new step on
top, so a run of rests falls away step by step and a hit leaps up. Its second argument is the
chance a cell switches each cycle, as mutate. Written as a count,
shiftreg(16, 0.05) throws a row of that many cells, half of them hits, and writes it
into the call when it is evaluated.
setbpm(120)
bass: n(shiftreg("x . x x . . x . x x . . . x . x", 0.05).range(0, 7).floor())
.scale("A1:minor").synth("Wavetable").postgain(0.3)
.bits(n) reads any pattern with steps the same way, n steps wide (8 when it
is left out): a step is a 1 when an event starts in it that is not a rest, 0 or false.
Acid lines
acid() is a row of bars like sliders(), a value from 0 to 1 per
step, with a row each under it for accents, long gates and octaves. It plays the values, so
scale it with .range() after it like any other signal. The rest rides on each
note and goes through whatever the chain does to the values: an accented note plays at full
velocity, the rest at 0.7; an octave mark plays the note 12 semitones up or down. A note
sounds for half its step; a long gate holds it into the next, which ties it on when the next
value is the same and slides into it (see .slide()) when it is not.
setbpm(126)
kick: s("bd*4").postgain(0.45)
acid: acid(16).range("F1", "F3").round().synth("Acid").preset("squelch")
acid(16) throws a line of that many steps and writes it into the call. The
new button throws another, by three sliders that move the line as they are
dragged: density, the chance a step plays; gravity, the
chance a step is 0; and notes, how many different values it uses. A drag
along the loop ruler picks the steps that play. Drag a bar to set it, and click it to turn the step off or
on. In the code, a step is its value with marks after it: ' an octave up
('' two), , one down, ! an accent and ~ a
long gate; . rests, and two | mark the loop.
mutate throws steps again every cycle, from the values the line already has.
A button as a rhythm
.struct() takes its rhythm from a button() as well as from a step
pattern: each press plays, on the next sixteenth after it, so a press is in time however it was
played. A second argument sets the grid, .struct(button(), 8) for eighths. Any
signal that goes between 0 and 1 is a rhythm the same way, a press wherever it rises past 0.5:
square(), a drawn shape, a recorded take.
.advance() takes the rhythm the same way and plays the pattern's values in turn,
the next one on each trigger, round and round. The values are the pattern's events in the
cycle the trigger lands in, in order, so <…> still changes them cycle by
cycle; a chord is one value. The trigger can be a step pattern too.
setbpm(120)
hit: note("c3").struct(button()).synth("Wavetable").postgain(0.4)
arp: n(sliders("0 4 7", 0, 12).advance(button())).scale("A1:minor").synth("Wavetable").postgain(0.4)
.record() on the button keeps the presses as a row of cells in the call:
button().record({ cycles: 2, take: steps("x . . . …") }), one cell per step of
the grid the presses play on, across the take's whole length (two cycles of sixteenths is 32
cells). Each press switches on the cell it lands on and leaves the rest, so a rhythm is tapped
in press by press, and from then on it plays every pass. The row is drawn as cells like any
steps(): click one to change what plays, or press the button again to add to it.
capture writes a button's recent presses the same way.
setbpm(120)
bass: n("0 3 5 7").advance(button().record({ cycles: 2 })).scale("C minor").sub(7).synth("Wavetable").postgain(0.4)
Size
Drag a widget's lower right corner to resize it, in either direction. The size is written into the
call when you let go: { width, height }, as in scope({ width: 480, height: 60 }).
A knob, a pad, imager() and chroma() stay square and take one
{ size }.
| Widget | width and height are |
|---|---|
steps · matrix · shiftreg | one cell's; { size } sets both |
sliders | one bar's; { size } sets the height |
slider · toggle · button | the control's; { size } sets the width |
knob · xy · .imager · .chroma | { size }: the side |
| the other displays | the display's; { height } alone keeps the usual width |
drums: s(matrix({ bd: "x . . . x . . .", hh: "x x x x x x x x" }, { width: 22, height: 14 })).postgain(0.4)
keys: n("0 4 7 4").scale("C minor").synth("Wavetable").gain(slider(0.7, { width: 160 }))
.postgain(0.4).scope({ width: 480, height: 60 })
Displays on a track
Called on a track, a display draws under its line. It is the same pattern going in and coming out, so it can go anywhere in the chain.
| Call | |
|---|---|
.scope() | the waveform |
.spectrum() | the frequencies, with their level in dB |
.waveform() | the level over the last cycles, a line per beat |
.meter() | the level now, beside the call; taller than wide it stands up, with dB marks |
.imager() | the stereo image: mono straight up, the sides left and right, the correlation below |
.punchcard() | the pattern's events as they will play, a row per value |
.chroma() | the notes sounding, on a circle of pitch classes |
.plot() | a signal's value over time |
chords: note("<[c3,e3,g3] [a2,c3,e3]>").synth("Wavetable").postgain(0.3).punchcard().chroma()
bass: note("c2 ~ c2 g1").synth("Wavetable").postgain(0.4).scope().spectrum()
hats: s("hh*8").postgain(0.3).meter({ width: 12, height: 60 })
The options each display takes: { cycles } for how many cycles .waveform(),
.punchcard() and .plot() show; { min, max } for the range of
.plot() and the dB range of .spectrum(); { scale, window }
for .scope()'s gain and its length in milliseconds.
A display of sound reads a tap on the track's output, and only a few tracks are tapped at once. A display past that number draws nothing and says so when you point at it.
Behind the code
Written on a line of its own, a display is drawn behind the code, filling the editor and staying put
as the code scrolls. punchcard() and chroma() show every track;
scope(), spectrum(), waveform(), meter() and
imager() show the whole song's output. Several share the editor in bands, top to bottom
in the order they are written. Delete the line and evaluate to take one away.
setbpm(124)
punchcard()
spectrum()
kick: s("bd*4").postgain(0.4)
hats: s("hh*8").postgain(0.2)
snare: s("~ sd ~ sd").postgain(0.3)
keys: n("<0 3> 5 7 <10 12>").scale("C minor").synth("Wavetable").postgain(0.3)
In DJ mode each deck draws its own, from its own code.
Track colors
.color() sets the color a track is drawn in everywhere: the arrangement, the mixer,
the displays. It takes a CSS color name or a hex color and changes nothing about the sound. A track
without one takes a color from the theme, picked by its name; tracks in a group take shades of the
group's color.
Click the swatch before the word color, or double-click the word, to open the color
picker. Its palette tab suggests colors that go with the rest of the song.
punchcard()
kick: s("bd*4").color('tomato').postgain(0.4)
hats: s("hh*8").color('#63b4ff').postgain(0.2)
keys: n("0 2 4 7").scale("C minor").synth("Wavetable").color('gold').postgain(0.3).scope()
bass: note("c2 ~ c2 eb2").synth("Wavetable").color().postgain(0.3)