First attempt at Live Coding Dance Music


#1

Greetings,

I am new to both sonic-pi and dance music. In the past, I did more electro-acoustic computer music. Nonetheless, I am intrigued by the idea of using the computer as a live instrument. Here’s my first attempt at live coding a bit of dance music. I am fairly happy with it up to about the ten-minute mark. The last five minutes don’t really make much sense as an ending.


#2

Welcome matey.

You’ll find quite a few of us posting stuff on Soundcloud, and lots of code examples of ‘dance music’ in the
forums.

A lot of people seem to think only in terms of live coding. Whilst its a major part of the appeal of Sonic Pi…
just making a nice 4 minute track that people will want to dance to, is also a good thing to try out. Whether
you can then incorporate parts of that in your live code ‘set’ is up to you… think of them as ‘modules’
you can drop into place while you are ‘live’…

Regards,

Just_Eli…


#3

Thanks for the comment! I’ll keep that in mind.


#4

can you post the code you used overhere? and nice job done…


#5

Sure thing. :slight_smile:

Please note: this was written prior to SP 3.10
The ‘quality’ of the TB303 changed in 3.10 due to
the synths being recompiled, so the '303 sounds different.
I’ve compensated a little, but it’s not perfect.

I think some of the other synths took a bit of a kicking too.

Eli…

#Elevation (Final Cut)
#by Eli...

#Please note: this was written prior to SP 3.10
# The 'quality' of the TB303 changed in 3.10 due to
# the synths being recompiled, so the '303 sounds different.


use_bpm 90
# Bass Clarinet
bass_rhythm = (ring 0.25, 0.75, 1, 0.75, 0.25, 0.5, 0.5).shuffle # makes 4 quarters or one bar on the whole
bass_line = (ring :a3, :g3,:d3, :r, :f3, :a3, :r, :g3,:a3, :r, :d3, :g3, :f3, :e3)
bass_room = (ring 100, 150, 200, 300)
bass_cycle = 32 # the complete bassline
bass_phrase = bass_cycle / 4 # One of the four patterns

bass_echo_phase = (ring 0.25, 0.5, 1, 2)

tracker = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
n = (ring :r, :r, :c2, :d3, :r, :f3, :r, :a1, :f2)

set_volume! 5

ripple = (ring, 0,1,)
ripple1 = (ring, 0,1,2)

define :start_loop do |i|
  tracker[i] = 1
end

define :stop_loop do |i|
  tracker[i] = 0
end

define :stop_all do
  tracker[0] = 0
  tracker[1] = 0
  tracker[2] = 0
  tracker[3] = 0
  tracker[4] = 0
  tracker[5] = 0
  tracker[6] = 0
  tracker[7] = 0
  tracker[8] = 0
  tracker[9] = 0
end

live_loop :beats do
  sleep 4
end

live_loop :bar do
  sleep 1
end

live_loop :kick do
  if tracker[0]>0 then
    sample :bd_ada
    sleep 1
    sample :bd_ada
    sample :sn_dolf, sustain: 0, release: 0.08, hpf: 80
    sleep 1
  else
    sleep 1
  end
end

live_loop :bass do
  if tracker[3]>0 then
    if rand(1) > 0.75
      n = (ring :r, :r, :c2, :d3, :r, :f3, :r, :a1, :f2)
    else
      n=n.shuffle
    end
    use_synth :fm
    use_transpose +0
    use_synth_defaults release: 0.125 + rrand(0, 0.2), amp: 0.5, pan: rrand(-0.5, 0.5)
    play n.look, cutoff: rrand(30, 130)
    sleep 0.25
    tick
  else
    sleep 1
  end
end

with_fx :reverb do
  live_loop :bass1 do
    if tracker[3]>0 then
      if one_in(4) then
        sleep 4
      else
        sync :bar
        use_synth :tb303
        
        #Please note: this was written prior to SP 3.10
        # The 'quality' of the TB303 changed in 3.10 due to
        # the synths being recompiled, so the '303 sounds different.
        
        use_synth_defaults cutoff: 55, release: 0.15, attack: 0.05, decay: 0.05,
          sustain_level: 0.3, cutoff_sustain_level: 0.7, sustain: 0.1, res: 0.6, amp: 0.1
        4.times do
          play (ring, :c2, :c2, :as1, :f2, :ds2).tick + 0.5, wave: ripple.look+1
          play (ring, :c2, :c2, :as1, :f2, :ds2).look + 0.5, wave: ripple1.look
          sleep (ring, 0.75, 0.75, 0.75, 0.75, 1).look
        end
      end
      ripple.tick
      if one_in 2 then
        ripple1.tick
        sleep 1
      end
    else
      sleep 1
    end
  end
end

with_fx :rhpf, res: 0.85, cutoff: 118, amp: 0.7 do
  live_loop :hats do
    if tracker[1]>0 then
      use_synth_defaults sustain_level: 0.5
      synth :chipnoise, sustain: 0, release: 0.09, freq_band: 15, amp: 0.1
      sleep 0.25
      if rand(1) < 0.75 then
        synth :chipnoise, sustain: 0, release: 0.09, freq_band: 15, amp: 0.05
        sleep 0.125
      else
        sleep 0.125
      end
      sleep 0.125
    else
      sleep 1
    end
  end
end

live_loop :rim do
  if tracker[2]>0 then
    with_fx :distortion do
      sleep 0.5
      use_sample_defaults amp: 0.2
      sample :elec_blip, sustain: 0.006, cutoff:110, rate: 0.8
      sleep 0.25
      sample :elec_blip, sustain: 0.005, cutoff:110, rate: 0.8 if one_in(5)
      sleep 0.25
    end
  else
    sleep 1
  end
end

live_loop :xylophone do
  if tracker[5]>0 then
    use_synth :sine
    use_synth_defaults coef: 0.1, detune: 0.1
    nlen = [1,2,3].choose
    cho = (chord_degree, [:i, :iii, :vi, :v].ring.tick, :f3, :minor, 4)
    if rand() > 0.7 then
      sync :beats
      3.times do
        play scale([:f3, :f4].choose, :minor).choose, amp: 0.25, release: nlen / 2.0
        sleep nlen / 4.0
      end
    else
      sync :bar
      play chord_invert( cho, [-1, 0, 1].choose), amp: 0.6, release: nlen
      sleep nlen
    end
  else
    sleep 0.1
  end
end

live_loop :background do
  if tracker[4]>0 then
    sync :bar
    use_synth :fm
    use_synth_defaults amp: 0.25, attack: 0.0, release: 2
    play (chord [:c4, :eb, :g4].choose, :M7)
    sleep 2
    play (chord :d4, :M7)
    sleep 2
  else
    sleep 0.1
  end
end

vol = (knit 0.75, 3, 0.125, 2, 0.25, 4, 0.35, 3).pick
vol_master = 1

live_loop :voice0 do
  if tracker[6]>0 then
    use_synth :piano
    sync :bar
    bass_line = (chord :a3, :m7, num_octaves: 2)
    sleep 0.25
    if spread([2,4].choose,16).tick
      play bass_line.look, amp: vol.look * vol_master
    end
    
  else
    sleep 0.1
  end
end

live_loop :voice1 do
  if tracker[6]>0 then
    use_synth :pluck
    voice1_line = (chord :c3, :M, num_octaves: 2)
    sync :bar
    spreader = rrand_i(3,8)
    1.times do
      if spread([2,spreader].choose,16).tick
        play voice1_line.look, attack: 0.001, amp: vol.look * vol_master
      end
      sleep 0.25
    end
  else
    sleep 0.1
  end
end

live_loop :voice2 do
  if tracker[6]>0 then
    use_synth :piano
    voice2_line = (chord :d3, :M, num_octaves: 2)
    repeater = [2,3,4].choose
    spreader = rrand_i(3,16)
    sync :bar
    repeater.times do
      if spread([2,spreader].choose,16).tick
        play voice2_line.look, amp: vol.look * vol_master
      end
      sleep 0.25
    end
  else
    sleep 0.1
  end
end

random_add = 1024

live_loop :clarinet do
  
  if tracker[7]>0 then
    use_synth :fm
    use_synth_defaults divisor: 0.5, depth: 4.0, attack: 0.05, sustain: 0, release: [bass_rhythm.look, 0.125].choose,
      amp: 0.5
    random = rand(1)
    if random  > 0.6
      bass_line = (ring :f3, :a3, :r)
    end
    if random  > 0.8
      bass_line = (ring :g3,:a3)
    end
    if random  > 0.9
      bass_line = (ring :a3, :g3,:d3, :r)
    end
    if random  < 0.6
      bass_line = (ring :d3, :g3, :f3, :e3)
    end
    with_fx :reverb, room: 0.75 do
      #with_fx :echo, phase: bass_echo_phase.look, decay: 6 do
      play bass_line.look,release: [bass_rhythm.look, 0.125].choose
      tick
    end
    sleep bass_rhythm.look
  else
    sleep 0.1
  end
end

kick=0
hats=1
rim=2
bass=3
background=4
xylophone =5
voice=6
clarinet=7

# the real fun starts here... this is what decides
# which instruments are playing, 

live_loop :loopy do
  start_loop kick
  sleep 2
  start_loop hats
  sleep 4
  start_loop rim
  sleep 4
  start_loop bass
  sleep 8
  start_loop background
  sleep 32
  stop_loop background
  sleep 8
  start_loop voice
  sleep 48
  stop_loop voice
  sleep 8
  start_loop background
  sleep 32
  stop_loop background
  sleep 8
  start_loop xylophone
  sleep 32
  stop_loop xylophone
  sleep 8
  start_loop background
  sleep 8
  start_loop clarinet
  sleep 48
  stop_loop clarinet
  sleep 8
  stop_loop background
  sleep 8
  start_loop voice
  sleep 48
  stop_loop voice
  sleep 8
  start_loop background
  sleep 48
  stop_loop background
  sleep 8
  start_loop xylophone
  sleep 32
  stop_loop xylophone
  sleep 12
  stop_all
  sample :bd_ada
  sleep 8
  stop
end

#6

Apologies, in v3.1.0 the :tb303 synth is totally broken. This will be fixed in the next release :slight_smile:


#7

Awww…

Sam, when it’s fixed, it’s fixed. The intention was to explain the difference from the track
up on SoundCloud… not to have a dig a you, silly.

And whoops! I think Tonny was actually asking for Barefoot’s code… not mine. :slight_smile:

Must learn to pay closer attention. That or stop posting at 4 am… :slight_smile:

Eli…