Sonic-PI: Sound synth application for learning coding and music

Sonic PI

I love it when I find a tool that combines my two favorite hobbies: music and computers. A gifted programmer named Sam Aaron has created an engaging tool for teaching music and code to makers young and old entitled Sonic-Pi. The tool delightfully blends an introduction to Ruby programming and concepts of music through written tutorials and a real time coding area. The tool can be used on a Raspberry-PI, Windows, or Mac.

Make sure to check out the introduction video on the front page of the Sonic-Pi website.

I liked how the Sonic-Pi tutorials decomposed the concepts of sound, loops, pitches, and music. I like that the tutorials progress from simple to complex ideas. Since music, R&B, and techno have loops and repetitions, students encounter natural introductions to the coding concepts of sequencing commands and repeating them.

During high school, my mother and I were looking for “mother/son” activities. We decided to take a course in cocktail piano together at a local college. It was great fun! In the course, we learned how to improvise piano pieces based on a melody line a chords.   The secret of most jazz musicians is that much of their creative thinking combines heart, physical execution and a kind of mathematical theory we call music theory. I’m not an expert in this subject, but it’s very fun.   It has enabled me to learn how to arrange music, basic scores, and improvise with groups.   You can think of it as the “math” or patterns that exists behind music. I think the Sonic-Pi tutorials do a good job of introducing the music theory concepts and code for ideas like scales, chords, rests, and the various timing ideas of music.

So, what does Sonic-PI code look like? Here’s my first program:


in_thread do
loop do
play_chord chord(:a, :minor)
sleep 2
play_chord chord(:g)
sleep 2
play_chord chord(:f)
sleep 2
play_chord chord(:e)
sleep 2
end
end
in_thread do
loop do
sample :drum_bass_hard
sleep 1
sample :drum_snare_hard
sleep 1
end
end

in_thread do
loop do
sample :drum_tom_hi_soft
sleep 0.5
sample :drum_cymbal_closed
sleep 0.5
end
end
loop do
play choose(scale(:a, :minor_pentatonic, num_octaves: 1))
sleep choose([1,0.25])
end

Here’s the break down; In the following code, we play the following chord progression: AM, G, F, E. The chord changes every two beats.


play_chord chord(:a, :minor)
sleep 2
play_chord chord(:g)
sleep 2
play_chord chord(:f)
sleep 2
play_chord chord(:e)
sleep 2

Since we want our chord progression to repeat itself, we wrap the chord progression in a loop. We also wrap it in an “in_thread” code block so that this progression can be executed in parallel with other musical ideas.

in_thread do
loop do
play_chord chord(:a, :minor)
sleep 2
play_chord chord(:g)
sleep 2
play_chord chord(:f)
sleep 2
play_chord chord(:e)
sleep 2
end
end

This small musical piece has a drum track executing in the loop. The following code executes a bass drum on beat 1 and a snare drum on beat 3. We put this musical idea in a loop and a thread so this idea can run in parallel with other ideas.


in_thread do
loop do
sample :drum_bass_hard
sleep 1
sample :drum_snare_hard
sleep 1
end
end

In the final element of code, I wrote a few lines to randomly generate a melody based on an A minor pentatonic scale. The “scale” function generates a set of notes included in the pentatonic scale. The “choose” function selects one of those notes at random. The program will hold the note from 1 beat or an eight note.


loop do
play choose(scale(:a, :minor_pentatonic, num_octaves: 1))
sleep choose([1,0.25])
end

I’m looking forward to trying this out with older middle school students or high school students. I know some “big kids” who will enjoy this as well. Hope you enjoy Sonic-Pi! Send us links to your songs if you make anything cool!

 

 

Top Stories on InspiredToEducate.NET

Learning To Code

Science Education

 

Join the Spark Macon Maker Space Community on Facebook

Photo credit : https://www.flickr.com/photos/dougbelshaw/