Ever imagined turning a few lines of code into a live electronic music performance?
Why Code Your Music?
Traditional music production often involves heavy digital audio workstations (DAWs), expensive plugins, and hours of trial and error. Code-based music creation changes that completely.
- You focus on patterns and logic rather than audio engineering.
- It’s lightweight and fast, without heavy software requirements.
- Perfect for live coding performances, workshops, or simply exploring creativity.
Sonic Pi: A Friendly Entry to Live-Coded Music
Sonic Pi, created by Sam Aaron, is an open-source live-coding environment originally built for education. Its simplicity and flexibility have made it popular among educators, hobbyists, and live performers.
Key Features
- Written in Ruby-like syntax that is easy to read and write.
- Built-in synths, samples, and effects.
- Live loop support for evolving patterns in real time.
- Runs on Windows, macOS, Raspberry Pi, and Linux.
- Free and open source.
Strengths
- Beginner-friendly and approachable.
- Great for classroom use and workshops.
- Reliable for live performances with low latency.
Limitations
- Less modular than some modern frameworks.
- Limited support for advanced modular synthesis compared to professional DAWs.
Strudel: Next-Generation Pattern-Based Music Coding
Strudel is a modern, browser-based live-coding environment inspired by Tidal Cycles, a popular Haskell-based music-coding tool.
Key Features
- Runs directly in your browser with no installation required.
- Uses JavaScript-like syntax for defining rhythmic and melodic patterns.
- Integrates with Web Audio and external synths or MIDI gear.
- Ideal for quick jams, workshops, and web-based live performances.
Strengths
- Lightweight and beginner-friendly.
- Excellent for sharing code snippets online.
- Strong pattern manipulation for rhythms and textures.
Limitations
- Still maturing and less feature-rich than Sonic Pi for live performance.
- Performance depends on browser and hardware.
Sonic Pi vs Strudel: Quick Snapshot
| Aspect | Sonic Pi | Strudel |
|---|---|---|
| Platform | Desktop app (Windows/macOS/Linux/RPi) | Browser-based |
| Syntax | Ruby-style | JavaScript-style |
| Best For | Education, workshops, live algorave | Quick pattern-based jams |
| Learning Curve | Beginner-friendly | Easy if you know JavaScript |
| Strength | Stability and built-in synth/effects | Web-native and lightweight |
| Limitations | Fewer pattern operators | Limited pro-level audio control |
Common Challenges to Overcome
While coding music is exciting and expressive, both tools share a few challenges:
- Latency and performance issues on lower-end devices.
- Adapting to pattern-based thinking instead of traditional notation.
- Handling live performance mistakes, as one typo can break a loop.
- Limited collaboration tools compared to DAWs.
Tips to Get Started
- Begin with Sonic Pi if you are new to live coding and follow its built-in tutorials.
- Try Strudel in your browser for quick pattern experiments.
- Focus on rhythm and repetition before working on complex sound design.
- Record your sessions and share them online; community feedback helps improve faster.
- Combine both tools: use Sonic Pi for synth sounds and Strudel for patterns, routing them via MIDI.
Playground Links (How to Run the Example Codes)
Sonic Pi
Sonic Pi is a desktop application, so there is no browser version.
Download and run locally: https://sonic-pi.net/. For quick demos without installing, you can watch live-coding sessions at https://in-thread.sonic-pi.net/.
Strudel
Strudel runs entirely in the browser, so you can start coding immediately.
Try it here: https://strudel.cc/play
Example Codes: Sonic Pi and Strudel Side by Side
1. Kick + Snare Basic Beat
Sonic Pi
live_loop :beat do
sample :bd_haus
sleep 0.5
sample :sn_dolf
sleep 0.5
end
Strudel
bd("x . x .").layer("snare", " . o . o ")
2. Hi-hat 16ths with Swing
Sonic Pi
use_bpm 120
live_loop :hats do
8.times do |i|
sleep (i.even? ? 0.22 : 0.28)
sample :drum_cymbal_pedal, amp: 0.8
end
end
Strudel
stack(
s("hat*8").swing(1/8, 0.1)
)
3. Minor Pentatonic Bass
Sonic Pi
use_bpm 100
scale_notes = scale(:e2, :minor_pentatonic)
live_loop :bass do
play scale_notes.choose, release: 0.25, cutoff: 80
sleep 0.5
end
Strudel
n("<0 2 3 5 7>~").scale("e2 minorPentatonic").slow(2).s("sinebass")
4. Chords + Arpeggio
Sonic Pi
use_synth :prophet
ch = chord(:a3, :minor7)
live_loop :pad do
play ch, sustain: 2, release: 2, amp: 0.6
sleep 2
end
live_loop :arp do
ch.each do |n|
play n, release: 0.15
sleep 0.125
end
end
Strudel
stack(
n("a3min7").s("pad").sustain(2),
arp("up", n("a3min7")).s("pluck").fast(4)
)
5. Euclidean Rhythm (3 hits over 8)
Sonic Pi
live_loop :euclid do
use_synth :fm
tick
play :e4, release: 0.1 if (spread 3, 8).look
sleep 0.25
end
Strudel
euclid(3,8).s("beep").fast(4)
6. Filtered Break with Slicer FX
Sonic Pi
Strudel
7. Polyrhythm: 4 over 3
Sonic Pi
Strudel
8. Random Melodic Generator
Sonic Pi
Strudel
9. MIDI Out (Drive External Synth)
Sonic Pi
Strudel
10. Call-and-Response (Lead Answers Pad)
Sonic Pi
Strudel
Notes
-
In Sonic Pi, wrap experimental sections with
with_fxand usecontrolto adjust live parameters. -
In Strudel, use
.every()for periodic transformations and.when()for conditional pattern changes.
Bibliography (APA Style)
- Aaron, S. (2016). Sonic Pi: Performance in education. Proceedings of the International Conference on New Interfaces for Musical Expression (NIME).
- Collins, N. (2023). Live coding of music: Concepts and practice. Oxford University Press.
- McLean, A., & Wiggins, G. (2010). TidalCycles: A language for live coding of pattern. Proceedings of the International Computer Music Conference (ICMC).
- Sonic Pi. (n.d.). Official website. Retrieved March 2025, from https://sonic-pi.net/
- Strudel. (n.d.). Official website. Retrieved March 2025, from https://strudel.cc/
- TOPLAP. (n.d.). Live coding community resources. Retrieved March 2025, from https://toplap.org/
- The MIDI Association. (n.d.). MIDI 1.0 detailed specification. Retrieved March 2025, from https://www.midi.org/
- Mozilla Developer Network. (n.d.). Web Audio API documentation. Retrieved March 2025, from https://developer.mozilla.org/docs/Web/API/Web_Audio_API
- Algorave. (n.d.). Official site. Retrieved March 2025, from https://algorave.com/
- Jack Audio Connection Kit. (n.d.). Low-latency audio toolkit. Retrieved March 2025, from https://jackaudio.org/
