Generative drums with change every 8 bars?

hi everyone I want to make generative drum loops with a change every 8 bars. I’ve got this example code:
“”"
live_loop :multi_beat do
use_random_seed 1000
8.times do
sample :elec_hi_snare if one_in(6)
sample :drum_cymbal_closed if one_in(2)
sample :drum_cymbal_pedal if one_in(3)
sample :bd_haus if one_in(4)
sleep 0.125
end
end

please could someone explain to me how to do this? thanks for all your kind help so far gang its wicked to be part of this community :slight_smile:

1 Like

Your example will play eight different drum patterns, and then repeat them. If you want to play the same pattern eight times and then change, you need to do something different.

I’m using bluetooth headphones at the moment, and can’t run Sonic Pi. But, I believe that the following will work.

set( :rnd, 5683 )

live_loop :drums do
    use_random_seed get( :rnd )

    8.times do
        sample :elec_hi_snare if one_in(6)
        sample :drum_cymbal_closed if one_in(2)
        sample :drum_cymbal_pedal if one_in(3)
        sample :bd_haus if one_in(4)
       sleep 0.125
    end
end

live_loop :controller do
    set( :rnd, rand_i( 10000 ))
    sleep 16
end

The first loop will always play a beat defined by the random seed that has been stored with ‘set’. The second loop changes that occasionally.

I’m not quite sure of the timing. Try halving or doubling the sleep in the second loop if you find that the first one repeats the same pattern for too many or not enough bars.

I perhaps like using brackets more than I should.

If you have a Mac have you tried the latest 3.2 beta? It should fix this issue.

1 Like

Ummm… Not yet. I think I tried to download it when you’d removed it for a bit and then haven’t tried since. I’ll give it a go.

EDIT: It sort of works, but the sound quality is really low quality and glitchy. And, anything else playing at the same time that Sonic Pi is running goes low quality and glitchy too.

EDIT2: And, I don’t get a visible cursor, which does make it a bit hard to edit. EDIT3: Cursor seems to have reappeared now.

But, at least it seems that my code above for @soundwarrior more or less works. Except that the following is a better version of it:

use_bpm 127

set :rnd, 1000

live_loop :drums do
  use_random_seed get :rnd
  
  8.times do
    
    sample :bd_haus if one_in(3)
    sample :sn_dolf if one_in(5)
    sample :drum_cymbal_closed if one_in(2)
    sleep 0.5
  end
end

live_loop :controller do
  sleep 31
  set :rnd, rand_i(10000)
  sleep 1
end

hi thanks for your help everyone I find this works well with dice to :slight_smile:

1 Like

One thing I forgot to mention is that if you want more control over the sequence of patterns, that you can create a ring of random seeds which is chosen by the second loop.

A ring of random seeds are something that I use quite a lot in pieces as it gives a lot of control in terms of playing around until I get ‘random’ sequences I like, but also in being able to introduce some repetition when I want it. E.g.

use_bpm 127

seeds = (ring 234, 3453, 234, 3763, 1293, 3872, 1293, 33536, 234, 1293)

set :rnd, 1000

live_loop :drums do
  use_random_seed get :rnd
  
  8.times do
    
    sample :bd_haus if one_in(3)
    sample :sn_dolf if one_in(5)
    sample :drum_cymbal_closed if one_in(2)
    sleep 0.5
  end
end

live_loop :controller do
  sleep 31
  set :rnd, seeds.tick
  sleep 1
end

Though, this may not be what @soundwarrior wants

1 Like