Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Title: ?
# Artist: ?
# Date: ?
# License: ?
# Sonic Pi v?
# Settings
use_bpm 100
bar_length = 4
use_random_seed 0
swing = (ring 0.01, -0.01)
# Scales
scl = scale(:a1, :augmented, 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 :some_part do |length = 8|
in_thread do
notes = (ring 14,15,16,17)
idx = get[:some_part_counter]
((bar_length * length) * 4).times do ; tick
with_synth :tri do
play scl[notes.tick(:n)], amp: rrand(0.2, 0.4), sustain: 0.2,
attack: (line 0.1, 0.5, steps: 128)[idx],
release: 0.1 if bools(1,0,1,0, 1,0,0,0, 1,0,0,1, 1,0,1,1).look
end
sleep 0.25 + swing.look
set :some_part_counter, idx += 1
end
end
end
define :another_part do |length = 8, pattern = 1|
in_thread do
notes = (ring 7,6,4,2).mirror if pattern == 1
notes = (ring 9,11,7,9).mirror if pattern == 2
((bar_length * length) * 4).times do ; tick
with_synth :tri do
play scl[notes.tick(:n)], amp: rrand(0.7, 0.8), sustain: 0.2,
release: (line 0.125, 0.5, steps: 16).look if bools(1,0,0,0).look
end
sleep 0.25 + swing.look
end
end
end
define :some_sample_part do |length = 8|
in_thread do
#s = "/path/to/sample.wav"
s = :loop_breakbeat
slices = (line 0, 15, steps: 16, inclusive: true)
with_fx :eq, low_note: 20, low: -0.5, mid_note: 59, mid: -0.8 do
((bar_length * length) * 4).times do ; tick
sample s, slice: slices.look, beat_stretch: 4, amp: 6
sleep 0.25 + swing.look
end
end
end
end
# Reset globals
set :some_part_counter, 0
# Structure
some_part(1) ; bar(1)
another_part(1,1) ; bar(1)
some_part ; another_part(8,1) ; some_sample_part ; bar
some_part ; another_part(8,2) ; bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment