Claudio Pietronik

The editor and the language

A module you write instead of wire: how the editor works, and what a program looks like — four inputs, four outputs, and every sample computed by your own code.

The editor

Clicking EDIT on the panel opens the editor in its own window: a code pane with syntax colouring, a menu bar, and a dock on the right holding the reference, the snippets and the patch library.

It compiles as you type. A pause is enough — the program is rebuilt and hot-swapped into the running graph, so the sound changes without a gap. When the code does not compile the error appears inline with its line and column, and the last good program keeps playing: a typo never drops the audio out.

The CODE editor
Write, compile, hear. The dock on the right carries this same manual inside the app, so nothing here has to be remembered.

The dock is three views of one library, and the difference between them is the size of what they hand you:

The Snippets tab
Snippets — the fifteen starter patches, then the library family by family. Picking one drops a working line in at the caret.
The Patches tab
Patches — eleven categories of twenty-four, each a whole program with a sentence saying what it is. Reference, the third tab, is the signature list further down this page.
  • File · Edit — reset to the default program, copy the lot, undo, redo, paste at the caret.
  • View — dark or light, and whether the dock is showing. Double-clicking the menu bar goes full screen.
  • Run — compile and run on demand, plus the copilot: auto-suggest as you type, or ask for a suggestion at the caret.
  • Help — the manual, in a popup, with the same text you are reading.

The shape of a program

The language runs once per sample, per voice. There is no callback to register and no buffer to loop over: you read in1..in4, you write out1..out4, and that is the whole contract. An output you never write passes its input through.

What makes it more than a calculator is state: a variable that survives to the next sample. Every filter, oscillator, counter and delay is built on that one idea.

state float ph = 0;                  // survives to the next sample
ph += 220 / sr; if (ph >= 1) ph -= 1;
out1 = sin(2 * pi * ph);             // a 220 Hz sine, from scratch

Above that there are functions, arrays, buffers for delay lines, structs for voice banks, and for loops — so a polyphonic engine is a struct array and a loop, not a special feature. Notes and times can be written as themselves: A3, C4, 5ms, 400ms.

The standard library arrives with import, one family at a time — osc, filter, drive, env, fx, mod, util, seq, phys, gran, dyn, trig, rnd, verb, eq, pan, scale — and every one of them is a plain function call:

import osc; import filter; import env; import trig;
float g = clockgate(2, 0.4);                        // its own clock
out1 = ladder(saw(A2), 1800, 0.5) * adsr(g, 8ms, 150ms, 0.5, 200ms) * 0.4;

A param line turns a number into a knob on the panel. Declare it with its range and read the name straight into the maths — the value arrives already scaled, so there is no mapping to write and nothing to keep in step:

param cutoff = 900  [120, 9000];
param res    = 0.35 [0, 0.9];
out1 = ladder(in1, cutoff, res);     // cutoff and res are now on the module

Longer programs are written in named cells rather than one scroll: Controls, Voice, Tone, Space in the picture above. Each carries its own line count, folds shut when you are not looking at it, and they compile as one program — so the structure you can see is the structure that runs.

It is sandboxed: a program that misbehaves cannot take the host down with it.

Snippets 15

The starter blocks in the dock: short, self-sounding, and meant to be pasted and then changed.

Detuned saw pad
import osc; import filter;
out1 = ladder(supersaw(A2, 0.03), 1200, 0.4) * 0.3;
FM bell
import osc; import env; import trig;
out1 = fm2(A3, 3.5, 6) * ar(metro(2), 1ms, 400ms);
Karplus pluck
import phys; import trig;
out1 = pluck(A3, metro(2)) * 0.5;
Filtered noise sweep
import filter; import mod;
out1 = svf_bp(noise(), 300 + (0.5 + 0.5 * lfo(0.2, 0)) * 3000, 8) * 0.5;
Dub delay
import phys; import fx; import trig;
float src = pluck(A2, metro(1)) * 0.5;
out1 = src + delayfx(src, 18000, 0.5);
Plate reverb
import osc; import env; import verb; import trig;
float src = fm2(C4, 2, 5) * ar(metro(1.5), 1ms, 300ms);
out1 = src + plate(src, 0.85, 0.4) * 0.4;
Wobble bass
import osc; import filter; import mod;
out1 = ladder(saw(A1), 200 + (0.5 + 0.5 * lfo(4, 0)) * 2000, 0.6) * 0.4;
Ring mod
import osc;
out1 = sine(A3) * sine(A3 * 1.5) * 0.5;
Saw chord
import osc; import filter;
float s = saw(C3) + saw(E3) + saw(G3);
out1 = ladder(s * 0.3, 1500, 0.35);
Bitcrush drone
import osc; import drive;
out1 = bitcrush(saw(A2) * 0.4, 5);
Random arp
import osc; import env; import trig; import rnd;
float p = 110 + (0.5 + 0.5 * randh(6)) * 440;
out1 = square(p, 0.4) * ar(metro(6), 1ms, 80ms);
Soft clip input
out1 = tanh(in1 * 3) * 0.7;
out2 = in2;
Note melody (array)
import osc; import trig; import seq;
array notes[5];
notes[0] = 48; notes[1] = 55; notes[2] = 60; notes[3] = 63; notes[4] = 67;
float gate = trig2gate(metro(4), 0.1);
float idx = floor((snh(noise(), gate) + 1) * 2.49);
out1 = saw(midi2freq(notes[idx])) * gate * 0.4;
Tape echo (buffer)
buffer tape[48000];
state float w = 0;
tape[w] = in1;
float r = w - 24000; if (r < 0) r += 48000;
out1 = in1 + tape[r] * 0.6;
w += 1; if (w >= 48000) w = 0;
Poly voices (struct bank)
import scale; import trig;
struct Voice { float ph; float note; float env; }
state Voice v[6];
state float next = 0;
if (metro(3) > 0) {
  v[next].note = degree(45, 22, rand(10));
  v[next].env  = 1;
  next += 1; if (next >= 6) next = 0;
}
float mix = 0;
for (i = 0; i < 6; i += 1) {
  v[i].ph += midi2freq(v[i].note + 24) / sr;
  if (v[i].ph >= 1) v[i].ph -= 1;
  v[i].env *= 0.9996;
  mix += sin(2 * pi * v[i].ph) * v[i].env;
}
out1 = mix * 0.3;