In this note
1amageek.Portfolio ↗ENGINEERING NOTES
English
MUSIC LIVE CODING / SWIFT MUSIC DSL1AMAGEEK / 2026-10-13

Music live coding — Editing becomes performance.

Do more than finish a track and press play. Shape it while it sounds. SwiftMusic’s declarations and MusicPlayground’s performance environment connect that ongoing experiment.

01

Make experimentation part of expression.

Write a rhythm, listen and change it. For this loop to become performance, editing and playback must share time. MusicPlayground places rhythm and controls beside the source, with independent A/B decks and a crossfader for moving between sounds.

Declarations combine subdivisions, repetitions, notes and dynamics. SwiftMusic represents musical relationships in rational time and bounds event expansion. Meaning is resolved before a plan reaches the host. This does not imply silent truncation of unlimited expansion or zero physical output latency.

02

Separate declaring music from producing audio.

Music and Sound describe structure; SoundCompiler transforms it into beat-domain events and a render plan. Compilation does not open an audio device. The host prepares audio, outputs it and decides when to adopt updates. Separating the DSL from the app keeps musical meaning distinct from performance state.

Writing directly in an audio callback gives access to output frames. SwiftMusic instead puts musical structure in a DSL, separate from device output. Reusable patterns and Sounds require contracts between supported declarations and plans the host can prepare and play. Editing, preparation, adoption and output are different operations.

03

Keep the current sound until the next is ready.

LiveMusicState tracks revisions and rejects old preparation results. Successful candidates remain pending until the host chooses a musical boundary. Failure records a diagnostic without changing currentSound. MusicPlayground’s SessionModel initiates preparation from edits. Inspected tests explicitly cover retaining sound after failure and rejecting stale results.

From responsibility to result.
  1. ComposerMusic / Sound
  2. SwiftMusicSoundCompiler
  3. HostPrepared audio
  4. Host timingMusical boundary
  5. ListenerAudio output
Implementation excerpt · Revision-aware adoption ↗
switch update {
case .prepared(let revision, let sound):
    pendingSound = sound
    pendingRevision = revision
case .failed(let revision, let error):
    diagnostic = error
    diagnosticRevision = revision
}

Do not roll performance back to a late edit.

LiveDSLIntegrationTests adopts a valid revision 0, then prepares an invalid pattern at revision 1. Failure records diagnostic while currentSound and currentRevision remain at 0. A subsequent valid candidate waits for adoptPendingAtBoundary rather than being adopted immediately. Another test arranges an old preparation completion after a newer update and describes its rejection.

revision 0 adopted
currentRevision = 0
revision 1 failed
diagnosticRevision = 1; currentRevision = 0
revision 2 prepared
pendingRevision = 2
adoptPendingAtBoundary()
currentRevision = 2
Read the evidence · Failed edit and stale-result tests ↗
04

The performance environment has real prerequisites.

MusicPlayground is a macOS source-distribution preview. Its README requires Swift 6.4, macOS 15+, a compiler and SDK. Sessions execute local Swift with the user’s permissions, so source must be trusted. The supplied promotional film does not establish all supported features or current release readiness.

The experience depends on which edit was adopted and when, not only whether compilation succeeded. LiveMusicState is a value representing those distinctions; the host owns mutation isolation and musical-boundary notification. That is not proof of audio-thread safety or completion of every app update path. Failure and time belong at the center of a design that lets experimentation continue as performance.

Product introduction · Open video file ↗

Read the evidence

Source reading date:

An explanation based on reading public design, implementation and test bodies. It is not a report of executing upstream tests or measuring device performance.

SwiftMusic / MusicPlaygroundExplore the project ↗