Skip to content

Instantly share code, notes, and snippets.

@xavriley
Created August 7, 2015 16:22
Show Gist options
  • Save xavriley/227bf01684b319546207 to your computer and use it in GitHub Desktop.
Save xavriley/227bf01684b319546207 to your computer and use it in GitHub Desktop.
Sonic Pi Beat Slicer 2.0
def nested_beat(el, stepsize=0)
if el.kind_of? Array
el.map {|x| nested_beat(x, (stepsize.zero? ? 1.0 : stepsize/el.length)) }
else
{level: stepsize, step: el}
end
end
def get_nested_beat(pattern)
nested_beat(pattern).flatten.map do |step|
[(1.0/step[:level]), step[:step]]
end
end
live_loop :dr do
use_sample_bpm :loop_amen
use_bpm_mul 0.5
stepsize = 1.0/16
t = (0..1).step(stepsize).each_cons(2).to_a
use_bpm_mul 0.7
bds = [0,2,11]
hhs = [1,3,5,6,8,10,13,14]
sns = [4,12]
ghs = [7,9,15] # ghost snares
bd, hh, sn, gh = [bds,hhs,sns,ghs].map {|idxs|
s,f = t.values_at(*idxs).choose
{start: s, finish: f}
}
rs = bd.merge(amp: 0)
@beat = [hh.merge(rate: 2),
[hh.merge(rate: 1.9),rs,rs,hh.merge(rate: 1.8),rs],
sn,
hh.merge(rate: 2)]
@break = [*[[rs,gh],[rs,gh],rs].shuffle,[rs, [bd,bd,bd,bd]]]
sample :drum_bass_hard
get_nested_beat((knit @beat, 3, @break, 1).tick).each do |mul, opts|
with_bpm_mul mul do
sample :loop_amen, opts
sleep stepsize
end
end
end
@xavriley
Copy link
Author

todo

  • rewrite with slice_points
  • work out how to change get_nested_beat to take a block with access to time
  • how to model triplets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment