Public Energy - Three o' three with Sonic Pi

Hi, I recreated the 303 house classic with Sonic Pi using the TB303

I am new to Spi so bare with me :slight_smile:
The only thing I struggled with, are the slide effects from the real TB-303 which combines notes…
Can I do this with spi?

Here is the code

use_bpm 134
t = 0.25  #general sleep value
x = 0.25  #general release value
lfo1 = ()
lfo2 = ()
lfo3 = ()

live_loop :lfo do
  lfo1 = (range 80,130,0.5).mirror.tick    #for cutoff
  lfo2 = (range -0.5,0.5,0.05).mirror.tick #for panning
  sleep 1
end

live_loop :resonance do
  lfo3 = (range 0.5,1,0.01).mirror.tick #for resonance
  sleep 2
end

define :t303 do |nte,rls,slp|  #note, release, sleep
  use_synth :tb303
  play nte , release: rls, cutoff: lfo1, pan: lfo2, res: lfo3
  sleep slp
end

live_loop :riff do
  
  32.times do
    
    t303 :r, x,t
    t303 :a2, x*4,t
    t303 :a2, x,t*2
    
    t303 :r, x,t
    t303 :r,x,t
    t303 :c2,x,t
    t303 :r,x,t
    
    t303 :a2, x,t
    t303 :r, x,t
    t303 :a2, x,t
    t303 :r, x,t
    
    t303 :a2, x,t
    t303 :d3, x,t
    t303 :e3, x,t
    t303 :g3, x,t
    
    t303 :r, x,t
    t303 :g2, x,t
    t303 :r, x,t
    t303 :as2, x,t
    
    t303 :r, x,t
    t303 :r, x,t
    t303 :r, x,t
    t303 :as2, x,t
    
    t303 :r, x,t
    t303 :as3, x*2,t*2
    t303 :as3, x,t
    
    t303 :gs2, x,t
    t303 :r, x,t
    t303 :as3, x,t
    t303 :r, x,t
    
  end
end

live_loop :kick do
  sample :bd_haus, amp: 2
  sample :sn_dub, amp: 0.75
  sleep 1
end
3 Likes

It’s a good start to something, keep at it :slightly_smiling_face:

You can make your code a bit cleaner by using rings for the notes and times, like so:

live_loop :riff do
  notes = [:r,:a2,:a2, :r,:r,:c2,:r, :a2,:r,:a2,:r, :a2,:d3,:e3,:g3,
           :r,:g2,:r,:as2, :r,:r,:r,:r,:as2, :r,:as3,:as3, :gs2,:r,:as3,:r].ring
  releases = (ring x,x*4,x,x)
  times = (ring t,t,t,t*2, t,t,t,t)
  
  32.times do
    t303(notes.tick, releases.look, times.look)
  end
end
2 Likes

wow excellent , will try it :slight_smile:

This is so much fun!

Eli…

use_debug false

use_bpm 60
load_samples :guit_em9, :bd_haus, :loop_industrial

q = 0

live_loop :beat do
  cue :do_it
  sleep 4
end

define :looper do |min,max|
  if (q < min)
    q = min
    return q
  end
  if (q < max )
    q +=1
    return q
  else
    q = min
    return q
  end
end

define :arp1 do |this_note1,scale,synths,oct,vol,min,max|
  live_loop :rp1, auto_cue: false do
    use_synth synths
    use_random_seed 310003
    q = looper(min,max)
    with_fx :reverb do
      ns = (scale this_note1, scale, num_octaves: oct).take(q)
      q*16.times do
        play ns.choose, detune: 12, release: 0.1, amp: v = vol + rand(0.5) , cutoff: rrand(70, 120)
        sleep 0.125
        
      end
    end
  end
end

define :arp2 do |this_note2,fx1,fx2,scale,synths,oct,vol,min,max|
  live_loop :rp2, auto_cue: false do
    with_fx fx1 do
      with_fx fx2  do
        use_synth synths
        use_random_seed 310003
        q = looper(min,max)
        ns = (scale this_note2, scale, num_octaves: oct).take(q)
        q*8.times do
          play ns.choose, detune: 12, release: 0.1, amp: v = vol + rand(0.5) , cutoff: rrand(70, 120)
          #control e, phase: 0.025
          sleep 0.125
        end
      end
    end
  end
end

live_loop :c do
  #stop
  sync :do_it
  this_note1=(ring :e2,:e3,:e4,:e3,:e2,:e4,:e5,:e3).tick
  this_note2=[:e3,:e4,:e5,:e2].choose
  
  in_thread do
    arp1(this_note2,:minor_pentatonic,(knit :mod_saw,6,:pulse,6 ).tick,4,1.6,(ring 1,2,1,3,1,4).look,1)
  end
  in_thread do
    arp2(this_note1,:flanger,:ixi_techno,:neapolitan_minor,:mod_fm,4,0.6,(ring 3,4).tick,(ring 2,1).look)
  end
end
2 Likes

Nice!

but you never used bd_haus while you loaded it in the beginning

It works as a charm :slight_smile:
This is the complete sequence

  notes = [:r,:a2,:a2, :r,:r,:c2,:r, :a2,:r,:a2,:r, :a2,:d3,:e3,:g3,
           :r,:g2,:r,:as2, :r,:r,:r,:as2, :r,:as3,:as3, :gs2,:r,:as3,:r].ring
  releases = (ring x,x*4,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x*2,x, x,x,x,x)
  times =    (ring t,t,t*2, t,t,t,t, t,t,t,t, t,t,t,t, t,t,t,t, t,t,t,t, t,t*2,t, t,t,t,t)
  
  32.times do
    t303(notes.tick, releases.look, times.look)
  end
end
1 Like

hi @hyprboy

would you please use 3 backticks to colorize your code ?

Yeah, I’m looking for a different beat, maybe trap, not sure yet. :slight_smile:

Eli…