Different tracks created with Sonic Pi last month

I’ve been teaching Sonic Pi about 2 month. Here are some of the tracks that I have been inspired to work with during this process. My own stuff and covers of music I like. Feel free to grab and develop the code.
Ty for all the inspiration in this forum and help. It have helped me a lot as a newbie.
Kind regards
Relaxnow


# 220420 12:26 Synth case overload

live_loop :met do
  sleep 1
end

with_fx :reverb, room: 0.8 do
  
  live_loop :mel1, sync: :met do
    use_synth :saw
    #use_synth :tri
    c = range(70,130,steps: 2.5).shuffle.tick(:range)
    p = knit(0+12,7, 3+12,2).tick
    riff1 = rrand_i(1,4)
    case riff1
    when 1
      play :f1, release: 0.15, pan: rrand(-1,1), cutoff: c, pitch: p
      #     sleep 0.125
    when 2
      play :f2, release: 0.15, pan: rrand(-1,1), cutoff: c, pitch: p
    when 3
      play :c3, release: 0.15, pan: rrand(-1,1), cutoff: c, pitch: p
      use_synth :tri
      play :c5, release: 0.08, pan: rrand(-1,1), pitch: ring(0,5,12,-5).choose#, cutoff: c
    when 4
      sleep 0.125
      sleep 0.125
    end
    sleep 0.125
  end
  
  live_loop :mel2, sync: :met do
    #stop
    use_synth :dsaw
    #use_synth :beep
    c = range(70,130,steps: 2.5).shuffle.tick(:range)
    p = knit(0,7, 3,2).tick
    riff2 = rrand_i(1,2)
    case riff2
    when 1
      play :f1, release: 0.15, pan: rrand(-1,1), cutoff: c, pitch: p
      #     sleep 0.125
    when 2
      play :f2, release: 0.15, pan: rrand(-1,1), cutoff: c, pitch: p
    when 3
      #      use_synth :tri
      #play :c5, release: 0.04, pan: rrand(-1,1), pitch: ring(0,5,12,-5).choose#, cutoff: c
    when 4
      sleep 0.125
      sleep 0.125
      
    end
    sleep 0.125
  end
  
  #oneshot
  use_synth :gnoise
  # play :f1, attack: 8, release: 8
  
end #end reverb

with_fx :bitcrusher, bit: 1.2 do
  live_loop :kick, sync: :met do
    sample :bd_haus, cutoff: 80, amp: 4, finish: 0.7 if spread(3,7).tick(:kick)
    #sleep 0.25
    sample :sn_generic, cutoff: 110, amp: 0.5, finish: 0.05,  pan: -0.5 if spread(5,7).tick(:kick)
    sample :sn_generic, cutoff: 110, amp: 0.7, finish: 0.03, pan: 0.5 if spread(3,5).tick(:kick)
    sleep 0.25
  end
end

# 220414 Bitcrusher on bass - with OSC
# Backup 220414 0110
# backup 220418

# Idea: Map OSC values in array
# https://www.rubyguides.com/2018/10/ruby-map-method/


use_osc "localhost", 5510

use_bpm 40
live_loop :met do
  sleep 1
end


# --- mixer --- # (0 stops 1 plays)

# oneshot
use_synth :bnoise
#play :c4, attack: 4, release: 4, pan: rrand(0,1)

# Case patterns on bass and drum
bass = 1         # sync drum - knit(3,1, 12,1, rrand_i(1,13),3, 14,1).tick
drum = 1         # sync met

# play both at once
arp1 = 1          # sync bass - pretty long (2*64)  spread(3,5)
arp2 = 1          # sync bass - pretty long (2*64)  spread(5,7)


# notes on repeat or arp (still needs som work)
c5repeat = 0     # sync met
ds5repeat = 0    # sync met
g5repeat = 0     # sync met
f5d5a5repeat = 0 # sync met - dont work with arp



# --- mixer end --- #



with_fx :bitcrusher, bits: 1.2 do
  
  live_loop :bass, sync: :drum do
    stop if bass<1
    
    # ------------- bass riff generator ------------- #
    
    # riff = 10    # 1 13 4  7   8  10
    # riff = rrand_i(1,14)   #random riff
    
    riff = knit(3,1, 12,1, rrand_i(1,13),3, 14,1).tick(:my_knit)
    
    puts "--- riff --- ", riff
    case riff
    when 1
      rythm = [1,2,0,1, 2,0,0,0, 1,2,0,1, 2,0,0,0]  # basic
    when 2
      rythm = [1,2,0,1, 2,0,1,0, 1,2,0,1, 2,0,3,0]  # basic2
    when 3
      rythm = [1,2,0,1, 2,0,1,0, 1,2,0,1, 2,1,3,2]  # basic3
    when 4
      rythm = [3,2,1,3, 2,0,1,0, 3,2,1,2, 3,2,1,2]  # nice 321
    when 5
      rythm = [2,2,1,2, 2,0,1,0, 2,2,1,2, 2,3,3,3]
    when 6
      rythm = [2,2,1,2, 2,0,1,0, 2,2,1,2, 2,1,3,2]
    when 7
      rythm = [1,2,1,2, 2,0,1,3, 2,2,1,2, 2,1,3,2]  # nice
    when 8
      rythm = [1,2,1,2, 2,0,1,3, 1,2,1,2, 2,0,1,3]  # nice
    when 9
      rythm = [1,2,1,2, 2,0,1,1, 2,1,2, 2,0,1,3, 1]
    when 10
      rythm = [1,1,0,2, 2,0,1,1, 3,3,1,2, 2,0,1,3]
    when 11
      rythm = [1,0,0,1, 1,0,0,1, 2,2,0,2, 2,0,1,1]
    when 12
      rythm = [1,0,0,1, 1,0,0,1, 1,0,0,1, 1,0,0,1]  # clean
    when 13
      rythm = [1,2,0,1, 1,0,2,1, 1,0,3,2, 1,0,2,1]  # nice breaklike
    when 14
      rythm = [1,0,0,0, 0,0,0,0, 1,0,0,0, 0,0,0,0]  # break
    end
    
    
    use_synth :saw
    
    x=16  #16   5 7 with random patterns
    x. times do |i|   #16   5 7 with random patterns
      r= 0.12
      c=80
      offset = range(0,0.5, step: 0.01).reflect.tick(:a)
      #puts range(0,0.5, step: 0.01).reflect.tick(:a)
      play :bb2, release: r, cutoff: c if rythm[i] ==1
      play :bb2+offset, release: r, cutoff: c if rythm[i] ==1
      
      c=110
      r= 0.1
      play :bb1, release: r, cutoff: c if rythm[i] ==1
      
      c=110
      r= 0.25
      play :c3, release: r, cutoff: c if rythm[i] ==2
      play :c3+offset, release: r, cutoff: c if rythm[i] ==2
      
      c=110
      r= 0.15
      play :ds3, release: r, cutoff: c if rythm[i] ==3
      
      sleep 0.25
    end
    
  end
  
  
  
  # ------------- hihats with :bitcrusher------------- #
  define :hats do |d|
    stop if drum<1
    density d do
      sample :drum_cymbal_closed,  amp: 0.2,
        pan: ring(-0.25,0.25).choose, finish: rrand(0.02,0.08)
      sleep 0.25
    end
  end
  live_loop :hats, sync: :met do
    hats (ring 2,2,2,2,4).choose
  end
  
end #end :bitcrusher


# ------------- notes on repeat ------------- #
live_loop :c5repeat, sync: :met do
  stop if c5repeat<1
  use_synth :saw
  play :c5, release: 0.1
  sleep 0.125
end
live_loop :ds5repeat, sync: :met do
  stop if ds5repeat<1
  use_synth :saw
  play :ds5, release: 0.1
  sleep 0.125
end
live_loop :g5repeat, sync: :met do
  stop if g5repeat<1
  use_synth :saw
  play :g5, release: 0.1
  sleep 0.125
end
live_loop :f5d5a5repeat, sync: :met do  # tension
  stop if f5d5a5repeat<1
  use_synth :saw
  play knit(:f5, 32, :d5,32, :a5,32).tick(:mel4), release: 0.1
  sleep 0.125
end

# ------------- arp 1 ------------- #
live_loop :arp1, sync: :bass do
  stop if arp1<1
  
  use_random_seed rrand_i(1,12)
  #  stop if rrand(1,2) == 1
  #stop if ring(0,1).choose == 0
  
  use_synth  :saw
  32.times do
    play (chord :c5, 'm7', num_octaves: 2).shuffle.tick(:arp1),
      release: 0.07, amp: 2, cutoff: range(80,110, step: 0.5).mirror.tick(:arp2) if spread(3,5).tick(:arp1t)
    sleep 0.125
  end
  #stop if arp1<1
  
  use_random_seed rrand_i(1,12)
  32.times do
    play (chord :c5, 'm7', num_octaves: 3).take(5).shuffle.tick(:arp1),
      release: 0.07, amp: 2, cutoff: range(80,110, step: 0.5).mirror.tick(:arp2) if spread(3,5).tick(:arp1t)
    sleep 0.125
  end
  #stop if arp1<1
  
  use_synth  :dtri
  64.times do
    play (chord :c4, 'm7', num_octaves: 3).take(5).reverse.tick(:arp1),
      release: 0.07, amp: 2, cutoff: range(80,110, step: 0.25).mirror.tick(:arp2) if spread(3,5).tick(:arp1t)
    sleep 0.125
  end
  
end

# ------------- arp 2 ------------- #
live_loop :arp2, sync: :bass do
  stop if arp2<1
  
  use_random_seed rrand_i(1,12)
  #  stop if rrand(1,2) == 1
  #stop if ring(0,1).choose == 0
  
  use_synth  :dsaw
  32.times do
    play (chord :c4, 'm7', num_octaves: 2).shuffle.tick(:arp1),
      release: 0.07, amp: 2, cutoff: range(80,110, step: 0.5).mirror.tick(:arp2) if spread(5,7).tick(:arp2t)
    sleep 0.125
  end
  #stop if arp2<1
  
  use_random_seed rrand_i(1,12)
  32.times do
    play (chord :c4, 'm7', num_octaves: 3).take(5).shuffle.tick(:arp1),
      release: 0.07, amp: 2, cutoff: range(80,110, step: 0.5).mirror.tick(:arp2) if spread(5,7).tick(:arp2t)
    sleep 0.125
  end
  #stop if arp2<1
  
  use_synth  :dpulse
  64.times do
    play (chord :c3, 'm7', num_octaves: 3).take(5).reverse.tick(:arp1),
      release: 0.07, amp: 2, cutoff: range(80,110, step: 0.25).mirror.tick(:arp2) if spread(5,7).tick(:arp2t)
    sleep 0.125
  end
  
end






live_loop :drum, sync: :met do
  stop if drum<1
  drumriff = rrand_i(1,8)
  case drumriff
  when 1
    rythm = [1,0,2,0, 1,0,2,0]
  when 2
    rythm = [1,0,2,1, 1,0,2,0]
  when 3
    rythm = [1,0,2,1, 0,1,1,2]
  when 4
    rythm = [1,0,2,1, 0,2,1,2]
  when 5
    rythm = [1,1,2,0, 0,1,2,0]
  when 6
    rythm = [1,0,2,1, 1,2,0,0]
  when 7
    rythm = [1,0,2,1, 1,2,0,2]
  when 8
    rythm = [1,0,2,1, 1,2,0,1]
  end
  
  8.times do |i|
    c =90
    sample :bd_haus, cutoff: c, amp: 4, pan: -0.25 if rythm[i] ==1
    c =110
    sample :bd_haus, cutoff: c, amp: 4, pan: 0.25 if rythm[i] ==1
    sample :sn_generic, cutoff: c, finish: 0.09, amp: 2 if rythm[i] ==2
    
    puts "rythm[i] = ",rythm[i]
    osc "/vars/spdrum1", rythm[i]
    
    
    sleep 0.25
    osc "/vars/spdrum1", 0
  end
end


5 Likes

Hi @Relaxnow

thanks for sharing your code !
i tested on my computer and very good sounds :slight_smile:
But actually, i don’t catch the use of OSC in your code… Would you mind give more details about this use ? The specified osc port value is useless as if i delete it, it triggers the bassdrum…
Thanks

Hi @nlb
Ty :slight_smile:

The OSC code can be deleted, since it does not affect the sound.
The OSC is for visuals in Improviz
The OSC is sending to Improviz on port 5510 with

use_osc "localhost", 5510

and

puts "rythm[i] = ",rythm[i]       # Text in Sonic Pi log
osc "/vars/spdrum1", rythm[i]     # Sends OSC kick drum value to Improviz 0,1 or 2 in spdrum1

and a small break before OSC is reset to “0” else Improviz keeps using 1 or 2 as value.

    sleep 0.25
    osc "/vars/spdrum1", 0

I havnt recorded any video of the code above with Improviz as I recall, but OSC from Sonic Pi can be used like this.

“Returning to Improviz with a better understanding of Sonic Pi with OSC”

I have done a lot of image creating in Improviz before I started learning Sonic Pi, so now I slowly try to combine them.

My stuff

Improviz images
https://www.flickr.com/photos/192433151@N07/albums