Hello from Brooklyn

One way is to use the matrix approach you were discussing in this thread

Another approach to that is to use the bools function which can be found in the Lang section of the help window. It basically operates the same way as using a ring of 1s and 0s but it automatically converts them to boolean values. Here’s a basic drum pattern using this method.

k = (bools, 1, 0, 0, 0, 1, 1, 0, 0)
s = (bools, 0, 0, 1, 0, 0, 0, 1, 0)
h = (bools, 1, 1, 1, 1, 1, 1, 1, 1)

t = 1.0

define :pattern do |b, s, r|
  if b.tick
    sample s
    sleep r
  else
    sleep r
  end
end

live_loop :kick do
  pattern k, :bd_tek, t/2
end

live_loop :snare do
  pattern s, :sn_dolf, t/2
end

live_loop :hat do
  pattern h, :elec_tick, t/4
end

This is ok for kick and snare patterns but would not be really effective for more complex patterns.

Another approach I’ve seen used for adding rests is to change the amp to zero to represent the rest. This can be used with more complex patterns by including a ring or knit for the amp value as well. Just be aware you will need to include .look instead of .tick for any other data structures you want to tick through in the same live loop.

Here’s an example of how that could be done with a trap hat pattern

t = 1.0

live_loop :hats do
  r = rrand(0.4, 0.8) #variable to store random amp for hits
  sample :drum_cymbal_closed, amp: (knit, r, 14, 0 ,2, r, 4).tick
  sleep (knit, t/4, 8, t/8, 8, t/4, 4).look 
end

This pattern is 4 beats = 2 beats of t/4, 1 beat of t/8 and the last beat is t/4
This is represented in the knit for the sleep value.

The rest happens on the 3rd beat for the last two hits of the t/8 subdivision
It would look like this = (1, 1, 1, 1, 1, 1, 0, 0)

The rests are executed from the knit in the amp values.
The numbers in the amp values are as follows:

r, 14 = r is the random values declared in the variable. The 14 is the number of hits before the rest happens. This comes from the 1st 8 in the sleep knit which is the 2 beats of t/4 added to 6 which is the number of t/8 hits before the 2 hits of rests using that subdivision.

0, 2 = This is the two t/8 worth of rest at amp: 0

r, 4 = The remaining beat of t/4 in the sleep knit at the random values set in the variable r.

To go back to the example you posted, here is a modified version using this technique to get the same results you had.

M = 4.0  # Constant representing the base length of a measure

p1 = M/2
p2 = M/4
p3 = (knit, M/16, 4, M/24, 6, M/16, 4, M/24, 6, M/16, 4, M/64, 8)

live_loop :kicks do
  sample :bd_tek, amp: rrand(2.5, 3.5)
  sleep p1
end

live_loop :snares do
  sample :sn_dolf, amp: (ring, 0, rrand(3.5, 4.5)).tick
  sleep p2
end

live_loop :hats do
  sample :elec_tick, amp: rrand(1.1, 2.1)
  sleep p3.tick
end

You’ll note that I’ve made some changes/omissions to the original code, some for cleaning up the code, some just to suit my own personal preferences ie I’m not a huge fan of defining a lot of functions to do basic commands.

But that main thing is the ring used for amp: in the snare loop to achieve the rest.

Hope this helps. Let me know if you have any further questions.

@Eli, I was not aware of the :r to represent rest. Thanks for sharing. But as nabisco pointed out, it is not so easy to change it’s duration within a more complex rhythmic pattern.

1 Like