Module

Hylograph.Music.Interpreter.WebAudio

Package
purescript-hylograph-music
Repository
afcondon/purescript-hylograph-music

WebAudio Interpreter for HATS

Interprets a HATS Tree as audio events using the Web Audio API.

Each Elem node in the tree is interpreted as a note, with attributes mapping to audio parameters (time, pitch, duration, volume, timbre). Fold nodes iterate over data, scheduling one note per datum.

Follows the same interpreter pattern as English.purs and Mermaid.purs, but produces audio output instead of text.

#interpretAudio Source

interpretAudio :: Tree -> MusicM Unit

Interpret a HATS tree as audio events

Walks the tree, scheduling a note for each Elem node. Attributes are interpreted as audio parameters:

  • time → note start time (seconds)
  • pitch → frequency (Hz)
  • duration → note length (seconds)
  • volume → amplitude (0.0 to 1.0)
  • timbre → waveform type ("sine", "square", "sawtooth", "triangle")

For Fold nodes, iterates over the enumeration and interprets each template result, using the iteration index for default timing.

#MusicM Source

newtype MusicM a

The Music interpreter monad

Carries an AudioContext reference for scheduling notes. Uses ReaderT pattern to thread the context through computations.

Instances

#runMusicM Source

runMusicM :: Ref AudioContext -> MusicM ~> Effect

Run a music program with an existing context ref

#initMusicContext Source

initMusicContext :: MusicM Unit -> Effect Unit

Initialize audio context and run a music program

Creates the Web Audio context and executes the computation. Must be called in response to user interaction (browser requirement).