Last active
March 20, 2022 21:41
-
-
Save mbutz/2ea7cdd19648c380a721 to your computer and use it in GitHub Desktop.
Sonic Pi Sequencer - Proof of concept
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 (beta) | |
# Not yet music, but a proof of concept and part of a toolbox to | |
# create pattern based music | |
# Rather than think about durations and time distances I'd like to think of | |
# bars and patterns. Something like that: | |
# | 16 | 1 | e | u | e | 2 | e | u | e | 3 | e | u | e | 4 | e | u | e | | |
# |----------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| | |
# | Bass | x | | x | x | | | x | | | x | | | | | x | | | |
# |----------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| | |
# | Snare | | x | | | x | | | | | | | | x | | | | | |
# |----------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| | |
# | o. Hihat | | | x | | | | | | x | | | | | | | | | |
# |----------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| | |
# | c. Hihat | x | x | | x | x | x | x | x | | x | x | x | | x | x | x | | |
# |----------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| | |
# | Shaker | x | | x | | x | x | | x | | x | | x | | x | x | | | |
# |----------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| | |
# | Click | | | | | | | | | | | x | | | x | | | | |
# |----------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---| | |
# The following code tries to step into this direction. | |
set_volume! 1 | |
# This should be crochets, so the following should be applied: | |
# crochet = 1 | |
# quaver = 1/2 = 0.5 | |
# semi-quaver = 1/4 = 0.25 | |
use_bpm 120 # beat = 16tel | |
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.5, rate: 1.5, attack: 0, sustain: 1, release: 0 | |
#sample :drum_snare_hard, amp: 1, rate: 1.2, attack: 0.02, sustain: 1, release: 1, pan: -0.25 | |
#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.7, attack: 0, sustain: 1, release: 0, pan: -0.25 | |
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 | |
# helper: return the actual bmp length based on the | |
# used rythmic pattern | |
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 | |
print "NOTE: No idea what rythmic pattern you mean!" | |
end | |
return d | |
end | |
define :play_melody_bar do |instr, melody_notes, melody_pattern| | |
# Look up the bmp value for the provided pattern | |
# therefore you have to sum up all values from | |
# subarrays of melody_pattern | |
d = 0.5 # fixme - just for testing | |
#melody_pattern.each { |i| puts i.count } | |
pattern = [] | |
melody_pattern.each do |i| | |
v = i.count * d | |
pattern.push(v) | |
end | |
play_pattern_timed melody_notes, pattern | |
end | |
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 | |
live_loop :_base do | |
base_pattern = [1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1] | |
play_rhythm_bar base, base_pattern | |
end | |
live_loop :_base_syn do | |
base_syn_pattern = [1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0] | |
play_rhythm_bar base_syn, base_syn_pattern | |
end | |
live_loop :_hiht do | |
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] | |
play_rhythm_bar hiht, hiht_pattern | |
end | |
live_loop :_snare do | |
with_fx :distortion do | |
snare_pattern = [0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0] | |
play_rhythm_bar snare, snare_pattern | |
end | |
end | |
live_loop :_snare_syn do | |
with_fx :reverb do | |
# 1 + 2 + 3 + 4 + | |
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] | |
play_rhythm_bar snare_syn, snare_syn_pattern | |
end | |
end | |
live_loop :_syn do | |
syn_instr = use_synth :sine | |
use_synth_defaults amp: 2, cutoff: 50, attack: 0, sustain: 0, release: 0.1 | |
syn_notes = [:c3,:c3,:c3,:c3,:g2,:bb2,:c3,:bb2,:g2] | |
syn_pattern = [[1],[1,0],[1,0,0,0,0,0,0],[1],[1],[1],[1],[1],[1]] | |
play_melody_bar syn_instr, syn_notes, syn_pattern | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment