17.4. Mini-notation tokenizer, parser, and fluent-DSL entry points

Module strudel_mini

17.4.1. Enumerations

TokenKind
Values:
  • WORD = 0 - Identifier: sound name, note name, or keyword.

  • NUMBER = 1 - Numeric literal.

  • TILDE = 2 - Silence ~.

  • LBRACKET = 3 - Opening bracket [ — start of a subsequence.

  • RBRACKET = 4 - Closing bracket ] — end of a subsequence.

  • LANGLE = 5 - Opening angle < — start of an alternation (slowcat).

  • RANGLE = 6 - Closing angle > — end of an alternation.

  • LPAREN = 7 - Opening parenthesis ( — reserved.

  • RPAREN = 8 - Closing parenthesis ) — reserved.

  • COMMA = 9 - Comma , — stack separator.

  • STAR = 10 - Star * — fast modifier (x*n = x played n times).

  • SLASH = 11 - Slash / — slow modifier (x/n = x stretched over n cycles).

  • BANG = 12 - Bang ! — replicate modifier.

  • AT = 13 - At @ — weight modifier (x@n occupies n units of the parent sequence).

  • QUESTION = 14 - Question ? — degrade modifier (random drop).

  • COLON = 15 - Colon : — sample-index modifier (bd:1 picks variation 1).

  • PIPE = 16 - Pipe | — bar separator in seq(…).

  • EOF_TOKEN = 17 - End-of-input marker.

17.4.2. Structures

Token
Fields:
  • kind : TokenKind - Token kind.

  • text : string - Source text of the token.

  • pos : int - Byte offset of the token in the original input string.

17.4.3. Tokenizer and parser

parse_note_name(name: string): float

Parse a note name with explicit octave (“c3”, “eb4”, “fs2”) into a MIDI number. Returns -1.0 on miss. Bare letters without an octave return -1 — this is intentional so s(“a e i”) parses as sound names, not notes.

Arguments:
  • name : string

parse_note_name_default(name: string; default_oct: int): float

Parse a note name allowing the octave to be omitted (falls back to default_oct). Accepts “d”, “d#”, “d#3”, “eb”. Returns -1.0 on miss.

Arguments:
  • name : string

  • default_oct : int

tokenize(input: string): array<Token>

Tokenize a mini-notation string into an array of Token. Uses peek_data for O(1) per-character access. An EOF_TOKEN is always appended at the end.

Arguments:
  • input : string

17.4.4. Fluent DSL constructors

n(notation: string): Pattern

Parse mini-notation as numeric values (each atom’s note field holds the number). Useful as a patternified parameter, e.g. slow(pat, n(“<2 16>”)).

Arguments:
  • notation : string

note(notation: string; sound: string = "sine"): Pattern

Alias for note_pattern. Example: note(“c3 e3 g3”).

Arguments:
  • notation : string

  • sound : string

note_pattern(notation: string; sound: string = "sine"): Pattern

Parse mini-notation for note patterns. Example: note_pattern(“c3 ~ e3 g3”) plays C3, silence, E3, G3 with the default “sine” sound. Any atom whose token looks like a note name is converted via default-octave parsing.

Arguments:
  • notation : string

  • sound : string

s(notation: string): Pattern

Parse mini-notation and return a Pattern of sound events. Example: s(“bd sd [hh hh] cp”) plays kick, snare, two hats in one step, clap.

Arguments:
  • notation : string

seq(notation: string; sound: string = "sine"): Pattern

Parse mini-notation with | bar separators for sequential melodies. Each bar plays for one cycle with its notes evenly subdivided. Example: seq(“e4 e4 f4 g4 | g4 f4 e4 d4”) plays two bars of four quarter-notes each.

Arguments:
  • notation : string

  • sound : string

set_s(pat: Pattern; notation: string): Pattern

Strudel-style .s() with mini-notation. Example: pat |> set_s(“<supersaw sawtooth>”). Single-token input goes through set_sound directly; mini-notation is parsed and sampled at each event’s onset.

Arguments:

17.4.4.1. set_vowel

set_vowel(pat: Pattern; vowel_pat: Pattern): Pattern

Set vowel from a pre-built pattern. Use when the vowel pattern needs transforms (slow, fast, rev) before applying — e.g. pat |> set_vowel(s(“<a e i o u>”) |> slow(5.0lf)).

Arguments:
set_vowel(pat: Pattern; notation: string): Pattern

17.4.4.2. vowel

vowel(pat: Pattern; vowel_pat: Pattern): Pattern

Alias for set_vowel (Pattern overload). Use when the vowel pattern needs transforms. Example: pat |> vowel(s(“<a e i>”) |> slow(4.0lf)).

Arguments:
vowel(pat: Pattern; notation: string): Pattern

17.4.5. Cycle-rate variants

every_degrade(n: int; prob: float; notation: string): Pattern

Randomly drop events from the pattern every n`th cycle. Example: `every_degrade(4, 0.5, “bd sd hh cp”) drops ~half the events on cycles 4, 8, …

Arguments:
  • n : int

  • prob : float

  • notation : string

every_fast(n: int; factor: double; notation: string): Pattern

Apply fast(factor) to the pattern every n`th cycle. Example: `every_fast(4, 2.0, “bd sd hh cp”) plays at double speed on cycles 4, 8, 12, …

Arguments:
  • n : int

  • factor : double

  • notation : string

every_slow(n: int; factor: double; notation: string): Pattern

Apply slow(factor) to the pattern every n`th cycle. Example: `every_slow(4, 2.0, “bd sd hh cp”) plays at half speed on cycles 4, 8, 12, …

Arguments:
  • n : int

  • factor : double

  • notation : string