Last active
November 2, 2017 19:24
-
-
Save mbutz/8bf1a47a608a368272f2 to your computer and use it in GitHub Desktop.
Sonic Pi Sequencer - Beta 2
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
# Sonic Pi Sequencer (v2) | |
# Simplified notation of synth lines, can now play chords | |
use_debug false | |
set_volume! 1 | |
use_bpm 120 # beat = quarter note | |
# TODO | |
# Make 'play_rhythm_bar' to work with an array of samples like 'play_melody_bar' | |
# Play random notes from an array, play from a range ... | |
# Possibly unite 'play_melody_bar' and 'play_rythm_bar' because the actually do quite similar things | |
# INSTRUMENTS | |
base = lambda do | |
sample :drum_bass_soft, amp: 4, rate: 0.4, attack: 0.02, sustain: 1, release: 1, pan: 0.2 | |
end | |
base_syn = lambda do | |
sample :drum_bass_hard, amp: 2, rate: 0.8, attack: 0, sustain: 1, release: 1, pan: -0.2 | |
end | |
snare = lambda do | |
sample :drum_snare_hard, amp: 1.3, rate: 1.4, attack: 0, sustain: 1, release: 0, pan: 0.2 | |
#sample :drum_snare_hard, amp: 1, rate: 1.2, attack: 0.02, sustain: 1, release: 1, pan: -0.254 | |
#sample :elec_bong, amp: 1, rate: 1.4, attack: 0, sustain: 0.1, release: 1 | |
end | |
snare_syn = lambda do | |
sample :drum_snare_hard, amp: 1, rate: 1.9, attack: 0, sustain: 1, release: 0, pan: 0.2 | |
end | |
hiht = lambda do | |
sample :drum_cymbal_closed, rate: 2, amp: 3 | |
end | |
beep = lambda do | |
sample :elec_blip, rate: 1.3, amp: 1 | |
end | |
syn_base_instr = lambda do | |
# use_synth :pretty_bell | |
use_synth :sine | |
use_synth_defaults amp: 2, cutoff: 120, attack: 0, sustain: 0.1, release: 0.2 | |
end | |
syn_line_instr = lambda do | |
use_synth :pretty_bell | |
use_synth_defaults amp: 0.5, attack: 0, sustain: 0.1, release: 0.02, pan: rrand(-1, 1) | |
end | |
# FUNCTIONS | |
# Helper function: return the actual bmp fraction based on the defined rythmic pattern | |
# which is quarter = 1, eighth = 0.5, sixteenth = 0.25 or thirty-second = 0.125 long beat | |
define :get_bmp_val do |a| | |
if a.count == 4 | |
d = 1 | |
elsif a.count == 8 | |
d = 0.5 | |
elsif a.count == 16 | |
d = 0.25 | |
elsif a.count == 32 | |
d = 0.125 | |
else | |
puts "NOTE: No idea what rythmic pattern you mean!" | |
end | |
return d | |
end | |
# Play rhythm (i.e. samples) | |
define :play_rhythm_bar do |instr, instr_pattern| | |
d = get_bmp_val instr_pattern | |
instr_pattern.each do |i| | |
if i != 0 | |
instr.call | |
end | |
sleep d | |
end | |
end | |
define :play_notes do |instr, notes| | |
t = get_bmp_val notes | |
notes.each do |n| | |
if n != :- | |
instr.call | |
play n | |
end | |
sleep t | |
end | |
end | |
# rhythmic patterns | |
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
# 1 e + e 2 e + e 3 e + e 4 e + e | |
base_pattern = [1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 ] | |
base_syn_pattern = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] | |
hiht_pattern = [1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0] | |
snare_pattern = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ] | |
snare_syn_pattern = [0,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0] | |
# melody in eighth pattern | |
# 1 e + e 2 e + e 3 e + e 4 e + e | |
syn_base = [[:c3,:eb3,:g3,:d4,:f4], | |
[:c3,:eb3,:g3,:d4,:f4], | |
:-,:c3,:-,:-,:bb2,:a2,:-,:-,:c3,:g2,:bb2,:c3,:bb2,:g2] | |
syn_line = [:c5,:g5,:f5,:g5,:b5,:g5,:a5,:f5,:c5,:g5,:f5,:g5,:eb5,:f5,:d5,:eb5] | |
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
# PLAY THE SHIT | |
live_loop :_base do | |
play_rhythm_bar base, base_pattern | |
end | |
live_loop :_base_syn do | |
play_rhythm_bar base_syn, base_syn_pattern | |
end | |
live_loop :_hiht do | |
play_rhythm_bar hiht, hiht_pattern | |
end | |
live_loop :_snare do | |
with_fx :distortion do | |
play_rhythm_bar snare, snare_pattern | |
end | |
end | |
live_loop :_snare_syn do | |
with_fx :reverb do | |
play_rhythm_bar snare_syn, snare_syn_pattern | |
end | |
end | |
# live_loop :_syn do | |
# play_melody_bar syn_instr, syn_base, syn_pattern | |
# end | |
live_loop :_syn_base do | |
play_notes syn_base_instr, syn_base | |
end | |
# live_loop :_syn_line do | |
# play_notes syn_line_instr, syn_line | |
# end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment