Skip to content

Instantly share code, notes, and snippets.

@ktbaek
Created May 26, 2018 16:06
Show Gist options
  • Save ktbaek/e2fb129de9cfdb61c6440f2f3d512814 to your computer and use it in GitHub Desktop.
Save ktbaek/e2fb129de9cfdb61c6440f2f3d512814 to your computer and use it in GitHub Desktop.
## Sonic Pi experiments
## Improved drum sequencer with 16th notes and swing percentage option
use_bpm 120
## define drum sounds
define :play_kick do |vol|
sample :bd_haus, amp: vol * 1.4, beat_stretch: 0.4
end
define :play_tom do |vol|
with_fx :reverb, room: 0.7 do
sample :drum_tom_lo_soft, finish: 0.2, cutoff: 75, amp: vol
end
end
define :play_snare do |vol|
sample :drum_snare_soft, amp: vol
end
define :play_hats do |vol|
sample :drum_cymbal_closed, amp: vol * 0.6
end
define :play_clap do |vol|
with_fx :reverb, mix: 0.2, room: 0.7 do
synth :cnoise, release: 0.7, decay: 0.02, sustain_level: 0.04, attack_level: 3, amp: vol * 1.5
sample :perc_snap, start: 0.02, release: 2, amp: vol * 0.2, rate: 0.4
sleep 0.01
synth :cnoise, release: 0.6, decay: 0.02, sustain_level: 0.04, attack_level: 1.5, amp: vol * 1.5
end
end
define :play_industrial do |vol|
with_fx :reverb, room: 0.8 do
sample :ambi_sauna, start: 0.05, finish: 0.07, cutoff: 100, amp: vol
end
end
## set volume categories
ghost = -> { rrand(0.2, 0.3) }
normal = -> { rrand(0.4, 0.6) }
accent = -> { rrand(0.8, 0.9) }
define :beats do |drum, trigger, at, vol|
## the method takes as parameters:
## drum = which instrument (drum) to use
## trigger = whether the index number or kick (on or off-beat) triggers the drum
## at = which indeces or kicks triggers the drum
## vol = volume
if at.include? trigger
send(drum, vol.call)
end
end
define :interval do |kick, swing_pct|
## defines interval time and adds swing
if (swing_pct < 50)
delay = 0
else
delay = (swing_pct - 50) * 0.005
end
if(kick % 2) == 0
# off beats need to be slightly late for swing
sleep (0.25 - delay)
else
sleep (0.25 + delay)
end
end
define :play_beat_bar1 do
## this is the sequencer. You can use either kick (1 to 4) or index (1 to 16) to
# trigger the drum. Both are useful.
[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4].each.with_index(1) do |kick, index|
beats(:play_kick, kick, at = [1], normal)
beats(:play_kick, kick, at = [4], ghost) if rand < 0.2
beats(:play_hats, kick, at = [3], normal)
beats(:play_hats, kick, at = [2,4], ghost) if rand < 0.1
beats(:play_tom, index, at = [7], normal)
beats(:play_tom, index, at = [15], normal) if rand < 0.1
beats(:play_snare, index, at = [5, 13], accent)
beats(:play_snare, index, at = [16], ghost)
beats(:play_clap, index, at = [5], ghost)
beats(:play_hats, kick, at = [1,2,3,4], ghost) if rand < 0.4
interval(kick, 60)
end
end
define :play_beat_bar2 do
## this is the sequencer. You can use either kick (1 to 4) or index (1 to 16) to
# trigger the drum. Both are useful.
[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4].each.with_index(1) do |kick, index|
beats(:play_kick, kick, at = [1], normal)
beats(:play_kick, kick, at = [4], ghost) if rand < 0.2
beats(:play_hats, kick, at = [3], normal)
beats(:play_hats, kick, at = [2,4], ghost) if rand < 0.1
beats(:play_tom, index, at = [7], normal)
beats(:play_tom, index, at = [15], normal) if rand < 0.3
beats(:play_snare, index, at = [5, 13], accent)
beats(:play_clap, index, at = [5, 11], ghost)
beats(:play_hats, kick, at = [1,2,3,4], ghost) if rand < 0.4
interval(kick, 60)
end
end
live_loop :drumbeat do
cue :bar1
play_beat_bar1
cue :bar2
play_beat_bar2
end
#stop
live_loop :bell do
sync :bar1
use_synth :blade
with_fx :echo, phase: 0.5, decay: 4 do
with_fx :reverb, room: 0.4, mix: 0.4 do
sleep 2.5
play_chord chord(:d3, :minor7), release: 0.7, amp: normal.call
sleep 1.5
end
end
end
live_loop :bell_1 do
sync :bar1
use_synth :blade
with_fx :reverb, room: 0.8, mix: 0.6 do
sleep 0.5
play_chord chord(:f3, :minor7), release: 0.5, amp: normal.call
end
end
live_loop :low do
#stop
tick
sync :bar1
12.times do
synth :zawa, wave: 0, phase: 0.8, release: 4, amp: 0.05, note: (knit :f3, 4, :d3, 4).look, cutoff: (line 60, 120, steps: 6).look
sleep 0.5
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment