tur/mini

stdlib/mini.tur
defstruct

MiniToken

(defstruct MiniToken [])

a single lexed token from a mini-notation string.

defn

mini-tokenize

(mini-tokenize [s])

lex a mini-notation string into a vector of tokens.

smini-notation string to lex
vec<MiniToken> in source order.

  (mini-tokenize "1 2 3")
defn

parse-expr

(parse-expr [tokens index])

recursive descent parser for mini-notation tokens.

tokensvec<MiniToken> produced by mini-tokenize
indexcurrent position in the token vector

Tuple of (NumPattern, remaining-index).

defn

apply-op

(apply-op [op left right])

apply an infix operator to two patterns.

opoperator character string
leftleft operand pattern
rightright operand pattern

NumPattern with the operator applied.

defn

parse-mini

(parse-mini [s])

parse a mini-notation expression string into a pattern.

smini-notation string (numbers, operators, brackets)
NumPattern.

  (parse-mini "1 2 3")
  (parse-mini "[1 2 3]")  ; => fast 2x
defmacro

s

(s [expr])

inline mini-notation macro.

(s "1 2 3")  ; same as (parse-mini "1 2 3")
defn

parse-drums

(parse-drums [s])

parse drum mini-notation into a sequenced drum pattern.

sspace-separated drum name string (e.g., "bd sd bd sd")
Pattern<map> producing drum parameters for each step.

  (parse-drums "bd sd bd sd")
defmacro

d

(d [expr])

drum pattern macro.

(d "bd sd")  ; same as (parse-drums "bd sd")
defn

parse-note

(parse-note [note-str & [default-octave 4])

parse a note name string into a MIDI note number.

note-strnote string (e.g., "c4", "g#5", "eb3")
default-octaveoctave to use when omitted (default: 4)
MIDI note number as int.

  (parse-note "c4")   ; => 60
  (parse-note "a4")   ; => 69
defn

parse-notes

(parse-notes [s])

parse a space-separated note string into a cycling MIDI pattern.

sspace-separated note string (e.g., "c4 e4 g4")
NumPattern cycling through MIDI note numbers.

  (parse-notes "c4 e4 g4")
defmacro

n

(n [expr])

note pattern macro.

(n "c4 e4 g4")  ; same as (parse-notes "c4 e4 g4")
defn

parse-chord

(parse-chord [s])

parse bracket-delimited chord notation into a constant chord pattern.

schord string (e.g., "[c4 e4 g4]")
Pattern<vec<int>> that always returns the same MIDI note vector.

  (parse-chord "[c4 e4 g4]")
defmacro

chord

(chord [expr])

chord pattern macro.

(chord "[c4 e4 g4]")  ; same as (parse-chord "[c4 e4 g4]")
defn

parse-rhythm

(parse-rhythm [s & [hit-value 1 rest-value 0])

parse an x/o shorthand rhythm string into a numeric pattern.

sstring of 'x' (hit) and 'o' (rest) characters
hit-valuevalue for hits (default: 1)
rest-valuevalue for rests (default: 0)
NumPattern cycling through hit/rest values.

  (parse-rhythm "x o x o")  ; => alternating 1 and 0
defmacro

r

(r [expr])

rhythm pattern macro.

(r "x o x o")  ; same as (parse-rhythm "x o x o")
defn

parse-with-repeat

(parse-with-repeat [s])

expand *n repetition notation before cycling.

spattern string where tokens may include *n suffix (e.g., "bd*2 sd")
NumPattern with expanded sequence.

  (parse-with-repeat "bd*2 sd")  ; => cycle of bd bd sd
defn

mini

(mini [s])

parse a complete mini-notation expression (alias for parse-mini).

smini-notation string

NumPattern.