Making a generative drum pattern am I doing it right?

Hi all hope you’re all doing well and staying safe during these times.
I’m trying to use Sonic Pi to make a generative drum pattern changes every few bars and doesn’t repeat endlessly below the end of this post is the code I’m using please could somebody check it and tell me if it’s correct it’s giving me errors on my end and I don’t know what they are. I’ve been away for awhile and I think I’ve forgotten some things. Your help with this matter would be most welcome kind regards Trey.
Here is the code:

set( :rnd, 5683 )

live_loop :drums do
use_bpm 140
use_random_seed get( :rnd )
8.times do
if spread(5,4).look
midi :B1, channel: 10
if dice(9) > 5

    midi :C2, channel: 10
    midi :f2, channel: 10
    midi :G2, channel: 10
    sleep 1.3
  end
end

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

Try …

set( :rnd, 5683 )
live_loop :drums do
  use_bpm 140
  use_random_seed get( :rnd )
  8.times do
    if spread(5,4).look
      midi :B1, channel: 10
      if dice(9) > 5
        midi :C2, channel: 10
        midi :f2, channel: 10
        midi :G2, channel: 10
        sleep 1.3
    end; end
    live_loop :controller do
      set( :rnd, rand_i( 10000 ))
      sleep 1
end; end; end

I have no midi , so don’t know if it
works … But it runs …

@hitsware - that’s probably almost there, but I think you are leaving the controller loop inside the 8.times repeating code.

@soundwarrior - are you able to focus the error panel when Sonic Pi triggers an error? There should be such an option in the main menu under View, Focus Errors (or as a shortcut as well). That way you should hopefully be able to have any errors available to a screen reader. (Otherwise, it’s something we’ll want to fix).

If the code example you gave is the total of the code you are trying to run, then as it is, it is missing a few things. A few of the code blocks are missing a corresponding end keyword to close up the blocks.
I suspect that the drums live loop and the controller live loop are intended to be two separate loops; in which case you probably wanted to make sure that the 8.times do, if spread(5,4).look, and if dice(9) > 5 all have matching end keywords to close those blocks up.
The example that @hitsware gave is close, but it looks like the added end keywords there are not quite in the correct spot. Here is how I think it would need to be:

set( :rnd, 5683 )

live_loop :drums do
  use_bpm 140
  use_random_seed get( :rnd )
  8.times do
    if spread(5,4).look
      midi :B1, channel: 10
      if dice(9) > 5

        midi :C2, channel: 10
        midi :f2, channel: 10
        midi :G2, channel: 10
        sleep 1.3
      end
    end
  end
end

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

I too do not have MIDI equipment to test with; but that seems more like what you want.

Hi both :slight_smile: I was able to get this block of code to work successfully thanks very much for your help.

set( :rnd, 5683 )

live_loop :gendrum do
use_bpm 140
with_swing 0.6 do
if ring(:true, true, false, true, true, false, true, false).tick
midi :B1, channel: 10
end

if dice(5) > 5
  midi :C2, channel: 10
end


if ring(:false, true, false, false, true).look
  midi :C3, channel: 10
end

end
sleep 1
end

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

I have another question do the true and false commands in a ring represent 16th notes like on a step sequencer or whole beats of a bar? Thanks very much for your help everyone :slight_smile:

Values in a ring have no meaning in themselves, but if you’re asking are they representing 16th notes or whole beats in this particular code example, then it’s entirely dependent on the sleep value between each, and the time signature of your composition. A fairly common pattern to represent note lengths from traditional western music notation is to assign note lengths to beats in Sonic Pi as follows:
4 beats = whole note
2 beats = Half note
1 beat = quarter note
0.5 beats = eighth note
0.25 beats = sixteenth note
So if we go by this representation, since we are sleeping for 1 beat between notes, each note could be considered a quarter note. (There would be four of these in an entire bar in a 4/4 time signature).
Does that make things any clearer?