Here is the final code:
live_loop :clock1 do
sleep 1
end
live_loop :clock4 do
sync :clock1
sleep 4
end
live_loop :clock8 do
sync :clock4
sleep 8
end
live_loop :bass, sync: :clock4 do
use_synth :tech_saws
with_fx(:reverb, room: 0.6, mix: 0.4, damp: 0.5) do
n = note knit(:a2, 16, :c3, 16, :e2, 16, :g2, 16).tick
play :a2, release: 4
sleep 4
end
end
def update_filter
return unless $filter
control $filter, cutoff: cosr(100, 20, 0.125), res: cosr(0.8, 0.1, 0.25)
end
live_loop :filter do
update_filter
sleep 0.125
end
live_loop :melody, sync: :clock4 do
use_synth :prophet
seq = cur_scale(num_octaves: [1, 2].choose)
steps = 32
pulse_counts = ring(1)
types = ring(:hold, :tick, :repeat).shuffle
slides = bools(0)
dur = 0.125
seeds = ring(10376, 10081978, 1081978, 131976, 2052008, 29122009)
$current_seed = seeds.tick(:s) if tick(:seeds) % 2 == 0
with_random_seed $current_seed do
seq = seq.pick steps
pulse_counts = ring(1, 2).pick steps
slides = bools(0).pick steps
types = types.pick steps
end
with_fx :level, amp: 1.0 do
with_fx(:reverb, room: 1, mix: 0.6, damp: 0.5) do
with_fx :rlpf, mix: 1 do |filter|
$filter = filter
norm_seq = seq.take steps
norm_pulses = pulse_counts.take steps
norm_types = types.take steps
norm_slides = slides.take steps
s = play norm_seq[0], amp: 0, sustain: dur * norm_pulses.to_a.sum, release: dur
steps.times do
idx = tick
current_note = norm_seq[idx]
pulse_count = norm_pulses[idx]
type = norm_types[idx]
is_slide = norm_slides[idx + 1]
case type
when :repeat
pulse_count.times do
control s, amp: 1, note: current_note
sleep dur / 2
control s, amp: 0
sleep dur / 2
end
when :hold
control s, amp: 1, note: current_note
sleep pulse_count * dur
control s, amp: 0
when :tick
control s, amp: 1, note: current_note
sleep dur / 2
control s, amp: 0
sleep (pulse_count * dur) - (dur / 2)
when :sleep
control s, amp: 0
sleep pulse_count * dur
end
if is_slide then
control s, note_slide: dur / 2
else
control s, note_slide: 0
end
end
end
end
end
end
live_loop :loop, sync: :clock8 do
sample :loop_safari, beat_stretch: 8, amp: 4
sleep 8
end
live_loop :d, sync: :clock8 do
sample :bd_haus, amp: 2 if spread(4, 16).tick
sample :drum_cymbal_pedal, amp: 1.5 if spread(5, 16).tick
sample :drum_snare_soft, amp: 1 if spread(11, 16).look
sleep 0.125
end