Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Title: Cave Diving (Binarysweets Remix)
# Artist: SR388
# Date: October 2020
# License: cc-by
# Sonic Pi v3.2.2 (Win10)
# https://binarysweets.bandcamp.com/album/3r
# Settings
use_bpm 106
bar_length = 4
use_random_seed 1
swing = (ring 0.01, -0.01)
# Scales
set :scl, scale(:c1, :major, num_octaves: 3)
# Functions
define :get_pitch_from_note do |note, sample_base_note, fine_tune|
return note - sample_base_note + fine_tune
end
define :bar do |length = 8|
sleep bar_length * length
end
# Loops
define :pad_1 do |length = 8|
in_thread do
scl = get :scl
cnt = get :pad_1_counter
with_fx :whammy, deltime: (line, 0.05, 0.5, steps: 8)[cnt], grainsize: (line, 0.075, 0.75, steps: 16)[cnt] do
with_fx :hpf, cutoff: 65 do
((bar_length * length) / 16).times do ; tick
with_fx :wobble, phase: 1, wave: 1 do
with_synth :saw do
play chord(scl[14], :m9), attack: 0.5, sustain: 4, decay: 4, release: 14, amp: rrand(0.5, 0.7), pan: -0.7
end
end
with_fx :wobble, phase: 2, invert_wave: 1, wave: 1 do
with_synth :fm do
play chord(scl[14], :m9), attack: 0.5, sustain: 4, decay: 4, release: 14, amp: rrand(0.5, 0.7), pan: 0.7
end
end
sleep 16
cnt += 1
set :pad_1_counter, cnt
end
end
end
end
end
define :pad_2 do |length = 8|
in_thread do
scl = get :scl
cnt = get :pad_2_counter
with_fx :hpf, cutoff: 65 do
((bar_length * length) / 16).times do ; tick
with_synth :hollow do
play chord(scl[14], :m9), attack: 0.5, sustain: 4, decay: 4, release: 12, amp: (line 1.0, 2.2, steps: 8)[cnt]
end
sleep 16
cnt += 1
set :pad_2_counter, cnt
end
end
end
end
define :pad_3 do |length = 8, pattern = 1|
in_thread do
scl = get :scl
s = "?/Sonic Pi/Samples/Synth Samples/Heven Voice C3.wav"
chords = chord(scl[14], :m9) if pattern == 1
chords = chord(scl[7], :m9) if pattern == 2
((bar_length * length) / 8).times do ; tick
chords.each do |note|
with_fx :echo, decay: 8, phase: 0.5 do
sample s,
rpitch: get_pitch_from_note(note, 48, 0),
amp: rrand(0.3, 0.5),
pan: [-0.5, 0.5].choose
end
end
sleep 8
end
end
end
define :kicks do |length = 8, pattern = 1|
in_thread do
s = "?/Sonic Pi/Tracks/2020/Remixes/SR388 - Cave Diving Remix/Samples/Drums1.wav"
sleep_time = 4
sleep_time = 2 if pattern == 2
sleep_time = 1 if pattern == 3
((bar_length * length) / sleep_time).times do ; tick
sample s, amp: rrand(0.9, 1.0)
sleep sleep_time + swing.look
end
end
end
define :snares do |length = 8, pattern = 1|
in_thread do
s = "?/Sonic Pi/Tracks/2020/Remixes/SR388 - Cave Diving Remix/Samples/Drums2.wav"
slices = (line 0, 16, steps: 16, inclusive: true)
num_slices = 32 if pattern == 1
num_slices = 16 if pattern == 2
num_slices = 8 if pattern == 3
((bar_length * length) * 4).times do ; tick
with_fx :rhpf, cutoff: (line 50, 100, steps: 32).look, res: 0.5 do
sample s, amp: rrand(0.6, 0.7), slice: slices.look, num_slices: num_slices
end
sleep 0.25 + swing.look
end
end
end
define :toms do |length = 8, pattern = 1|
in_thread do
s = "?/Sonic Pi/Tracks/2020/Remixes/SR388 - Cave Diving Remix/Samples/Toms.wav"
((bar_length * length) / 4).times do ; tick
sample s, amp: rrand(0.8, 0.9), rpitch: 0.01, pan: -1 if bools(0, 1).look
sample s, amp: rrand(0.8, 0.9), rpitch: -0.01, pan: 1 if bools(0, 1).look
#sample s, amp: rrand(0.8, 0.9), pan: -0.5 if bools(0, 1).look
sleep 4 + swing.look
end
end
end
define :bass do |length = 8, pattern = 1|
in_thread do
scl = get :scl
notes = (ring 7,6,8,7, 5,11,12,9) if pattern == 1
idx = 0
((bar_length * length) * 4).times do ; tick
if bools(1,0,0,0, 1,0,1,0, 0,0,0,0, 1,0,0,0, 1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1).look
with_fx :bitcrusher, bits: (ring 16,16,16,16, 8,8,3).look do
play scl[notes[idx]], amp: rrand(0.2, 0.3), release: 0.5
end
idx += 1
end
sleep 0.25 + swing.look
end
end
end
define :lead do |length = 8, pattern = 1|
in_thread do
scl = get :scl
notes = (ring 14,17,12,11) if pattern == 1
notes = (ring 15,16,11,18) if pattern == 2
idx = 0
with_fx :ping_pong do
((bar_length * length) / 8).times do ; tick
use_synth_defaults wave: 2, phase: 0.75, range: 8, res: (ring 0.6,0.7,0.8,0.9).look
with_synth :zawa do
play scl[notes[idx]]+24, attack: 4, sustain: 2, decay: 1, release: 8, amp: 0.4
end
idx += 1
sleep 8 + swing.look
end
end
end
end
# Reset globals
set :pad_1_counter, 0
set :pad_2_counter, 0
# Structure
with_fx :compressor, threshold: 0.5 do
pad_1 ; kicks ; toms ; bar
pad_1 ; kicks ; toms ; bar
pad_1 ; kicks ; toms ; snares ; bar
pad_1 ; kicks ; toms ; snares ; bar
pad_1 ; kicks(8,2) ; snares ; toms ; bar
pad_1 ; kicks(8,2) ; snares ; toms ; bar
pad_1 ; kicks(8,2) ; snares ; toms ; bass ; pad_2 ; bar
pad_1 ; kicks(8,2) ; snares ; toms ; bass ; pad_2 ; bar
pad_1 ; kicks(8,2) ; snares(8,2) ; toms ; bass ; pad_2 ; bar
pad_1 ; kicks(6,2) ; snares(6,2) ; toms ; bass ; pad_2 ; bar
pad_1 ; kicks(8,3) ; snares(8,3) ; toms ; bass ; pad_2 ; pad_3 ; bar
pad_1 ; kicks(8,3) ; snares(8,3) ; toms ; bass ; pad_2 ; pad_3 ; bar
kicks(8,2) ; snares(8,3) ; toms ; bass ; pad_2 ; pad_3 ; lead ; bar
kicks(7,2) ; snares(7,2) ; toms ; bass ; pad_2 ; pad_3 ; lead(8,2) ; bar
pad_2 ; pad_3(8,2) ; bar
pad_2 ; pad_3(8,2) ; bar
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment