noizZze

Rhythm Generation With an Euclidian Algorithm

The original post on this is at wesen’s where you can pick up the idea and hear some samples. In this post I simply show the Ruby implementation of the algorithm. It doesn’t work with lists, but rather does simple math to achieve the same effect.

The idea of distributing pulses is curious. It lacks one important aspect though – shifting. Currently all patterns start with “1”. Thanks wesen, for sharing this. Here comes the Ruby version.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def distribute(pulses, steps)
  pauses    = steps - pulses
  per_pulse = (pauses / pulses).to_i
  remainder = pauses % pulses

  rhythm = []
  pulses.times do |pulse|
    rhythm << 1
    per_pulse.times { rhythm << 0 }
    rhythm << 0 if pulse < remainder
  end

  return rhythm
end

# 1 0 0 1 0 0 1 0
puts distribute(3, 8).inspect