You Just Have To Pay Attention

April 3, 2021 1:29 PM

Generative ambient piano + synths made in Sonic Pi.

I was recently introduced to Sonic Pi by scruss, and it's a very cool interactive programming environment for making music live. Also a great teach tool both for music and programming.
This is my first effort, using only sounds that come with the environment. I might add analog guitars or bass later, not sure.

This is the code:
whole = 4.0
double = whole*2
half = whole/2
quart = whole/4
eight = whole/8
sixth = whole/16
use_bpm 60
root = :E2
live_loop :main do
  puts("counter", tick(:ctr))
  set :ctr, look(:ctr)
  if (get :ctr) > 60 # stop main loop
    stop
  end
  
  progression = [
    [root, :major, double],
    [root+7, :major, double],
    [root+9, :minor, double],
    [root+5, :major, whole],
    [root+5, :major, whole],
  ]
  note, kind, time = progression.tick(:prog)
  print(note, kind)
  if look(:ctr) > 3 # start main piano chords
    use_synth :piano
    with_fx :gverb  do
      play (chord note, kind), sustain: time*2, attack: 0.5
    end
  end
  
  if look(:ctr) > 6 # start overtone chords
    use_synth :pretty_bell
    overamp =   (1+Math.sin(tick(:overamp)/5+3.14159))/8
    with_fx :flanger do
      with_fx :ring_mod do
        play (chord note+12, kind, invert:2), sustain: time, attack: time/2, amp:overamp
      end
    end
  end
  
  
  use_synth :piano
  set :bassnote, note
  set :basskind, kind
  play note, sustain: time, attack: 0.5
  use_synth :piano
  
  with_fx :flanger do
    with_fx :panslicer, mix: 0.35 do
      if look(:ctr) > 8 # start single notes
        time_warp rand(0.05) do
          play (chord note, kind, num_octaves: 3).tick(:arp), sustain: time/2, decay:time/2
          sleep time/2
          play (chord note, kind, num_octaves: 2).tick(:arp)+12, sustain: time/2, decay:time/2
        end
      end
      if one_in(4)
        sleep time/4
        print('non chord')
        if look(:ctr) > 12 # start extra notes
          time_warp rand(0.1) do
            play (scale note, kind, num_octaves: 2).choose, sustain: time/4, decay:time/4
          end
        end
        sleep time/4
      else
        sleep time/2
      end
    end
  end
end # end main loop




if (get :ctr) > 56 # stop industrial sample
  stop
end
live_loop :beat do
  sleep 12
  with_fx :gverb, spread: 1, damp: 0.3, room: 30, amp: 0.5 do
    with_fx :ring_mod, mix: 1, phase: 8 do
      if one_in(2)
        sample :loop_industrial, release:0.6, finish: 0.8
      end
    end
  end
end

live_loop :beat2 do
  if (get :ctr) > 54 # stop at 2.5 mins
    stop
  end
  sleep 2
  if not one_in(3)
    with_fx :echo, phase:2.0/8*1.5, decay:2 do
      sample :drum_heavy_kick, amp:0.4
    end
  end
  if not one_in(4)
    sleep 2
    with_fx :echo, phase:2.0/8*1.5, decay:2 do
      sample :drum_bass_hard, amp:0.4
    end
  end
end

# bass piano
live_loop :bass do
  if (get :ctr) > 56 # stop bass notes
    stop
  end
  note = (chord get(:bassnote), get(:basskind))[[2,0].look(:bassline)]-12
  time_warp -1 do
    use_synth :hollow
    play note-12, pan:[0.8,0.7,-0.8,-0.7].look(:bassline), attack:0, release:0.75, sustain:[7,2].look(:bassline), amp:3
    use_synth :piano
    play note, sustain: 0.5, pan:[-0.5,-0.4,0.5,0.4].look(:bassline), attack:0, release:0.25, sustain:[7,2].look(:bassline), amp:0.7
  end
  with_fx :panslicer, phase:1, wave:3  do
    use_synth :fm
    play note-12, sustain:[7,2].look(:bassline), amp:1
  end
  sleep [1,7].tick(:bassline)
end

posted by signal (4 comments total) 2 users marked this as a favorite

It's a I V vi IV progression, playing the chords and partial arpeggios over them
plus a few non-chord notes from the scale of each chord.
Not a lot of randomness, mostly just overlapping different length sequences. Only uses random to decide whether or not to play certain beats and to add some 'humanizing' to the chord arpeggios.
posted by signal at 1:42 PM on April 3


I am extremely interested in Sonic Pi! I'd love to hear how it's working out for you. I'm interested in building a little rig that makes it into a generative sequencer, like a low rent monome teletype.
posted by q*ben at 2:05 PM on April 3


I'm just getting started, but would love to have somebody to bounce ideas off of!
posted by signal at 2:23 PM on April 3


I’d love to know how you’d get it to work in a live environment as there are a lot of complex sequencers I can use with preparation, and a lot of simple live sequencers, but not a lot beyond the teletype that lets you set up a system and then slowly evolve it over time. I like the ethos and approach of this system, but would probably be building a little dedicated Pi kit to use as an instrument and don’t want to do that unless I’ll use it... but I’ll demo on my computer for now and see how it works. Thanks!
posted by q*ben at 8:39 PM on April 3


« Older If I Should Fall In Love Again   |   Ambient Office v3: Pam Tam Newer »

You are not logged in, either login or create an account to post comments