MDN
3 min readSep 18, 2019

ICLC 2017, International Conference on Live Coding

Sonic Pi: is it Teaching or Live Coding?

Knowing programmatic thinking in Ruby, anyone can make digital music with live coding music tools, using loops, set and get methods, conditionals and iterations.

STEM education has taught me that code can democratize in magic ways. You can make beats without drums…

Sonic Pi, a live coding environment based on Ruby, originally designed to support both computing and music lessons in schools, (was) developed by Sam Aaron in the University of Cambridge Computer Laboratory in collaboration with Raspberry Pi Foundation.

Live Coding is the presentation of the coding act as performance, often as collaboration, producing sound and vision in realtime through runtime.

“..a creativity technique centred upon the writing of source code and the use of interactive programming in an improvised way.”

Could teachers who code in front of a classroom be live coding? What makes it different from teaching code live?

Specifically, “Representation and manipulation of time,” ie. temporal recursion (is a variation on recursively timed events/tasks), and an attribute of Live Coding.

Sonic Pi through the use of SuperCollider, can manipulate the time of any sampled music, as seen in this example of an Amen break cut-up:

Sample slicing through setting and getting variables might feel like a leap, but the main concept of the loop is easy to understand. Music starts and loops.

The main piece of code within Sonic Pi is the live_loop. Just like in Ruby, when creating a loop it requires a do and an end. The live_loop requires that a unique variable be declared immediately following the method.

With the examples below, copy/paste them into Sonic Pi and change the existing values. Perhaps add another sample to your live_loop, or create a new live_loop from what you understand of the code. There are no mistakes, only opportunities.

Here are two loops, one triggering samples routinely, and the second using conditionals:

live_loop :rhythm do
use_bpm 120
sample :bd_808
sample :bd_808, attack: 10, attack_level: 10
sleep 1
sample :bd_klub, amp: 0.5
sleep 1
end
with_fx :reverb do
live_loop :chords do
use_bpm 120
8.times do
play chord(:E4, :minor),amp: 0.5, release: 0.2, pan: 1 if one_in(1)
play chord(:E4, :minor),amp: 0.7, release: 0.2, pan: -1 if one_in(3)
play chord(:A4, :minor),amp: 0.5, release: 0.2, pan: 1 if one_in(3)
play chord(:A3, :minor),amp: 0.8, release: 0.2, pan: -1 if one_in(4)
sleep 0.25
end
end
end

The 8.times do loop 4 chords, each which have between a one-in-one to a one-in-four chance of playing. The loop plays through 8 times and stops, only to have a new live_loop :chords instance be called with new probability.

The use_bpm method calls differently: it behaves like Ruby code and assigns all code below the declaration inside the live_loop :chords to 120 beats per minute.

Another example shows a very familiar block of code:

live_loop :block do
2.times do
define :my_player do |n|
play n
end

my_player rrand(0,65)
sleep 0.5
my_player rrand(0,85)

end
end

While this example generates random tones, and may not classify to some as music, it is an amazing confluence caused by code. The enumerable method of this code block is very easy to see, as define :myplayer iterates through the two random values assigned to :myplayer, separated by a sleep method.

The Sonic Pi application has great documentation and sample code to help anyone start making music through a practice in Live Coding. Share.

Is teaching coding also the act of “live coding?” Our opinion is yes. Is live coding as performance also a form of education: again yes. Both are true. ;)

Live Coding through Education (Sam Aaron, https://www.raspberrypi.org/education/)

Collaboration and learning through live coding (Dagstuhl Seminar, September, 2013 www.dagstuhl.de/13382)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

MDN
MDN

Written by MDN

Composer, Designer, Educator

No responses yet

Write a response