So I’ve created a proof of concept for a ‘beat pattern’ language for creating beats from a string of characters. For now, it’s just a way to learn programming for Sonic Pi, although I hope to develop it into something useful. Here’s a demonstration:
…and here’s the code:
use_bpm 120
def playbeat(beatstring)
samp = ":drum_bass_hard"
sleep_dur = 1
for i in (0..beatstring.length-1).step(2)
note = beatstring[i]
dur = beatstring[i+1]
case note
when "h"
samp = :drum_cymbal_closed
when "s"
samp = :good_snare
when "k"
samp = :drum_bass_hard
end
case dur
when "1"
sample samp
sleep 1
when "2"
2.times do
sample samp
sleep 0.5
end
when "4"
4.times do
sample samp
sleep 0.25
end
end
end
end
live_loop :beatz do
playbeat("k2s1k1s2")
end
live_loop :hh do
playbeat("h1")
end
It’s very limited and simplistic at the moment, but provides a quick and dirty way to throw together simple beats in a pretty compact form. The one thing I like is that you can play multiple notes with a single note/duration combination (e.g., h4 will play four 16th notes with a high-hat sound). On the other hand-- this notation doesn’t allow you to (for instance) play two eighth notes using a different sound for each note. So: it will eventually become less compact as I address these limitations…
Bryan