Skip to content

Instantly share code, notes, and snippets.

@smn
Last active June 17, 2017 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smn/274d6741854fcdd18ab0 to your computer and use it in GitHub Desktop.
Save smn/274d6741854fcdd18ab0 to your computer and use it in GitHub Desktop.
binary black sheep do you have any wool?
# CDEFGABC
the_song = <<-BA_BA_BLACKSHEEP
10000000
10000000
00001000
00001000
00000100
00000100
00001000
00001000
00010000
00010000
00100000
00100000
01000000
01000000
10000000
BA_BA_BLACKSHEEP
def read_notes(ones_and_zeros)
note_map = [:C3,:D3,:E3,:F3,:G3,:A3,:B3,:C4]
notes = ones_and_zeros.each_with_index.collect do |one_or_zero, index |
if one_or_zero == '1'
note_map[index]
end
end
notes.select { |note| note }
end
def play_song(song, params)
speed = params[:speed] || 4.0
song.each_line do |line|
play_chord read_notes(line.strip.each_char), release: (1.0/speed)
sleep (1.0/speed)
end
end
def song_duration(song, params)
speed = params[:speed] || 4.0
song.strip.split.length * (1.0/speed)
end
print song_duration the_song, :speed => 2
with_fx :distortion do
play_song the_song, :speed => 4
end
@xavriley
Copy link

Nice work! I really like how you've effectively created a tracker interface just using 0's and 1's!

Just wanted to say that Sonic Pi has a define method which behaves a lot like def. It's best to use that to make sure Sonic Pi can do all the optimisations it needs to. Not a big deal in this example but it helps when you're doing more complex stuff :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment