Binary Drum Sequencer - new ways to code drums

Hello!

I’ve been playing around with some new ways to create drum tracks in Sonic Pi. This one is fast and fun and I think some of you will be tempted to try it out.

Briefly, this style of live coding keeps all your drums in a single live_loop, uses a single ticker and a single sleep command. It should save your fingers from working too hard to create complex drum loops.

All it takes is a bit of binary know-how, and some ruby sugar to make it work.

use_bpm 240

live_loop :drums do
  tick
  on 5[look%4] {sample :bd_tek}
  on 3[look%4] {sample :bd_klub}
  on 7[look%4] {sample :bd_boom}
  on 10[look%4] {sample :elec_cymbal, rate: 3}
  sleep 1
end

What’s great about ruby is that when you index into an integer it treats it like a binary number and spits out 1s and 0s. When combined with sonic pi’s ‘on’ which accepts 1s and 0s, you have a fast drum sequencer.

Play with the integers to change the pattern. Change the modulo to create polyrhythms. It’s very flexible that way.

Any feedback would be appreciated. Have a nice day!

Marc

9 Likes

hmm
I got an error using your syntax with { }

Runtime error: NoMethodError
Thread death ±-> :live_loop_drums
undefined method `call’ for Nil:nilClass

Changing to the version below worked

use_bpm 240

live_loop :drums do
  tick
  on 5[look%4] do;sample :bd_tek ;end
  on 3[look%4] do;sample :bd_klub;end
  on 7[look%4] do;sample :bd_boom;end
  on 10[look%4] do;sample :elec_cymbal, rate: 3;end
  sleep 1
end

EDIT or use this alternative using if instead of on

use_bpm 240

live_loop :drums do
  tick
  sample :bd_tek if 5[look%4] >0
  sample :bd_klub if 3[look%5] >0
  sample :bd_boom if 7[look%4] >0
  sample :elec_cymbal, rate: 3 if 10[look%4] >0
  sleep 1
end
4 Likes

@marc @robin.newman
I like this approach. Thanks you for the code and refinements.
Will be giving it a go.

Cheers

What an absolute game changer for drum sequencing. Smart idea!

After playing around with this a little and pulling in custom samples I got some pretty interesting results. I added some rings to alter the pitches of some samples in a pattern.

Your idea is giga brain!
There is a lot of tricks that could be pulled off. Think bitwise operators!

x = 0xA96B
y = 0x4889
z = 0x4647
w = 0xABAB

puts "The bits or sequencer of x #{x.to_s(2)}"
puts "The bits or sequencer of y #{y.to_s(2)}"
puts "The bits or sequencer of z #{z.to_s(2)}"
puts "The bits or sequencer of w #{w.to_s(2)}"

live_loop :drums do
  use_bpm 90
  tick
  sample :bd_tek  if x[look % (x.size*4)] == 1
  sample :bd_klub if y[look % (y.size*4)] == 1
  sample :bd_boom if z[look % (z.size*4)] == 1
  sample :elec_cymbal, rate: 3 if w[look % (w.size*4)] == 1
  sleep 1
end

Although I kind of don’t get how ruby knows to do this or what size it will be based on the dec number.

It’s not like you know if it’s a int or long int or unsigned etc…

If you keep it to hex I think you could have better timing. Knowing it will be one measure. A word is a measure now! Programming mode on the calculator just get real.