Last active
June 17, 2017 01:15
-
-
Save smn/274d6741854fcdd18ab0 to your computer and use it in GitHub Desktop.
binary black sheep do you have any wool?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 likedef
. 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 :)