# Public Energy - Three o' three with Sonic Pi

**URL:** <https://in-thread.sonic-pi.net/t/public-energy-three-o-three-with-sonic-pi/3548>\
**Category:** Creations & Ideas\
**Created:** [April 1, 2020, 10:44am UTC](https://in-thread.sonic-pi.net/t/public-energy-three-o-three-with-sonic-pi/3548 "2020-04-01T10:44:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyprboy](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hyprboy](https://in-thread.sonic-pi.net/u/hyprboy)\
**Post date:** [April 1, 2020, 10:44am UTC](https://in-thread.sonic-pi.net/t/public-energy-three-o-three-with-sonic-pi/3548/1 "2020-04-01T10:44:20Z")

</div>

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

I am new to Spi so bare with me 🙂  
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

```ruby
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

```

---

<div class="post-metadata">

**Author:** ![binarysweets](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/binarysweets/32/2683_2.png) [@binarysweets](https://in-thread.sonic-pi.net/u/binarysweets)\
**Post date:** [April 14, 2020, 10:18am UTC](https://in-thread.sonic-pi.net/t/public-energy-three-o-three-with-sonic-pi/3548/2 "2020-04-14T10:18:47Z")

</div>

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

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

```ruby
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
```

---

<div class="post-metadata">

**Author:** ![hyprboy](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hyprboy](https://in-thread.sonic-pi.net/u/hyprboy)\
**Post date:** [April 14, 2020, 10:31am UTC](https://in-thread.sonic-pi.net/t/public-energy-three-o-three-with-sonic-pi/3548/3 "2020-04-14T10:31:13Z")

</div>

wow excellent , will try it 🙂

---

<div class="post-metadata">

**Author:** ![Eli](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/eli/32/116_2.png) [@Eli](https://in-thread.sonic-pi.net/u/Eli)\
**Post date:** [April 14, 2020, 8:37pm UTC](https://in-thread.sonic-pi.net/t/public-energy-three-o-three-with-sonic-pi/3548/4 "2020-04-14T20:37:48Z")

</div>

This is so much fun!

Eli…

```ruby
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

```

---

<div class="post-metadata">

**Author:** ![hyprboy](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hyprboy](https://in-thread.sonic-pi.net/u/hyprboy)\
**Post date:** [April 15, 2020, 7:14am UTC](https://in-thread.sonic-pi.net/t/public-energy-three-o-three-with-sonic-pi/3548/5 "2020-04-15T07:14:05Z")

</div>

> [@Eli](#):
>
> bd\_haus

Nice!

but you never used bd\_haus while you loaded it in the beginning

---

<div class="post-metadata">

**Author:** ![hyprboy](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hyprboy](https://in-thread.sonic-pi.net/u/hyprboy)\
**Post date:** [April 15, 2020, 8:40am UTC](https://in-thread.sonic-pi.net/t/public-energy-three-o-three-with-sonic-pi/3548/6 "2020-04-15T08:40:12Z")

</div>

It works as a charm 🙂  
This is the complete sequence

```ruby
  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

```

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [April 15, 2020, 8:45am UTC](https://in-thread.sonic-pi.net/t/public-energy-three-o-three-with-sonic-pi/3548/7 "2020-04-15T08:45:04Z")

</div>

hi @hyprboy

would you please use 3 backticks to colorize your code ?

> [@Fibonacci & Reich & Antwerp Central](http://in-thread.sonic-pi.net/t/fibonacci-reich-antwerp-central/3644/4):
>
> [https://commonmark.org/help/tutorial/09-code.html](https://commonmark.org/help/tutorial/09-code.html) backtick is the keyword

---

<div class="post-metadata">

**Author:** ![Eli](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/eli/32/116_2.png) [@Eli](https://in-thread.sonic-pi.net/u/Eli)\
**Post date:** [April 15, 2020, 4:49pm UTC](https://in-thread.sonic-pi.net/t/public-energy-three-o-three-with-sonic-pi/3548/8 "2020-04-15T16:49:39Z")

</div>

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

Eli…
