home/ modules/ sonic-pi-debugging-and-recovery

Sonic Pi: debugging common errors and recovering under pressure

  • learner can read Sonic Pi error messages and trace them to their specific cause — missing sleep, duplicate loop name, bad synth/sample name, or sync deadlock
  • learner can avoid or repair the six most common Sonic Pi runtime traps (no-sleep, duplicate name, bundled-name confusion, sync deadlock, thread-local BPM, with_fx scope) without stopping the audio
  • learner can modulate a running synth node using the capture-and-control idiom with a pre-set slide parameter
  • learner can deploy a minimal panic-fallback groove from memory to leave no silence while rebuilding after a catastrophic error

Author a three-loop Sonic Pi session — kick, bass, and melody — that deliberately exercises every major failure mode, fixing each in place without restarting the buffer so the other loops keep playing throughout: start with a live_loop missing sleep (observe the did-not-sleep error and fix), introduce a duplicate loop name and confirm the second silently replaces the first rather than adding a voice (observe and fix), write a melody note as a string `play "e3"` and confirm it does not sound, then switch to the idiomatic symbol `play :e3`, reference a non-existent synth/sample name and look up its real bundled name to fix it, introduce a syntax error (unbalanced do/end) and confirm the already-running loops keep playing while the bad run is rejected, trigger a sync deadlock on a non-existent cue tag (observe the frozen loop, fix with the correct tag), and mis-scope a with_fx around only part of its intended sound (observe which calls are processed and fix). Add BPM control with use_bpm and confirm it only affects the loop it is set in. Then capture a synth node handle, set its matching *_slide opt, and automate one parameter with control on the live node. When anything breaks mid-session, deploy the panic-fallback groove from memory to bridge the gap without leaving silence.

A Sonic Pi live session fails differently from a normal program: errors can silence one loop while the rest keep playing, a bad synth name can just drop to silence with no log entry, and a sync on the wrong tag blocks a thread forever without surfacing anything readable. On a stage or in a stream, these failures arrive with no time to google. This module is the systematic inoculation — you encounter every common error in a safe drill context first, so your hands know the fix before a performance demands it.

The arc is deliberately adversarial. Each exercise hands you broken code, asks you to read the log (or notice the silence), identify the cause from the atom that governs it, and apply the minimal fix — no restarting the buffer, keeping the other loops running throughout. The first cluster covers the live_loop lifecycle: “A live_loop with no sleep throws a did-not-sleep error and stops” and its twin-misconception atom (“Every Sonic Pi live_loop body must call sleep or sync or it stops”) establish that sleep or sync is not optional. These two atoms look similar but address complementary failure modes — the first is L1 gotcha-recognition, the second is the L5 internalized rule — and both must be reflexive. Alongside them, duplicate-name replacement and buffer-reeval swap-at-boundary are the two mechanics that surprise every programmer who treats Sonic Pi like a script runner rather than a live instrument.

The second cluster is naming and symbols. Sonic Pi has a closed synth/sample/fx namespace — :kick, :bass, :verb are all errors — and the real names (:bd_haus, :tb303, :reverb) must be drilled until they are rote. The symbols-not-strings misconception (play "e3" silently doing nothing vs play :e3) is the single most common beginner error across every tutorial channel. Both atoms belong in the required set because the capstone explicitly tests them.

The concurrency cluster forms the third arc. sync on a tag that never fires blocks the loop forever without error — the sync-deadlock atom is the single most dangerous Silence Trap in Sonic Pi, because you have no log to read. use_bpm being thread-local is the subtler cousin: the loop reads right, sounds wrong, and nothing errors. with_fx block scope — only sounds inside the do...end go through the effect — trips up everyone who writes the fx header above a loop body rather than around it. These three traps require separate minimal reproductions in the drills; do not batch them.

The control/modulation cluster (control-needs-handle and control-node-lifecycle) is the gateway to expressive live parameter gestures. The key insight is that a synth node is a one-time allocated voice: to automate it later, you must capture its return value at creation, set the matching *_slide opt before calling control, and ensure the node is still alive (long sustain: or an fx handle). Without all three conditions, control silently does nothing.

The capstone synthesises all of this into a session that has been broken and repaired from every angle. The panic-fallback drill is the non-negotiable close: write a minimal always-valid groove from memory — :bd_haus kick loop, :saw bass with sync:, use_bpm once at top — and deploy it under a simulated crisis. Internalise that fallback as your safety net, not a last resort.

Supporting atoms enrich rather than gate: sonicpi-sleep-in-beats grounds the BPM unit confusion, sonicpi-range-excludes-end and sonicpi-tick-vs-look are the off-by-one cluster that supplements ring-indexing once the live-loop mechanics are solid, sonicpi-runaway-feedback-level explains the one audio hazard that produces no error (feedback clipping), and sonicpi-live-loop-auto-cues-own-name illuminates why sync: :loop_name works without explicit cues — clarifying the sync-deadlock atom’s boundary condition. sonicpi-not-in-rig is a one-read reference: Sonic Pi has no FFT bridge to the rig’s Hydra layer, so audio-reactive visuals require Strudel instead — file it and move on.

Atoms in this module

Required — these gate the capstone

A Sonic Pi live_loop with no sleep and no sync throws a 'did not sleep' error and stops
Fact L1 Foundations F
Every Sonic Pi live_loop body must call sleep or sync or it stops with a runtime error
Principle L5 Voice F
Two Sonic Pi live_loops with the same name are not independent — the second replaces the first
Misconception L1 Foundations F
Defining two Sonic Pi live_loops with the same name does not create two voices — the second silently replaces the first
Misconception L5 Voice F
Sonic Pi synth, sample, and fx names must exist in the bundled set; names like :kick, :bass, :verb are errors — the real names are :bd_haus, :tb303, :reverb
Fact L1 Foundations F
Sonic Pi idiomatically uses symbols not strings for samples and notes — play :e3 or play 52 work but play "e3" does not
Fact L1 Foundations F
A Sonic Pi sync on a non-existent cue tag blocks the loop forever without throwing any error
Misconception L5 Voice F
Sonic Pi's use_bpm is thread-local; setting it in one live_loop does not change the tempo in another
Fact L1 Foundations F
Sonic Pi's with_fx wraps a code block, not a voice; only play/sample calls inside the do…end block are processed through the effect
Principle L1 Foundations F
To modulate a running Sonic Pi effect or synth you must capture its block-argument handle and call control on it
Procedure L1 Foundations F
Sonic Pi control on a synth node requires capturing its handle and setting *_slide before calling control
Procedure L5 Voice F
A Sonic Pi syntax error aborts the run but all currently running live_loops keep playing
Concept L5 Voice F
A minimal groove using only bundled synths and samples with a sleep in every loop is the safe Sonic Pi recovery
Procedure L5 Voice F

Supporting — enrichment, not gating

Re-running a Sonic Pi buffer does not restart the piece; it swaps each live_loop body in at its next boundary and loops keep their .tick counters
Concept L1 Foundations F
Sonic Pi's sync waits for the next cue from that point, so a loop with sync at the top delays its first pass by up to one cue period
Concept L1 Foundations F
In Sonic Pi, .tick mutates the ring counter while .look only reads it — calling .tick twice in one pass advances twice
Fact L1 Foundations F
Sonic Pi's (range 0, 8) excludes the end value (0..7) while (line 0, 8, steps: 9) includes it — a common off-by-one source
Misconception L1 Foundations F
Sonic Pi sleep arguments are in beats, not seconds — use use_bpm to set the tempo that determines their duration
Fact L5 Voice F
Sonic Pi has no clip protection — high echo/reverb feedback or stacked loud amp: causes distortion with no error
Principle L5 Voice F
A Sonic Pi live_loop automatically cues its own name each cycle, making sync :loop_name safe without explicit cue calls
Fact L5 Voice F
An unknown Sonic Pi synth, sample, or fx name usually errors, though a bad sample name can just fall silent
Fact L5 Voice F
Sonic Pi cannot feed the rig's 4-bin FFT bridge for audio-reactive visuals — it runs in its own IDE with a bundled SuperCollider server
Fact L1 Foundations FJ