Sail with me into the Pi - Part 3
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
module NumberMethods | |
def beat; self; end | |
def beats; self; end | |
def triplet; self.to_f / 3; end | |
def triplets; self.to_f / 3; end | |
def bar; self * 4; end | |
def bars; self * 4; end | |
end | |
::Numeric.send(:include, NumberMethods) | |
@synths = { | |
vamp: :tri, | |
bass: :saw, | |
riff: :prophet | |
} | |
def vamp(notes, length) | |
use_synth @synths[:vamp] | |
length.times do | |
with_fx :reverb, damp: 0.8, room: 0.4 do | |
play notes, attack: 0.01, sustain: 1.triplets, release: 1.triplet | |
sleep 1.beat | |
end | |
end | |
end | |
def bass_hit(root) | |
use_synth @synths[:bass] | |
root_note = note(root) | |
notes = [root_note, (root_note + 7), (root_note + 12)] | |
play notes, :sustain => 2.beats, :release => 2.triplets | |
sleep 2.beats | |
end | |
def riff_pluck(note, length) | |
use_synth @synths[:riff] | |
play note, attack: 0, decay: 0, sustain: 0, release: 1.triplet | |
sleep length | |
end | |
def riff_triplet(note) | |
3.times { riff_pluck(note, 1.triplet) } | |
end | |
def riff_Eb | |
sleep 2.beats | |
riff_triplet(:Eb4) | |
riff_triplet(:Gb4) | |
riff_pluck(:Ab4, 1.beat) | |
riff_pluck(:Bb4, 1.beat) | |
riff_pluck(:Ab4, 2.triplets) | |
riff_pluck(:Gb4, 1.triplet) | |
riff_pluck(:Eb4, 1.beat) | |
end | |
def riff_Db | |
sleep 2.beats | |
riff_triplet(:Db4) | |
riff_triplet(:Eb4) | |
riff_pluck(:Bb3, 1.beat) | |
riff_pluck(:Eb4, 1.beat) | |
riff_pluck(:Gb4, 2.triplets) | |
riff_pluck(:Eb4, 1.triplet) | |
riff_pluck(:Db4, 1.beat) | |
end | |
def short_riff_Gb | |
sleep 2.beats | |
riff_triplet(:Bb4) | |
riff_triplet(:Db5) | |
end | |
def short_riff_Db | |
sleep 2.beats | |
riff_triplet(:Eb5) | |
riff_pluck(:Gb5, 1.beat) | |
end | |
#--------------------------- | |
def bass_loop | |
in_thread do | |
bass_hit(:Eb2) | |
sleep 6.beats | |
bass_hit(:Eb2) | |
sleep 6.beats | |
bass_hit(:Db2) | |
sleep 6.beats | |
bass_hit(:Gb2) | |
sleep 2.beats | |
bass_hit(:Db2) | |
sleep 2.beats | |
end | |
end | |
def vamp_loop | |
in_thread do | |
vamp([:eb4, :gb4, :eb3], 6) | |
vamp([:eb4, :ab4, :eb3], 2) | |
vamp([:eb4, :gb4, :eb3], 6) | |
vamp([:eb4, :ab4, :eb3], 2) | |
vamp([:db4, :f4, :db3], 8) | |
vamp([:gb4, :db5, :gb3], 4) | |
vamp([:db4, :f4, :db3], 4) | |
end | |
end | |
def riff_loop | |
in_thread do | |
2.times { riff_Eb } | |
riff_Db | |
short_riff_Gb | |
short_riff_Db | |
end | |
end | |
use_bpm 120 | |
vamp([:eb4, :ab4], 2) | |
vamp_loop | |
wait 8.bars | |
bass_loop | |
vamp_loop | |
riff_loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment