---
name: tuttidaw-code
description: Write, fix and explain TuttiDAW Code: Strudel-compatible live-coding pattern programs (mini-notation, note/s/n, scales, chords, effects, samples) that play on TuttiDAW instruments and effects, plus TuttiDAW-only .inst/.fx/.midifx devices. Use when asked for Strudel or TuttiDAW code, a beat/melody/loop as code, a tuttidaw.com/code link, a Pattern Clip, or when a pattern program errors.
---

# TuttiDAW Code

TuttiDAW Code is a pattern language for music: a superset of Strudel
(strudel.cc) that plays on TuttiDAW's instruments and effects. A program is
JavaScript built from pattern functions; double-quoted strings are
mini-notation. It loops: one cycle = one bar.

## Core syntax

```js
setcpm(30)                                   // cycles (bars) per minute: 30 = 120 BPM in 4/4
drums: s("bd [~ bd] sd ~, hh*8").bank("tr909") // a labelled voice = one track
bass: note("c2 [~ c2] eb2 g1").s("sawtooth").lpf(800)
chords: chord("<Cm7 Ab^7 Fm7 G7>").voicing().inst("Electric").fx("Reverb:Large Hall")
_lead: n("0 2 4 7").scale("C:minor")         // a leading _ mutes a voice
```

- Mini-notation: `a b c` steps share a cycle; `~` rest; `[a b]` one step;
  `<a b>` one per cycle; `a,b` together; `*n` `/n` faster/slower; `@n`
  longer; `!n` repeat; `x(3,8)` Euclidean; `?` maybe; `a|b` random choice;
  `{a b c, d e}` polymeter; `bd:3` variant.
- Pitches: `note("c4")` = MIDI 60; no octave = octave 3. `n("0 2 4").scale("C:minor")`
  plays scale degrees (root in octave 3). `chord("Am7").voicing()` voices
  chord symbols.
- Time: `.fast` `.slow` `.early` `.late` `.rev` `.ply` `.iter` `.every(n, f)`
  `.lastOf(n, f)` `.off(t, f)` `.superimpose(f)` `.struct("x ~ x")`
  `.mask("1 0")` `.swingBy(1/3, 4)`; combine with `stack` `cat` `seq`
  `arrange([4, a], [2, b])`. `f` is an arrow function: `x => x.fast(2)`.
- Sound: `s("bd sd hh cp oh")` drums (`.bank("tr808")`), waveforms
  `sine triangle square sawtooth supersaw`, `piano`, `gm_*` names.
- Controls: `.gain` `.velocity` `.pan` `.lpf` `.hpf` `.lpq` `.room` `.size`
  `.delay` `.delaytime` `.delayfeedback` `.shape` `.crush` `.attack`
  `.decay` `.sustain` `.release`; signals `sine saw tri perlin rand` with
  `.range(a, b)` `.slow(n)` `.segment(n)`.
- TuttiDAW only: `.inst("Device:Preset", {key: value})` instrument,
  `.midifx(...)` before it, `.fx(...)` after it, in call order. Params use the
  device's keys and units (`"4s"`, `"-6dB"`, `"1/16"`); constants only for now.
  `toggle(1)` is an inline switch. These disable the strudel.cc link.

## Top mistakes

1. **Octaves**: code `c4` is MIDI 60, but TuttiDAW's piano roll (like
   Ableton Live) labels MIDI 60 as C3. Write code names; a request for "C3"
   from a Live user may mean MIDI 60.
2. **Arithmetic on controls**: `note("c e").add(12)` does nothing (warning);
   write `note("c e").add(note(12))` or `n("0 2".add(7))`.
3. **Multi-word scales** need colons inside quotes: `"C:harmonic:minor"`,
   `"A:minor:pentatonic"`. `"C:harmonic minor"` is two steps.
4. **Device calls inside callbacks** fail: `every(2, x => x.fx(...))` is an
   error; a voice has one chain. Put `.inst/.fx/.midifx` on the voice.
5. **Patterned device params** (`{cutoff: "<300 900>"}`) are not applied
   yet; use Strudel controls (`.lpf("<300 900>")`) for movement.
6. **One `.inst` per voice**; a second is an error. Use another voice.
7. **Single vs double quotes**: double quotes are mini-notation; single
   quotes are plain strings (`register('name', ...)`, `.scale('C minor')`).
8. **No browser APIs**: no `fetch`, `import`, timers or DOM; code runs in a
   deterministic sandbox (seeded `Math.random`, fixed `Date`).
9. **Unknown sound names** fall back with a warning; check
   `references/sounds.md` and `references/devices.md`.
10. **Voice labels** become track names: label every voice
    (`kick:`, `bass:`) instead of `$:` when the program goes to the studio.

## Workflow: write -> check -> listen

1. **Write** the smallest program that does the job; label each voice.
2. **Check** it before handing it over:
   - with TuttiDAW's MCP server (`https://tuttidaw.com/api/mcp`):
     `read_pattern` without a clipId returns the language reference, and
     `write_pattern` compiles and renders code into a Pattern Clip, returning
     errors with line, column and a fix. A Pattern Clip plays notes only;
     devices apply in group programs and on /code;
   - otherwise compare every name with `references/functions.md` and
     `references/devices.md`.
3. **Listen**: give the user a link that opens the program on
   `https://tuttidaw.com/code#<payload>`, where the payload is the
   UTF-8 code in base64, URI-encoded (`encodeURIComponent(btoa(utf8))`, the
   same as strudel.cc's long links). The page plays it without an account;
   **Open in TuttiDAW** saves it as a project with one track per voice.
4. Fix what the diagnostics report; change one thing at a time.

## References

Read only what the task needs:

- `references/getting-started.md`: Getting started. What TuttiDAW Code is, how a program loops, and how to play your first line.
- `references/first-sounds.md`: First sounds. Drums with s(), pitches with note(), and the difference between them.
- `references/mini-notation.md`: Mini-notation. The rhythm language inside the quotes - sequences, rests, groups, alternation, polymeter, Euclidean rhythms and chance.
- `references/time-and-structure.md`: Time and structure. Functions that speed up, shift, reverse, repeat and combine patterns, and arrange them into sections.
- `references/harmony-and-scales.md`: Harmony and scales. Note names and octaves, scale degrees, transposition, chord symbols, voicings and arpeggios.
- `references/sounds.md`: Sounds. Drum kits and banks, synth waveforms, General MIDI instrument names, Ensemble sounds and your own samples.
- `references/effect-controls.md`: Effect controls. Filters, reverb, delay, distortion, panning, envelopes and synth controls - and moving them with signals.
- `references/sample-operations.md`: Sample operations. Play part of a sample, change its speed, cut it into slices, fit it to the tempo and choke it.
- `references/tuttidaw-extensions.md`: TuttiDAW extensions. Load any TuttiDAW instrument, MIDI effect or audio effect with presets and parameters; voices, groups and Open in TuttiDAW.
- `references/javascript.md`: JavaScript in code. Variables, functions, loops and register - and the sandbox, determinism and limits that keep shared code safe.
- `references/muse.md`: Muse on /code. Ask TuttiDAW's AI assistant to write, explain, fix or restyle your program, from text, a Strudel tune, a screenshot or a reference track.
- `references/functions.md`: every function, method and signal, with signature, description and example (generated from the engine).
- `references/devices.md`: every instrument and effect for `.inst/.fx/.midifx`, with `references/devices/<id>.md` per device: param keys, ranges, units, presets (generated from the device catalogue).

Language: PATTERN LANGUAGE 1.1.0, engine 12.
Human guide: https://tuttidaw.com/code/learn
