# 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 --- Cheat-sheet (also at https://beatscript.app/docs/cheatsheet.md): # BeatScript cheat sheet Generated from docs/BEATSCRIPT.md. BeatScript writes a whole track as text: pattern lines become Petri nets on decks A and B, and every other line is a control call. The grammar and rules are authoritative: run `check` and fix every `line:col` error before playing. ## The rules in one screen - A program is **lines**. A line is blank, a `# comment`, or one statement. A line that starts with `|` continues the statement above it. - The first line is the version line, `#! beatscript 2`; a text without one is BeatScript 1 ("Versions"). - Words are lower case. Deck names are `A` and `B`. Numbers are plain: `5`, `0.7`, `2k` (= 2000), `50%` (= 0.5), and **wherever the language takes a number it takes arithmetic**: `tempo 120 + 6`, `at bar $i * 2 + 1`, `kick e($i % 4 + 1, 8)`. - A statement is `[when:] [target:] body [when guard]`. Each head ends in a colon, and they read left to right: *when* (`every 16 bars`), *whose* (`deck A`, `master`), then *what*; a trailing `when $i % 2 == 0` keeps the line only where the condition holds. - Time is **bars** (four beats), and a beat is a quarter of a bar: `over 2 beats`, `at bar 16 beat 3`. Seconds appear only where a sound or a check needs them (`attack=5ms`, `assert length == 3m30s`). A pattern is one **cycle** (one bar) long, and its terms share the cycle equally; `hihat/12` gives a part a cycle of its own. - Text in, same net out: the same program text always gives the same net CIDs and the same program CID. Everything is **total** (no recursion, every count written out) and **deterministic** (chance is a hash of the text and the bar; nothing reads a clock, a random source or the machine). - A mistake is an error with a line, a column, what was expected and the nearest name; the program is refused whole. ## Grammar (EBNF) ```ebnf program = { line } ; line = [ statement ] NEWLINE ; statement = setting | headed | let | def | repeat | section | arrange | arrange_block | start | launch | end | loop | evolve | wire | assert | set | station ; setting = "tempo" tempo | "swing" arith | "key" KEY ; tempo = arith [ "->" arith "over" dur [ shape ] ] ; headed = "deck" deck ":" parts [ guard ] | "at" pos [ "for" dur ] ":" "deck" deck ":" parts [ guard ] | [ timing ":" ] [ target ":" ] control [ cguard ] | [ timing ":" ] "control" ":" ( engine | do | duck | mix ) [ cguard ] (* the control deck *) | [ timing ":" ] ( invoke | duck | mix ) [ cguard ] ; timing = when [ "for" dur ] | "for" dur ; when = "every" dur [ "from" ( arith | pos ) ] | "on" "phrase" (* every 8 bars: a phrase *) | "on" "next" "bar" | "on" "next" "phrase" [ "8" | "16" | "32" ] | "at" pos | "after" NAME | "before" NAME dur ; dur = arith ( "bar" | "bars" | "beat" | "beats" ) ; pos = "bar" arith [ "beat" arith ] ; guard = "when" expr ; (* kept where it holds *) cguard = "when" cexpr ; target = "deck" deck | "master" ; deck = "A" | "B" | PARAM ; control = action | engine | do | sing ; parts = pitem { "|" pitem } ; pitem = part | "stack" "(" pargs ")" | "then" "(" pargs ")" ; pargs = { pexpr "," } pitem { "," pexpr } ; pexpr = pitem | "silence" ; part = role [ "/" INT ] pattern { param } | role ref { param } ; role = "kick" | "snare" | "hihat" | "clap" | "bass" | "melody" | "harmony" | "arp" ; param = pname "=" pvalue | "voice-lead" [ "=" ( "on" | "off" ) ] ; pname = "vel" | "oct" | "len" | "inst" | "seed" | "kit" | "sound" | "route" | "glide" | "decay" | "pitch-drop" | "cutoff" | "res" | "env" | "accent" | "drive" ; pvalue = arith [ ".." arith ] | WORD | PARAM ; pattern = term { term } ; term = atom [ mark ] [ "*" ( INT | "(" arith ")" ) ] { "?" [ prob ] } [ "~" INT ] ; mark = ( "!" | GHOST ) [ "^" ] [ "&" ] [ RATCHET ] | "^" [ "!" | GHOST ] [ "&" ] [ RATCHET ] | "&" [ RATCHET ] | RATCHET ; atom = "x" (* a hit *) | "~" (* a rest *) | NOTE (* c3 f#2 bb4 *) | INT | "(" arith ")" | degrees (* deg(1 b3 5' ~) *) | ROMAN [ "/" INT ] | PARAM | "[" pattern { "," pattern } "]" | "<" pattern ">" | choose | call | NAME ; (* a let pattern's name *) call = NAME "(" [ arg { "," arg } ] ")" ; arg = arith | KEY | CHORD | ROMAN [ "/" INT ] | NAME | NAME "=" ( arith | WORD ) | "[" pattern "]" | degrees | call | PARAM ; degrees = "deg" "(" dstack ")" ; dstack = dseq { "," dseq } ; dseq = dterm { dterm } ; dterm = dleaf [ mark ] [ "*" INT ] | "~" | "x" | "[" dstack "]" | "<" dseq ">" | "(" ( dterm | arith ) ")" ; dleaf = ( INT | SDEG ) { "'" } { "," } ; prob = NUMBER | "(" arith ")" ; choose = "choose" "[" pattern "]" "weights" weight { weight } [ "seed=" INT ] ; weight = NUMBER | "(" arith ")" ; action = "filter" ( "lp" | "hp" ) change (* hertz: 20 .. 20k *) | "filter" ( "off" | "open" ) | ( "delay" | "reverb" | "crush" | "drive" | "resonance" ) change (* 0 .. 1: how much *) | ( "level" | "low" | "mid" | "high" ) change ; engine = "tempo" tempo | MACRO NAME ( "on" deck [ span ] | span "on" deck ) ; change = value (* a plain value *) | value "->" value span [ shape ] | lfo ; span = "over" dur ; value = carith ; do = ( "do" WORD | SUGAR ) [ WORD ] { STRING } { NAME "=" doval } [ span [ shape ] ] ; doval = arith [ "->" arith ] | WORD | STRING | "[" [ doval { "," doval } ] "]" | lfo ; shape = "linear" | "exp" | "log" | "s-curve" | "step" INT ; lfo = "lfo" wave dur { "depth=" value | "center=" value | "phase=" NUMBER } [ span ] ; wave = "sine" | "tri" | "square" | "saw" ; arith = sum ; sum = product { ( "+" | "-" ) product } ; product = unary { ( "*" | "/" | "%" ) unary } ; unary = [ "-" ] primary ; primary = NUMBER | PARAM | "(" arith ")" | ( "min" | "max" ) "(" arith { "," arith } ")" ; carith = csum ; csum = cproduct { ( "+" | "-" ) cproduct } ; cproduct = cunary { ( "*" | "/" | "%" ) cunary } ; cunary = [ "-" ] cprimary ; cprimary = NUMBER | PARAM | "(" carith ")" | ( "min" | "max" ) "(" carith { "," carith } ")" | input ; expr = or ; or = and { "or" and } ; and = not { "and" not } ; not = [ "not" ] compare ; compare = operand [ cmp operand ] ; operand = sum | WORD ; cexpr = cor ; (* a control line's guard *) cor = cand { "or" cand } ; cand = cnot { "and" cnot } ; cnot = [ "not" ] ccompare ; ccompare = coperand [ cmp coperand ] ; coperand = csum | WORD ; cmp = "==" | "!=" | "<" | "<=" | ">" | ">=" ; input = "knob" "(" INT ")" | "pad" "(" INT ")" | "fader" "(" deck ")" | "held" "(" "key" ")" | "held" "(" PITCH ")" ; let = "let" NAME "=" ( sexpr | arith | ref | TOKEN { TOKEN } ) ; def = "def" NAME "(" [ NAME { "," NAME } ] ")" [ "in" ":" type { "," type } ] [ "out" ":" type { "," type } ] "{" { def_line } "}" ; def_line = [ statement | emit ] NEWLINE ; invoke = NAME "(" [ tokens { "," tokens } ] ")" ; (* a def's call *) tokens = TOKEN { TOKEN } ; repeat = "repeat" INT [ "every" INT "bars" ] "{" { body_line } "}" ; body_line = [ statement ] NEWLINE ; section = "section" NAME INT "bars" "{" { line } "}" | "section" NAME "from" ref ; arrange = "arrange" sexpr { sexpr } | "arrange" NAME ":" sexpr { sexpr } [ arr_end ] | "arrange" "from" ( seed | template ) | "arrange" "from" gen ; arr_end = "then" NAME | "loop" [ INT ] | "end" ; start = "start" NAME ; launch = "launch" NAME "on" "pad" "(" INT ")" [ "next" ( "bar" | "phrase" [ "8" | "16" | "32" ] ) ] ; sexpr = NAME | "silence" (* the empty section *) | "stack" "(" sexpr { "," sexpr } ")" (* at the same time *) | "then" "(" sexpr { "," sexpr } ")" ; (* one after another *) end = "end" [ "at" "bar" INT | "after" NAME ] ; loop = "loop" ; arrange_block = "arrange" "{" { arr_gap } NAME { arr_gap | NAME } "}" [ block_end ] | "arrange" NAME ":" "{" { arr_gap } NAME { arr_gap | NAME } "}" [ arr_end ] ; arr_gap = NEWLINE | "," | mutation NEWLINE ; mutation = ( "~" | "@" ) [ INT ] ( switch | mut_target mut_op { "|" mut_op } { "," mut_target mut_op { "|" mut_op } } ) ; switch = "control" [ NAME ] ( "on" | "off" ) ; mut_target = GLOB | NAME ; mut_op = NAME { NUMBER | "-" NUMBER | NAME } ; block_end = "end" | "loop" | "loop" INT [ "then" { NAME } "end" ] ; ref = seed | gen | stored ; seed = SEED "(" NAME "," INT [ "," structure ] ")" [ "." role ] [ "[" INT [ ".." INT ] "]" ] ; stored = CID [ "." NAME ] [ "." role ] ; gen = GEN NAME "seed" "=" ( INT | NAME ) { gen_param } ; gen_param = "bpm" "=" NUMBER | "key" "=" KEY | "length" "=" ( "short" | "standard" | "long" ) | "section" "=" NAME | "part" "=" role ; structure = "standard" | "loop" | "minimal" | "extended" ; template = "template" "(" NAME "," ( PHRASE | STRING | NAME ) { "," binding } ")" ; binding = NAME [ "." role ] "=" ( source | [ "-" ] INT ) ; source = gen | NAME | notes | form | stored | track ; notes = "[" pattern "]" | "<" "[" pattern "]" { "[" pattern "]" } ">" ; form = "template" "(" NAME { "," binding } ")" [ "." NAME [ "." role ] ] ; track = CID "." NAME [ "." NAME ] [ "." role ] ; evolve = "evolve" "every" INT "bars" "{" { NEWLINE } { rule NEWLINE { NEWLINE } } [ bound NEWLINE { NEWLINE } ] "}" ; rule = ( role | "deck" deck ) ":" op { "|" op } [ "when" "gen" [ "%" INT ] cmp INT ] ; op = ( "rotate" | "transpose" | "octave" | "invert" | "reverse" | "thin" | "fill" | "slow" | "fast" ) { NUMBER | "<" NUMBER { NUMBER } ">" } [ "seed=" INT ] ; (* seed= on thin and fill *) bound = "stop" "when" "gen" ( "==" | ">=" | ">" ) INT | "for" INT "gens" ; type = "chords" | "key" | "bass" | "melody" | "drums" | "rhythm" | "bars" | "tempo" | "pattern" ; emit = "emit" [ type | "out" ] tokens ; wire = "wire" NAME "." port "->" NAME "." port ; port = type | "in" | "out" ; duck = "duck" deck "under" deck "." role db { "attack=" time | "release=" time } ; mix = "mix" "{" { NEWLINE } mixitem { ( "," | NEWLINE ) { NEWLINE } mixitem } { NEWLINE } "}" ; mixitem = deck "level" arith | deck "eq" band arith [ "db" ] | "master" "level" arith | deck "pan" arith ; band = "low" | "mid" | "high" ; db = DECIMAL "db" ; (* glued: 6db *) time = DECIMAL ( "ms" | "s" ) ; (* glued: 5ms *) sing = "sing" ( lyric | PHRASE | NAME ) "on" role { "bars=" INT | "key=" KEY | "voice=" NAME } ; lyric = STRING ; lyric_text = { TEXT | "/" SPACE | escape } [ "/" { TEXT } ] ; escape = "/" PHONES "/" ; assert = "assert" ( "ends" | "period" [ "(" NAME ")" ] cmp INT | "length" ( ( "==" | "!=" ) clock [ "±" clock ] | ( "<" | "<=" | ">" | ">=" ) clock ) | "level" leveldeck cmp levelexpr [ "in" NAME ] | "key" ( "==" | "!=" ) KEY [ "in" NAME ] | "never" subject ( "beside" | "during" ) subject [ "in" NAME ] | subject "ends" "on" INT [ "in" NAME ] ) ; subject = "sing" | ldeck | [ ldeck "." ] role ; clock = DECIMAL "m" [ DECIMAL "s" ] | DECIMAL "s" | DECIMAL "ms" ; (* 3m30s 90s 500ms *) leveldeck = { lfactor lop } ldeck { lop lfactor } ; lop = "+" | "-" | "*" | "/" ; ldeck = "A" | "B" | "master" ; levelexpr = lterm { ( "+" | "-" ) lterm } ; lterm = lfactor { ( "*" | "/" ) lfactor } ; lfactor = NUMBER | ldeck | "(" levelexpr ")" ; set = "set" "{" { NEWLINE } { ( set_play | set_mix | set_next ) NEWLINE { NEWLINE } } "}" ; set_play = "play" ( NAME | STRING | gen ) [ "until" until_when ] ; set_next = "next" step [ "until" until_when ] ; until_when = TIME | "bar" INT | NAME | "after" NAME ; set_mix = "mix" INT ( "bar" | "bars" ) "with" TRANSITION [ "," "tempo" NUMBER "->" NUMBER ] ; TIME = DECIMAL UNIT { DECIMAL UNIT } ; TRANSITION = "crossfade" | "filter_exit" | "echo_out" | "cut" ; station = "station" "{" { NEWLINE } { station_line NEWLINE { NEWLINE } } "}" ; station_line = "from" gen | "next" step | "forms" NAME { NAME } ; step = "seed" "=" ( "+" INT | "~" ) ; ``` `NAME` is a lower-case word (letters, digits, `_`, and `-` between letters), `WORD` any word. `INT` is a whole number (arithmetic that comes to one is fine: `repeat 2 + 1`); `NUMBER` also takes a fraction and the `k` / `%` marks, and `DECIMAL` is a number with no mark, before a glued unit (`UNIT`: `6db`, `5ms`, `2s`, `3m30s`, `1h30m`; `hz` after a filter's cutoff, `filter lp 300hz`, is the number and nothing else; the hours of `1h` are read only after a set's `until`). `NOTE`, `PITCH` (a note with its octave), `KEY`, `CHORD` and `ROMAN` are pitch words read as one token (`f#2`, `c4`, `d:dorian`, `am7`, `ii°`); `SDEG` a written degree in `deg( )` (`b3`, `#4`); `PARAM` a def's or a repeat's `$name`; `SUGAR` a control noun said without `do`; `STRING` a double-quoted string; `TOKEN` any token; `GLOB` a name with `*` in it; `CID` a saved program's id; `SEED` `seed` or `seed@2`; `GHOST` a ghost's `.` and `RATCHET` a ratchet's `:N` (`x.` `x:3`). `±` may be written `+-` after a unit (`3m30s +- 5s`). In a lyric, `PHONES` is an escape's text: `aa ae uh aw eh er ii ee uu oo ay ie oy ow oh p b t d k g f v s z sh zh th dh h m n ng l r w y ch j`, `-` cuts a word, `_` rests, `:` holds a vowel, `!` accents it; `/` and a space: a phrase break. A phrase's `NAME` is one `use phrase @id as NAME` gave; `use theme ode_to_joy as tune` names a theme ("Name a source"). ## Patterns: mini-notation ```text kick x ~ x ~ 4 terms: quarter notes, hits on 1 and 3 kick x x x x x x x x 8 terms: eighths snare ~ x ~ x hits on 2 and 4 hihat x*8 eight hits, one an eighth hihat [x x] x [x x] x groups: two hits squeezed into one slot bass c2 ~ [c2 eb2] g2 notes bass 1 ~ 3 5 scale degrees of the key bass 1 ($i + 1) 5 a degree computed (inside a repeat or a def) melody alternation: one a bar, then round kick e(5,8) euclid: five hits over eight steps kick e(3,8,2) the same, rotated by two harmony [c3,e3,g3] a comma inside [] stacks: three notes at once hihat x*8?0.7 each of the eight hits kept with chance 0.7 (seeded) bass choose [c2 e2 g2] weights 3 1 1 one of the three a bar, c2 three times as often melody deg(1 b3 5' ~) degrees with accidentals and octave marks, one slot harmony Roman numerals: a chord of the key a bar (bare, one a quarter); a section's own `key` re-reads them hihat/12 x x ~ x a cycle of twelve sixteenths: four terms of three steps, drifting against the bar bass c2~3 e2 elongate: c2 ~ ~, the step takes three slots hihat x*8? a bare ? is ?0.5 ``` - `*n` plays its term `n` times in its slot (`n` is 1 to 64, and may be `(arithmetic)`). `*2` is `a b` inside one bar (the alternation advances twice). - A pattern with an alternation is as many bars long as it needs (the least common multiple of the deck's alternations, at most 64 bars); the net is that long and loops. A cycle of its own (`hihat/12`) or chance lengthens it too ("How long a program can be"). - The grid is sixteenths: a term off it (three or five in a bar) snaps to the nearest step, with a warning (`x x x`: steps 0, 5, 11). - A hit plays the drum's note in a drum part, the key's root in the part's octave in a tonal one. A note plays itself, a degree that step of the key's scale (`1` the root, `8` an octave up), a Roman numeral a chord of the key (`harmony`), its bass tone (`bass`, `melody`) or the chord a note at a time (`arp`). - Default octaves: bass 2, harmony 3, melody 4, arp 4. `oct=N` sets it. ### Generators | call | does | |---|---| | `e(k, n)` / `e(k, n, rot)` / `euclid(...)` | `k` hits over `n` steps, rotated by `rot`. As a term it takes one slot, so `kick e(5,8)` is a bar of eight steps and `kick x e(3,8)` puts the eight steps in the second half. `0 <= k <= n`, `1 <= n <= 64` ("Euclidean rhythms and polymeter"). | | `markov(key, density)` / `markov(density)` / `markov(key, density, seed)` | a Markov melody of one bar in the key's scale. The key is the program's `key` (or the section's) when left out. `density` 0..1. Same seed, same notes: the seed is, when left out, taken from the text of the part. | | `arp(chord, mode, n)` | the chord's notes one at a time over `n` steps (default 8) in `up`, `down` or `updown`. Either takes `shift=n`: its notes `n` key degrees up (-21..21; `up n` writes it). | | `chord(chord)` / `chord(chord, octave)` | the chord's notes together. A chord is a symbol (`am7`) or a numeral (`V7`). | | `choose [a b c] weights 3 1 1 [seed=4]` | one option a bar, picked by a hash, by weight (not a call: it has its own words, "Seeded chance"). | ### Parameters | param | value | does | |---|---|---| | `vel=90` / `vel=70..100` | 1..127 | velocity. A range gives each hit its own, by a hash of its place: the same text, the same velocities. | | `oct=2` | -1..8 | the part's octave. | | `len=3` | 1..16 | note length in steps (drums 1, tonal 2). | | `inst=sub-bass` | a name | the instrument. | | `seed=7` | a whole number | the seed of the part's generators (and of its chance terms, unless they say their own). | | `glide=70` `decay=900` `pitch-drop=7` | ms, ms, semitones | tonal: `^` bends into the next note; each note's tail; starts 7 semitones high. On `inst=acid-bass` a `^` slides without `glide=` (60 ms) and `decay=` is its filter's sweep. | | `cutoff=400` `res=80` `env=60` `accent=90` `drive=20` | Hz 20..12000, then 0..100 each | tonal, the acid voice's knobs: the filter's floor, its resonance, how far each strike opens it (100 is 6 octaves), how much an accent `!` does, how hard the oscillator drives the filter. Defaults 300, 72, 45, 80, 0. On any other voice they are ignored, with a warning. | | `voice-lead` / `voice-lead=off` | on or off | a `harmony` (or `arp`) part of chords: each chord after the first is voiced for the least motion from the one before; bare, it is on. | A **range** `a..b` is *any value from a to b*, only ever for a parameter of a part. A **ramp** `a -> b` is *moving from a to b*, only for a control change, with `over N bars` (or beats). ### Settings `tempo 126` (BPM, 40..300), `swing 0.1` (0..1), `key am`. A setting applies to the whole program. `key` is the default for notes with no octave, scale degrees, Roman numerals, `markov`, and the key tag the share carries. No `key`: C major. No `tempo`: the decks keep theirs. ## Control ```text master: filter lp 2k deck A: filter hp 400 master: filter off master: delay 0.4 master: reverb 0.3 / crush 0.5 / drive 0.6 master: level 0.8 deck A: level 0.7 / low 0 / mid / high duck B under A.kick 6db mix { A level 0.7, A eq low -3 } deck B: sing "words" on melody at bar 16: tempo 128 -> 140 over 4 bars macro riser on A over 8 bars ``` ### Time words | word | fires | |---|---| | (none) | once, on the first bar line after the statement is added or changed (in a `section`: on its first bar); a value that names an input (`knob(1)`) follows it on every bar | | `every 16 bars:` | on bars 16, 32, 48 ... (never on bar 0) | | `every 2 beats:` | every half bar, from the program's first bar: at 1/2, 1, 1 1/2 ... of a bar (never at 0). The finest is `every 1/64 bar` | | `every 4 bars from 8:` | on bars 8, 12, 16 ... (`from` takes a bar, a fraction of one, or a position: `from bar 3 beat 2`) | | `on next phrase [8\|16\|32]:` | once, on the first bar that is a multiple of 8 (or 16, 32) | | `at bar 32:` | once, on bar 32 (in a `section`: bar 0 is its first bar, so `at bar 4` is the fifth) | | `at bar 16 beat 3:` | once, on the last quarter of bar 16 (beats count from 0: `beat 4` is an error, write `at bar 17`) | | `after drop:` | once, on the bar the section `drop` ends on | | `before drop 4 bars:` | once, four bars ahead of the section: the roll that leads into a drop (`before drop 2 beats:` is a half bar ahead) | | `for 4 bars` / `for 2 beats` | after any of the above: the effect is **put back** after that long (`for 4 bars:` alone is now) | ## The whole surface: `do` ```text do [] [] key=value ... [over N bars [shape]] ``` ```text every 16 bars: freeze phrase bars=2 at bar 8 for 4 bars: trick on deck=A kind=stutter do vocoder set mix=0 -> 1 over 8 bars ``` ### The wheel ```text wheel load preset=NAME # an instrument, by its id from `do wheel presets` wheel key root=C transpose=2 # the key every note is re-wound for: root C, F#3, Bb2 ..., transpose -24..24 wheel sequence notes="C E G B" # the notes the path plays, in order; without notes, the preset's own wheel motor on=true speed=2 # a cord instrument's motor: on / off, speed in m/s (0..25) wheel level db=3 # the wheel's level, dB -20..40 wheel play wheel pause ``` A wheel line takes a time head like any other (`at bar 16: wheel play`). The browser engine on beatscript.app plays the wheel too, the same instrument as the booth: the wheel goes into the master after the decks, so `master:` filter, reverb and level reach it. ## Functions and structure - **`let name = ...`** at the top. One token (`8`, `c2`, `am`) is a value put in place of every later use of the name (so `at bar late:` and `bass root` work, and the canonical text shows the value). More tokens are a pattern, used as `bass kicks`, in `` alternations, in `[a, b]` stacks and as the pattern a transform takes. **Arithmetic** that is the whole value is a number: `let n = 2 * 4` is 8 (an earlier scalar may be used in it: `let m = n + 1`); `let r = 3*2` is the number 6, the degree 3 twice is `let r = [3 3]`. A section expression names a composition (`let verse = stack(groove, wash)`). A name cannot be a word of the language, a note, a chord, a key or a Roman numeral (`let kick`, `let a` and `let vi` are errors). - **`def name(a, b) { ... }`** is a macro: its body is lines, and `$a` is where an argument goes. A call `name(x, y)` is a line, with `at bar N:` / `after X:` / `before X N bars:` or none. The body is read when it is called, so an error in it says where in the def and which call. **A def that calls itself, directly or through another def, is an error** (`ping -> pong -> ping`) found before anything runs. A def may declare a **boundary** (`def walker(oct) in: chords, key out: bass { ... }`) and be glued to others with `wire`: typed ports, below. - **`repeat N { ... }`** with `N` written out (1 to 64). `repeat 8 every 2 bars { ... }` shifts copy `i` by `i * 2` bars; `$i` and `$n` are the index and the count, and are put in place before an expression is read (`at bar $i * 2 + 1`). Written out, a program is at most 4096 lines ("Bounds on the text"). A def's body may have a `repeat` of its own: its `$i` and `$n` are the repeat's. - **`when` guards** end a line (`drop(A, 8) when $i != 0`, `deck A: kick x ~ x ~ when $i % 4 == 3`): the line is kept in the copies where the condition holds and removed, before it is checked, in the others. They see `$i`, `$n` and a def's `$params` ("Guards", above). - **`section name N bars { ... }`** and **`arrange a b c`**: the song is the sections in that order (a section may be named twice; without `arrange`, in the order written). A section is 1 to 256 bars, and its body is statements, one to a line (`{` ends the line it is on; a block of a `def` or `repeat` may be on one line, a section's may not). Lines outside every section apply to the whole song, a section's own part of the same role wins, and a deck a section does not use is stopped there. After the last section the last nets play on. `section` and `arrange` belong at the top, not inside another block. `arrange` also takes `stack(...)`, `then(...)` and `silence` ("Composition: stack and then"). A section may open with a `key` of its own and may set a `tempo`. ### Ending | line | does | |---|---| | `end after outro` | where the section `outro` ends (the song stops there, later sections never play) | | `end at bar 64` | on bar 64 of the song (of the program, with no sections) | | `loop` | at the song's end it starts again from the first section, its `at` lines firing again each lap | | `arrange set: drop wubs then close` | a named arrangement that goes on to another one (below) | | `arrange set: drop wubs loop` | a named arrangement that repeats itself for ever: the song's lap starts at it, not at the first section | | `launch drop on pad(2)` | a hit of pad 2 brings in the section (or arrangement) `drop` on the next phrase line, where it loops; `next bar` or `next phrase 16` set the line | | `arrange close: outro end` | a named arrangement that ends the song | | `start set` | the arrangement that plays first (default: the first written) | ### Evolving ```text section drop 32 bars { deck B: melody [a4 c5 e5 g5] | bass [a2 ~ e2 ~] deck A: kick x ~ x ~ | hihat x*8 evolve every 8 bars { melody: rotate 1 | transpose <0 5 7 0> hihat: thin 0.1 seed=3 bass: invert when gen % 2 == 1 stop when gen == 3 } } ``` | transform | does | |---|---| | `rotate n` | every hit `n` steps (sixteenths) along its bar, wrapping | | `reverse` | the steps of a bar backwards | | `transpose n` / `octave n` | pitches up `n` semitones / octaves (tonal parts; a drum's note is the drum) | | `invert` | pitches turned over about the part's first note (tonal parts) | | `thin p [seed=s]` | drops the share `p` of the hits, picked by a hash of (seed, generation, bar, step, note): the same seed, the same hits | | `fill p [seed=s]` | each step of a bar with no hit on it takes, with chance `p` (a hash of seed, generation, bar and step), a copy of the hits of the step before it that has some; a bar with no hits stays empty | | `slow n` | the first `1/n` of each bar played over the whole of it: a hit at step `s` moves to `s*n` (its length with it), what would fall past the bar's end is gone (`n` 1 to 16) | | `fast n` | each bar played `n` times in the time of one: a hit at `s` lands at `s/n` and again every `16/n` steps (`n` 1, 2, 4, 8 or 16) | ### Pattern transforms | call | does | |---|---| | `transpose(p, n)` / `octave(p, n)` | `n` semitones / octaves up (a hit in a tonal part is its root first) | | `reverse(p)` / `rotate(p, n)` | the steps backwards / moved `n` steps along | | `every(n, p)` / `every(n, p, q)` | `p` on every `n`th bar (the 4th, 8th ...), `q` (or a rest) on the others | | `degrade(p, a)` / `degrade(p, a, seed)` | drops the share `a` of the hits: seeded, so the same text is the same hits | | `slow(p, n)` / `fast(p, n)` | `p` stretched over `n` bars / played `n` times a bar | | `humanize(p, seed)` / `humanize(p, seed, amount)` | velocities wander by up to `amount` (default 10), seeded | | `maybe(p, prob)` / `maybe(p, prob, seed)` | keeps each hit of `p` with chance `prob` (0 to 1): `p` with `?prob` on every hit | | `rests(p)` / `rests(p, q)` | a hit on each step where `p` rests / `q` kept there | | `ply(p, n)` | each step of `p` `n` times in its slot (`*n` on each) | | `palindrome(p)` | `p`, then `p` backwards: `<[p] reverse(p)>` | | `iter(p, n)` | `p` a `1/n` of its steps later each bar | | `off(p, n)` / `off(p, n, k)` | `p` and a copy `n` steps later (`k` semitones up) | | `poly(p, q ...)` / `poly(n, p, q ...)` | each walked `n` steps a bar (the first's count when left out), stacked | Marks touch their step: `c2!` an accent (velocity +27), `x.` a ghost (40%), `e2^` a slide (held into the next step; with `glide=` it bends), `x&` a flam, `x:3` a ratchet (3 hits in the sixteenth, 2 to 8). Not `!` with `.`. ### Arrange mutations ```text arrange { intro build drop ~ acid_a rot 2, hoov_a up 3 # from here on wubs build2 ~3 acid_* drift 0.15 # a glob, on every 3rd pass only peak @ hoov_b rev # the next section only @ control off # the control deck: none of its lines fire in the next section outro } loop 4 then outro end ``` | op | does (to the pattern's steps: see **The steps** below the table) | |---|---| | `rot n` / `rev` / `swap` / `mirror` / `shuffle` | rotate `n` steps later / backwards / swap neighbours / the first half, then backwards / a seeded permutation | | `thin p` / `fill p` / `euclid k` | each sounding step rests with chance `p` / each rest takes the step before it with chance `p` / the hits re-spread as `k` Euclidean hits | | `half` / `double` / `stutter n` | the first half at half speed / the pattern twice in the bar / the first `1/n` of it `n` times | | `ratchet p` / `swing amt` | a sounding step struck twice with chance `p`: doubled on the grid (`*2`) when its step is longer than a sixteenth, else ratcheted inside it (`x:2`, again `x:4`, at most `x:8`), so no hit snaps / every second step later by `amt` of a step (on the sixteenth grid) | | `up n` / `down n` / `oct n` / `invert` / `drift p` | scale degrees of the `key` up / down / octaves / turned over about the first note / a step up or down with chance `p`. A Roman numeral moves by degrees too (in A minor `i` up 2 is `III`, the key's own triad there; `V7` up 1 is `VI7`) | | `vel n` / `accent p` | accents on the `n` strongest steps (`vel -n` takes `n` off) / an accent with chance `p` | | `morph b p` / `xfer b` / `mask b` | each step becomes `b`'s with chance `p` / `b`'s rhythm with these notes / rests where `b` rests | | `grow` / `decay` | one rest filled / one sounding step taken out (seeded; they pile up pass on pass) | | `voice n` / `spread` | each chord `[a3,c4,e4]` or `chord(am7)` inverted `n` times / its every second note an octave up | | `jux op` | the pattern stays the left copy, `op` of it plays hard right (`jux rev`) | Try [arrange-in-eight-lines](https://beatscript.app/examples/arrange-in-eight-lines.beatscript). ### Start from a seed ```text arrange from seed(techno, 42) the whole track section intro from seed(techno, 42)[1..8] bars 1 to 8 as a section deck B: bass seed(techno, 42).bass[17..24] inst=fm-bass a part's bars; your params win let riff = seed(techno, 42).bass[17..20] the same, named (say which part) arrange from seed@2(jazz, 7) seeds v2: the track, swung section hook from .drop a saved program's section (parts, key) deck B: bass .drop inst=hoover its part (the line's role; .melody another) arrange from template(deep-house, @tempest_such_stuff) a phrase as a track arrange from template(rondo, @hands_up, refrain=ode_to_joy) a form, a role bound: docs/forms.md ``` ### Sung lyrics **Found phrases:** pick a line for its meter: https://beatscript.app/docs/found-phrases.md ## Radio: stations **Radio:** a station is an endless program, track N always the same: `station { }` holds `from gen@2 techno seed=42` (track 0), `next seed=~` (the step) and `forms seeded rondo fugue` (in turn); MCP `station` and `POST /api/station` give track `n`, its segue and neighbours; MCP `artifact` with `station` makes a page: https://beatscript.app/docs/radio.md ## Sounds | param | takes | does | |---|---|---| | `inst=wobble-lead` | a voice | the part's instrument. An unknown name is an **error with the nearest names**; a family word (`inst=reese`) is accepted with a **warning** that it plays the generic saw bass, and which voices have a sound of their own. `inst=acid-bass` (or `inst=acid`) is a 303: `!` accents, `^` slides, `cutoff=` `res=` `env=` `accent=` `drive=` turn its knobs | | `kit=drums-808` | a kit | a drum part's kit (set once the net has landed) | | `sound=synth:wobble-lead` | `own`, `synth`, `synth:NAME`, `inst:NAME` | the role's sound option on the deck, set once the net has landed | ## On beatscript.app - Everything above checks here; `import` and `` need the program (a link carries it). `sample` checks (a local file needs `use restricted`), but a program with either is not public: never stored or rendered: only its inline link. - `loop`, the booth's lines (`move`, `swap pairs`, `load`, `sync`, `queue`, `crossfader`, `play`, `stop`, `mute`) and the sugar nouns (`wheel`, `trick`, `freeze`, `vocoder`, `vocal`) check. The browser engine plays `wheel` and `move` (every move but a `phrase_sync` that steps a seed); it does not play `swap pairs`, `load`, `sync`, `queue`, `macro` (`render` and `listen` do) or the other sugar nouns: the page lists each as "not played here". The grammar above leaves them and the DJ tier out (`solo drums`, `loop 4 beats`, `jump -8 beats`, `cue`: `needs: booth`). - `inst=` and `kit=` take what `/api/instruments` lists. - ✦generate (key G): the seeded generator, no model or sign-in; `[` `]` step the seed as it plays. --- Grammar, from the language reference (https://beatscript.app/docs/BEATSCRIPT.md): ## The rules in one screen - A program is **lines**. A line is blank, a `# comment`, or one statement. A line that starts with `|` continues the statement above it. - The first line is the version line, `#! beatscript 2`; a text without one is BeatScript 1 ("Versions"). - Words are lower case. Deck names are `A` and `B`. Numbers are plain: `5`, `0.7`, `2k` (= 2000), `50%` (= 0.5), and **wherever the language takes a number it takes arithmetic**: `tempo 120 + 6`, `at bar $i * 2 + 1`, `kick e($i % 4 + 1, 8)`. - A statement is `[when:] [target:] body [when guard]`. Each head ends in a colon, and they read left to right: *when* (`every 16 bars`), *whose* (`deck A`, `master`), then *what*; a trailing `when $i % 2 == 0` keeps the line only where the condition holds. - Time is **bars** (four beats), and a beat is a quarter of a bar: `over 2 beats`, `at bar 16 beat 3`. Seconds appear only where a sound or a check needs them (`attack=5ms`, `assert length == 3m30s`). A pattern is one **cycle** (one bar) long, and its terms share the cycle equally; `hihat/12` gives a part a cycle of its own. - Text in, same net out: the same program text always gives the same net CIDs and the same program CID. Everything is **total** (no recursion, every count written out) and **deterministic** (chance is a hash of the text and the bar; nothing reads a clock, a random source or the machine). - A mistake is an error with a line, a column, what was expected and the nearest name; the program is refused whole. ## Grammar (EBNF) The grammar is [`crates/djlive/grammar.ebnf`](https://beatscript.app/grammar.ebnf), the language's one source of truth. The block below is generated from it (do not edit it here), and so is the [Grammar page](https://beatscript.app/grammar), which draws every production as a railroad diagram. `crates/djlive/tests/grammar.rs` holds it to the parser both ways: every example program is a sentence of it, and every sentence it writes is a program the parser reads. `{ x }` zero or more, `[ x ]` optional, `( a | b )` choice, `"x"` a literal word or mark, `(* ... *)` a comment; an UPPER-CASE name that is no production is a kind of token (below). Whitespace separates tokens and is otherwise free; a line end ends a statement (except before `|`). ```ebnf (* == Programs and lines == *) program = { line } ; line = [ statement ] NEWLINE ; (* a comment is "#" to the end of the line; it is not a token *) statement = setting | headed | let | def | repeat | section | arrange | arrange_block | start | launch | import | end | loop | evolve | wire | assert | sample | cue | use | set | station ; (* == Settings == *) setting = "tempo" tempo | "swing" arith | "key" KEY ; (* a setting reads no input: it is the program's own *) tempo = arith [ "->" arith "over" dur [ shape ] ] ; (* tempo 126 tempo 100 -> 130 over 8 bars exp *) (* == Lines: when, where, what == *) headed = "deck" deck ":" parts [ guard ] | "at" pos [ "for" dur ] ":" "deck" deck ":" parts [ guard ] (* a placed part, in a section *) | [ timing ":" ] "row" ":" "clip" NAME { cparam } [ cguard ] (* an audio placement on the loop row *) | [ timing ":" ] [ target ":" ] control [ cguard ] | [ timing ":" ] "control" ":" ( engine | do | duck | mix ) [ cguard ] (* the control deck *) | [ timing ":" ] ( invoke | duck | mix ) [ cguard ] ; (* a def's call, a duck and a mix name their decks themselves *) timing = when [ "for" dur ] | "for" dur ; cparam = "crop" "=" arith ".." arith (* source beats: crop=32..64 *) | "gain" "=" arith | "fade" "=" ( "off" | "beat" | "bar" | time ) | "route" "=" "vocoder" [ ":" INT ] ; (* the vocoder's modulator; vocoder:2 .. 4 *) when = "every" dur [ "from" ( arith | pos ) ] (* every 16 bars every 2 beats every 4 bars from 8 *) | "on" "phrase" (* every 8 bars: a phrase *) | "on" "next" "bar" | "on" "next" "phrase" [ "8" | "16" | "32" ] | "at" pos (* once, on that place of the program *) | "after" NAME (* once, where that section ends *) | "before" NAME dur ; (* once, that long ahead of that section *) dur = arith ( "bar" | "bars" | "beat" | "beats" ) ; (* 4 bars 1/2 bar 2 beats *) pos = "bar" arith [ "beat" arith ] ; (* bar 16 bar 16 beat 3 a beat is 0 to 3 *) guard = "when" expr ; (* kept where it holds *) cguard = "when" cexpr ; (* a control line's guard may read an input *) target = "deck" deck | "master" ; deck = "A" | "B" | PARAM ; (* PARAM: in a def body, filled in when it is called *) control = action | engine | do | sing ; (* == Parts == *) parts = pitem { "|" pitem } ; (* only after "deck X:" and with no time word *) pitem = part (* each item between `|` has a part in it *) | "stack" "(" pargs ")" (* over parts: `stack` is `|` *) | "then" "(" pargs ")" ; (* over parts: the per-bar alternation

*) pargs = { pexpr "," } pitem { "," pexpr } ; pexpr = pitem | "silence" ; (* silence: the unit of both *) part = role [ "/" INT ] pattern { param } (* hihat/12 x x ~ x : a cycle of 12 sixteenths *) | role ref { param } ; (* bass seed(techno, 42)[17..24]: a generated part's bars; bass .drop: a stored program's *) role = "kick" | "snare" | "hihat" | "clap" (* drum parts: a hit plays the drum's note *) | "bass" | "melody" | "harmony" | "arp" ; (* tonal parts: a hit plays the key's root *) param = pname "=" pvalue (* vel=70..100 oct=2 len=3 inst=sub-bass glide=60 *) | "voice-lead" [ "=" ( "on" | "off" ) ] ; (* a switch, on when it is bare *) pname = "vel" | "oct" | "len" | "inst" | "seed" | "kit" | "sound" | "route" (* velocity, octave, length, voice, its generators' seed, a drum kit, a sound, where it plays *) | "glide" | "decay" | "pitch-drop" (* tonal, an 808: glide= decay= ms, pitch-drop= 1 to 24 semitones *) | "cutoff" | "res" | "env" | "accent" | "drive" ; (* the acid voice's knobs: cutoff= Hz 20 to 12000, the rest 0 to 100; not reserved words *) pvalue = arith [ ".." arith ] | WORD | PARAM ; (* a number, a range drawn per hit, a name; a $name in a body *) (* == Mini-notation: the rhythm of a part == *) pattern = term { term } ; term = atom [ mark ] [ "*" ( INT | "(" arith ")" ) ] { "?" [ prob ] } [ "~" INT ] ; (* x*4 c2! e2^ x:3 x*8?0.7 *) (* sugar: x? is x?0.5, c2~3 is c2 ~ ~ *) mark = ( "!" | GHOST ) [ "^" ] [ "&" ] [ RATCHET ] | "^" [ "!" | GHOST ] [ "&" ] [ RATCHET ] | "&" [ RATCHET ] | RATCHET ; (* accent ghost slide flam ratchet, any order *) atom = "x" (* a hit *) | "~" (* a rest *) | NOTE (* c3 f#2 bb4 *) | INT (* a scale degree of the key: 1 3 5 *) | "(" arith ")" (* a degree computed: ($i + 1) *) | degrees (* deg(1 b3 5' ~) *) | ROMAN [ "/" INT ] (* i VI V7/7: a chord of the key; /3 /5 /7 an inversion *) | PARAM (* a def's parameter: $chords *) | "[" pattern { "," pattern } "]" (* a group: squeezed into one slot; commas stack *) | "<" pattern ">" (* alternation: one term per cycle *) | choose (* choose [a b c] weights 3 1 1 *) | call | NAME ; (* a let pattern's name *) call = NAME "(" [ arg { "," arg } ] ")" ; (* e(5,8) markov(0.6, shift=2) arp(am7, up) chord(am) maybe(p, 0.5) *) arg = arith | KEY | CHORD | ROMAN [ "/" INT ] | NAME | NAME "=" ( arith | WORD ) | "[" pattern "]" | degrees | call | PARAM ; (* a chord of chord() and arp(): a symbol (am7) or a numeral (V7 bVII V7/7), the numeral read in the key in force *) (* == Degrees, Roman numerals, chance == *) degrees = "deg" "(" dstack ")" ; (* one slot, its terms squeezed into it like [..] *) dstack = dseq { "," dseq } ; dseq = dterm { dterm } ; dterm = dleaf [ mark ] [ "*" INT ] | "~" | "x" | "[" dstack "]" | "<" dseq ">" | "(" ( dterm | arith ) ")" ; dleaf = ( INT | SDEG ) { "'" } { "," } ; (* 5' an octave up, 1, down; b3 flat, #4 sharp *) prob = NUMBER | "(" arith ")" ; (* 0 to 1, or a percent: ?0.3 ?30% ?(1 / 4) *) choose = "choose" "[" pattern "]" "weights" weight { weight } [ "seed=" INT ] ; (* one weight for each option *) weight = NUMBER | "(" arith ")" ; (* == Control: what the mix does == *) action = "filter" ( "lp" | "hp" ) change (* hertz: 20 .. 20k *) | "filter" ( "off" | "open" ) | ( "delay" | "reverb" | "crush" | "drive" | "resonance" ) change (* 0 .. 1: how much *) | ( "level" | "low" | "mid" | "high" ) change (* deck X: / master: level *) | "load" SPEC (* deck X: *) | "play" | "stop" | "sync" | "mute" | "unmute" | ( "mute" | "unmute" | "solo" ) ( STEM | role ) (* deck X: a stem (solo mutes the other three), or one part by its role [booth] *) | "loop" ( arith "beats" | "off" ) (* deck X: a slip loop, `for` lets go [booth] *) | "jump" ( arith ( "beats" | "bars" ) | NAME "." NAME ) ; (* deck X: a beat jump, back when negative; or to a cue point [booth] *) STEM = "drums" | "bass" | "vocals" | "other" ; (* a net deck's: its drum roles, bass, the melody (the lead), the rest *) engine = "crossfader" change (* no target, or control: *) | "tempo" tempo (* at bar 16: tempo 128 -> 140 over 4 bars *) | "swap" "pairs" [ "with" MOVE ] (* the booth's: the desktop app plays these *) | "move" MOVE "on" deck [ span ] | "load" "pair" SPEC [ "group" INT ] | "queue" ( "play" | "pause" | "stop" | "next" | "loop" | "jump" INT | "add" WORD ) | MACRO NAME ( "on" deck [ span ] | span "on" deck ) ; (* macro riser on A over 8 bars: the DJ macro catalogue, by id; MACRO is macro or macro@1 *) change = value (* a plain value *) | value "->" value span [ shape ] (* a ramp: 2k -> 8k over 8 bars exp *) | lfo ; (* a value that keeps moving *) span = "over" dur ; value = carith ; (* a control's value may read inputs: 200 + knob(3) * 7800 *) MOVE = "filter_exit" | "echo_out" | "loop_roll" | "bass_swap" | "phrase_sync" | "vocoder_handoff" ; SPEC = NAME ":" INT | NAME ; (* dnb:2602 acid-bass *) do = ( "do" WORD | SUGAR ) [ WORD ] { STRING } { NAME "=" doval } [ span [ shape ] ] ; (* the control registry: noun, verb; SUGAR: a noun said with no `do` (vocoder, freeze, wheel ...) *) doval = arith [ "->" arith ] | WORD | STRING | "[" [ doval { "," doval } ] "]" | lfo ; (* == Shapes and lfo == *) shape = "linear" | "exp" | "log" | "s-curve" | "step" INT ; lfo = "lfo" wave dur { "depth=" value | "center=" value | "phase=" NUMBER } [ span ] ; (* lfo sine 2 bars center=3k depth=1k *) wave = "sine" | "tri" | "square" | "saw" ; (* == Arithmetic and guards == *) arith = sum ; (* worked out once, when the program is read, over exact rationals *) sum = product { ( "+" | "-" ) product } ; product = unary { ( "*" | "/" | "%" ) unary } ; (* "/" is exact; "%" is Euclidean *) unary = [ "-" ] primary ; primary = NUMBER | PARAM | "(" arith ")" | ( "min" | "max" ) "(" arith { "," arith } ")" ; carith = csum ; (* arithmetic that may read inputs: only in a control *) csum = cproduct { ( "+" | "-" ) cproduct } ; cproduct = cunary { ( "*" | "/" | "%" ) cunary } ; cunary = [ "-" ] cprimary ; cprimary = NUMBER | PARAM | "(" carith ")" | ( "min" | "max" ) "(" carith { "," carith } ")" | input ; expr = or ; (* a guard: kept when it is true *) or = and { "or" and } ; and = not { "and" not } ; not = [ "not" ] compare ; compare = operand [ cmp operand ] ; (* words compare with == and != only *) operand = sum | WORD ; cexpr = cor ; (* a control line's guard *) cor = cand { "or" cand } ; cand = cnot { "and" cnot } ; cnot = [ "not" ] ccompare ; ccompare = coperand [ cmp coperand ] ; coperand = csum | WORD ; cmp = "==" | "!=" | "<" | "<=" | ">" | ">=" ; input = "knob" "(" INT ")" | "pad" "(" INT ")" | "fader" "(" deck ")" (* performed: only in a control value or guard *) | "held" "(" "key" ")" | "held" "(" PITCH ")" ; (* PITCH: a note with its octave, c4 *) (* == Structure: lets, defs, sections, the arrangement == *) let = "let" NAME "=" ( sexpr | arith | ref | TOKEN { TOKEN } ) ; (* one token is a value; more tokens are a pattern *) def = "def" NAME "(" [ NAME { "," NAME } ] ")" [ "in" ":" type { "," type } ] [ "out" ":" type { "," type } ] "{" { def_line } "}" ; (* $NAME inside, filled in when it is called *) def_line = [ statement | emit ] NEWLINE ; (* a def's body line; `emit` says what an out port carries *) invoke = NAME "(" [ tokens { "," tokens } ] ")" ; (* a def's call *) tokens = TOKEN { TOKEN } ; repeat = "repeat" INT [ "every" INT "bars" ] "{" { body_line } "}" ; (* the count is written out, 1 to 64 *) body_line = [ statement ] NEWLINE ; (* a repeat's body line: $i is the pass, 0 up *) section = "section" NAME INT "bars" "{" { line } "}" (* 1 to 256 bars; a `key` may open the body *) | "section" NAME "from" ref ; (* section intro from seed(techno, 42)[1..8] section hook from .drop *) arrange = "arrange" sexpr { sexpr } | "arrange" NAME ":" sexpr { sexpr } [ arr_end ] (* with a NAME it is one of several arrangements *) | "arrange" "from" ( seed | template ) (* the whole of a generated track: arrange from seed(techno, 42), or of a phrase: arrange from template(deep-house, @tempest_such_stuff) *) | "arrange" "from" gen ; (* the whole program a generator call prints: arrange from gen@2 techno seed=42 *) arr_end = "then" NAME | "loop" [ INT ] | "end" ; (* only after a NAME: see "Several arrangements" *) start = "start" NAME ; (* the named arrangement that plays first; default the first written *) launch = "launch" NAME "on" "pad" "(" INT ")" [ "next" ( "bar" | "phrase" [ "8" | "16" | "32" ] ) ] ; (* a hit of the pad brings the scene, a section or an arrangement, in on that bar line: 8 bars by default *) sexpr = NAME (* a section, or a let that names a composition *) | "silence" (* the empty section *) | "stack" "(" sexpr { "," sexpr } ")" (* at the same time *) | "then" "(" sexpr { "," sexpr } ")" ; (* one after another *) end = "end" [ "at" "bar" INT | "after" NAME ] ; (* a song ends after its last section by default *) loop = "loop" ; (* a song starts again at its end *) (* == Arrange mutations == *) arrange_block = "arrange" "{" { arr_gap } NAME { arr_gap | NAME } "}" [ block_end ] (* at least one section; see "Arrange mutations" *) | "arrange" NAME ":" "{" { arr_gap } NAME { arr_gap | NAME } "}" [ arr_end ] ; (* a named arrangement with mutations *) arr_gap = NEWLINE | "," | mutation NEWLINE ; (* a mutation runs to the end of its line *) mutation = ( "~" | "@" ) [ INT ] ( switch | mut_target mut_op { "|" mut_op } { "," mut_target mut_op { "|" mut_op } } ) ; (* ~ from here on, @ the next section only; ~3: every 3rd pass *) switch = "control" [ NAME ] ( "on" | "off" ) ; (* the control deck's lines fire or not: all of them, or one call's (~ control freeze off); a line of its own *) mut_target = GLOB | NAME ; (* a let pattern, or a glob: acid_* *) mut_op = NAME { NUMBER | "-" NUMBER | NAME } ; (* rot 2 thin 0.1 oct -1 morph b 0.5 jux rev: the operators of "Arrange mutations" *) block_end = "end" | "loop" | "loop" INT [ "then" { NAME } "end" ] ; (* default end; loop N: 1 to 256 passes, then a coda *) (* == Start from a seed == *) ref = seed | gen | stored ; (* music from elsewhere, written out as BeatScript before the program is read *) seed = SEED "(" NAME "," INT [ "," structure ] ")" [ "." role ] [ "[" INT [ ".." INT ] "]" ] ; (* a track of the beats generator: genre, seed; a part, bars from 1; SEED is seed (seeds v1) or seed@2 (v2: with its genre's swing) *) stored = CID [ "." NAME ] [ "." role ] ; (* a saved program's section or part, by its CID: .drop .drop.bass; a bare is a program with no sections [host] *) gen = GEN NAME "seed" "=" ( INT | NAME ) { gen_param } ; (* gen@2 techno seed=42 section=drop part=bass: the seeded generator, called; GEN is gen@2 or a bare gen [host] *) gen_param = "bpm" "=" NUMBER | "key" "=" KEY | "length" "=" ( "short" | "standard" | "long" ) | "section" "=" NAME | "part" "=" role ; structure = "standard" | "loop" | "minimal" | "extended" ; (* the generator's song structures; standard is the default *) (* == Phrase templates == *) template = "template" "(" NAME "," ( PHRASE | STRING | NAME ) { "," binding } ")" ; (* a template's name and a phrase, a phrasebook id or words in quotes (NAME: one a `use phrase` line named): the phrase is the vocal line of a track; then a form's roles *) binding = NAME [ "." role ] "=" ( source | [ "-" ] INT ) ; (* a role of the form and what fills it: ground=gen@1 dubstep seed=54876 part=bass; one part of a seed role: a.bass=[d2 ~ a1 ~]; a form's number: delay=6 interval=-12 *) source = gen | NAME | notes | form | stored | track ; (* an engine call; a public-domain theme by id (ode_to_joy); notes; another template, or one section of it; a stored program's part or sections; a stored set's track *) notes = "[" pattern "]" | "<" "[" pattern "]" { "[" pattern "]" } ">" ; (* a bar, or bars one after another *) form = "template" "(" NAME { "," binding } ")" [ "." NAME [ "." role ] ] ; (* a form inside another takes no phrase: forms nest 3 deep; .both is one of its sections, .both.arp that section's part *) track = CID "." NAME [ "." NAME ] [ "." role ] ; (* a stored set's track by number: .track2, its section .track2.drop, its part .track2.drop.bass [host] *) (* == Evolving == *) evolve = "evolve" "every" INT "bars" "{" { NEWLINE } { rule NEWLINE { NEWLINE } } [ bound NEWLINE { NEWLINE } ] "}" ; (* a rule a line; the bound last *) rule = ( role | "deck" deck ) ":" op { "|" op } [ "when" "gen" [ "%" INT ] cmp INT ] ; op = ( "rotate" | "transpose" | "octave" | "invert" | "reverse" | "thin" | "fill" | "slow" | "fast" ) { NUMBER | "<" NUMBER { NUMBER } ">" } [ "seed=" INT ] ; (* seed= on thin and fill *) bound = "stop" "when" "gen" ( "==" | ">=" | ">" ) INT | "for" INT "gens" ; (* == Typed ports == *) type = "chords" | "key" | "bass" | "melody" | "drums" | "rhythm" | "bars" | "tempo" | "pattern" ; emit = "emit" [ type | "out" ] tokens ; (* a line of a def body: what an out port carries *) wire = "wire" NAME "." port "->" NAME "." port ; (* at the top: wire changes.out -> walker.chords *) port = type | "in" | "out" ; (* == Mix moves and sung lyrics == *) duck = "duck" deck "under" deck "." role db { "attack=" time | "release=" time } ; mix = "mix" "{" { NEWLINE } mixitem { ( "," | NEWLINE ) { NEWLINE } mixitem } { NEWLINE } "}" ; (* in a section: put back where the section ends *) mixitem = deck "level" arith | deck "eq" band arith [ "db" ] | "master" "level" arith | deck "pan" arith ; band = "low" | "mid" | "high" ; db = DECIMAL "db" ; (* glued: 6db *) time = DECIMAL ( "ms" | "s" ) ; (* glued: 5ms *) sing = "sing" ( lyric | PHRASE | NAME ) "on" role { "bars=" INT | "key=" KEY | "voice=" NAME } ; (* a tonal role; PHRASE: a phrasebook id, @hands_up; NAME: a phrase a `use phrase` line named *) lyric = STRING ; (* its text is lyric_text; docs/beatscript/phonemes.md *) lyric_text = { TEXT | "/" SPACE | escape } [ "/" { TEXT } ] ; (* "/" and a space is a phrase break; "/" and a phoneme opens an escape, to the next "/" (with none, a break too); a word touching "=" before an escape is its label, kept and not sung: jingle=/j ii ng g uh l/ *) escape = "/" PHONES "/" ; (* PHONES (beatscript-v1): aa ae uh aw eh er ii ee uu oo ay ie oy ow oh p b t d k g f v s z sh zh th dh h m n ng l r w y ch j, "_" a rest, "-" cuts a word, ":" holds a vowel one more note, "!" accents it *) (* == Assertions == *) assert = "assert" ( "ends" | "period" [ "(" NAME ")" ] cmp INT | "length" ( ( "==" | "!=" ) clock [ "±" clock ] | ( "<" | "<=" | ">" | ">=" ) clock ) | "level" leveldeck cmp levelexpr [ "in" NAME ] | "key" ( "==" | "!=" ) KEY [ "in" NAME ] | "never" subject ( "beside" | "during" ) subject [ "in" NAME ] (* assert never A.snare beside A.snare assert never B during sing: refused where it is false *) | subject "ends" "on" INT [ "in" NAME ] ) ; (* assert bass ends on 1: the lowest note of its last onset is that degree of the key *) subject = "sing" | ldeck | [ ldeck "." ] role ; (* sing: the vocal; a deck; A.snare; bass on both decks *) clock = DECIMAL "m" [ DECIMAL "s" ] | DECIMAL "s" | DECIMAL "ms" ; (* 3m30s 90s 500ms *) leveldeck = { lfactor lop } ldeck { lop lfactor } ; (* a level read: it names a deck *) lop = "+" | "-" | "*" | "/" ; ldeck = "A" | "B" | "master" ; levelexpr = lterm { ( "+" | "-" ) lterm } ; (* arithmetic over the words A, B and master: their levels *) lterm = lfactor { ( "*" | "/" ) lfactor } ; lfactor = NUMBER | ldeck | "(" levelexpr ")" ; (* == Sets, samples, imports == *) set = "set" "{" { NEWLINE } { ( set_play | set_mix | set_next ) NEWLINE { NEWLINE } } "}" ; (* programs of programs: an item a line *) set_play = "play" ( NAME | STRING | gen ) [ "until" until_when ] ; (* a saved program, its CID in the canonical text, or a generator call [host] *) set_next = "next" step [ "until" until_when ] ; (* the track before it, a generator call, with its seed stepped [host] *) until_when = TIME | "bar" INT | NAME | "after" NAME ; (* a time, a bar of the track, a section's start or end *) set_mix = "mix" INT ( "bar" | "bars" ) "with" TRANSITION [ "," "tempo" NUMBER "->" NUMBER ] ; TIME = DECIMAL UNIT { DECIMAL UNIT } ; (* units glued: 20m 90s 1h 3m30s *) TRANSITION = "crossfade" | "filter_exit" | "echo_out" | "cut" ; (* == Radio: stations == *) station = "station" "{" { NEWLINE } { station_line NEWLINE { NEWLINE } } "}" ; (* endless and deterministic: position N is always the same track [host] *) station_line = "from" gen | "next" step | "forms" NAME { NAME } ; (* the first track's call; the step from a track to the next; the forms in turn *) step = "seed" "=" ( "+" INT | "~" ) ; (* seed=+1 counts on; seed=~ draws from a hash of the track before's CID *) import = "import" ( NAME | STRING ) ; (* a snippet's name in quotes, or its CID [host] *) sample = "sample" NAME "from" STRING [ "license" license ] [ "else" NAME ] | "loop" STRING "as" NAME [ "else" NAME ] ; (* restricted sounds: a local file, an Apple Loop by its hash *) license = "cc0" | "cc-by" | "all-rights-reserved" | "restricted-private" ; cue = "cue" NAME "." NAME "at" pos ; (* cue tune.drop at bar 32 beat 2: a named place in a sample [booth] *) use = "use" "restricted" (* the program is private: it may use restricted assets *) | "use" use_source "as" NAME ; (* a name for a source, written out where it is used (docs/beatscript/ext-roles.md) *) use_source = stored (* .drop: a section; .drop.bass: a line; : a source for a role *) | gen (* gen@2 techno seed=42 section=drop, part=bass: a section or a line; with neither, a source for a role *) | "template" "(" NAME { "," binding } ")" [ "." NAME ] (* template(passacaglia, ground=...): a form, for a role; .ground: a canned section of it *) | template "." NAME (* template(deep-house, @tempest_such_stuff).night: a canned section, sung with that phrase *) | "theme" NAME (* a theme of the public-domain library: a line, in the program's key *) | "phrase" PHRASE (* a phrasebook line: a phrase, for sing and template *) | GENRE NAME "." NAME ; (* genre@1 techno.drop: a section of a genre template, frozen *) ``` `NAME` is a lower-case word (letters, digits, `_`, and `-` between letters), `WORD` any word. `INT` is a whole number (arithmetic that comes to one is fine: `repeat 2 + 1`); `NUMBER` also takes a fraction and the `k` / `%` marks, and `DECIMAL` is a number with no mark, before a glued unit (`UNIT`: `6db`, `5ms`, `2s`, `3m30s`, `1h30m`; `hz` after a filter's cutoff, `filter lp 300hz`, is the number and nothing else; the hours of `1h` are read only after a set's `until`). `NOTE`, `PITCH` (a note with its octave), `KEY`, `CHORD` and `ROMAN` are pitch words read as one token (`f#2`, `c4`, `d:dorian`, `am7`, `ii°`); `SDEG` a written degree in `deg( )` (`b3`, `#4`); `PARAM` a def's or a repeat's `$name`; `SUGAR` a control noun said without `do`; `STRING` a double-quoted string; `TOKEN` any token; `GLOB` a name with `*` in it; `CID` a saved program's id; `SEED` `seed` or `seed@2`; `GHOST` a ghost's `.` and `RATCHET` a ratchet's `:N` (`x.` `x:3`). `±` may be written `+-` after a unit (`3m30s +- 5s`). In a lyric, `PHONES` is an escape's text: `aa ae uh aw eh er ii ee uu oo ay ie oy ow oh p b t d k g f v s z sh zh th dh h m n ng l r w y ch j`, `-` cuts a word, `_` rests, `:` holds a vowel, `!` accents it; `/` and a space: a phrase break. A phrase's `NAME` is one `use phrase @id as NAME` gave; `use theme ode_to_joy as tune` names a theme ("Name a source"). Some marks must **touch** the token before them, because a space would change what they mean: `hihat/12`, `x?0.3`, `A.kick`, `6db` `120ms` `3m30s`, `e2!` `c2^` `x.` `x&` `x:3`, the octave marks of `deg( )` (`5'` `1,`), and the two-mark comparisons `==` `!=` `<=` `>=`. A space where they must touch is an error that says so. Everywhere else whitespace is free. `%` is the percent mark when it follows a digit with no space (`50%`) and the modulo operator otherwise: write `$i % 4` with spaces. The header lines of a `.beatscript` file are comments to the language, all but the version line, and have a grammar of their own (F14): ```text #! beatscript 2 the version line ("Versions"): BeatScript 2; none, or #! btw 1, is BeatScript 1 #! genre: techno one genre of the BeatScript ontology: a name, genre:techno, bw:Techno or an IRI #! tags: acid, four on floor, drop terms of it, by local name, label or IRI ``` The productions were read against the parser (where a long note and the parser disagreed, the parser won), and the examples of the feature sections below are lines of the programs in `examples/beatscript/`, every one of which `crates/djlive/tests/examples_beatscript.rs` compiles. ### Which target takes which action | action | no target | `deck A:` / `deck B:` | `master:` | `control:` | |---|---|---|---|---| | a part line (`kick x ~ x ~`) | — | yes (a time word only as `at bar N [for M bars]:`, inside a section: a placed part) | — | — | | `swap pairs`, `move`, `load pair`, `queue`, `crossfader` | yes | — | — | yes | | `load SPEC`, `play`, `stop`, `sync`, `mute`, `unmute` | — | yes | — | — | | `mute STEM`, `unmute STEM`, `solo STEM`, `loop`, `jump` (the DJ tier) | — | yes | — | — | | `filter`, `delay`, `reverb`, `crush`, `resonance` | — | yes (that deck's insert) | yes (the Master's) | — | | `drive` | — | yes (that deck's drive) | yes (both decks' drive) | — | | `level`, `low`, `mid`, `high` | — | yes (the strip) | `level` only (the master level) | — | | `tempo` | yes (a place, not a repeat) | — | — | yes (with a time word) | | `duck`, `mix` | yes (they name their decks) | — | — | yes | | `sing "words" on melody` | yes (the only deck that has the role) | yes | — | — | | a `def`'s call | yes (the deck is an argument) | — | — | — | A line that puts an action on a target that does not take it is an error that says which targets do. `control:` is the control deck ("The control deck"): a head in the place of a target, for the engine calls only. --- Example program "markers-demo" (CC0-1.0, https://beatscript.app/examples/markers-demo.beatscript): ```beatscript #! beatscript 2 #! name: markers-demo #! license: CC0-1.0 #! visibility: public tempo 124 key am let kk = x ~ ~ ~ x ~ ~ ~ x ~ ~ ~ x ~ ~ ~ let hh = ~ ~ x ~ ~ ~ x ~ ~ ~ x ~ ~ ~ x ~ let riff = a2 ~ a2 a2 ~ c3 ~ a2 e2 ~ e2 g2 ~ e2 ~ e2 let lead = <[e5 ~ ~ ~ d5 ~ c5 ~ ~ ~ ~ ~ a4 ~ ~ ~] [~ ~ ~ ~ a4 ~ ~ ~ c5 ~ ~ ~ e5 ~ ~ ~]> def groove(deck, bars) { deck $deck: kick kk | hihat hh vel=70..95 | bass riff inst=wobble-lead repeat $bars every 1 bars { master: filter lp 300 -> 2800 over 1 bars } } section build 8 bars { deck A: kick kk | hihat hh master: filter hp 100 -> 5000 over 8 bars } section drop 16 bars { groove(A, 16) deck B: melody lead inst=pwm-lead evolve every 4 bars { melody: rotate 2 | transpose <0 5 7 0> stop when gen == 3 } at bar 2: master: reverb 0.3 } arrange build drop ```