Trying all 8 beat long snare drum patterns

Here snare drum is allowed to take all possible permutations of 8 beats.

use_bpm 120

SN_all = [[0, 0, 0, 0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0, 0, 0, 1],
          [0, 0, 0, 0, 0, 0, 1, 0],
          [0, 0, 0, 0, 0, 0, 1, 1],
          [0, 0, 0, 0, 0, 1, 0, 0],
          [0, 0, 0, 0, 0, 1, 0, 1],
          [0, 0, 0, 0, 0, 1, 1, 0],
          [0, 0, 0, 0, 0, 1, 1, 1],
          [0, 0, 0, 0, 1, 0, 0, 0],
          [0, 0, 0, 0, 1, 0, 0, 1],
          [0, 0, 0, 0, 1, 0, 1, 0],
          [0, 0, 0, 0, 1, 0, 1, 1],
          [0, 0, 0, 0, 1, 1, 0, 0],
          [0, 0, 0, 0, 1, 1, 0, 1],
          [0, 0, 0, 0, 1, 1, 1, 0],
          [0, 0, 0, 0, 1, 1, 1, 1],
          [0, 0, 0, 1, 0, 0, 0, 0],
          [0, 0, 0, 1, 0, 0, 0, 1],
          [0, 0, 0, 1, 0, 0, 1, 0],
          [0, 0, 0, 1, 0, 0, 1, 1],
          [0, 0, 0, 1, 0, 1, 0, 0],
          [0, 0, 0, 1, 0, 1, 0, 1],
          [0, 0, 0, 1, 0, 1, 1, 0],
          [0, 0, 0, 1, 0, 1, 1, 1],
          [0, 0, 0, 1, 1, 0, 0, 0],
          [0, 0, 0, 1, 1, 0, 0, 1],
          [0, 0, 0, 1, 1, 0, 1, 0],
          [0, 0, 0, 1, 1, 0, 1, 1],
          [0, 0, 0, 1, 1, 1, 0, 0],
          [0, 0, 0, 1, 1, 1, 0, 1],
          [0, 0, 0, 1, 1, 1, 1, 0],
          [0, 0, 0, 1, 1, 1, 1, 1],
          [0, 0, 1, 0, 0, 0, 0, 0],
          [0, 0, 1, 0, 0, 0, 0, 1],
          [0, 0, 1, 0, 0, 0, 1, 0],
          [0, 0, 1, 0, 0, 0, 1, 1],
          [0, 0, 1, 0, 0, 1, 0, 0],
          [0, 0, 1, 0, 0, 1, 0, 1],
          [0, 0, 1, 0, 0, 1, 1, 0],
          [0, 0, 1, 0, 0, 1, 1, 1],
          [0, 0, 1, 0, 1, 0, 0, 0],
          [0, 0, 1, 0, 1, 0, 0, 1],
          [0, 0, 1, 0, 1, 0, 1, 0],
          [0, 0, 1, 0, 1, 0, 1, 1],
          [0, 0, 1, 0, 1, 1, 0, 0],
          [0, 0, 1, 0, 1, 1, 0, 1],
          [0, 0, 1, 0, 1, 1, 1, 0],
          [0, 0, 1, 0, 1, 1, 1, 1],
          [0, 0, 1, 1, 0, 0, 0, 0],
          [0, 0, 1, 1, 0, 0, 0, 1],
          [0, 0, 1, 1, 0, 0, 1, 0],
          [0, 0, 1, 1, 0, 0, 1, 1],
          [0, 0, 1, 1, 0, 1, 0, 0],
          [0, 0, 1, 1, 0, 1, 0, 1],
          [0, 0, 1, 1, 0, 1, 1, 0],
          [0, 0, 1, 1, 0, 1, 1, 1],
          [0, 0, 1, 1, 1, 0, 0, 0],
          [0, 0, 1, 1, 1, 0, 0, 1],
          [0, 0, 1, 1, 1, 0, 1, 0],
          [0, 0, 1, 1, 1, 0, 1, 1],
          [0, 0, 1, 1, 1, 1, 0, 0],
          [0, 0, 1, 1, 1, 1, 0, 1],
          [0, 0, 1, 1, 1, 1, 1, 0],
          [0, 0, 1, 1, 1, 1, 1, 1],
          [0, 1, 0, 0, 0, 0, 0, 0],
          [0, 1, 0, 0, 0, 0, 0, 1],
          [0, 1, 0, 0, 0, 0, 1, 0],
          [0, 1, 0, 0, 0, 0, 1, 1],
          [0, 1, 0, 0, 0, 1, 0, 0],
          [0, 1, 0, 0, 0, 1, 0, 1],
          [0, 1, 0, 0, 0, 1, 1, 0],
          [0, 1, 0, 0, 0, 1, 1, 1],
          [0, 1, 0, 0, 1, 0, 0, 0],
          [0, 1, 0, 0, 1, 0, 0, 1],
          [0, 1, 0, 0, 1, 0, 1, 0],
          [0, 1, 0, 0, 1, 0, 1, 1],
          [0, 1, 0, 0, 1, 1, 0, 0],
          [0, 1, 0, 0, 1, 1, 0, 1],
          [0, 1, 0, 0, 1, 1, 1, 0],
          [0, 1, 0, 0, 1, 1, 1, 1],
          [0, 1, 0, 1, 0, 0, 0, 0],
          [0, 1, 0, 1, 0, 0, 0, 1],
          [0, 1, 0, 1, 0, 0, 1, 0],
          [0, 1, 0, 1, 0, 0, 1, 1],
          [0, 1, 0, 1, 0, 1, 0, 0],
          [0, 1, 0, 1, 0, 1, 0, 1],
          [0, 1, 0, 1, 0, 1, 1, 0],
          [0, 1, 0, 1, 0, 1, 1, 1],
          [0, 1, 0, 1, 1, 0, 0, 0],
          [0, 1, 0, 1, 1, 0, 0, 1],
          [0, 1, 0, 1, 1, 0, 1, 0],
          [0, 1, 0, 1, 1, 0, 1, 1],
          [0, 1, 0, 1, 1, 1, 0, 0],
          [0, 1, 0, 1, 1, 1, 0, 1],
          [0, 1, 0, 1, 1, 1, 1, 0],
          [0, 1, 0, 1, 1, 1, 1, 1],
          [0, 1, 1, 0, 0, 0, 0, 0],
          [0, 1, 1, 0, 0, 0, 0, 1],
          [0, 1, 1, 0, 0, 0, 1, 0],
          [0, 1, 1, 0, 0, 0, 1, 1],
          [0, 1, 1, 0, 0, 1, 0, 0],
          [0, 1, 1, 0, 0, 1, 0, 1],
          [0, 1, 1, 0, 0, 1, 1, 0],
          [0, 1, 1, 0, 0, 1, 1, 1],
          [0, 1, 1, 0, 1, 0, 0, 0],
          [0, 1, 1, 0, 1, 0, 0, 1],
          [0, 1, 1, 0, 1, 0, 1, 0],
          [0, 1, 1, 0, 1, 0, 1, 1],
          [0, 1, 1, 0, 1, 1, 0, 0],
          [0, 1, 1, 0, 1, 1, 0, 1],
          [0, 1, 1, 0, 1, 1, 1, 0],
          [0, 1, 1, 0, 1, 1, 1, 1],
          [0, 1, 1, 1, 0, 0, 0, 0],
          [0, 1, 1, 1, 0, 0, 0, 1],
          [0, 1, 1, 1, 0, 0, 1, 0],
          [0, 1, 1, 1, 0, 0, 1, 1],
          [0, 1, 1, 1, 0, 1, 0, 0],
          [0, 1, 1, 1, 0, 1, 0, 1],
          [0, 1, 1, 1, 0, 1, 1, 0],
          [0, 1, 1, 1, 0, 1, 1, 1],
          [0, 1, 1, 1, 1, 0, 0, 0],
          [0, 1, 1, 1, 1, 0, 0, 1],
          [0, 1, 1, 1, 1, 0, 1, 0],
          [0, 1, 1, 1, 1, 0, 1, 1],
          [0, 1, 1, 1, 1, 1, 0, 0],
          [0, 1, 1, 1, 1, 1, 0, 1],
          [0, 1, 1, 1, 1, 1, 1, 0],
          [0, 1, 1, 1, 1, 1, 1, 1],
          [1, 0, 0, 0, 0, 0, 0, 0],
          [1, 0, 0, 0, 0, 0, 0, 1],
          [1, 0, 0, 0, 0, 0, 1, 0],
          [1, 0, 0, 0, 0, 0, 1, 1],
          [1, 0, 0, 0, 0, 1, 0, 0],
          [1, 0, 0, 0, 0, 1, 0, 1],
          [1, 0, 0, 0, 0, 1, 1, 0],
          [1, 0, 0, 0, 0, 1, 1, 1],
          [1, 0, 0, 0, 1, 0, 0, 0],
          [1, 0, 0, 0, 1, 0, 0, 1],
          [1, 0, 0, 0, 1, 0, 1, 0],
          [1, 0, 0, 0, 1, 0, 1, 1],
          [1, 0, 0, 0, 1, 1, 0, 0],
          [1, 0, 0, 0, 1, 1, 0, 1],
          [1, 0, 0, 0, 1, 1, 1, 0],
          [1, 0, 0, 0, 1, 1, 1, 1],
          [1, 0, 0, 1, 0, 0, 0, 0],
          [1, 0, 0, 1, 0, 0, 0, 1],
          [1, 0, 0, 1, 0, 0, 1, 0],
          [1, 0, 0, 1, 0, 0, 1, 1],
          [1, 0, 0, 1, 0, 1, 0, 0],
          [1, 0, 0, 1, 0, 1, 0, 1],
          [1, 0, 0, 1, 0, 1, 1, 0],
          [1, 0, 0, 1, 0, 1, 1, 1],
          [1, 0, 0, 1, 1, 0, 0, 0],
          [1, 0, 0, 1, 1, 0, 0, 1],
          [1, 0, 0, 1, 1, 0, 1, 0],
          [1, 0, 0, 1, 1, 0, 1, 1],
          [1, 0, 0, 1, 1, 1, 0, 0],
          [1, 0, 0, 1, 1, 1, 0, 1],
          [1, 0, 0, 1, 1, 1, 1, 0],
          [1, 0, 0, 1, 1, 1, 1, 1],
          [1, 0, 1, 0, 0, 0, 0, 0],
          [1, 0, 1, 0, 0, 0, 0, 1],
          [1, 0, 1, 0, 0, 0, 1, 0],
          [1, 0, 1, 0, 0, 0, 1, 1],
          [1, 0, 1, 0, 0, 1, 0, 0],
          [1, 0, 1, 0, 0, 1, 0, 1],
          [1, 0, 1, 0, 0, 1, 1, 0],
          [1, 0, 1, 0, 0, 1, 1, 1],
          [1, 0, 1, 0, 1, 0, 0, 0],
          [1, 0, 1, 0, 1, 0, 0, 1],
          [1, 0, 1, 0, 1, 0, 1, 0],
          [1, 0, 1, 0, 1, 0, 1, 1],
          [1, 0, 1, 0, 1, 1, 0, 0],
          [1, 0, 1, 0, 1, 1, 0, 1],
          [1, 0, 1, 0, 1, 1, 1, 0],
          [1, 0, 1, 0, 1, 1, 1, 1],
          [1, 0, 1, 1, 0, 0, 0, 0],
          [1, 0, 1, 1, 0, 0, 0, 1],
          [1, 0, 1, 1, 0, 0, 1, 0],
          [1, 0, 1, 1, 0, 0, 1, 1],
          [1, 0, 1, 1, 0, 1, 0, 0],
          [1, 0, 1, 1, 0, 1, 0, 1],
          [1, 0, 1, 1, 0, 1, 1, 0],
          [1, 0, 1, 1, 0, 1, 1, 1],
          [1, 0, 1, 1, 1, 0, 0, 0],
          [1, 0, 1, 1, 1, 0, 0, 1],
          [1, 0, 1, 1, 1, 0, 1, 0],
          [1, 0, 1, 1, 1, 0, 1, 1],
          [1, 0, 1, 1, 1, 1, 0, 0],
          [1, 0, 1, 1, 1, 1, 0, 1],
          [1, 0, 1, 1, 1, 1, 1, 0],
          [1, 0, 1, 1, 1, 1, 1, 1],
          [1, 1, 0, 0, 0, 0, 0, 0],
          [1, 1, 0, 0, 0, 0, 0, 1],
          [1, 1, 0, 0, 0, 0, 1, 0],
          [1, 1, 0, 0, 0, 0, 1, 1],
          [1, 1, 0, 0, 0, 1, 0, 0],
          [1, 1, 0, 0, 0, 1, 0, 1],
          [1, 1, 0, 0, 0, 1, 1, 0],
          [1, 1, 0, 0, 0, 1, 1, 1],
          [1, 1, 0, 0, 1, 0, 0, 0],
          [1, 1, 0, 0, 1, 0, 0, 1],
          [1, 1, 0, 0, 1, 0, 1, 0],
          [1, 1, 0, 0, 1, 0, 1, 1],
          [1, 1, 0, 0, 1, 1, 0, 0],
          [1, 1, 0, 0, 1, 1, 0, 1],
          [1, 1, 0, 0, 1, 1, 1, 0],
          [1, 1, 0, 0, 1, 1, 1, 1],
          [1, 1, 0, 1, 0, 0, 0, 0],
          [1, 1, 0, 1, 0, 0, 0, 1],
          [1, 1, 0, 1, 0, 0, 1, 0],
          [1, 1, 0, 1, 0, 0, 1, 1],
          [1, 1, 0, 1, 0, 1, 0, 0],
          [1, 1, 0, 1, 0, 1, 0, 1],
          [1, 1, 0, 1, 0, 1, 1, 0],
          [1, 1, 0, 1, 0, 1, 1, 1],
          [1, 1, 0, 1, 1, 0, 0, 0],
          [1, 1, 0, 1, 1, 0, 0, 1],
          [1, 1, 0, 1, 1, 0, 1, 0],
          [1, 1, 0, 1, 1, 0, 1, 1],
          [1, 1, 0, 1, 1, 1, 0, 0],
          [1, 1, 0, 1, 1, 1, 0, 1],
          [1, 1, 0, 1, 1, 1, 1, 0],
          [1, 1, 0, 1, 1, 1, 1, 1],
          [1, 1, 1, 0, 0, 0, 0, 0],
          [1, 1, 1, 0, 0, 0, 0, 1],
          [1, 1, 1, 0, 0, 0, 1, 0],
          [1, 1, 1, 0, 0, 0, 1, 1],
          [1, 1, 1, 0, 0, 1, 0, 0],
          [1, 1, 1, 0, 0, 1, 0, 1],
          [1, 1, 1, 0, 0, 1, 1, 0],
          [1, 1, 1, 0, 0, 1, 1, 1],
          [1, 1, 1, 0, 1, 0, 0, 0],
          [1, 1, 1, 0, 1, 0, 0, 1],
          [1, 1, 1, 0, 1, 0, 1, 0],
          [1, 1, 1, 0, 1, 0, 1, 1],
          [1, 1, 1, 0, 1, 1, 0, 0],
          [1, 1, 1, 0, 1, 1, 0, 1],
          [1, 1, 1, 0, 1, 1, 1, 0],
          [1, 1, 1, 0, 1, 1, 1, 1],
          [1, 1, 1, 1, 0, 0, 0, 0],
          [1, 1, 1, 1, 0, 0, 0, 1],
          [1, 1, 1, 1, 0, 0, 1, 0],
          [1, 1, 1, 1, 0, 0, 1, 1],
          [1, 1, 1, 1, 0, 1, 0, 0],
          [1, 1, 1, 1, 0, 1, 0, 1],
          [1, 1, 1, 1, 0, 1, 1, 0],
          [1, 1, 1, 1, 0, 1, 1, 1],
          [1, 1, 1, 1, 1, 0, 0, 0],
          [1, 1, 1, 1, 1, 0, 0, 1],
          [1, 1, 1, 1, 1, 0, 1, 0],
          [1, 1, 1, 1, 1, 0, 1, 1],
          [1, 1, 1, 1, 1, 1, 0, 0],
          [1, 1, 1, 1, 1, 1, 0, 1],
          [1, 1, 1, 1, 1, 1, 1, 0],
          [1, 1, 1, 1, 1, 1, 1, 1]]

BD = [1, 0, 1, 0, 1, 0, 1, 0]

#(255.downto(2)).each do |i|
32.times do
  tick
  sample :drum_snare_soft,amp:1 if SN_all[67].look == 1
  sample :drum_bass_soft,amp:1 if BD.look == 1
  sample :drum_cymbal_open,amp:0.2
  sleep 0.5
end
#end


All 8 beat patterns are generated by python code:

>>> r = itertools.product([0,1],repeat = 8)
>>> for s in r:
	print(list(s))
2 Likes

Python is not required.

a=[]
(0..255).each do |i|
  a[i]=("0"*(8-i.to_s(2).length)+i.to_s(2)).to_s.chars.map(&:to_i)
end
puts a
2 Likes

This is for ruby experts. In python its simple and straightforward for me.

Or… for Sonic Pi people to learn from.

Been experimenting with similar things in Puredata, recently. More specifically, I convert such binary sequences to hexadecimal (or octal, in the case of ternary beats). I then display the seq along with its number.
To generate the seqs, I go in reverse: running through all numbers from 0 to FF (or 0 to 255, as @H_Tachibana did) and converting the numbers to binary.

Now, it’s important to remember that the number of steps in a seq is probably not the same as the number of beats. For beat patterns, it’s quite frequent to have four subdivisions per beat (16ths in the case of 4/4). So, it can be convenient to have each beat represented by a hex digit. A bar is a four-digit number. Some of these patterns are fairly common so it’s neat to have a way to document them.
And, of course, when you have such a routine (in SPi, Pd, Python, JS…), you can generate all possible sequences (64k of them, for a full bar of 4/4 with 16ths). Or just generate them individually, on the fly.

There is no point in going into Python/Ruby/C/xyz “competitions” here, but since I know one possibly more idiomatic Ruby version, I’d share it here:

[1,0].repeated_permutation(8).each { puts _1.inspect } # prints something similar to OP
all_patterns = [1,0].repeated_permutation(8) # as a list of list (actually an enumerator
2 Likes

Thank you very much.
I only know Ruby from Sonic Pi.
I did not know about “repeated_permutation and combination”.

As simple as the python code.

Code to run all the patterns:

BD = (ring 1, 0, 1, 0, 1, 0, 1, 0)

[1,0].repeated_permutation(8).each do |snare_pattern|
  puts snare_pattern
  
  snare_pattern.each do |hit|
    sample :drum_snare_soft,amp:1 if hit == 1
    sample :drum_bass_soft,amp:1 if BD.tick == 1
    sample :drum_cymbal_open,amp:0.2
    sleep 0.5
  end
end
1 Like