Aratu music written to play, and to change while it plays

5. From text to sound

▶ Open in Aratu to hear and change the examples

When you edit, the text goes through these stages, each in a module of the compiler (written in Rust and brought to the browser as WebAssembly):

  1. Lexing. The text is cut into lines, blocks and words.
  2. Gathering. Motifs, rows, lists and the key are collected first, so a line can use them from anywhere in the text.
  3. Parsing. Each line becomes a statement in a syntax tree (AST), with the exact place each piece is written, for the messages and for lighting the notes.
  4. Model. The statements become parts, lines, patterns, sections and orders, with the checks: whether each bar fits the meter, whether the names exist.
  5. Unrolling. Repeats, jumps, % and x4 become a plain sequence of bars.
  6. Dynamics and time. Each note gets its strength, and positions become seconds through the tempo map. Positions are exact fractions: a triplet is 1/3 of a beat, with no rounding.
  7. Scheduling. For the bars asked for, out come the events: each note, each hit, each parameter change, with its moment in seconds.

Scheduling is deterministic: the same text, the same seed and the same starting bars always give the same events. That is why the player can ask for one bar at a time, a little before it sounds, and an edit can come in at the next bar without anything starting over.

The events go to the audio engine. Recorded sounds and drum kits play on Manguebyte's engine (an AudioWorklet running WebAssembly); the others on the stand-in engine built with the browser's Web Audio.