SonicPi - for musical programmers
Can programmers perform in front of an audience? Can you compose music with programming languages... well, if you think not, let me show you otherwise
I feel as if I’ve been sitting under a rock for a decade. I’m a highly experienced software engineer/programmer/developer with a wealth of experience spanning pretty much close to three decades. Now that is a scary thought. I thought I knew about many things coding wise, well I clearly don’t. How on earth have I never come across SonicPi!
Turns out there are a whole host of other products much like it and I’ll come back to those.
SonicPi was created by Sam Aaron, who wanted to create a musical programming tool that would help teach school children and beyond. It’s now used by 1.5 million people from school age and professional artists alike.
I came across this tool via my Mastodon account, yes like many people, I have jumped ship from Twitter, though I’ve not shut down the latter. One of the people mentioned it and so off I trotted to YouTube, where I found a bunch of videos recorded by Sam and one or two professional performers who use SonicPi on stage.
As you can see there are a lot of resources online for you if you want to get into it. However I want to give it a go, get my teeth properly into it.
Lets give it a go
The first thing I did was to download SonicPi for my Mac, it came out on Linux originally but quite recently was released on Mac and Windows.
So I grabbed a copy from
Somehow after following the excellent tutorial, I created this:
use_bpm 60
live_loop :kick do
sample :bd_haus, rate: 1
sleep 0.5
end
live_loop :snare do
sleep 0.5
sample :sn_dolf
sleep 0.5
end
live_loop :hihat do
sample :drum_cymbal_closed
sleep 0.25
end
live_loop :bass do
use_synth :prophet
play :E1, release: 3
sleep 2
end
live_loop :bleep do
use_random_seed 123
4.times do |i|
16.times do
use_synth :beep
play chord(:E3, :minor).choose, attack: 0, release: 0.1, cutoff: rrand_i(50, 90) + i * 10
sleep 0.125
end
end
end
live_loop :chords do
use_synth :blade
[1, 3, 6, 4].each do |d|
(range -2, 2).each do |i|
play_chord (chord_degree d, :e, :minor, 3, invert: i)
sleep 2
end
end
end
This is how the above sounds:
In the above example we’ve 6 loops/tracks running in parallel, if you look at the start of each “live_loop”, they are assigned with a name and then within either use a synth or a sample and either slice elements of a sample or play a series of chords.
It gets very clever when you change the parameters for any of the above instruments in the code, to tweak the knobs on the synth. I noticed in some of Sam’s videos he’s connected controllers and external instruments such as a Moog or some DAW software to play virtual instruments you already own. Now that is worth exploring, as I’ve tonnes of those.
Randomisation in music
One of the beauties of programming is that you can iterate (loop) through a series of values, you can randomise, you can mathematically adjust parameters, such as cutoff frequencies over a period of time. It’s a perfect marriage.
Here is another example:
live_loop :multi_beat do
use_random_seed 2000
8.times do
c = rrand(70, 130)
n = (scale :e1, :minor_pentatonic).take(3).choose
synth :tb303, note: n, release: 0.1, cutoff: c if rand < 0.9
sample :elec_hi_snare if one_in(6)
sample :drum_cymbal_closed if one_in(2)
sample :drum_cymbal_pedal if one_in(3)
sample :bd_haus, amp: 1.5 if one_in(4)
sleep 0.125
end
end
The audio output sounds like this:
I’ll be writing more about this soon. I’ve also been exploring Supercollider which I’ve hooked up to Logic. So should be able to link with VCV.
Thanks Nick; that was an interesting read. You sound quite excited by this SonicPi project which seems to have quite a healthy open-source community around it. It sounds good. Some of the videos are well... very impressive. Can you hook it up to your VCV Lab yet?!