Creating Music in Sonic Pi—Part 1

Part 2 Part 3

Meeting the Requirements

High schoolers in my state are required to complete a Capstone project to finish off their senior year. It is really up to the individual as to how they meet the requirements, so I decided to create some music using Sonic Pi.

Sonic Pi is touted on their website as the “future of music.” Instead of a arranging notes manually, you write code to describe the sound you want, instead of using midi keyboards[1], you use an actual keyboard (bad joke).

Proof of Progress

After spending a few weeks messing around with the editor, learning the ropes and creating some sound, I knew it was time to record at least something. And I did. Below is the ≈10 minute recording of some “music” I made, below that is the code to make the sound. This was recorded live and edited in real time, so the code you see below is not the entire piece, it is only a snapshot of the end. In a later post, I will explain how it works in detail. I would recommend starting around the two minute mark.

# Welcome to Sonic Pi use_bpm 180 live_loop :kick do with_fx :distortion, distort: 0.7, reps: 8 do cue :kick sample :bd_klub sleep 0.5 end end live_loop :tick do sync :kick ##| sample :elec_tick, rate: 0.5 end live_loop :beep do ##| use_synth :chipbass ##| 10.times do sync :kick ##| end ##| play :d3 end live_loop :bump do 2.times do sync :kick end ##| sample :bd_808 end live_loop :snare do with_fx :reverb, reps: 2 do 5.times do 3.times do sync :kick end ##| sample :elec_hi_snare, amp: 0.5 end sleep 0.5 sample :elec_lo_snare, rate: 0.3, amp: 0.75 end end live_loop :bassline do chords = ring :e2, :g2, :e2, :e3, :d3 i = 0 with_fx :ping_pong, feedback: 0.99 do with_fx :distortion, distort: 0.5, reps: chords.length do wait = 3 if i == chords.length - 1 then wait -= 1 end wait.times do sync :kick end use_synth :dtri ##| play chords[i], attack: 0, sustain: 1, release: 0, detune: 0.5 i += 1 end end end

Footnotes