# BeatScript > BeatScript: AI-assisted algorithmic composition. BeatScript is also the name of its small, total, deterministic language for writing whole music tracks as text. Programs compile to Petri nets, play in the browser, in the djrust desktop app and in the BeatScript Android app, and are content-addressed: the same canonical text always has the same CID. Programs are CC0 by default and remixable by fork. Key facts: - Everything generated here is public: programs, share links, cards and rendered audio are stored publicly under CC0-1.0, and a compose prompt goes to a third-party model. Never put anything private in a prompt. Terms: https://beatscript.app/privacy. - Who authored a program and what rights it has (CC0, prompts and authorship, lineage, private work), in plain language: https://beatscript.app/authorship. - Source: https://github.com/stackdump/beatscript (MIT); programs CC0. Feature requests welcome as issues; no outside code or pull requests. - One line per deck (`deck A: kick x ~ x ~ | snare ~ x ~ x`), parts joined with `|`, 16 steps a bar. Mini-notation: `x` hit, `~` rest, `[..]` group, `<..>` per-bar alternation, `c2!` accent, `e2^` slide, `chord(am)`, `e(5,8)` euclid. - Structure: `let`, `def` (no recursion), `repeat N`, `section NAME N bars { ... }`, `arrange`, `end after`, `loop`. - Control lines: ramps `a -> b over N bars`, `at bar N:`, `every N bars:`, `before
N bars:`, `do `. A part line may take `at bar N for M bars:` inside a section (a placed part); `row: clip NAME crop=A..B route=vocoder` plays a declared sample on the loop row; `deck A: mute|unmute|solo ROLE` mutes one part. Seeded transforms (`rotate`, `transpose`, `degrade`, `humanize`); `evolve every N bars { ... }` with a reported tail and period. - Only instruments from https://beatscript.app/api/instruments. Always run check (the MCP tool, or POST https://beatscript.app/api/check) and fix every line:column error before playing: a program with an error is refused whole. - Share link: https://beatscript.app/#.: the program as `fmt` prints it, its `#!` header lines and comments kept. The CID is of the canonical text, so formatting and comments never change it (they travel unsealed). ## Docs - [BEATSCRIPT.md](https://beatscript.app/docs/BEATSCRIPT.md): the language reference: its two halves (structure, the track's own source, and engine calls, pinned and versioned), grammar (EBNF), mini-notation, control lines, placed parts, audio placements, part mute and the timeline report, evolve, canonical form, share links - [cheatsheet.md](https://beatscript.app/docs/cheatsheet.md): the compact grammar, the same text the compose prompt uses; read this first - [Found phrases](https://beatscript.app/docs/found-phrases.md): the technique for sung lines: borrow public-domain text for its shape, pick a line for its meter (trochees chant on the kick, iambs lilt on the offbeat, anapests and dactyls want a triplet feel, shanties call and respond), keep the vocal low, cycle it buried and spotlit, cross it onto the drums with xfer, fix pronunciation with phoneme escapes ([page](https://beatscript.app/docs/found-phrases)) - [Forms](https://beatscript.app/docs/forms.md): arrange shapes from classical music: quodlibet (themes take turns and cross-morph), passacaglia (a fixed ground under cumulative variations), canon (a theme chasing its own copy), rondo (a refrain returning mutated), fugue (a subject re-entering transposed), theme and variations (one source, a transform a section); each a template built from public-domain themes, `arrange from template(quodlibet, @psalm42_deep_calleth)` ([page](https://beatscript.app/docs/forms)) - [Radio: stations](https://beatscript.app/docs/radio.md): a station is one small program (`station { from gen@2 techno seed=42; next seed=~; forms seeded passacaglia }`) naming an endless, deterministic run of tracks: position N is always the same track (the same CID), the walk steps the seed (`seed=+N` counts on, `seed=~` draws from the CID of the track before), the forms take turns, and the segue from N to N+1 is the cross form of their seeds; a listener turns knobs (genre, seed, step, forms, tempo, key, length) and keeps N; the MCP `station` tool and POST https://beatscript.app/api/station answer it ([page](https://beatscript.app/docs/radio)) - [Polish a mix](https://beatscript.app/docs/polish.md): the loop for polishing a mix with the MCP `listen` tool: check, listen, change one line, listen again with `compare` (the previous version's CID or text: deltas, and the warnings fixed and introduced); what it measures per part and on the master (bands, centroid, width, correlation, crest; true peak, PLR, short-term max, loudness range), clashes between parts, delivery `targets` (streaming -14 LUFS / -1 dBTP, apple, broadcast, club), the order of fixes (not heard, clipping, clashes, balance, loudness, width) and the lines that make each one (`level`, `vel=`, `mix { B eq low -6 }`, `duck B under A.kick 6db`, `filter hp`, `drive`), and what the language cannot do yet ([page](https://beatscript.app/docs/polish)) - [Drafts and marks](https://beatscript.app/docs/marks.md): the listening prototyper's library: drafts (the programs you built, one per title, newest first) and marks (the heart, Mark this: a program CID with the bar and beat that sounded, when, the source and from where), kept by your account for the web editor and the Android app (`POST https://beatscript.app/api/marks/sync`, offline first, Creative Commons programs only: a private program's stay on its device); a mark opens `https://beatscript.app/?cid=#bar=`; the MCP `marks` tool reads them ([page](https://beatscript.app/docs/marks)) - [Embed a program](https://beatscript.app/docs/embed.md): one embed config (https://beatscript.app/embed-config.schema.json) for every surface: and (the editor as an MCP server inside a Claude artifact or any page: check, fmt, expand, generate, share and the rest offline, compose and store through the artifact's capabilities), an iframe of https://beatscript.app/embed/ (?compact=1, ?theme=light), the element (https://beatscript.app/embed.js), oEmbed (https://beatscript.app/oembed?url=&format=json), /c/ cards that play (twitter:player, og:audio), a README card (https://beatscript.app/card/.svg), Jupyter, VS Code, Obsidian, and the rendered audio (https://beatscript.app/api/render/?format=opus); per target, whether the engine runs and what it gets instead; the MCP embed tool writes each one ([page](https://beatscript.app/docs/embed)) - [Build your own](https://beatscript.app/docs/sdk.md): the supported surfaces and how each is versioned (the language and its CIDs, the JSON reports, the embed config, the npm player and studio pinned by exact version and SRI, the MCP server and HTTP API, the ontology release, the engine crates as a git dependency pinned by rev); MIT code, CC0 programs and output; the engine crates for native builders (djlive, beatscript-api, beatscriptls, djengine, djhost and its features audio, sf2, midi, decode, network, off by default) and the UniFFI crate the Android and iPad apps use; check, fmt, expand and highlight outside the studio: the `beatscript` CLI, `beatscript lsp`, the MCP, ``'s tools, the wasm module's exports, Rust and HTTP ([page](https://beatscript.app/docs/sdk)) - [Stage view](https://beatscript.app/docs/api#stage-view): https://beatscript.app/?view=stage&cid= (or &example=, or a share link's #...) shows a program on a projector or second screen: full screen (a button and F; Esc leaves it and never stops the music), read-only, large high-contrast type that follows the system's light or dark theme and prefers-contrast, the firing markers and the follow-scroll on, and for a `set { }` the tracklist line (`2/5 now · next `); record mode (?record=1, the demo video) is the same page without the person - [Instruments](https://beatscript.app/api/instruments): the voices, families, drum kits and palettes a program may name (JSON) - [API reference](https://beatscript.app/docs/api.md): every HTTP route, sign-in and tokens, compose, render streaming, sessions, the MCP tools with examples - [Ontology](https://beatscript.app/ontology/): the BeatScript ontology, the vocabulary behind BeatScript (genres, grooves, rhythms, sections, the engine concepts and the language's own grammar, voices, controls and MCP tools) as Turtle, JSON-LD, SPARQL (https://beatscript.app/ontology/sparql) and a read-only MCP server (https://beatscript.app/ontology/mcp); term IRIs under https://beatscript.app/ontology/ns#. Derived from the bitwrap ontology 0.2.0 (each term linked to its bitwrap IRI by prov:wasDerivedFrom), it evolves on its own - [llms-full.txt](https://beatscript.app/llms-full.txt): this file with the cheat-sheet, the grammar and an example program inlined - [Grammar](https://beatscript.app/grammar): every production as a railroad diagram; [grammar.ebnf](https://beatscript.app/grammar.ebnf) is the language's one grammar (EBNF), held to the parser both ways - [Authorship and rights](https://beatscript.app/authorship): who authored a program and what rights it has, in plain language ([markdown](https://beatscript.app/authorship.md)) ## Open data Every public CC0 program, in every format, free to fetch (GET, CORS open, no sign-in): - A program by CID: https://beatscript.app/p/ (its page), https://beatscript.app/p/.beatscript (its canonical text, which hashes to the CID), https://beatscript.app/p/.jsonld (its linked data), https://beatscript.app/api/render/?format=opus (its audio); https://beatscript.app/p/ also answers by Accept (text/beatscript or text/plain, application/ld+json, audio/*) - [JSON Feed](https://beatscript.app/feed.json) and [Atom](https://beatscript.app/feed.atom): the newest public CC0 programs, each with its .beatscript, .jsonld and render - [Sitemap](https://beatscript.app/sitemap.xml): every public CC0 program's page - [Dumps](https://beatscript.app/dumps/): content-addressed archives of all of them (programs/.beatscript, programs/.jsonld, a manifest of CIDs); [the newest](https://beatscript.app/dumps/latest.json) - [Schema](https://beatscript.app/schema): the vocabulary (@vocab https://beatscript.app/schema#), the embedded block, and links to the BeatScript ontology (https://beatscript.app/ontology/ns#) - [Phrasebook](https://beatscript.app/phrasebook): lines of verse, scripture, speech and work song first published before 1929 (CC0; each with its source, its meter as a step pattern and a sing example), to sing by id (sing @tempest_such_stuff on melody); [the file](https://beatscript.app/phrasebook.txt) and [linked data](https://beatscript.app/phrasebook.jsonld), and by CID at https://beatscript.app/phrasebook/.txt and https://beatscript.app/phrasebook/.jsonld (404 for any CID this server does not ship) - [Theme library](https://beatscript.app/themes): melodies, basses and figures composed and first published before 1929 (CC0; each as BeatScript bars in a stated key, let-ready, with its role, meter, work, composer, year and pairings), to borrow as found material and build forms from; [the file](https://beatscript.app/themes.txt) and [linked data](https://beatscript.app/themes.jsonld), and by CID at https://beatscript.app/themes/.txt and https://beatscript.app/themes/.jsonld - [Open data](https://beatscript.app/docs/open-data): what is published, what never is (private and non-CC0 programs), and how to mirror it ## Examples - [arrange-in-eight-lines](https://beatscript.app/examples/arrange-in-eight-lines.beatscript): One 4-bar section played eight times while the arrange rewrites its patterns: `~` changes a part from here on, `@` for the next section only. (CC0-1.0, 124 BPM, 32 bars) - [arrange-mutations](https://beatscript.app/examples/arrange-mutations.beatscript): An arrangement that rewrites its own patterns as it goes. (CC0-1.0, 132 BPM, 132 bars) - [hand-dubstep-140-v4](https://beatscript.app/examples/hand-dubstep-140-v4.beatscript): A whole dubstep track in one program: nine sections from intro to outro. (CC0-1.0, 140 BPM, 68 bars) - [matrix-130](https://beatscript.app/examples/matrix-130.beatscript): A D-phrygian driving track in eight sections with generated arps and an evolve that settles into a cycle. (CC0-1.0, 130 BPM, 80 bars) - [trance-138](https://beatscript.app/examples/trance-138.beatscript): A 64-bar trance track (intro 16, breakdown 16, drop 24, outro 8) said once with lets, two defs, four sections and an arrange. (CC0-1.0, 138 BPM, 64 bars) - [hand-dubstep-140-v2](https://beatscript.app/examples/hand-dubstep-140-v2.beatscript): The first whole-track dubstep program, and the shortest one here: six sections in 64 bars. (CC0-1.0, 140 BPM, 64 bars) - [markers-demo](https://beatscript.app/examples/markers-demo.beatscript): A 24-bar program that lights up every kind of marker in the editor. (CC0-1.0, 124 BPM, 24 bars) - [first-beat](https://beatscript.app/examples/first-beat.beatscript): A four-line beat: tempo, drums on deck A, bass and a pad on deck B, and an end. (CC0-1.0, 124 BPM, 8 bars) - [acid-line](https://beatscript.app/examples/acid-line.beatscript): A squelchy FM bass line with an accent (!) and a slide (^), a kick and hats, and a filter cutoff and resonance that ramp over 16 bars. (CC0-1.0, 132 BPM, 16 bars) - [evolve-demo](https://beatscript.app/examples/evolve-demo.beatscript): A program that changes itself: every 4 bars the melody rotates and climbs and the hi-hat thins out, until generation 7. (CC0-1.0, 118 BPM, 32 bars) - [vocals](https://beatscript.app/examples/vocals.beatscript): Lyrics that read like code: words through the lexicon, phonemes between slashes, two phrases from the phrasebook, the vocoder fading in on deck A. (CC0-1.0, 124 BPM, 32 bars) - [trap-expression](https://beatscript.app/examples/trap-expression.beatscript): A short trap beat written with the expression marks: ratchet rolls (x:3, x:4) and ghosts (x.) on the hats, a snare flam (x&) every other bar. (CC0-1.0, 140 BPM, 2 bars) - [pattern-sugar](https://beatscript.app/examples/pattern-sugar.beatscript): A 24-bar groove written with pattern sugar: c2~3 elongate, a bare x? (x?0.5), ply, poly, off, iter and palindrome. (CC0-1.0, 126 BPM, 24 bars) - [such-stuff-as-dreams-122](https://beatscript.app/examples/such-stuff-as-dreams-122.beatscript): A phrase compiled to a track: one line, template(deep-house, @tempest_such_stuff), is deep house at 122 whose vocal line is Shakespeare's verse. (CC0-1.0, 122 BPM, 128 bars) - [assyrian-122](https://beatscript.app/examples/assyrian-122.beatscript): The same deep house over an anapestic line: Byron's "The Assyrian came down like the wolf on the fold" has the triplet feel, so the voice and the s... (CC0-1.0, 122 BPM, 192 bars) - [commit-message-122](https://beatscript.app/examples/commit-message-122.beatscript): Any words are a phrase: a commit message, make the drop deeper and move the kick, has its stress worked out (small words weak, the first syllable o... (CC0-1.0, 122 BPM, 128 bars) - [All examples as JSON](https://beatscript.app/api/examples): name, title, description, cid, bpm, bars, license ## Phrase templates - [Phrase templates](https://beatscript.app/docs/BEATSCRIPT.md#phrase-templates): `arrange from template(NAME, PHRASE)` compiles a phrase, a phrasebook id (`@tempest_such_stuff`) or any words in quotes, to a whole track, written out as plain BeatScript like a seed: the phrase is the vocal line (its syllables set the line's length, its stress the accents and the beats, its meter the subdivision) and the arrangement is the template's own; `expand` shows the text - template `deep-house`: deep house at 122: a night/spot cycle, the voice buried then spotlit, crossed onto the shaker; the phrase is the vocal line. `arrange from template(deep-house, @tempest_such_stuff)`; examples: [such-stuff-as-dreams-122](https://beatscript.app/examples/such-stuff-as-dreams-122.beatscript), [assyrian-122](https://beatscript.app/examples/assyrian-122.beatscript), [commit-message-122](https://beatscript.app/examples/commit-message-122.beatscript) - template `quodlibet`: a quodlibet at 96 in D: public-domain themes take turns by section and cross-morph toward each other and away in cycles; the phrase sung over the ground. `arrange from template(quodlibet, @psalm42_deep_calleth)` - template `passacaglia`: a passacaglia at 100 in G minor: a ground that never changes (Holst's five-beat ostinato) under cumulative variations; the phrase sung over the ground. `arrange from template(passacaglia, @eccl3_season)` - template `canon`: a canon at 90 in D: Pachelbel's violin line chased by copies of itself, a bar and a beat behind, over his ground; the phrase sung over them. `arrange from template(canon, @mgm_pease_porridge_hot)` - template `rondo`: a rondo at 116 in C: Joplin's Entertainer as the refrain, returning mutated between episodes (Bach's Prelude in C, the phrase sung). `arrange from template(rondo, @shanty_drunken_sailor)` - template `fugue`: a fugue at 104 in B minor: Grieg's Mountain King as the subject, answered a fifth up and re-entering transposed while Bach's Badinerie morphs toward it; the phrase sung over the subject. `arrange from template(fugue, @tyger_burning_bright)` - template `theme-and-variations`: a theme and variations at 84 in D-flat: Dvorak's New World Largo, a different transform in each section and no cross-morphs; the phrase sung in one. `arrange from template(theme-and-variations, @dickinson_chariot_death)` - template `cross`: a cross at 120 in D: two sources (two seeds, in any genres: `a=gen@1 dubstep seed=54876, b=gen@1 house seed=7`) take turns and overlap, and morph toward each other and back in cycles; the phrase sung over the crossing. `arrange from template(cross, @psalm42_deep_calleth)` ## API - [MCP server](https://beatscript.app/mcp): streamable HTTP; tools check, fmt, eval, load, get, share, open, render, record, list_examples, instruments, stop, devices, queue (an up-next list that never composes); writes need a bearer token. There is no compose tool: write the program yourself (cheat-sheet, list_examples, instruments, then check until ok) - [Compose](https://beatscript.app/docs/api.md#compose): POST https://beatscript.app/api/compose writes a program from a prompt for the web app (signed in, rate limited, capped; not an MCP tool) - [Render](https://beatscript.app/docs/api.md#render): GET https://beatscript.app/api/render/?format=opus|wav streams the offline render as it renders - [Linked data](https://beatscript.app/docs/api.md#linked-data-json-ld): the versioned JSON-LD @context (https://beatscript.app/context/beatscript-v1.jsonld, the BeatScript vocabulary under https://beatscript.app/schema#; BeatScript 1 documents name the first one, https://beatscript.app/context/v1.jsonld) and a program's JSON-LD document (https://beatscript.app/c/.jsonld) - [Share links](https://beatscript.app/docs/api.md#share-links): the link format, and how to open one safely - [Sign-in and tokens](https://beatscript.app/docs/api.md#sign-in-and-tokens): wallet or browser-key challenge, cookie, bearer tokens for MCP ## Optional - [Generator you can read](https://blog.stackdump.com/posts/generator-you-can-read): the post behind the language: a generator whose output is text you can read and edit