A patch is a graph, and the node editor is how it is built (0004 ). This is a second way to say the same thing in text, so that a patch can be written in an editor, reviewed in a diff, and generated by a program.
It is a pipeline language: a signal is written left to right through |>,
and nesting is wiring. It parses to a Patch and nothing else — there is no
second engine behind it, no interpreter, and no runtime of its own.
buildis exact. Text in, patch out, deterministic.printis lossy. A patch prints back as text for reading and diffing, not for byte-identity. What it loses is listed at the end.
Source files are .fbks, beside the .fbk document they build into and the
.fbkb bundle that packs one up.
1. Hello
// Three drifting sine fields summed and read through a cosine palette. let across = x |> sine(freq: 0.8, phase: t * 0.11) let down = y |> sine(freq: 0.9, phase: t * -0.07) let round = rings(freq: 1.1, offset: t * -0.13) let field = across + down + round + t * 0.15 let r = field |> sine(freq: 0.2, phase: 0, amp: 0.42, bias: 0.5) let g = field |> sine(freq: 0.2, phase: 0.1, amp: 0.42, bias: 0.5) let b = field |> sine(freq: 0.2, phase: 0.2, amp: 0.42, bias: 0.5) rgb(r: r, g: g, b: b) |> out.color
That is the Plasma preset: fourteen modules and nineteen wires, and every line of
it is a decision. _ is where the pipe lands when the module has no in for it.
2. Statements
Fifteen forms, and no others.
// a comment, to end of line
let NAME = pipeline // bind a signal, and name the node
let (A, B) = call // take a def's several results apart
def NAME(a, b = 1) = body // a subgraph with holes in it
pipeline |> out.color // a terminated pipeline: the only side effect
NAME.port = 0.6 // set a knob
NAME.port <- pipeline // back-wire, which is how a cycle is closed
off NAME // switch a module off, so it is a wire
panel NAME = 0.5, cc: 21, … // a knob on the patch's panel
requires flyback.picture, … // the plugins the patch cannot be built without
group "Name" { statements } // draw these together on the canvas
description "What it is for" // say what the patch is for, once
author "Who made it" // say who made the patch, once
tags "drone" "slow" // words to find the patch by, once
length 2:30.50 // how long the patch plays for, onceA comment starts with //; # is refused as hash-comment, since in a
language of notes it is a sharp, and a part of a patch that wants a heading
wants a group.
Statements are newline-separated. A pipeline may be broken across lines freely;
a line ending in |> or ,, or a line beginning with |>, a string, a {
or a ., continues the one before it, so a group’s brace may stand on a line of
its own. Whatever a statement leaves unread on its line is a complaint, never
something skipped.
A mistake is said as what it is: 1e3 and 220Hz are not numbers, a curly
quote or a long minus pasted from a document is named as one and read as the
plain character, -> or | is not a pipe, a ) with nothing open closes
nothing, and an unclosed bracket says where it was opened. Text nested more than
128 deep, or a step block longer than a sequence holds, is refused rather than
read.
A text with any mistake in it is refused whole, and a statement refused is one complaint however often what it would have bound is read after it.
Every complaint has a line, a column and a stable code, one of IssueCode —
pipe-lands-nowhere, bound-twice, unknown-module and the rest.
flyback-cli check --json writes all three. A misspelling is said and not
guessed at: a nearest name offered as a repair is as often the wrong one.
3. The pipe rule
This is the whole language in one paragraph (0144 ).
socket: _takes the source’s first output, wherever it is written;- otherwise an
intakes it, wherever in the list it sits, and so does a module’s only socket;- otherwise a position — the module’s own first two sockets,
xandy, with neither named in the call — takes the first two;- otherwise a color takes the module’s one color socket, where the source declares a color and the module has exactly one;
- otherwise the pipe is refused, and the complaint says to write
_.
Nothing is inferred from a socket the text did not name. The same call means the same wiring whatever arguments sit beside it.
_ is the general case. Most modules have no in, and a pipe into one says
where it goes:
beat.gate |> adsr(gate: _, decay: 240ms)
steps |> note(note: _)
rings(freq: 3) |> hsv(hue: _, saturation: 0.85)_ goes in a named argument, once per call. With nothing piped in, or written
anywhere but a call’s argument, it is an error. In a def’s call it stands for
the parameter it is written in place of, and without it what is piped in is the
first parameter.
A pipeline is a statement, never an argument. A pipeline inside an argument
is an error, and what it meant is a let above and a name in the call:
let pitch = steps |> note(note: _)
saw(freq: pitch)That keeps every statement one chain, and every edit a one-line edit.
Rule 2 is load-bearing. Three modules in the catalog do not put their signal input first:
| Module | Ports |
|---|---|
math.smoothstep |
edge0, edge1, in |
math.step |
edge, in |
math.remap |
in, in low, in high, out low, out high |
It is why bands |> smoothstep(0.15, 0.85) puts bands on in and the two
numbers on the edges. Guessing “the first socket left” instead would wire
bands into edge0, read perfectly, and mean something else — the worst kind
of mistake, and the reason there is no such guess.
Rule 3 is what makes geometry chain, and it is the only place more than one signal moves at once:
rotate(angle: t * 0.15) // outputs (x, y)
|> kaleidoscope(segments: 6) // inputs (x, y, segments) — the pair fills both
|> clouds(z: t * 0.3, scale: 2.5)A position is what the engine itself calls one — the x and y that
0050
normals to
Coordinates together — so it is a fact about the catalog rather than a list
kept here. Names need not agree across the join: To polar hands back
(radius, angle) and Checker takes (x, y), and the Grid preset joins them,
because what matches is that both are a position.
A single signal piped into a module with a position and no in is refused, since
there is no pair to hand on: wave |> checker(x: _) says which half it is.
Everything but a position is one signal. Forwarding every output a source
has would put a sequencer’s gate into Note’s octave and its index into the
cents, which compiles, plays, and is not a tune. So a Note Sequencer’s three
outputs and a MIDI In’s four go one at a time, and the others are taken by name.
No coercion happens here: widening a scalar to a color is the compiler’s job (0007 ), not the parser’s.
Outputs other than the first
A binding is its module’s first output. Any other is taken by name:
let riff = notes(rate: 4) [ A3 C4 E4 G4 ]
riff // the 'out' output — the note number
riff.gate // the gate
riff.index // where in the pattern it has got toA let binds the node rather than one of its outputs, so a binding piped into a
position carries its pair on — plane |> checker(size: 3) is both of To polar’s
outputs — and anywhere else is its first output alone.
A call takes the same selector, so a module read once needs no name to be read by:
let beats = tempo(bpm: 104).beats // the count of beats, not the rate
beats |> notes(rate: 2) [ A2 E3 ].gate // the sequencer's gate, with the beats arriving
|> adsr(gate: _)Here the let binds the one output that was chosen, which is all the name can
then stand for: beats.bpm = 90 has no module to turn a knob on. A selector
binds tighter than the pipe, so after a stage it chooses among the stage’s
outputs. It follows a bracketed pipeline as well — (a |> b()).gate — and a
def that hands back a module.
The pipe into an oscillator is its domain
An oscillator has an in, so a pipe lands there — which is right for
x |> sine(freq: 1.5), and wrong for a pitch. A pitch is the freq socket and
has to say so:
let pitch = steps |> note(note: _)
sine(freq: pitch) // a tune
x |> sine(freq: 1.5) // a fieldThis is the same distinction the assistant handbook spends five paragraphs on,
and the language cannot paper over it: what is on in decides what the module
does.
4. Naming
A module’s short name is the last dotted segment of its type id.
osc.sine becomes sine, space.kaleidoscope becomes kaleidoscope,
flyback.picture.circle becomes circle.
The type id and not the label, deliberately.
0020
guarantees a type
id is stable, and says in as many words that a module may be “renamed in the UI
(Name is separate from TypeId)” without touching saved patches. A language
keyed to the label would break every text patch the next time somebody improved
a caption. Keyed to the type id, it inherits the guarantee the file format
already has.
It also means the catalog is the language: a plugin’s modules are usable the moment it loads, and there is no alias table to keep in step.
Ambiguity is an error, resolved by writing the type id in full. Across the built-in
modules there is one collision, mix (math.mix, color.mix). A plugin’s module never
takes a built-in’s short name, so a text reads the same whichever plugins are loaded:
hsv is color.hsv even with the Picture plugin installed, whose own is
flyback.picture.hsv in full.
One more is legal but ugly: midi.in shortens to in, which reads badly beside
the port of that name. Write midi.in in full.
A patch says which plugins it needs, on a line of its own:
requires flyback.picture, flyback.effects. It is read before anything else,
so a build without one of them says so once, by name, instead of once for every
module the plugin would have given. It is optional to write, and a printing
always writes it for a patch that uses a plugin’s modules.
Port names map the same way, with spaces becoming underscores and matching
case-insensitively: in low becomes in_low and gate length becomes
gate_length. Arguments may be positional or named; positional arguments fill
unnamed inputs left to right, after the pipe has taken its own.
A name is bound once. A second let of the same name is an error naming
the line of the first, including one inside a group, since a group’s names are
visible after it. t, x, y, radius, angle, aspect and out are
already bound in every patch, so a let or a def parameter by one of those
names is an error too. A word therefore means the same thing on every line
that reads it.
A socket takes one wire. Wiring a socket that the text already wired, by a
second |> out.color or a second <-, is an error naming the line of the
first. It is not quietly replaced.
A knob is set once. A second number for the same knob, in a call or as
name.port = …, is an error naming the line of the first.
5. Sugar
Everything above falls out of the catalog. This is the short list that does not.
| Written | Means |
|---|---|
x, y, radius, angle, aspect |
the five outputs of coord |
t |
the output of time |
t.length, t.progress |
its other two: how long the patch plays for, and t divided by it |
a + b, a - b, a * b, a / b, a % b, -a |
one math.expression for the whole sum |
A3, C#4, Bb2 |
a note number, on any PortDisplay.Note port |
20ms, 1.5s, 4us |
log₁₀ seconds, on any PortDisplay.Duration port |
-2..2 |
two positional arguments: a low and a high |
out |
the one output node, which every patch has |
x, y, radius, angle, aspect and t each name one shared node per patch, not
a fresh one per mention. A patch that reads the clock in eight places has one
Time in it, which is what the presets do by hand and what a normalled socket
already does invisibly.
Precedence, loosest first: |>, then + -, then * / %, then .., then
unary -, then a call and a .port selector. The range sits below the minus
deliberately — -2..2 is a range from minus two, and the other way round parses,
compiles and means something else. So t * 0.2 |> sine() groups as
(t * 0.2) |> sine(), which is what it looks like.
A call to one of the Maths modules an Expression stands for — mul(...),
fract(...), floor(...) and the rest of the one- and two-input ones
(0109
) — builds an
Expression too, and joins the sum it sits in: fract(t * 60) * 2 - 1 is one
Expression, fract(a * 60) * 2 - 1.
A sum is one Expression, however much of it there is
(0106
).
(fract(t * 60) * 2 - 1) * aspect is an Expression reading t, a Fraction, and
an Expression reading the Fraction and aspect whose formula is
(a * 2 - 1) * b. The numbers are written into the formula and the signals are
its sockets, each once however often it is read. A call such as fract(...) is
still the module it names. A sum reading more than the four signals an
Expression has sockets for gives its busier side an Expression of its own. It is
the same program the Maths modules it replaces would have been, op for op.
A printing writes an Expression back as its sum
(0107
) wherever that
reads back as the same module. What is wired into it and cannot stand in a sum
written out — a pipeline, another sum, a module the sum reads twice — is given
a let and named there, so the sum stays a sum. A function the formula calls
is written as the call, floor(x * 8) / 8, with every argument, and a socket
that follows a panel knob as the knob, t * rate(0..2). Otherwise it writes
the call, x |> expression(a: _, formula: "clamp(a * 8, 0, 1)"). That happens
when the formula calls a Maths module of three sockets or more, which stays a
module of its own; calls one function twice; is longer than a fused formula may
run; is switched off; or reads a socket that rests on its knob.
Duration literals
A PortDisplay.Duration port holds log10 seconds. This is the sharpest
edge in the whole instrument, and the presets carry hand-written comments to
survive it — // so -2.4 is about four milliseconds, // so this is 10^-1.7.
Here those knobs are written as what they are:
adsr(attack: 4ms, decay: 200ms, sustain: 0, release: 32ms)Writing 20ms on a port that is not a Duration is an error rather than a silent
-1.699. The literal is driven by PortSpec.Display, so it works on a plugin’s
ports without the plugin declaring anything.
x and y are usually unnecessary
0050 normals every Space, Pattern and Feedback position socket to Coordinates, and every domain socket to Time. So a chain can begin with no input at all, and an oscillator placed and left alone is already oscillating.
6. out
There is exactly one output node, it is always present, and it can be neither
added nor removed (0037
).
So out is a keyword rather than something a patch declares:
someColor |> out.color
someSignal |> out.left
out.volume = 0.6out.right is normalled to out.left, so a mono patch is stereo without saying
so. A patch that never mentions out is legal, and renders black.
The Output does nothing to make the picture heard. A Scan does that, for the
branch it reads
(0077
). At radius: 0
it reads a single point, so x and y can trace any path, including a TV-style
raster that crosses the whole frame line by line:
let across = (fract(t * 60) * 2 - 1) * aspect
let down = 1 - fract(t * 0.5) * 2
scan(someField, radius: 0, x: across, y: down) |> out.left7. off
A module can be switched off, and one that is off is a wire (0117 ):
let wash = grain |> vignette(color: _, dark: 0.6)
off washThe statement takes one name and no port — a socket cannot be switched off, only the module it is on. It reads the same way the canvas’s Ctrl+B does: whatever is patched into the module comes out of it unchanged, and where nothing is patched in, nothing comes out and the socket at the far end rests on its own knob, exactly as it would with the wire pulled out. So an effect in a chain passes its signal on and a voice with nothing feeding it falls silent, which is one rule and not two.
The socket handed on is the one called in, failing that the one the output
is named after, failing that the first. Only a wire is handed on, never a normal — off on an oscillator is
silence and not the clock.
out cannot be switched off. Write out.volume = 0.
A printing writes off for every module that is off, and gives each one a
binding to be said by, including the x and t of section 5.
8. What a module carries that is not a knob
A sequencer’s notes, a Quantiser’s scale, an Arrangement’s parts, a Sample’s or a MIDI File’s file (0061 ) go in a trailing block:
let riff = notes(rate: 4, gate_length: 0.5) [ A3 C4 [E4 G4] ~ ]
let snap = quantiser() [ C D E G A ]
let song = arrangement(rate: 1/32) [ 1 1 0 1 | 0 >1 1 0 ]
let clip = sample("kick.wav")
let photo = picture("sunset.png")
let tune = midi.file("riff.mid", voice: 2, channel: 1)How the computer keyboard is laid out belongs to the patch rather than to any module, so it is a line of its own, once, and a printing puts it first (0099 ):
keyboard scale [ D E F G A B C ]The brackets hold the notes of one of an Auto Chord’s scales, the first of them
its tonic. The scale runs up from the tonic along the A row, with the Q row
an octave up and the Z row an octave down. keyboard piano is the tracker layout, and
what a patch that says nothing gets.
What the patch is for belongs to it the same way. It is one line of prose, the one the preset gallery shows under a patch’s name and the panel shows with nothing selected, and a printing puts it first. Too long for the page, it runs on as further strings, each joined to the last by a space:
description "A photograph put through the same geometry a generated field goes through,"
"once you choose one."A string has no escapes, so a description never holds a straight double quote; one typed into the panel is turned into a curly one.
Who made the patch and the words to find it by go under the description, a line each:
author "Ada"
tags "drone" "slow-build"An author is held to one line the way a description is. A tag is lower case, with a hyphen for a space and no quote, and a patch keeps its first eight different ones.
How long the patch plays for goes under those, in minutes and seconds to the hundredth, the way the status bar tells the time. The seek bar spans it, and the patch stops at its end unless the seek bar loops:
length 2:30.50Plain seconds (length 95.5) and a duration (length 90s) read too, from a tenth
of a second to a day; anything else is bad-length. A patch that says nothing
plays for three minutes in the editor, or on until paused where its Endless
setting is on and in the viewer, and a printing says nothing for it.
A block goes after the brackets and there is at most one, so it needs no name. A file goes inside them and has no name either — a call carries at most one string without one, and that string is the file. Both are positional because there is only ever one of each to say.
A plugin’s own fields
Anything else a module carries is a field a plugin declares (0055 ), and those are named arguments like any knob:
let land = fractal(octaves: "6")
let keys = midi.in(device: "Launchkey 49", voice: 2)
let kick = midi.in(device: "Syntakt", channel: 1)
let pad = midi.in(voices: 4)
let box = midi.clock(device: "Syntakt")
let px = expression(x, formula: "(floor(a * 45) + 0.5) / 45")
let card = text(lines: "Hello|World", font: "tiny", line: beats)Four shapes and four spellings. A number is written on whatever scale the
field reads on, so a note-scaled one is its note and a time-scaled one is its
time — exactly as a knob is. A switch is 1 or 0. A choice is a
string, because what is stored is an id and an id is not a number, and so is
text, which is what was typed — an Expression’s formula is the one the
engine ships. A string is one line with no escapes, so in text that takes
several lines, like Text’s, a | is a line break. Such text holding a | of
its own has no spelling, and is left out of a printing the way a string holding
a quote is.
The formula is not this language, though it reads like its arithmetic: it is
read where the Expression is compiled, over the sockets a to d rather than
over names, so x and t mean nothing inside it and are wired in instead.
A field is addressed by its key, which is what a saved patch files it under,
and its label is accepted too because that is the word the inspector shows. Only
the key is ever written back: a label is free to be reworded and a .fbks
written today has to go on meaning the same thing after it is.
A socket is looked for first, so a module whose field and socket share a name gives the socket. That is a module worth renaming rather than a rule worth inventing.
Step notation
The step block borrows TidalCycles’ mini-notation, because it is the best
worked answer to this exact problem and because it maps onto
Step(Value, Length, Volume) almost exactly.
| Notation | Means | Expands to | Costs |
|---|---|---|---|
A3 C4 E4 |
three steps | three steps of length 1 | — |
~ |
a rest | Volume = 0 |
— |
A3%0.6 |
velocity | Volume = 0.6 |
— |
A3!3 |
repeat | three identical steps | 3 steps |
A3(3,8) |
Euclidean | eight steps, three sounding | 8 steps |
<A3 C4> |
alternate on each pass | the list doubled, at half rate |
twice the steps |
[A3 C4] |
subdivide one step | two steps of length 0.5 | leaves the fast path |
A3@3 |
elongate | one step of Length = 3 |
leaves the fast path |
Every one of these is expanded by the parser into a flat list of steps. No
module is added, no opcode is invented, and the engine is not touched — which is
the only reason it is worth having. A values block takes plain numbers where a
notes block takes note names, because the two sequencers differ only in how a
step’s value reads.
Two costs, and the notation must not hide either.
- A sequencer costs ops in proportion to its step count. Each step emits a
threshold and a pair of multiplies.
<A3 C4>over a four-step bar is an eight-step sequencer and twice the ops. Tidal’s alternation is free because it schedules events; here it is unrolled. - Uneven lengths leave the fast path.
EmitSequencetakes a much cheaper route when every step is the same length — one division, oneFract, oneFloor. Only two forms break that, and it is worth knowing which:@nand[a b]put the whole module onto the positional path, while!n,<a b>and the Euclidean form all keep every step the same length and stay on the fast one. So the notation that costs nothing but steps is separable from the notation that changes how the module compiles.
Whatever gets through is clamped by Step.Sane(), so the parser can be
permissive and let the engine’s own tolerance do the work.
A name goes into a block with $. notes() [ $root C3 ~ ] writes what
root stands for into the block before it is read: a number or a note as
itself, and a list as its items one step after another, so [ $riff ~ ] is the
riff and a rest. What follows a name applies to what it wrote last: $root!3
repeats the root, and $riff!2 repeats only the riff’s last note. It is how a
loop or a def varies a pattern:
for root in [A2, F2, C3] {
notes(rate: 4) [ $root ~ $root C4 ] |> note(note: _) |> saw(freq: _)
}A signal, a text or a duration is refused. A block that reads a name is not rewritten when its steps are edited on the canvas, since that would replace the name with what it stood for.
~ and %0 are not the same step. A ~ is a rest: no note and no volume.
E5%0 is that note, silenced. They sound alike and compile differently — the
second keeps the pitch in the program, which is what a phrase does when it holds
a note through a gap rather than stopping. Whole band’s lead uses the second,
and writing ~ there is a patch that plays the same and is not the same patch.
Arrangement notation
An Arrangement’s block is a row of levels for each part, one a section, with |
between the parts. A level is a number, with > before one that glides there
from the section before’s level across the whole section:
let song = arrangement(in: beats, rate: 1/32) [
1 1 1 1 0 0 1 1 |
0 0.8 0.8 0.8 0 0 0.8 0.8 |
0 0 >1 1 0.5 >1 1 0 ]Part N comes out of song.part_N, the first of them out of song itself. Only
| ends a part, so a long one may run over several lines, and a printing breaks a
block too long for one line at each |. A part shorter than the longest holds at
nought to the end. Up to 8 parts of up to 32 sections; more is too-many-parts,
and anything that is not a level is level-syntax.
For a longer piece, chain Arrangements. next is in with the Arrangement’s
length taken off, so piped into a second one’s in it starts that one where the
first ends; until then the second hands on whatever is wired into its parts:
let verse = arrangement(in: beats, rate: 1/32, loop: 0) [ 1 1 0 1 | 0 1 1 1 ]
let chorus = verse.next |> arrangement(rate: 1/32, part_1: verse, part_2: verse.part_2) [
1 >0.5 1 1 |
1 1 1 0 ]Use chorus’s parts from then on. Each section comes from the one before, and
the second’s first section from the first’s last. loop: 0 keeps the first on its
last section once it ends, so its section and progress stop there rather than
starting over; leave it on the last of a chain to bring the piece round to that
one’s first section.
Song notation
A patch has at most one Song, the sequence of sections the editor shows in its Sequence pane under the canvas. Its parts are named, and each loops over as many sections as it has, so parts of different lengths come round at different times. Its block is a line for each part, the name and a colon first:
let song = beat.beats |> song(rate: 1/16, fade: 0.05) [
kick: 1 1 1 1 0 1 1 1 1 1 1 1 0 0 1 1
bass: 0 0 1 1 1 0.8 0 1 1 1 1 0
pad: >1 1 1 0.5
]A part is read by its name, song.kick; song.section counts the longest part’s
sections from 1, song.progress runs 0 to 1 through each, and song.played counts
the sections played without coming round. The next name starts the next part, so
a long one may run over lines, and a printing carries a part on every 16 sections.
A name is a letter or _ and then letters, digits and _, one no other part has
and none of the Song’s own outputs; anything else, or a level before any name, is
part-name. Up to 8 parts of up to 256 sections, or too-many-parts; a second
song() in a patch is one-song.
9. The panel
A patch’s knob panel is written as the knobs it has, a line each, and a socket follows one by naming it where a number would go:
panel cutoff = 0.4, label: "Filter cutoff", cc: 21, channel: 2, device: "midi:elektron-syntakt" panel level = 0.8 saw(freq: 110) |> filter(cutoff: cutoff(200..4000), resonance: 0.3) |> out.left out.volume = level
The number is where the knob rests, from 0 to 1. It means nothing on its own
scale: each socket that follows it reads it over a range, the socket’s own
unless the text gives one, as cutoff(200..4000) does, and swept in decades
from a knee where the socket is or where knee: says. A range is written the
way the socket reads a number, so a length of time is snap(20ms..400ms). The
Output’s knobs are never in a call, so they follow one by a statement,
out.volume = level.
label is what the panel shows, where that is not the knob’s own name. cc,
channel and device are the MIDI controller it follows; without channel
it hears the controller on any channel. held, a bare word, keeps the knob
where it is when the panel is randomized: panel level = 0.8, held.
A panel holds at most 32 knobs, switches and buttons together; a panel line
past that is too-many-controls.
switch or button, a bare word, plays the knob as one, resting at 0 for off
or 1 for on. A switch flips at each press and stays; a button is on only while
held. Either takes note: in place of cc: for a pad or a key, and a switch on
a controller button that holds itself down, sending on and off at alternate
presses, says latching. A socket follows one as it does a knob, reading the
bottom of its range when off and the top when on:
panel drop = 0, switch, cc: 64, device: "midi:launchkey-49"
panel hit = 0, button, note: 36, channel: 10, device: "midi:launchkey-49"A knob is a name like a let: bound once, never one of the words every patch
already has, and never a module’s name, since cutoff(200..4000) is written
like a call. It is not a signal, so it is never piped, and a socket that follows
one takes no number as well. A sum may read one, sine(freq: 3) * level or
t * rate(0..2): each mention is a socket of the sum’s Expression following the
knob, over the range written or the socket’s own. Neither a def nor a group
declares one, since a knob belongs to the whole patch; it is declared outside
and passed in or read.
10. def — a subgraph with holes in it
def voice(note, bands, hue, rate, phase) =
...
voice(A2, 1, 0.00, 0.06, 0.00)
voice(E3, 2, 0.33, 0.09, 0.30)Pure macro expansion, resolved before a single node exists. Each call site stamps out its own copy; there is no runtime dispatch, no new opcode, and the compiled program is identical to the same patch written longhand. A def that calls itself is refused, since it is stamped out rather than run.
A def shares nothing between its call sites. Each call stamps out its own
copy of every module in the body, so two calls to a def containing a sine
are two oscillators and not one. (The t, x and y of section 5 are the
exception, being one shared node per patch wherever they are written.) A value that should be shared is a let outside the
def, passed in as an argument — which is the same distinction the graph itself
makes between a module and a wire from one.
Each call is drawn as a box. The modules a call stamps out are a shut group,
named after the let that binds the call’s result, let bass = voice(A2), and
otherwise after the def. Only the outermost call is boxed: a def called inside
another def’s body is in its caller’s box, and one called inside a group block
is in the block’s. What the caller passes in, and the clock and coordinates,
stay outside. A call that places a single module draws no box and says
nothing; a group block round it draws one.
The body is a block. Its result is the final expression, which may be a tuple,
and let (a, b) = f(...) takes one apart. A single-expression body needs no
braces.
A def may be written inside another def’s body, a loop’s or a group’s. It is in sight in that block and every block inside it, and nowhere else, and it takes no name a def in sight already has. It reads what its block sees: the outer def’s parameters, the loop’s names for the pass, the lets above it. A def at the top of the patch reads only its parameters and the defs, so what it needs is passed in.
Arguments
A call gives a def its arguments the way it gives a module its sockets:
def voice(note, hue = 0, rate = 0.06) = ...
voice(A2)
voice(E3, rate: 0.09)
voice(hue: 0.33, note: C4)Named arguments claim their parameters first, then the pipe lands, then the arguments without a name fill what is left, in order. A parameter nothing gave takes its default, and one with no default is refused by name.
The pipe lands on in where the def has a parameter called that, as on a
module, and otherwise on the first parameter no argument names. _ puts it
anywhere else: pitch |> tone(0.5, _). A pipe into a def whose in is already
given is refused, not moved along.
A default is a value, not a signal: a number, a note, a duration, a text, or arithmetic on those. A default that placed a module would place one unseen at every call that left it out, so a signal is passed in. A note or a duration is checked where the parameter is read, as if it were written there. Parameters with a default come after every one without.
This is worth having because a NodeGroup deliberately is not a reusable
definition — 0054
says so, and gives the reason: a Connection names ports by index, so a group
cannot be instantiated twice. A macro sidesteps that entirely by expanding
before any connection is built. The two are complementary: a group is a box
drawn round nodes that exist, a def is a stencil for nodes that do not yet.
The Four voices preset is a for loop over four voices in C#. It is a def and
four calls here, or one call in a loop, below.
Loops
for stamps its body out once per item of a list, as the text is built, and is
worth the list of what each pass ends with
(0208
). Nothing
loops when the patch plays: the patch is the modules the passes placed, the
same as the copies written out.
let voices = for (pitch, level) in [(A2, 0.5), (E3, 0.3), (A3, 0.2)] {
sine(freq: note(pitch), amp: level)
}
sum(voices) |> out.left- A list is
[a, b, c]where a value goes: numbers, notes, texts, signals, or bracketed tuples like(A2, 0.5). Items are separated by commas and may run over several lines. A[straight after a call’s)is still that module’s block. for name in list { ... }binds each item to the name in turn;for (a, b) in listtakes each item’s tuple apart. A loop may count instead:for k in 1..4is 1, 2, 3 and 4, both ends in.- The body is a def’s: statements, then what a pass is worth, which may be a tuple. Names bound inside a pass are that pass’s alone, and the names outside are in sight. A body with nothing at the end only places modules.
let (a, b) = for ...takes a loop of tuples apart into a list per part:let (tones, levels) = for v in voices { (tone(v), level(v)) }, thensum(tones). A written list of tuples comes apart the same way....listspreads a list over a call’s free sockets in order, each tuple’s parts a socket apiece:mixer(...for v in voices { (v, 0.5) })fillsin_1,level_1,in_2,level_2and on.sum(list), orlist |> sum(), adds the items up exactly asa + b + cwould.sumis only this word where nothing else in the patch is calledsum.- A text bound to a name names a file as the literal does, so
for file in ["kick.wav", "snare.wav"] { sample(file) }plays both.
A panel knob and the lines about the whole patch (requires, keyboard,
description, author, tags, length) are written outside a loop. A def
written in a loop’s body is that body’s. A group in it draws a box a pass, and a
named one is numbered for its pass: group "Voice" is “Voice 1”, “Voice 2” and
on, and “Voice 2.3” in a loop inside a loop. One patch’s loops stamp out at most 4096 passes between them. A printing
writes a loop out unrolled.
Positions
xs[i] reads one item of a list, or one part of a tuple, counted from one as a
loop’s passes are; len(xs) counts the items. Both are worked out as the text
is built, so together they let a loop walk a table:
let chords = [(A2, C3, E3), (F2, A2, C3), (C3, E3, G3)]
let voices = for i in 1..len(chords) {
let (root, third, fifth) = chords[i]
let level = 0.3 / i
sine(freq: note(root), amp: level) + sine(freq: note(third), amp: level)
+ sine(freq: note(fifth), amp: level)
}
sum(voices) |> out.left- The bracket touches what it reads:
chords[i],[110, 220][2], androws[1][2]for a list of lists. A bracket after a space is a module’s block, as it always was. - The position is a whole number the text writes down, or arithmetic on one. A signal, a fraction, or a position past either end is refused with the list’s length.
len(xs), orxs |> len(), is a number, and is a word of the language only where nothing else in the patch is calledlen.- A number read by position twice is a knob’s to turn as little as a number read through a name twice.
Fold
fold is a loop whose passes each take what the pass before ended with, and it
is worth only what the last pass ends with
(0236
).
It unrolls as the text is built, like for: the patch is the chain of copies,
each wired into the next.
// Each pass halves what it was handed and adds the next harmonic.
let tone = fold k in 1..4 from sine(freq: 110, amp: 0.2) with sound {
sound * 0.5 + sine(freq: 110 * k, amp: 0.2)
}
tone |> out.leftfold list from seed with name { ... }. The first pass readsseedbyname; every later pass reads bynamewhat the pass before ended with.fold 1..4 from 1 with n { n * 2 }is 16.- The items may be named as a loop’s are,
fold k in 1..4orfold (a, b) in pairs, or left unnamed where only the count matters. - A tuple is carried in brackets:
fold 1..8 from (0, 1) with (a, b) { (b, a + b) }, andlet (a, b) = fold ...takes the last apart. Every pass ends with as many things as the names wait for. - The passes count towards the 4096 a patch’s loops stamp out between them.
foldis a word only where a list follows it.fold(drive: 2)is still the Fold module, andfromandwithare words only inside a fold.
If
if builds one branch and leaves the other out, chosen as the text is built
(0234
). As with a loop,
nothing is decided while the patch plays: the patch is the modules the branch
placed.
def voice(pitch, dark = 0) = {
let tone = saw(freq: note(pitch), amp: 0.3)
if dark { tone |> filter(cutoff: 600) } else { tone }
}
let voices = for pitch in [A2, C3, E3, A3] {
if pitch < E3 { voice(pitch) } else { voice(pitch, dark: 1) }
}
sum(voices) |> out.left- The condition compares with
==,!=,<,<=,>and>=, joins withandandor, and turns round withnot. A plain number holds where it is not zero. Numbers, notes and durations compare by size; texts only with==and!=. - It reads only what the text writes down: numbers, notes, durations, texts,
and the names a
let, a def’s parameter or a loop bound them to. A signal or a panel knob changes while the patch plays, after the text is built, and is refused. To choose between signals as the patch plays, mix them:mix(a, b, step(0.5, signal)). elseis optional and may start the next line;else ifchains. Each branch is a block like a loop’s body: statements, then what it is worth. Anifwith no branch taken is worth an empty list and places nothing.- Names bound in a branch stay in it. A panel knob and the lines about the
whole patch are written outside an
if, as outside a loop. - A comparison means something only in a condition.
let big = k > 2is refused. - A number a condition reads is not a knob’s to turn. Turning a knob on the canvas never rewrites it, as for any number read through a name twice, so a knob never changes which modules exist.
A printing writes out the branch that was taken.
11. Groups
A group is a box drawn round nodes on the canvas. The compiler is never told about it, so it is presentation — but the largest preset in the box uses ten of them as its primary organizing device, and a text form that dropped them would be unreadable at that size.
group "Bass" {
let tuned = riff |> note(note: _)
let body = saw(freq: tuned, amp: 0.8)
}Members are the nodes declared inside the block. A group built from text is
shut, and the sockets on its edge are the ones its wires cross. A group with no
name is group { … }. A panel knob or a requires line inside a group is
refused. A def written in a group is in sight only inside it, though its names
stay in sight after it.
A group may hold another group. Only the outermost draws a box, and the inner
group’s modules are in it; a printing writes them in the outer block. A group may
hold a single module (ADR-0221); one that places none is left out with a warning.
The clock and the
coordinates t and x reach for belong to the whole patch and are in no group,
however early a block reads them; a group that holds its own is written
let time = time() inside it.
A group may be opened more than once. Blocks with the same name are one group, which is how a printing says a group whose modules cannot all be written together:
group "Bass" {
let root = beat.beats |> values(rate: 0.25) [ 0 -2 -4 -5 ]
}
group "Lead" {
let lead = root |> tune(transpose: 12) [ C D E G A ]
}
group "Bass" {
let answer = lead |> slew(time: 80ms)
}12. Cycles
A pipeline cannot express a loop, so the back-wire does:
// An integrator: each evaluation adds a little of the source to what it held. let sum = square(freq: 110) * 0.06 |> add(a: _) sum.b <- sum * 0.94 sum |> out.left
Any wire may run backwards, and the one that closes a loop is the one that does (0075 ). The parser has no cycle theory of its own — it emits the wires, and which of them carries the evaluation before is settled once, for the canvas and the compiler alike.
A cycle means one evaluation of delay at either sink: the sample before to the
ear, and to the eye the frame before, taken from the pixel being drawn and no
other (0074
). To read
elsewhere in the previous frame — the camera-pointed-at-its-own-monitor tunnel
— use the feedback module, which is not a cycle at all and needs no back-wire.
13. If you know TidalCycles
The step notation is borrowed, so expectations will arrive with it. Four differences, in the order they will bite.
- Time is seconds, not cycles. There is no
cps. 0048 is emphatic about it: a patch that wants a different rate multipliest, visibly, and a tempo is atempomodule wired into a sequencer’sratelike any other signal. - Alternation is unrolled, not scheduled.
<a b>doubles the step list, and it costs ops. - There is no
every,jux,offorsometimesBy. Those transform a pattern with a function, and nothing on a wire here can carry a pattern — a wire carries one or three floats.defcovers the cases that really are “this subgraph again, varied”; the rest have no expression.everycould be made to compile both variants and crossfade, which doubles the program to buy one combinator, and is not worth it. - There is no randomness in the notation. No
?, nodegradeBy. The engine haspattern.clouds, so a wandering gate is a wire rather than a character.
And one difference the other way. One graph drives the picture and the
sound. Tidal’s visual counterpart is Hydra, and they are two systems bridged
over a socket; here let lfo = sine(freq: 0.1) sets a hue and a tremolo depth
from the same node, and the two sinks compile separately out of that one graph,
each paying only for what it reaches
(0022
).
14. What print loses
| Survives | Lost |
|---|---|
| modules, wires, knob values | node ids, which are regenerated |
| what a module carries — notes, scales, file paths | canvas positions, re-laid by PatchLayout.Arrange |
| a plugin’s declared fields, as named arguments | whether a group is open, and a socket on its edge with no wire |
let names, as the node’s own label |
comments, formatting, and every def, expanded, each call’s box a group block |
| plugin requirements, recomputed on write | — |
| which modules are switched off | — |
| the panel’s knobs, what each follows, and every socket following one | — |
which plugins the patch needs, as its requires line |
— |
| groups, their names and what is in each | a group inside another, folded into the outermost |
| the patch’s length, in minutes and seconds | — |
A knob or a field still holding what a fresh module holds is written nowhere. A printing is for reading, and every module restating its whole shape would bury what somebody actually changed.
What it does guarantee is that the text means the same instrument: print a
patch, build it again, and the two compile to the same program, opcode for
opcode and register for register. Every preset in the box is a test of exactly
that. PatchIO is what keeps a patch exactly; this keeps what it does.
Where the lines break is worked out afterwards, by a pass of its own, the
way where the modules sit is. A statement is written as one line and then
folded to fit a page: a pipeline breaks before each |>, a call with too many
arguments breaks after each comma, and a tune longer than a line is filled
across several. Every one of those is a break the lexer joins straight back up
— §2’s continuation rules are what make it safe — so a folded printing builds
to the patch the unfolded one did.
A printing writes a group as blocks. A chain stops at a box’s edge: a
module whose wire leaves its group gets a let inside the group, and whatever
reads it outside uses the name, so every statement in a block places only that
group’s modules. The bindings are ordered so a group’s come out together as far
as what they read allows, and a group that still cannot is opened again further
down. Two boxes that share a name are written apart as “Bass” and “Bass 2”. A
Coordinates or a Time in a box is written as the module it is,
let time = time(), rather than as the bare word, which would put it wherever
it is first read.
A let name becomes the node’s rename label, so a patch built from text opens
in the editor already labeled, and printing recovers the names somebody chose.
Nodes inlined into a chain stay anonymous, which is right — they had no name to
lose. A let nobody named takes the module’s short name, except for plain
arithmetic — an Expression, a Remap, a Clamp — whose type says nothing of its
job: that is named after the socket it drives, filter_cutoff, or freq where
it drives the same socket on different modules. One that drives several kinds
of socket, or feeds another sum, keeps its short name.
The printer emits a let for any module that more than one wire leaves, that
nothing leaves, whose output is read from a socket other than the first — a
Sequencer’s gate reads better off a name than off the end of the call that
wrote its tune — or that somebody named. It inlines everything else into
chains, and gives a let to anything that would otherwise be a pipeline inside
an argument. A module with no in is piped on the socket the longest chain
arrives at, written _, so the line follows the patch’s own spine and the names
and coordinates it reads go in the brackets.
Numbers are written to whatever precision reads back as the same knob, and no
further: a twelfth prints as 0.083333336 rather than 0.083333, because the
short spelling is a different float and would compile to a second constant
beside the first.
15. Grammar
patch = { statement } ;
statement = comment
| "let" ident "=" pipeline
| "let" "(" ident { "," ident } ")" "=" ( call | loop )
| "def" ident "(" [ param { "," param } ] ")" "=" body
| pipeline
| selector "=" expr
| selector "<-" pipeline
| "off" ident
| "panel" ident "=" number { "," ( ident ":" ( number | string ) | "held" | "switch" | "button" | "latching" ) }
| "keyboard" ( "piano" | "scale" "[" { pitch } "]" )
| "requires" plugin { "," plugin }
| "group" [ string ] "{" { statement } "}"
| "description" string { string }
| "author" string
| "tags" string { string }
| "length" ( number [ ":" number ] | duration ) ;
param = ident [ "=" expr ] ;
body = pipeline | "{" { statement } result "}" ;
result = pipeline | "(" pipeline { "," pipeline } ")" ;
pipeline = expr { "|>" stage } ;
stage = call outputs | selector ;
expr = term { ("+" | "-") term } ;
term = ranged { ("*" | "/" | "%") ranged } ;
ranged = factor [ ".." factor ] ;
factor = [ "-" ] primary ;
primary = literal | ( selector | list ) { position } | tuple | loop | choice
| ( call | "(" condition ")" ) outputs ;
position = "[" expr "]" ; (* touching what it follows *)
outputs = { "." ident } ;
list = "[" [ pipeline { "," pipeline } [ "," ] ] "]" ;
tuple = "(" pipeline "," pipeline { "," pipeline } ")" ;
loop = "for" ( ident | "(" ident { "," ident } ")" ) "in" pipeline
"{" { statement } [ result ] "}" ;
choice = "if" condition "{" { statement } [ result ] "}"
[ "else" ( choice | "{" { statement } [ result ] "}" ) ] ;
condition = both { "or" both } ;
both = negated { "and" negated } ;
negated = "not" negated | pipeline [ ( "==" | "!=" | "<" | "<=" | ">" | ">=" ) pipeline ] ;
call = name "(" [ arg { "," arg } ] ")" [ block ] ;
arg = [ ident ":" ] ( expr | "_" ) | "..." pipeline ;
block = "[" { step } "]" | "[" levels { "|" levels } "]" ;
levels = { [ ">" ] number } ;
selector = ident [ "." ident ] ;
name = ident { "." ident } ;
literal = number | note | duration | string ;
plugin = name | string ;
note = ("A".."G") [ "#" | "b" ] [ "-" ] digit ;
duration = number ( "us" | "ms" | "s" ) ;step is the mini-notation of section 8, where $name writes in what a name stands for, and pitch a note with no octave,
D or F#, or its number from 0 to 11. A name with dots is a type id
written in full; a selector with a dot is a binding and one of its ports.
outputs is the same choice made on a module with no name. The grammar lets
one follow another and the binder refuses the second, since one output has no
outputs of its own. The binder also refuses an argument holding a pipeline,
bracketed or not, and a _ anywhere but an argument of a stage — a named one,
where the stage is a module.
16. Every shipped preset, transliterated
This is the proof that the syntax reaches the catalog. Each of the engine’s
presets is a file in Graph/Presets/
,
and is written here as plainly as it can be said. Where the language cannot say
something the preset says, that is a hole and it is marked as one.
Empty
The Output, alone. An empty file.
Plasma — Presets.Plasma
description "Three drifting sine fields summed and read through a cosine palette — the hello world of video synths." let across = x |> sine(freq: 0.8, phase: t * 0.11) let down = y |> sine(freq: 0.9, phase: t * -0.07) let round = rings(freq: 1.1, offset: t * -0.13) let field = across + down + round + t * 0.15 let r = field |> sine(freq: 0.2, phase: 0, amp: 0.42, bias: 0.5) let g = field |> sine(freq: 0.2, phase: 0.1, amp: 0.42, bias: 0.5) let b = field |> sine(freq: 0.2, phase: 0.2, amp: 0.42, bias: 0.5) rgb(r: r, g: g, b: b) |> out.color
Kaleidoscope — Presets.Kaleidoscope
description "Rotating wedges filled with clouds that boil over time." rotate(angle: t * 0.15) |> kaleidoscope(segments: 6) |> clouds(z: t * 0.3, scale: 2.5) |> hsv(hue: _, saturation: 0.9, value: 1) |> out.color
One clock and two speeds off it, as the preset has — t is the same node both
times.
Grid — Presets.Grid
description "Tile, mirror and polar in a row, so what each one does to the plane is"
"separable."
let plane = translate(dx: sine(freq: 0.06))
|> tile(tiles: 3)
|> mirror()
|> polar()
let hue = plane.angle |> remap(-3.15..3.15, 0..1)
plane |> checker(size: 3)
|> remap(0..1, 0.14..1)
|> hsv(value: _, hue: hue, saturation: 0.7)
|> out.colorplane is piped as the pair (radius, angle) into Checker, and read once more
by name for the hue. That is the fan-out the preset draws with two wires.
Feedback tunnel — Presets.FeedbackTunnel
description "Each frame re-read slightly rotated, scaled and dimmed, with fresh rings"
"on top."
let pulse = t * 0.25
let past = rotate(angle: t * 0.08)
|> scale(scale: 1.05)
|> feedback()
|> gain(gain: 0.95, bias: 0)
let fresh = rings(freq: 1.5, offset: pulse)
|> smoothstep(0.8, 1)
|> hsv(value: _, hue: pulse, saturation: 1)
past |> max(a: _, b: fresh) |> out.colorThe Smoothstep is where the in rule earns itself: the rings go to in, which
is the module’s third port.
Three channels — Presets.ThreeChannels
description "One field read three times, a little apart: a color is three signals, and" "here they disagree." let apart = sine(freq: 0.08) |> remap(-1..1, 0..0.1) let plane = rotate(angle: t * 0.06) |> kaleidoscope(segments: 6) |> translate(dx: 0.55) let flow = t * 0.15 let red = plane |> scale(scale: 1 + apart) |> rings(freq: 2.5, offset: flow) |> smoothstep(0.75, 1) let green = plane |> rings(freq: 2.5, offset: flow) |> smoothstep(0.75, 1) let blue = plane |> scale(scale: 1 - apart) |> rings(freq: 2.5, offset: flow) |> smoothstep(0.75, 1) rgb(r: red, g: green, b: blue) |> out.color
The preset is a loop over three channels in C#, and three lines here rather than
a def: the three share plane and flow, and what is shared is a let
outside.
Trails — Presets.Trails
description "A dot on a looping path and a Trails keeping where it has been, so a point" "draws a ribbon." let px = sine(freq: 0.3, amp: 0.5) let py = sine(freq: 0.2, phase: 0.25, amp: 0.3) let dot = hypot(x - px, y - py) |> smoothstep(0.09, 0.03) hsv(hue: t * 0.08, saturation: 0.85, value: dot) |> trails(zoom: 0.985, angle: 0.015, persist: 0.99) |> out.color
One of the few patches that names x and y: a distance from somewhere other
than the middle needs the pixel’s own position to take that somewhere from. The
Smoothstep’s edges are the wrong way round on purpose, which reads it backwards.
Loop — Presets.Loop
description "A wire running backwards: a lowpass built from an add and a multiply, with" "its one number swept." let keep = sine(freq: 0.1) |> remap(-1..1, 0.92..0.996) let sum = square(freq: 110) * (1 - keep) |> add(a: _) sum.b <- sum * keep sum |> out.left out.volume = 0.2
keep is read twice, once as it is and once taken from one, and the two shares
are what make this a filter that comes out as loud as it went in.
Two channels — Presets.TwoChannels
description "Stereo from one voice: left and right fed differently rather than panned."
let root = note(A2)
let twin = note(root.note, cents: 9)
let shape = pulse(freq: 1.5, width: 0.3)
|> adsr(gate: _, attack: 10ms, decay: 126ms, sustain: 0.4, release: 158ms)
saw(freq: root, amp: 0.7) * shape |> out.left
saw(freq: twin, amp: 0.7) * shape |> out.right
out.volume = 0.55The second Note is fed from the first one’s note output rather than its hz,
which is the whole trick — nine cents of detune on the same note number.
Staircase — Presets.Staircase
description "A slope caught six times a second by a Sample & Hold, which makes steps," "and steps are a tune." let clock = pulse(freq: 6) let slope = sine(freq: 0.11) + sine(freq: 0.37, amp: 0.5) let height = slope |> remap(-1.5..1.5, 45..81) let stair = hold(in: height, trigger: clock) let pitch = tune(in: stair) [ A C D E G ] triangle(freq: pitch) * (clock |> adsr(gate: _, attack: 3ms, decay: 120ms, sustain: 0.2, release: 60ms)) |> out.left out.volume = 0.5
The one clock goes to the Hold’s trigger and the envelope’s gate, so a pitch
is caught on the same edge that plucks it.
Heads or tails — Presets.HeadsOrTails
description "One riff and a coin for every note: heads plays it on the left, tails an" "octave down on the right, and the odds drift." let riff = notes(rate: 8) [ A3 C4 E4 G4 A4 G4 E4 D4 ] let coin = riff.gate |> chance(gate: _, chance: sine(freq: 0.07, amp: 0.4, bias: 0.5)) triangle(freq: note(riff)) * (coin |> adsr(gate: _, attack: 3ms, decay: 150ms, sustain: 0.1, release: 80ms)) |> out.left sine(freq: note(riff, octave: -1)) * (coin.else |> adsr(gate: _, attack: 3ms, decay: 250ms, sustain: 0.3, release: 120ms)) |> out.right out.volume = 0.5
coin is Chance’s gate and coin.else the notes it let fall, so every note of
the riff plays on exactly one side.
Drone — Presets.Drone
description "One slow oscillator setting both the hue of the image and the tremolo on" "the tone." let slow = sine(freq: 0.15, amp: 0.5, bias: 0.5) sine(freq: 110) * slow |> out.left rings(freq: 3, offset: t) |> autoremap() |> hsv(value: _, hue: slow, saturation: 0.85) |> out.color out.volume = 0.6
One node reaching both sinks, which is the patch. Nothing about it is said twice.
Sequence — Presets.Sequence
description "One sequencer heard and seen at once: the steps are the tune and the" "color." let steps = notes(rate: 3, gate_length: 0.66) [ A3 C4 D4 E4 G4 E4 D4 C4 ] let pitch = steps |> note(note: _) sine(freq: pitch) * steps.gate |> out.left let bands = steps.index |> remap(0..1, 1.5..9) let bright = steps.gate |> remap(0..1, 0.4..1) rings(freq: bands) |> remap(-1..1, 0.05..1) |> mul(a: _, b: bright) |> hsv(value: _, hue: steps.index, saturation: 0.8) |> out.color out.volume = 0.5
All three of the sequencer’s outputs, each used for what only it can do.
Four voices — Presets.FourVoices
The preset is a for loop over four voices in C#. It is a def here — and it
is the patch that decides def must be able to hand back more than one thing,
since a voice contributes a tone, a tint, and one fader that opens both.
description "Four faders that are one signal each, opening a voice and a band together."
def voice(pitch, bands, hue, rate, phase) = {
let level = sine(freq: rate, phase: phase, amp: 0.5, bias: 0.5)
let tone = sine(freq: note(pitch))
let tint = radius |> sine(freq: bands, amp: 0.5, bias: 0.5)
|> hsv(value: _, hue: hue)
(tone, level, tint)
}
let (toneA, levelA, tintA) = voice(A2, 1, 0.00, 0.06, 0.00)
let (toneB, levelB, tintB) = voice(E3, 2, 0.33, 0.09, 0.30)
let (toneC, levelC, tintC) = voice(A3, 3, 0.58, 0.13, 0.60)
let (toneD, levelD, tintD) = voice(C#4, 4, 0.83, 0.17, 0.85)
mixer(toneA, levelA, toneB, levelB, toneC, levelC, toneD, levelD) |> out.left
mixer(tintA, levelA, tintB, levelB, tintC, levelC, tintD, levelD)
|> gain(color: _, gain: 0.6)
|> out.color
out.volume = 0.25The band goes to value because _ puts it there. HSV has no in, so a pipe
into it always says which of its three sockets it means.
Heard — Presets.Heard
description "A drum the picture listens to rather than being told about, through a"
"Meter."
let voiced = sine(freq: 70)
* (pulse(freq: 2, width: 0.08)
|> adsr(gate: _, attack: 2.5ms, decay: 126ms, sustain: 0, release: 100ms))
let heard = meter(voiced, window: 32ms)
voiced |> out.left
rings(freq: 5)
|> remap(-1..1, 0.1..1)
|> mul(a: _, b: heard.peak + 0.18)
|> hsv(value: _, hue: heard, saturation: 0.75)
|> out.color
out.volume = 0.6Both of the Meter’s readings: peak is the hit and lights the rings, level —
which is what the bare name means — takes the hue, so the color lags the flash
by as much as a room does.
Duck — Presets.Duck
description "A pad that gets out of the way each time the kick hits, on a Scope drawing"
"how far."
let kick = sine(freq: 55)
* (pulse(freq: 2, width: 0.08)
|> adsr(gate: _, attack: 2.5ms, decay: 126ms, sustain: 0, release: 100ms))
let pad = saw(freq: 110, amp: 0.25) + saw(freq: 165, amp: 0.2)
|> duck(left: _, key: kick, depth: 0.8, release: 200ms)
pad + kick |> out.left
scope(pad.gain, window: 2s, scale: 1.25) |> out.color
out.volume = 0.5The kick’s sound is the key, and it is added back after the Duck, which never
turns down what keys it. The Scope charts gain, the level the Duck applies,
rather than the pad, so a dip is a line falling rather than a waveform thinning.
Waveform — Presets.Waveform
description "Sine, triangle, square and saw faded one into the next, on a Scope drawing" "the shape being heard." let pitch = 110 let voice = mixer( in_1: sine(freq: pitch), level_1: max(sine(freq: 0.08, phase: 0.25), 0), in_2: triangle(freq: pitch), level_2: max(sine(freq: 0.08), 0), in_3: square(freq: pitch), level_3: max(sine(freq: 0.08, phase: 0.75), 0), in_4: saw(freq: pitch), level_4: max(sine(freq: 0.08, phase: 0.5), 0)) voice |> out.left scope(voice, window: 30ms, scale: 1.5) |> out.color out.volume = 0.25
A socket with a space in its name takes an underscore, so the Mixer’s in 1 is
in_1. Each fader is the top half of a slow sine, a quarter of a turn after the
last.
Sidebands — Presets.Sidebands
description "One sine bending another's phase at audio rate, on an Analyzer showing the"
"partials that grows."
let strike = pulse(freq: 0.5, width: 0.1)
|> adsr(gate: _, attack: 2ms, decay: 1500ms, sustain: 0, release: 300ms)
let depth = sine(freq: 0.07) |> remap(-1..1, 0.2..1.6)
let root = note(A3)
let modulator = sine(freq: root * 3.5)
let voice = sine(freq: root, phase: modulator * (strike * depth)) * strike
voice |> out.left
analyzer(voice, window: 50ms, range: 72) |> out.color
out.volume = 0.3root * 3.5 is a frequency times a number, which is an Expression like any
other: the language has no idea that one side of it is a pitch.
Ahead and behind — Presets.AheadAndBehind
description "A Probe and a Scope on one signal, which is the only way to see how they" "differ." let sweep = sine(freq: 0.4) |> remap(-1..1, 90..320) let tone = saw(freq: sweep) tone |> out.left let split = y |> step() color.mix(scope(tone, window: 25ms), probe(tone, window: 25ms), split) |> out.color out.volume = 0.3
Two things worth noticing. color.mix is written in full because mix is one
of the two ambiguous short names. And the split is y |> step() rather than
step(y), because Threshold is [edge, in] — a positional y would have
become the edge.
Lissajous — Presets.Lissajous
description "Two sines a fifth apart, left against right on a Beam: a knot that turns" "because the fifth is a little sharp." let left = sine(freq: 110, amp: 0.85) let right = sine(freq: 165.2, amp: 0.85) left |> out.left right |> out.right beam(x: left, y: right, persistence: 30ms, intensity: 1.2) |> out.color out.volume = 0.2
Each sine is one speaker and one axis of the Beam, so what is drawn is the stereo being heard. Three cycles across against two up is a fifth’s knot.
Ring scan — Presets.RingScan
description "A loop swept round a field at audio rate, so the picture is the waveform."
let bands = rings(freq: 4)
let where = sine(freq: 0.2) |> remap(-1..1, 0.2..0.75)
let loop = scan(bands, rate: 110, radius: 0.35, x: where, scale: 1)
loop |> out.left
bands |> remap(-1..1, 0.05..0.55)
|> hsv(value: _, hue: where, saturation: 0.7)
|> add(a: _, b: loop.view)
|> out.color
out.volume = 0.25In key — Presets.InKey
description "One cloud field snapped to a pentatonic: heard as a melody, seen as the" "terraces it was cut into." let field = clouds(z: t * 0.3, scale: 2.2) let beat = pulse(freq: tempo(180), width: 0.12) let key = field |> remap(0..1, 45..69) |> quantiser(hold: beat) [ C D E G A ] let pitch = key |> note(note: _) sine(freq: pitch) * (beat |> adsr(gate: _, attack: 4ms, decay: 141ms, sustain: 0, release: 32ms)) |> out.left let hue = key * (1 / 12) |> fract() |> remap(0..1, 0.02..0.6) let shade = field |> remap(0..1, 0.22..0.95) hsv(hue: hue, saturation: 0.6, value: shade) |> out.color out.volume = 0.55
1 / 12 is two literals, so it is folded to a knob value rather than emitting a
Divide. Arithmetic between literals is constant-folded at parse time;
arithmetic involving a signal emits an Expression. That is what keeps
t * 0.2 an Expression and 1 / 12 a number.
Nebula — Presets.Nebula
description "Everything the video side can do, folded, warped and trailing its own"
"frames."
let boil = t * 0.12
let pulse = t * 0.2
let folded = rotate(angle: t * 0.05) |> kaleidoscope(segments: 8)
let field = folded |> clouds(z: boil, scale: 1.4)
let shimmer = field + pulse |> fract()
let fresh = folded
|> warp(by: field, amount: 0.5)
|> rings(freq: 2.5, offset: pulse)
|> smoothstep(0.15, 0.85)
|> hsv(value: _, hue: shimmer, saturation: 0.85)
fresh |> trails(zoom: 0.99, angle: 0.015, persist: 0.92) |> out.colorfolded fans out to the Clouds and to the Warp, which is the two wires the
preset draws from one node. field + pulse |> fract() groups as
(field + pulse) |> fract(), because the pipe is the loosest operator there is.
Whole band — Presets.WholeBand
The showcase, and the stress test: a whole song, a hundred and sixty-four
modules in fifteen groups. It is also the patch that argues hardest for group,
since the C# builds it that way already.
description "A whole song from the engine's own modules: seven parts in a room, twelve"
"phrases, one picture."
let beat = tempo(112)
group "Song" {
// drums, snare, bass, second string, pad, how far the filters open
let band = beat.beats |> arrangement(rate: 1/32) [
0 1 1 1 1 1 1 0 1 1 1 0 |
0 0 1 1 1 1 1 0 1 1 0 0 |
0 0 1 1 1 1 1 0 1 1 1 0 |
0 1 1 1 1 1 1 1 1 1 1 0 |
0.9 0.8 0.45 0.5 0.75 0.75 0.5 1 0.8 0.8 0.6 0.9 |
0.1 0.3 0.6 0.7 1 1 0.7 0.2 1 1 0.45 0.1
]
// the chorus, the lead, a fill
let form = beat.beats |> arrangement(rate: 1/32) [
0 0 0 0 1 1 0 0 1 1 0 0 |
0 0 0 1 1 1 1 1 1 1 1 0 |
0 0 0 1 0 1 0 1 0 1 0 0
]
let filling = (form.progress |> step(edge: 0.875)) * form.part_3
let ramp = form.progress |> remap(0.875..1, 0.35..1)
let chorusRoot = beat.beats |> values(rate: 0.25, gate_length: 1, shape: 0) [ -4 3 -2 0 -4 3 -5 -5 ]
let verseRoot = beat.beats |> values(rate: 0.25, gate_length: 1, shape: 0) [ 0 -2 -4 -5 ]
let root = math.mix(
verseRoot,
chorusRoot,
form)
}
let hiss = noise()
group "Kick" {
let verseKick = beat.beats |> values(shape: 0.01) [
1 ~ ~ ~ ~ ~ 0.75 ~ 0.95 ~ ~ ~ ~ ~ 0.6 ~
]
let chorusKick = beat.beats |> values(shape: 0.01) [
1 ~ ~ ~ 0.9 ~ ~ ~ 0.95 ~ ~ ~ 0.9 ~ 0.6 ~
]
let kickGate = math.mix(verseKick.gate, chorusKick.gate, form) * band
let kickHard = math.mix(verseKick, chorusKick, form) |> hold(trigger: kickGate)
let kickLevel = kickGate |> adsr(gate: _, attack: 1.26ms, decay: 240ms, sustain: 0, release: 79ms)
let sweep = kickGate |> adsr(gate: _, attack: 0.5ms, decay: 44.7ms, sustain: 0, release: 15.8ms)
let kickFreq = sweep |> remap(0..1, 46..200)
let kick = sine(freq: kickFreq) * kickLevel * kickHard * 1.7
|> clamp(-1, 1)
let duck = duck(key: kickLevel, depth: 0.55, attack: 100us, release: 100us)
}
group "Hats" {
let hatSeq = beat.beats |> values(gate_length: 0.4, shape: 0.01) [
0.8 0.3 0.55 0.3 0.75 0.3 0.6 0.35 0.8 0.3 0.55 0.3 0.75 0.35 0.65 0.5
]
let shut = (1 - fract(beat.beats * 4) |> pow(a: _, 10)) * hatSeq * band
let open = (1 - fract(beat.beats + 0.5) |> pow(a: _, 3)) * form
let hatLevel = shut + open * 0.6
let hats = (hiss |> filter(cutoff: 7000, resonance: 0)).high * hatLevel
}
group "Snare" {
let snareSeq = beat.beats |> values(shape: 0.01) [
~ ~ ~ ~ 1 ~ ~ ~ ~ ~ ~ ~ 0.95 ~ ~ 0.45
]
let snareHit = snareSeq.gate * band.part_2
let snareGate = math.mix(snareHit, hatSeq.gate, filling)
let snareHard = math.mix(snareSeq, ramp, filling) |> hold(trigger: snareGate)
let snareLevel = snareGate |> adsr(gate: _, attack: 0.5ms, decay: 158ms, sustain: 0, release: 63ms)
let wires = (hiss |> filter(cutoff: 1100, resonance: 0)).high |> filter(cutoff: 6500, resonance: 0)
let shell = sine(freq: 185, amp: 0.6) * (snareLevel * snareLevel)
let snare = (wires * 2.2 * snareLevel + shell) * snareHard
}
group "Bass" {
let verseBass = beat.beats |> values(rate: 2, gate_length: 0.6) [
0@1.5 0%0.6@0.5 7%0.85 0%0.7 0@1.5 12%0.7@0.5 0%0.85 7%0.75
]
let chorusBass = beat.beats |> values(rate: 2, gate_length: 0.7) [
0 0%0.7 0%0.85 0%0.7 0 0%0.7 12%0.85 0%0.75
]
let bassGate = math.mix(verseBass.gate, chorusBass.gate, form) * band.part_3
let bassHz = math.mix(verseBass, chorusBass, form) + root + 33 |> note(note: _)
let accent = bassGate |> slew(rise: 25.1188643ms, fall: 25.1188643ms)
let pluck = (bassGate |> adsr(gate: _, attack: 1ms, decay: 126ms, sustain: 0.4, release: 63ms)) * accent
let cutoffTop = band.part_6 |> remap(0..1, 900..2600)
let cutoff = pluck |> remap(in_low: 0, out_low: 70,
out_high: cutoffTop)
let low = saw(freq: bassHz, amp: 0.8) |> filter(cutoff: cutoff, resonance: 0.8)
let bass = ((low * pluck |> drive(drive: 3)) + sine(freq: bassHz, amp: 0.75) * pluck) * duck.gain
}
group "Strings" {
let firstArp = beat.beats |> values(rate: 2) [
57 64%0.7 69%0.8 64%0.7 72.6%0.9 64%0.7 69%0.8 64%0.7
]
let secondArp = beat.beats |> add(a: _, b: -0.25) |> values(rate: 2) [
69 72.6 76 72.6 69 76 72.6 69
]
let stringTone = band.part_6 |> remap(0..1, 900..2200)
let firstTuned = firstArp |> tune(transpose: root) [ C D E F G G# A B ]
let firstPlucked = string(trigger: firstArp.gate,
freq: firstTuned,
decay: 708ms)
let secondTuned = secondArp |> tune(transpose: root) [ C D E F G G# A B ]
let secondStrike = secondArp.gate * band.part_4
let secondPlucked = string(trigger: secondStrike,
freq: secondTuned,
decay: 708ms)
let firstString = (firstPlucked |> filter(cutoff: stringTone, resonance: 0)) * 2.2
let secondString = (secondPlucked |> filter(cutoff: stringTone, resonance: 0)) * 2.2
let strings = firstString + secondString
let between = strings * 0.5
let stringsL = firstString + between
let stringsR = secondString + between
}
group "Pad" {
let padRootFreq = root + 57 |> note(note: _)
let padRoot = pulse(freq: padRootFreq,
width: sine(freq: 0.17, amp: 0.22, bias: 0.5), amp: 0.5)
let padMiddle = pulse(freq: tune(in: 60.6, transpose: root) [ C D E F G G# A B ],
width: sine(freq: 0.23, amp: 0.22, bias: 0.5), amp: 0.5)
let padFifthFreq = root + 64 |> note(note: _)
let padFifth = pulse(freq: padFifthFreq,
width: sine(freq: 0.29, amp: 0.22, bias: 0.5), amp: 0.5)
let padTone = band.part_6 |> remap(0..1, 700..2400)
let padToneL = mixer(in_1: padRoot, level_1: 0.8, in_2: padMiddle, level_2: 0.9,
in_3: padFifth, level_3: 0.35)
|> filter(cutoff: padTone, resonance: 0)
let padToneR = mixer(in_1: padRoot, level_1: 0.8, in_2: padMiddle, level_2: 0.35,
in_3: padFifth, level_3: 0.9)
|> filter(cutoff: padTone, resonance: 0)
let padLevel = (band.part_5 |> slew(rise: 2.51188643s, fall: 2.51188643s)) * duck.gain
let padL = padToneL * padLevel
let padR = padToneR * padLevel
}
group "Lead" {
let hook = beat.beats |> notes(gate_length: 0.62, shape: 0.045) [
A4 C5%0.8 E5%0.9 C5%0.6 F5 E5%0.85 E5%0 D5%0.9
B4%0.8 D5%0.7 G5 F5%0.85 E5%0.9 D5%0.6 C5%0.95 C5%0
B4%0.85 A4 G4%0.7 A4%0.8
]
let melody = beat.beats |> notes(rate: 2, gate_length: 0.85, shape: 0.03) [
C5@3 A4%0.8 C5%0.9@2 F5@2 E5@4 D5%0.85@2 C5%0.9@2
D5@3 B4%0.8 D5%0.9@2 G5@2 E5@6 E5%0@2
]
let leadStep = math.mix(hook, melody, form)
let leadGate = math.mix(hook.gate, melody.gate, form) * form.part_2
let tuned = leadStep |> note(note: _)
let wide = note(tuned.note, cents: sine(freq: 5.4, amp: 9))
let fifthFreq = leadStep + 7 |> note(note: _)
let fifth = triangle(freq: fifthFreq, amp: 0.5)
* sine(freq: 0.043, amp: 0.5, bias: 0.5)
let leadEnvSustain = form |> remap(0..1, 0.3..0.7)
let leadEnv = leadGate |> adsr(gate: _, attack: 3.16ms, decay: 112ms,
sustain: leadEnvSustain, release: 141ms)
let leadTone = leadEnv |> remap(0..1, 500..5200)
let leadToneL = saw(freq: tuned, amp: 0.7) + fifth |> filter(cutoff: leadTone, resonance: 0)
let leadToneR = saw(freq: wide, amp: 0.7) + fifth |> filter(cutoff: leadTone, resonance: 0)
let leadLevel = leadEnv * (form |> remap(0..1, 0.6..0.9))
let leadL = leadToneL * leadLevel
let leadR = leadToneR * leadLevel
}
group "Room" {
let room = mixer(in_1: snare, level_1: 0.5, in_2: leadL + leadR, level_2: 0.4,
in_3: strings, level_3: 0.5, in_4: hats, level_4: 0.12)
|> filter(cutoff: 2600, resonance: 0)
|> reverb(size: 0.3, decay: 0.5, mix: 1)
}
group "Desk" {
let drums = desk(left_1: kick, level_1: 0.85,
left_2: snare, level_2: 0.6,
left_3: hats, right_3: hats * 1.45, level_3: 0.4,
left_4: bass, level_4: 0.8)
let master = desk(left_1: stringsL, right_1: stringsR, level_1: 0.8,
left_2: padL, right_2: padR, level_2: 0.42,
left_3: leadL, right_3: leadR, level_3: 0.6,
left_4: room, right_4: room.wide, level_4: 0.17,
bus_left: drums.bus_left, bus_right: drums.bus_right,
trim: 0.7)
master.left |> out.left
master.right |> out.right
}
group "Picture: Geometry" {
let foldSegments = root |> remap(-5..3, 4..10)
let foldZoom = kickGate |> remap(0..1, 0.96..1.3)
let fold = transform(angle: t * 0.055 + root * 0.08,
zoom: foldZoom,
order: "turn")
|> kaleidoscope(segments: foldSegments)
let field = fold |> clouds(z: t * 0.18, scale: 2.1)
let filamentBands = leadGate |> remap(0..1, 2.2..4.4)
let filament = fold
|> warp(by: field,
amount: sine(freq: 0.071, amp: 0.25, bias: 0.45) + firstArp.gate * 0.15)
|> rings(freq: filamentBands + band.part_6 * 1.6, offset: t * 0.4)
|> smoothstep(0.2, 0.95)
}
group "Picture: Color" {
let freshValue = filament * ((kickGate |> remap(0..1, 0.75..1.7)) + hatLevel * 0.35) |> clamp(0, 1)
let bassLift = bassGate |> remap(0..1, 0.55..0.95)
let freshHue = leadStep * (1 / 12) + field * 0.9 + (t * 0.02 + form * 0.45) |> fract()
let freshSaturation = bassLift * (snareGate |> remap(0..1, 1..0.3))
let fresh = hsv(
hue: freshHue,
saturation: freshSaturation,
value: freshValue)
}
group "Picture: Feedback" {
let warmAngle = kickGate |> remap(0..1, 0.012..0.05)
let warm = transform(zoom: 1.035, angle: warmAngle)
|> feedback()
|> color.split()
let cool = transform(zoom: 0.972, angle: -0.016)
|> feedback()
|> color.split()
let fade = band.part_6 |> remap(0..1, 0.78..0.9)
rgb(warm, cool.g, cool.b)
|> gain(gain: fade, bias: 0)
|> max(a: _, b: fresh)
|> out.color
}
out.volume = 0.62A rounded constant is a different program. The pad’s swell is a Slew at
four tenths of a decade, which is 2.51188643s, and the compiler keeps one
register for each distinct number. Written 2.51s the patch plays the same and
carries a constant the preset does not have — so a duration that has to match
another one in the patch is written in full, and one that stands alone can be
rounded.
17. What writing these out changed
The transliteration was done before any parser existed, precisely so that the holes would show up while the design was still cheap to move. Four did.
- The pipe rule was wrong. “Fills the first unnamed input” put the signal in
edge0on Smoothstep andedgeon Threshold. Three shipped presets would have compiled, rendered, and meant something else. Hence theinclause in section 3. defneeded more than one result. Four voices is the patch that motivated macros, and a voice hands back a tone, a tint and one fader shared between them. A single-pipeline body could not say it without duplicating the fader and changing the graph.- Groups had to be expressible. Whole band organizes a hundred and sixty-six modules
into fifteen of them. Dropping groups on
printwould have made the one patch that most needs reading the one least able to be read. - Literal arithmetic has to fold. In key sets a knob to
1 / 12. Without constant folding that is a Divide module the preset does not have.
Two limitations are recorded rather than fixed, because both are the language
declining to hide something true about the engine: a computed duration is in
decades and gets no ms sugar, and a pipe into an oscillator is its domain
rather than its pitch.
Then building it found three more. Every preset above is a test: the patch the language builds is compiled and compared with the C# one, opcode for opcode and register for register. Standing all twenty up against that turned up what reading them could not.
- The pipe rule was wrong a second time. “A binding forwards every output”
reads well on geometry and is a disaster elsewhere —
steps |> note()put the sequencer’sgateinto Note’soctaveand itsindexinto thecents. Only a position takes two signals now; everything else takes one. Section 3 is the rule as it ended up. -2..2was parsing as the negation of2..2, because the minus bound tighter than the range. The same class of mistake as theedge0one, and invisible for the same reason: it parses.- A sharp is the character a comment starts with, so
C#4read as the nameCfollowed by a comment that ate the rest of the line. The note is matched before the name now.
The first of those is worth dwelling on. It was wrong in the specification, it survived being written out by hand across twenty patches, and it was caught only by compiling both and comparing them. Reading does not find that kind of mistake, because the mistake reads correctly.
Then agents wrote it. Unsteered, they wrote hsv(hue: h, saturation: s, value: v) after a pipe and expected the signal to go somewhere, and they bound
every pipeline to a name rather than nest one in an argument
(language-for-agents.md
). “The first socket the call
did not name” was a guess that hung on the arguments beside it, so it became
_, and a pipeline inside an argument became an error.