Step 08 of 11
Command reference
Every command in the course: what it does, what its numbers mean, with an example.
- 8.1 How to read it
- 8.2 Tempo and playing
- 8.3 Mini-notation
- 8.4 Sounds and notes
- 8.5 Chords
- 8.6 Rhythm and time
- 8.7 Copies and layers
- 8.8 Note shape (envelope)
- 8.9 Effects
- 8.10 Signals
- 8.11 Building songs
- 8.12 Visuals
8.1How to read this reference
Every command used in the course, grouped by what it does. Each row shows the command, what it does, what its numbers mean, and a short example. The Strudel examples are complete: copy one into Strudel and press Ctrl+Enter.
8.2Tempo and playing
How fast the music runs, and how layers start and stop.
| Command | What it does | Values · numbers |
|---|---|---|
setcpm(124/4) | Sets the tempo. Strudel counts cycles (bars) per minute. Example setcpm(90/4)
$: s("bd*4") | BPM ÷ beats per bar. 124/4 = 124 BPM in 4/4. |
$: … | Starts a layer: a pattern that plays. Several layers play together. Example $: s("bd*4")
$: s("hh*8") | – |
_$: … | Mutes one layer without deleting it. Example $: s("bd*4")
_$: s("hh*8") | – |
Ctrl+Enter · Ctrl+. | Runs the code · stops everything. | – |
samples("github:user/repo") | Loads an extra sample pack from GitHub. | The address of the pack. |
8.3Mini-notation: the symbols inside quotes
Everything inside "…" is mini-notation.
| Command | What it does | Values · numbers |
|---|---|---|
"bd sd hh" | Spaces: steps one after another, sharing the bar evenly. Example s("bd sd hh") | 3 steps = a third of a bar each. |
"bd [sd sd]" | [ ]: squeezes several steps into one. Example s("bd [sd sd]") | |
"[c4,e4,g4]" · "bd*4, hh*8" | Comma: at the same time (a chord, or two rhythms at once). Example note("[c4,e4,g4]").s("piano") | |
"<c4 e4 g4>" | < >: one item per bar, in turn. Example note("<c4 e4 g4>").s("piano") | 3 items = a 3-bar cycle. |
"hh*8" | *n: plays the step n times in its space. Example s("hh*8") | |
"[c4 e4]/2" | /n: stretches the step over n bars. Example note("[c4 e4 g4 b4]/2").s("piano") | |
"bd!3 sd" | !n: repeats the step as n separate steps. Example s("bd!3 sd") | bd!3 sd = bd bd bd sd |
"c4@3 e4" | @n: makes a step n times longer than the others. Example note("c4@3 e4").s("piano") | c4@3 e4: C lasts ¾ of the bar. |
"bd ~ sd ~" | ~: a rest (silence). Example s("bd ~ sd ~") | |
"hh*8?" | ?: each step plays only half of the time, at random. Example s("hh*8?") | |
"bd(3,8)" | (k,n,r): a Euclidean rhythm, k hits spread as evenly as possible over n steps, rotated by r. Example s("bd(3,8), hh*8") | (3,8) = the tresillo, x ~ ~ x ~ ~ x ~ |
"bd:3" | :n: picks sample number n of a sound. Example s("bd:0 bd:3") | 0 = the first one. |
"{bd sd hh}%4" | { }%n: polymeter, steps run at n per bar and wrap around. Example s("{bd sd hh}%4") | A 3-step loop at 4 per bar drifts against the beat. |
8.4Sounds and notes
What plays, and at which pitch.
| Command | What it does | Values · numbers |
|---|---|---|
s("bd") | Which sound: a sample (bd, piano, gm_…) or a synth wave (sine, sawtooth, square, triangle, supersaw, white, pink).Example s("bd sd:2") | A name; :n picks a variant. |
.bank("RolandTR909") | Which drum machine the drum names come from. Example s("bd sd").bank("RolandTR808") | TR909, TR808, TR707, LinnDrum… see the sound bank. |
note("c4 e4") | The pitch, by name or MIDI number. Example note("c4 eb4 g4").s("piano") | c4 = 60 = middle C. Sharps/flats: c#4 eb4. |
n("0 2 4") | A number. On its own it picks a sample variant; with .scale it is a scale step.Example n("0 2 4").scale("C4:major").s("piano") | 0 = first. |
.scale("C4:major") | Turns step numbers into notes of a scale. Example n("0 1 2 3 4 5 6 7").scale("A3:minor").s("piano") | root+octave:scale. Scales: major, minor, dorian, mixolydian, minor pentatonic, major pentatonic, blues… |
.add(12) | Adds numbers. On notes = semitones up; on n with a scale = scale steps up. Example n("0 2 4".add("<0 3>")).scale("C4:major").s("piano") | Negative numbers go down. |
.transpose(12) | Moves notes up or down in semitones. Example note("c4 e4 g4").transpose(12).s("piano") | 12 = one octave, 7 = a fifth. |
8.5Chords
Chord symbols and how they become notes. To write chords note by note, see 3.4 Chords from notes.
| Command | What it does | Values · numbers |
|---|---|---|
chord("<Am F C G>") | Chord symbols: C, Am, G7, C^7 (maj7), Dm9, Bo (dim), D2 (sus2), Dsus (sus4)… All names.Example chord("<Am F C G>").voicing().s("piano") | One symbol per step. |
.voicing() | Turns chord symbols into notes, choosing a voicing close to the previous chord. Example chord("<C G Am F>").voicing().s("piano") | Always comes after dict, mode, anchor. |
.dict("triads") | Which set of voicings to use. Example chord("<C G Am F>").dict("triads").voicing().s("piano") | ireal (default, jazz voicings with 7ths), triads, lefthand, guidetones, legacy. |
.mode("above").anchor("c4") | Where the voicing sits. below (default): top note at or under the anchor; above: bottom note at or above it; root: root position; duck: like below, but avoids the anchor note.Example chord("<C G Am F>").dict("triads").mode("above").anchor("c4").voicing().s("piano") | Anchor: a note name; the default is c5. |
.rootNotes(2) | Only the root of each chord, in the given octave: a ready-made bass line. Example chord("<Am F C G>").rootNotes(2).s("sawtooth").lpf(400) | Octave number. Use it without .note(). |
.arp("0 1 2 1") | Plays the notes of a stacked chord one at a time, by position. Example note("[c4,e4,g4]").arp("0 1 2 1").s("piano") | 0 = lowest note; numbers past the top wrap round. |
8.6Rhythm and time
Commands that change when things happen.
| Command | What it does | Values · numbers |
|---|---|---|
.struct("x ~ x x") | A rhythm template: the pattern plays only on the x steps. Example note("[c3,e3,g3]").struct("x ~ x x ~ x ~ ~").s("piano") | x = hit, ~ = rest. |
.mask("1 0 1 1") | Silences parts: 0 = muted, 1 = plays. Example s("hh*8").mask("1 0 1 1") | "<0!4 1!4>" = silent for 4 bars, then plays for 4. |
.fast(2) · .slow(2) | Plays faster or slower. Example s("bd sd").fast(2) | 2 = twice as fast / spread over 2 bars. |
.late(.25) · .early(.25) | Shifts in time. Example s("cp").late(.25) | In bars: .25 = one beat in 4/4. |
.ply(2) | Repeats each event n times inside its own length. Example s("bd sd").ply(2) | 2 = doubles every hit (a roll). |
.swingBy(1/3, 4) | Shuffle: splits the bar into n parts and delays the second half of each part. Example s("hh*8").swingBy(1/3, 4) | First number: how much (0 = straight, 1/3 = triplet swing). Second: parts per bar. |
.degradeBy(.3) | Drops events at random. Example s("hh*16").degradeBy(.3) | 0–1: the share removed (.3 = 30 %). |
.sometimesBy(.5, x => x.ply(2)) | Applies a change to a random share of events. Example s("hh*8").sometimesBy(.3, x => x.ply(2)) | 0–1: the probability. |
.segment(8) | Turns a smooth signal into n separate steps per bar. Example n(irand(8).segment(8)).scale("A3:minor pentatonic").s("piano") | Steps per bar. |
.rev() | Plays each bar backwards. Example n("0 1 2 3").scale("C4:major").rev().s("piano") | – |
8.7Copies and layers
Commands that play a pattern together with changed copies of itself. x => … means "take the pattern x and change it like this".
| Command | What it does | Values · numbers |
|---|---|---|
.off(1/8, x => x.add(note(12))) | Adds a copy that starts later and is changed by the function. Example note("c4 e4 g4").off(1/8, x => x.add(note(12))).s("piano") | Delay in bars: 1/8 = an eighth note in 4/4. |
.superimpose(x => x.transpose(12)) | The original plus a changed copy, at the same time. Example note("c4 e4 g4").superimpose(x => x.transpose(12)).s("piano") | – |
.layer(x => …, x => …) | Only the changed copies; the original is not played on its own. Example note("c4 e4").layer(x => x.s("piano"), x => x.s("sawtooth").transpose(12).gain(.4)) | Any number of functions. |
.jux(rev) | Original in the left speaker, a changed copy in the right. Example n("0 1 2 3").scale("C4:major").s("piano").jux(rev) | – |
8.8Note shape (envelope)
How each note starts, holds and ends.
| Command | What it does | Values · numbers |
|---|---|---|
.attack(.1) | Fade-in time. Example note("c3").s("sawtooth").attack(.5) | Seconds. 0 = instant, .5 = slow swell. |
.decay(.2) | Time to fall from full volume to the sustain level. Example note("c3*4").s("sawtooth").decay(.2).sustain(0) | Seconds. |
.sustain(.5) | The level held after the decay. Example note("c3*4").s("sawtooth").decay(.2).sustain(.5) | 0–1. 0 = a short pluck, 1 = held at full volume. |
.release(1) | Fade-out after the note ends. Example note("c3 ~").s("sawtooth").release(1) | Seconds. |
.clip(.5) | Note length relative to its step. Example note("c4 e4 g4 c5").s("piano").clip(.3) | 1 = the whole step, .5 = half (short), 2 = overlaps the next note. |
.penv(24).pdecay(.1) | A pitch envelope: the note starts higher and slides down. Used for synth kicks and booms. Example note("a1*4").s("sine").penv(24).pdecay(.1).decay(.3).sustain(0) | penv: semitones above; pdecay: seconds for the slide. |
8.9Effects
Short list. For what every number means and which values to choose, see Effect numbers explained.
| Command | What it does | Values · numbers |
|---|---|---|
.gain(.8) | Volume. Example s("hh*8").gain(".2 .8") | 1 = normal, 0 = silent. |
.pan(.3) | Left–right position. Example s("hh*8").pan(sine) | 0 left · .5 centre · 1 right. |
.lpf(800) · .lpq(10) | Low-pass filter: removes highs · resonance peak. Example note("a1*8").s("sawtooth").lpf(800).lpq(10) | Hz (20–20000) · 0–50. |
.hpf(300) | High-pass filter: removes lows. Example s("hh*8").hpf(3000) | Hz. |
.vowel("a") | Makes the sound "talk". Example note("[a3,c4,e4]*4").s("sawtooth").vowel("<a e i o>") | a e i o u |
.room(.4) · .roomsize(4) | Reverb amount · reverb length. Example s("~ cp").room(.4).roomsize(4) | 0–1 · seconds. |
.delay(.5) · .delaytime(.375) · .delayfeedback(.4) | Echo volume · time between echoes · how many echoes. Example note("a4 ~ ~ ~").s("triangle").delay(.5).delaytime(.375).delayfeedback(.4) | 0–1 · seconds · 0–0.98. |
.shape(.4) · .distort("3:.5") | Saturation · distortion (amount:volume). Example note("a1*4").s("sawtooth").distort("3:.5") | 0–1 · 0–10 : 0–1. |
.crush(4) · .coarse(8) | Bitcrusher (lower = dirtier) · downsampling (higher = rougher). Example s("bd*4, hh*8").crush(4) | 16 → 1 · 1 → 32. |
.phaser(2) · .tremolo(4) | Swirl · volume pulsing. Example note("[c3,e3,g3]").s("supersaw").tremolo(4).gain(.5) | Speed per second. |
.orbit(2) | A separate effects channel, so layers can have different reverb and delay settings. Example s("~ cp").room(.9).roomsize(8).orbit(2) | A channel number. |
8.10Signals: values that move
Signals are smooth values between 0 and 1 that change during each bar. Put them where a number goes: .lpf(sine.range(300, 3000)).
| Command | What it does | Values · numbers |
|---|---|---|
sine | A smooth wave: 0.5 → 1 → 0 → 0.5 once per bar. Example s("hh*16").gain(sine.range(.2, .8)) | 0–1 |
saw · isaw | A ramp: saw rises 0 → 1, isaw falls 1 → 0, each bar. Example note("a2*16").s("sawtooth").lpf(saw.range(300, 3000)) | 0–1 |
tri · square | tri: up then down in straight lines. square: 0 for half the bar, 1 for the other half. Example s("hh*16").gain(tri.range(.2, .8)) | 0–1 |
rand · irand(8) | Random values: rand gives 0–1, irand(n) a whole number from 0 to n−1. Example s("hh*16").gain(rand.range(.2, .8)) | |
run(8) | The numbers 0, 1, 2 … n−1 as a pattern. Example n(run(8)).scale("C4:major").s("piano") | |
.range(a, b) | Rescales a 0–1 signal to the range a … b. Example note("a2*16").s("sawtooth").lpf(sine.range(300, 3000)) | Any two numbers. |
.slow(4) | On a signal: one sweep takes 4 bars instead of 1. Example note("a2*16").s("sawtooth").lpf(saw.range(300, 3000).slow(4)) | |
.round() | Rounds to whole numbers (for scale steps). Example n(sine.range(0, 7).segment(8).round()).scale("C4:major").s("piano") |
8.11Building songs
Combining patterns into layers, sections and songs.
| Command | What it does | Values · numbers |
|---|---|---|
stack(a, b) | Plays several patterns together, as one. Example stack(s("bd*4"), s("hh*8")) | |
cat(a, b) | One pattern per bar, in turn. Example cat(s("bd*4"), s("bd*2 sd*2")) | |
arrange([4, a], [8, b]) | Plays blocks in order, each for its number of bars. Each block starts from its own beginning. Example arrange([2, s("bd*4")], [2, s("bd*4, hh*8")]) | Bars per block. |
"<0 1>".pick([a, b]) | Chooses a pattern by number (or name) every bar. Follows the global clock. Example "<0 1>".pick([s("bd*4"), s("hh*8")]) | 0 = the first in the list. |
const verse = … | Stores a pattern under a name, to use it again. | |
const keys = p => note(p)… | A function: an instrument that can play any chords you give it. |
8.12Visuals
Drawings of the music in the editor. See 6 Visuals.
| Command | What it does | Values · numbers |
|---|---|---|
._pianoroll() | A piano roll inside the code, under the line. Example note("c4 e4 g4 b4").s("piano")._pianoroll() | |
.pianoroll() | A piano roll in the background of the editor (one background visual at a time). Example note("c4 e4 g4 b4").s("piano").pianoroll() | {labels: 1} shows note names. |
._punchcard() · ._scope() · ._spectrum() · ._pitchwheel() · ._spiral() | Other drawings: events as blocks, the waveform, the frequencies, the notes on a circle, a spiral. Example s("bd*4, hh*8")._punchcard() | |
.color("cyan") | The colour of a layer in the visuals. Example note("c4 e4").s("piano").color("cyan")._pianoroll() | Any CSS colour name. |
all(x => x.pianoroll()) | Applies something to every $: layer at once. |
Tested with Strudel 1.3. Course text: CC BY-SA 4.0, code: CC0 1.0 (licences).