Learn SONIC-PI with Real Code Examples
Updated Nov 26, 2025
Code Sample Descriptions
1
Hello World Tune in Sonic Pi
play 60
sleep 0.5
play 62
sleep 0.5
play 64
sleep 0.5
play 67
sleep 1
play 72
A simple Sonic Pi script that plays a short 'Hello World' melody.
2
Simple Drum Beat
sample :bd_haus
sleep 0.5
sample :sn_dub
sleep 0.5
sample :bd_haus
sleep 0.5
sample :sn_dub
sleep 0.5
Plays a basic drum pattern using Sonic Pi samples.
3
Ascending Scale
play 60
sleep 0.25
play 62
sleep 0.25
play 64
sleep 0.25
play 65
sleep 0.25
play 67
sleep 0.25
play 69
sleep 0.25
play 71
sleep 0.25
play 72
Plays a C major ascending scale.
4
Arpeggio Example
play 60
sleep 0.25
play 64
sleep 0.25
play 67
sleep 0.25
play 72
sleep 0.25
Plays a simple arpeggio of a C major chord.
5
Simple Bassline
use_synth :fm
play 36
sleep 0.5
play 38
sleep 0.5
play 40
sleep 0.5
play 41
sleep 0.5
Plays a repeating bassline pattern.
6
Random Notes
8.times do
play choose([60,62,64,65,67,69,71,72])
sleep 0.25
end
Plays 8 random notes within an octave.
7
Melody with Reverb
with_fx :reverb, mix: 0.5 do
play 60
sleep 0.5
play 64
sleep 0.5
play 67
sleep 0.5
end
Plays a simple melody with a reverb effect.
8
Simple Drum Roll
16.times do
sample :sn_dub
sleep 0.125
end
Plays a drum roll using the snare sample.
9
Chord Progression
play_chord [:c4, :e4, :g4]
sleep 1
play_chord [:f4, :a4, :c5]
sleep 1
play_chord [:g4, :b4, :d5]
sleep 1
play_chord [:c4, :e4, :g4]
sleep 1
Plays a basic C major chord progression.
10
Simple Ambient Loop
use_synth :hollow
loop do
play 60
sleep 1
play 65
sleep 1.5
play 69
sleep 0.75
end
Creates a looping ambient soundscape using synths and sleep timings.