Die Laserstrahlen schnitten durch die Rauschwaden als der Subwoofer den Bass tief in die Körper der Menge pumpte. Die Atmosphäre war erfüllt von einem berauschenden Mix aus Synthesizern und Tanzen. Aber irgendetwas stimmte nicht in diesem Nachtklub. Über der DJ-Kabine leuchtete in bunten Farben futuristischer Text; bewegte sich, tanzte, blinkte. Dies war keine abgefahrene Lichtshow, sondern einfach eine Projektion von Sonic Pi, das auf einem Raspberry Pi lief. Der Insasse der DJ-Kabine drehte keine Platten, nein, er schrieb und bearbeitete Programmcode. Live. Das ist Live-Coding.
Es mag sich wie eine weit hergeholte Geschichte aus einem futuristischen Nachtklub anhört, aber Musik auf diese Weise zu programmieren, ist ein wachsender Trend, bekannt als Live-Coding (http://toplap.org). Eine aktuelle Richtung, die diese Art des Musikmachens eingeschlagen hat, ist der Algorave (http://algorave.com) - Veranstaltungen, auf denen Künstler wie ich Musik zum Tanzen programmieren. Du musst aber zum Live-Coden nicht in einem Nachtklub sein. Mit Sonic Pi v2.6+ kannst du überall loslegen, wohin du deinen Raspberry Pi und ein Paar Kopfhörer oder Lautsprecher mitnimmst. Wenn du das Ende dieses Artikels erreicht hast, wirst du bereits deine eigenen Beats programmieren und live bearbeitest. Wohin do von dort weiter gehst, wird einzig von deiner Vorstellungskraft beschränkt.
Der Schlüssel zum ‘live-coding’ mit Sonic Pi ist das Beherrschen des ‘live_loops’. Schauen wir uns einen an:
live_loop :beats do
sample :bd_haus
sleep 0.5
end
Ein ‘live-loop’ hat 4 Hauptbestandteile. Der erste ist sein Name. Unser ‘live-loop’ oben heißt ‘: Beats’. Du kannst frei entscheiden, wie du deinen ‘live_loop’ nennen möchtest. Sei kreativ! Ich benutze oft Namen, die dem Publikum etwas über die Musik mitteilen, die ich mache. Der zweite Bestandteil ist das Wort ‘do’, welches anzeigt wo der ‘live_loop’ beginnt. Der dritte ist das Wort ‘end’, das markiert, wo der ‘live_loop’ endet. Schließlich gibt es noch den Block innerhalb des ‘live_loops’, der beschreibt, was die Schleife wiederholen soll - das ist der Teil zwischen ‘do’ und ‘end’. In unsrem Fall spielen wir ein Bass-Drum-Sample und warten einen halben Takt. Dies führt zu einem schönen regelmäßigen Bass Beat. Auf gehts, kopiere den ‘live_loop’ in einem leeren Sonic Pi-Buffer und drücke ‘Ausführen’. Boom, Boom, Boom!
Ok, so what’s so special about the live_loop
? So far it just seems like a glorified loop
! Well, the beauty of live_loop
s is that you can redefine them on-the-fly. This means that whilst they’re still running, you can change what they do. This is the secret to live coding with Sonic Pi. Let’s have a play:
live_loop :choral_drone do
sample :ambi_choir, rate: 0.4
sleep 1
end
Drücke den ‘Ausführen’-Button oder ‘Alt-R’. Du hörst jetzt einen wunderschönen Chor-Sound. Jetzt, während dieser läuft, änderst du ‘rate’-Wert von ‘0,4’ auf ‘0,38’. Drücke erneut ‘Ausführen’. Woah! Hörst du wie sich die Tonhöhe des Chors ändert? Ändere den Wert wieder zurück auf ‘0,4’. Nun setze den Wert auf ‘0,2’, runter bis ‘0,19’ und dann wieder auf ‘0,4’. Siehst du, wie du durch das Ändern eines Parameters, im laufenden Programm, die volle Kontrolle über die Musik erlangen kannst? Spiele ein bisschen mit den Werten für ‘rate’ - wähle deine eigenen Werte. Versuche negative Zahlen, wirklich kleine Zahlen und ganz große Zahlen. Viel Spass!
One of the most important lessons about live_loop
s is that they need rest. Consider the following live_loop
:
live_loop :infinite_impossibilities do
sample :ambi_choir
end
If you try running this code, you’ll immediately see Sonic Pi complaining that the live_loop
did not sleep. This is a safety system kicking in! Take a moment to think about what this code is asking the computer to do. That’s right, it’s asking the computer to play an infinite amount of choir samples in zero time. Without the safety system the poor computer will try and do this and crash and burn in the process. So remember, your live_loop
s must contain a sleep
.
Music is full of things happening at the same time. Drums at the same time as bass at the same time as vocals at the same time as guitars… In computing we call this concurrency and Sonic Pi provides us with an amazingly simple way of playing things at the same time. Simply use more than one live_loop
!
live_loop :beats do
sample :bd_tek
with_fx :echo, phase: 0.125, mix: 0.4 do
sample :drum_cymbal_soft, sustain: 0, release: 0.1
sleep 0.5
end
end
live_loop :bass do
use_synth :tb303
synth :tb303, note: :e1, release: 4, cutoff: 120, cutoff_attack: 1
sleep 4
end
Here, we have two live_loop
s, one looping quickly making beats and another looping slowly making a crazy bass sound.
One of the interesting things about using multiple live_loop
s is that they each manage their own time. This means it’s really easy to create interesting polyrhythmical structures and even play with phasing Steve Reich style. Check this out:
# Steve Reich's Piano Phase
notes = (ring :E4, :Fs4, :B4, :Cs5, :D5, :Fs4, :E4, :Cs5, :B4, :Fs4, :D5, :Cs5)
live_loop :slow do
play notes.tick, release: 0.1
sleep 0.3
end
live_loop :faster do
play notes.tick, release: 0.1
sleep 0.295
end
In each of these tutorials, we’ll end with a final example in the form of a new piece of music which draws from all of the ideas introduced. Read this code and see if you can imagine what it’s doing. Then, copy it into a fresh Sonic Pi buffer and hit Run and actually hear what it sounds like. Finally, change one of the numbers or comment and uncomment things out. See if you can use this as a starting point for a new performance, and most of all have fun! See you next time…
with_fx :reverb, room: 1 do
live_loop :time do
synth :prophet, release: 8, note: :e1, cutoff: 90, amp: 3
sleep 8
end
end
live_loop :machine do
sample :loop_garzul, rate: 0.5, finish: 0.25
sample :loop_industrial, beat_stretch: 4, amp: 1
sleep 4
end
live_loop :kik do
sample :bd_haus, amp: 2
sleep 0.5
end
with_fx :echo do
live_loop :vortex do
# use_random_seed 800
notes = (scale :e3, :minor_pentatonic, num_octaves: 3)
16.times do
play notes.choose, release: 0.1, amp: 1.5
sleep 0.125
end
end
end