Drums transition problem

Hello,
For a 8H project of 2H per week, I have to create a program and the one that i have chosen is a ‘Voez’-like in Python, and decided to use Sonic pi for the music.
Learning in this lapse of time to code in Sonic Pi was hard, so I learned all that I could and took some template on that incredible world that is internet.
The thing is that my brain is stucked on the C/C++ programming langage and I’m lost about what to do for this program :

define :normalDrum do
  hat   [5, 0, 5, 0,  5, 0, 5, 0,  5, 0, 5, 0,  5, 0, 5, 0]
  kick  [9, 0, 9, 0,  0, 0, 0, 0,  9, 0, 0, 3,  0, 0, 0, 0]
  snare [0, 0, 0, 0,  9, 0, 0, 2,  0, 1, 0, 0,  9, 0, 0, 1]
end

define :breakDrum do
  hat   [5, 0, 0, 5,  5, 0, 5, 0,  5, 0, 5, 0 , 5, 0, 5, 0]
  kick  [9, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 9]
  snare [0, 0, 3, 5,  0, 3, 5, 0,  3, 3, 4, 4,  5, 5, 7, 0]
end

define :use_kit do |kit_name|
  current_drum_kit = drum_kits[kit_name]
end

define :hat do |pattern|
  run_pattern :hat, pattern
end

define :kick do |pattern|
  run_pattern :kick, pattern
end

define :snare do |pattern|
  run_pattern :snare, pattern
end


normalDrum()

live_loop :pulse do
  sleep 0.05
end

define :run_pattern do |name, pattern|
  live_loop name do
    if switch < 3
      normalDrum()
      switch = switch + 1
    else
      breakDrum()
      switch = 0
    end
    
    sync :pulse
    
    pattern.each do |p|
      sample current_drum_kit[name], amp: p/9.0
      sleep 0.25
    end
  end
end

The aim is to play 3 times the normalDrum(), and then play the breakDrum() once. It works the first time, but then it play 1 time the normalDrum() and one time the breakDrum(). Any idea about how to solve it (or any question) ?

Thank you a lot !

No way this program works.

have a look at the tutorial / examples section in sonicpi’s help.

Here is something that works:
#Drum patterns

#Samples to use
hat =  :drum_cymbal_closed
kick =  :drum_bass_hard
snare =  :drum_snare_hard

#Patterns
#Normal Pattern, Section 0:
pat_hat_n = (bools 1,1,1,1,1,1,1,1)
pat_kick_n = (bools 1,0,0,0,1,0,0,0)
pat_snare_n = (bools 0,0,1,0,0,0,1,0)
#Break Pattern, Section 1:
pat_hat_b = (bools 1,1,1,1,1,1,1,1)
pat_kick_b = (bools 1,0,0,1,0,1,0,0)
pat_snare_b = (bools 0,0,1,0,0,0,1,0)
#Section Pattern:
sections = (ring 0,0,0,1).stretch(8)


live_loop :play_patterns do
  tick
  if sections.look == 0
    sample hat if pat_hat_n.look
    sample kick if pat_kick_n.look
    sample snare if pat_snare_n.look
  end
  if sections.look == 1
    sample hat if pat_hat_b.look
    sample kick if pat_kick_b.look
    sample snare if pat_snare_b.look
  end
  sleep 0.25
end

HERE is a more general drum pattern player.

For the future:
When you submit code, please comment it. People can only help when they know what’s going on in the program.

It’s just a part of the program, i just wanted to focus on my problem. Sorry if I didn’t showed enough :s

1 Like

Hi there, thanks for your question!

In order to help you with problems as best we can we need to know:

  1. what you’re trying to do
  2. what you’re observing
  3. how this appears to be different from what you expect

With as much information on these three things we can really start to unpick what’s going on and give the clearest and simplest advice.

With your question we’re missing what you’re trying to do - specifically how you are calling the functions you define in the code snippet. It would also be useful to know what kind of rhythm/sound/groove you’re aiming for and why it’s not what you want.

Super happy to help as much as I can if you can give a bit more information along these lines!

Good luck getting it done :slight_smile:

1 Like