How to do beat repeat

I’ve been wanting to do more IDM kinda music lately, got into ableton live, but drawing midi is boring and I’m super bad at playing drums on a midi controller or coming up with good patterns in the first place. So here comes sonic pi to the rescue!

I came up with a pattern I like and will be sending it via midi to ableton to experiment with. But I wanted to se if I could do some beat repeat directly in sonic pi. I found a thread by @sub_repeat but I could not reply, maybe it’s locked or patreons only.

Some people on the tread did not rally understand what @sub_repeat was looking for. So here’s an example:

like any IDM or aphex twin track the beat pattern usually jumps all over the place, have a listen:

So each kick or snare and the like sometimes “glitches” and repeats every like 16th or 32th. This effect is called beat repeat. Usually is controlled by probability, you’d have a simple drum pattern and each hit would have a random chance of “glitching out” or repeating.

I’m not sure the solution I came up with is the best that could be done, so I wanna ask here to the sonic pi wizards. I made this code as a proof of concept:

yesnorepeat = 0 #This variable will turn beat repeat on and off if value is 0 or 1

live_loop :debug do #prints out the value of yesnorepeat
  puts yesnorepeat
  sleep 0.5
end

live_loop :beatrepeat do #here the magic happens
  sleep  rrand_i(1,16) #waits a random amount of time to start the beat repeat effect
  yesnorepeat = 1
  sleep  rrand_i(1,2) #waits random amount to stop the effect
  yesnorepeat = 0
end

live_loop :snare do
  if yesnorepeat == 0 then #if beat repeat is off then play this pattern
    sleep 0.5
    sample :bd_boom , cutoff:100 if spread(2,4).tick
  else #if beat repeat is on play the same sample every 0.1 seconds
    sleep 0.1
    sample :bd_boom , cutoff:100
  end
end

With my method you would have to set up a separate beat repeat live loop for each kick, snare, tom or hi-hat for them to glitch out independently. And you can simply change the random values on the beat repeat live loop to increase or decrease the probability of the effect.

So yeah, is there any way I can improve my code or any of you know more IDM tricks?

Not to die idiot what this means ?

@nlb Looks like this might help you https://en.wikipedia.org/wiki/Intelligent_dance_music EDIT (don’t feel bad. I didn’t know either :slightly_smiling_face:)

1 Like

@alexesc Haven’t tried anything yet, but sounds like the density function might be useful in this context. perhaps worth having a look at that.

1 Like

Good topic. I’m not a big fan of the Glitch myself. Which is shame as I always wanted to like Aphex Twin but I find it distressing to listen to. I also have a son who is big into IDM. Fortunately for me it’s not all glitch. He’s very down on EDM though, that’s for the kids :slight_smile:

This is how I’d approach it. Putting the repeats into their own threads so they can run away on their own without interrupting the timing of the drum loops. Plus heavy use of the dice() function to add apparent randomness. Horrible :smiley:

use_bpm 280

with_fx :reverb, mix: 0.1, room: 0.6 do |reverb|
  with_fx :echo, phase: 0.75, mix: 0.1, decay: 5.0 do |echo|
    
    live_loop "main" do
      
      if tick(:fx_start)==0 then
        set :reverb, reverb
        set :echo, echo
      end
      control get[:reverb], mix: 0.3
      control get[:echo], mix: 0.1
      
      cue "bar"
      sleep 4
    end
     
    
    live_loop "hihat" do
      sync "/cue/bar"
      a=0.3
      pedal = [1,1,1,2].ring.tick(:pedal)
      in_thread do
        accent = [1.0,0.4,0.4,0.4].ring
        4.times do
          sample :drum_cymbal_closed, amp: a*accent.tick
          sleep 1.0
          
          in_thread do
            n = dice(8)-3
            n.times do
              sample :drum_cymbal_closed, amp: a
              sleep 1.0/4
            end
          end
          
        end
      end
      
    end
    
    live_loop "snare" do
      sync "/cue/bar"
      a=0.4
      in_thread do
        sleep 1
        in_thread do
          n = dice(8)-3
          k = [3,4].choose
          n.times do
            sample :drum_snare_hard, amp: a
            sleep 1.0/k
          end
        end
        sleep 3
        if dice(3)>2 then
          sample :drum_snare_hard, amp: a
        end
      end
    end
    
    
    live_loop "kick" do
      sync "/cue/bar"
      a = 0.3
      in_thread do
        if dice(3)>1 then
          sample :bd_mehackit, amp: a*2
        end
        sleep 2.5
        
        if dice(3)>2 then
          sample :bd_mehackit, amp: a
        end
        
        in_thread do
          n = dice(8)-3
          k = [3,4].choose
          n.times do
            sample :bd_mehackit, amp: a/2
            sleep 1.0/k
          end
        end
      end
    end
  end
end