skode

Skode / “ands”: a typed model of the Skred command language.

Follows the C lexer (parts/ands.c in octetta/pulp), not just the output of any one converter:

Not modelled: macro expansion and $$N, the C parser’s persistent string/array buffers beyond what was parsed since a command last fired, and anything the engine does with a command once it is dispatched.

Types

pub type Arg {
  Lit(Num)
  VarRef(Int)
  StreamRef(Int)
  ReturnRef(Int)
}

Constructors

  • Lit(Num)
  • VarRef(Int)
  • StreamRef(Int)
  • ReturnRef(Int)

One chunk: what ends at ;, a newline or EOT. A comment is always last.

pub type Chunk {
  Chunk(ops: List(Op), remark: option.Option(String))
}

Constructors

pub type Command {
  Command(
    atom: String,
    args: List(Arg),
    array: option.Option(List(Arg)),
    string: option.Option(String),
  )
}

Constructors

+ is beats, ~ is seconds. A negative amount means ticks (tempo steps).

pub type DeferMode {
  Beats
  Seconds
}

Constructors

  • Beats
  • Seconds
pub type Num {
  Value(Float)
  Rest
  Tie
}

Constructors

  • Value(Float)
  • Rest

    lone - e -- ---: plain NaN, “keep the existing value” / rest

  • Tie

    lone . _ .. ... __: NaN with payload 0x7FF8000000000001, a tie

pub type Op {
  Voice(Int)
  Note(midi: Int, cents: option.Option(Float))
  MasterVolume(db: Float)
  Freq(Float)
  Amp(db: Float)
  Level(Float)
  Pan(Float)
  Wave(Int)
  Mode(Int)
  Loop(Bool)
  Bend(Float)
  BendRange(Int)
  Glide(time: Float, curve: option.Option(Int))
  Slew(time: Float, curve: option.Option(Int))
  Detune(wave: Int, cents: Float)
  SampleWindow(option.Option(#(Int, Int)))
  WaveLoop(wave: Int, start: Int, end: Int)
  Pattern(Int)
  MasterPattern(Int)
  PatternSpeed(Int)
  Run(Bool)
  QueueStart(Bool)
  ClockSpeed(Int)
  Ratchet(Int)
  Goto(Int)
  Clock(bpm: Int, subdivision: Int)
  EmitEvent(Int)
  Step(ops: List(Op), at: Int)
  OnEvent(ops: List(Op), id: Int)
  Puts(String)
  LoadWave(path: String, id: Int)
  NameWave(name: String, id: Int)
  Defer(mode: DeferMode, amount: Arg, body: List(Op))
  MacroDef(name: String, body: String)
  Stray(List(Arg))
  Generic(Command)
}

Constructors

  • Voice(Int)
  • Note(midi: Int, cents: option.Option(Float))
  • MasterVolume(db: Float)
  • Freq(Float)
  • Amp(db: Float)
  • Level(Float)
  • Pan(Float)
  • Wave(Int)
  • Mode(Int)
  • Loop(Bool)
  • Bend(Float)
  • BendRange(Int)
  • Glide(time: Float, curve: option.Option(Int))
  • Slew(time: Float, curve: option.Option(Int))
  • Detune(wave: Int, cents: Float)
  • SampleWindow(option.Option(#(Int, Int)))
  • WaveLoop(wave: Int, start: Int, end: Int)
  • Pattern(Int)
  • MasterPattern(Int)
  • PatternSpeed(Int)
  • Run(Bool)
  • QueueStart(Bool)
  • ClockSpeed(Int)
  • Ratchet(Int)
  • Goto(Int)
  • Clock(bpm: Int, subdivision: Int)
  • EmitEvent(Int)
  • Step(ops: List(Op), at: Int)

    [ops] x12

  • OnEvent(ops: List(Op), id: Int)

    [ops] e>3

  • Puts(String)
  • LoadWave(path: String, id: Int)
  • NameWave(name: String, id: Int)
  • Defer(mode: DeferMode, amount: Arg, body: List(Op))

    +4 rest-of-chunk; consecutive defers in one chunk accumulate in the engine

  • MacroDef(name: String, body: String)
  • Stray(List(Arg))

    numbers with no command to take them (the C parser drops these)

  • Generic(Command)

    any other atom, or a known atom with sentinel/variable/odd arguments

Values

pub fn arg_to_string(a: Arg) -> String
pub fn chunk_to_string(c: Chunk) -> String
pub const defer_blanks: Bool

Whether + 4 v0 / ~ 1.5 f 440 (blanks between the sigil and its amount) read as the guide documents them. This matches the fixed C parser (ands-defer-space.patch). Set it to False to preview against an engine build that predates the fix, where such a defer is a zero delay whose body starts with the number.

pub fn generic_atoms(ops: List(Op)) -> List(String)

Atoms the typed layer doesn’t know (still valid, still sent as typed).

pub fn op_to_string(op: Op) -> String
pub fn ops_to_string(ops: List(Op)) -> String

A defer swallows the rest of its chunk, so an op list that puts anything after a Defer will not read back the same. Parsed chunks never do.

pub fn parse_ops(src: String) -> List(Op)

All ops of a program, chunk boundaries and comments dropped.

pub fn parse_program(src: String) -> List(Chunk)
pub fn program_to_string(chunks: List(Chunk)) -> String
pub const pulp_version: String

Upstream Pulp / Skred audio engine release version this AST aligns with.

pub const version: String

Version of the Skode AST & parsing package.

✨ Search Document