Belated greetings

Hi all. This is a slightly belated introduction. I’m new to Sonic Pi, but I think I can claim very far from new in terms of music programming. I feel that I’m making good progress. I spent a few hours todays and racked up some personal firsts, such as controlling Max/MSP and Logic Pro X from inside Sonic Pi. I’m starting to develop personal preferences, e.g. I quite like using the ‘at’ command for drum beats as it makes it easier for me to design them and make them flexible, e.g. through variables set via ‘set’ and read through ‘get’.

5 Likes

Hi there, welcome to the community and thank-you so much for supporting continued development on Patreon :slight_smile:

It’s lovely to hear that you feel like you’re making good progress with Sonic Pi. I look forward to seeing some of your results and hope that you’ll consider sharing them with us all here.

It’s also awesome to see that you’ve homed straight in on get, set and at. These are (in my opinion) the most exciting parts of Sonic Pi and I look forward to what you get up to with them!

Happy live coding…

1 Like

Thanks. I’m working on what’s going to be my first complete piece now. I wouldn’t call it musically innovative, but hope to be able to share it sometime in the near future. I’m keeping it solely Sonic Pi only, with no external samples or other software involved. After that it’ll be onwards and upwards. I hope.

1 Like

What follows isn’t anything to be proud of, except that I’ve learned through a long life so far that whatever you’re doing, it’s best to get things ‘finished’ early on, and start again as learning is more important when starting out than getting a good result.

https://vocaroo.com/i/s1h7aTLcwQbd

EDIT: OK, it looks as if one thing I’ll need to study up on is how to post code to this forum :smile: What’s the best method?

use_debug false
use_bpm 125

ts = (scale :e3, :dorian, num_octaves: 4)
roots = (ring 0, 0, 2, 4, 0, 0, 4, 3).repeat(3) + (ring 5, 4, 5, 4)
pans = (ring -1, 1)
seeds = (ring 63, 128, 666, 63, 128, 775, 3712)
cutoffs = (ring 30, 30, 30, 90)
amps = (ring 1, 1, 1, 3)
fills = (ring false, false, false, true)

barCount = 0;

set :drummode, 'intro'
set :bassmode, 'intro'
set :melomode, 'intro'
set :chordmode, 'intro'
set :melomode, 'normal'

live_loop :chords do
  sync :loop
  use_synth :dsaw
  tick
  use_synth_defaults amp: amps.look, sustain: 4, attack: 0.5, release: 0.5
  
  if get( :chordmode ) == 'normal'
    
    with_fx :reverb, room: 0.7, mix: 0.5 do
      with_fx :rhpf, cutoff: cutoffs.look, res: 0.7 do
        
        with_fx :ixi_techno, min_cutoff: 50, max_cutoff: 70, res: 0.3 do
          
          play [ts[roots.look], ts[roots.look+2],
                ts[roots.look+4], ts[roots.look+6]]
        end
      end
    end
  end
  
  if get( :chordmode ) == 'alternate'
    use_synth_defaults amp: 0.3, sustain: 0, attack: 0.01, release: 2, decay: 2
    with_fx :reverb, room: 0.7, mix: 0.5 do
      with_fx :rlpf, cutoff: 60 , res: 0.7 do
        
        
        play [ts[roots.look], ts[roots.look],
              ts[roots.look+4]]
        
        sleep 2
        
        play [ts[roots.look] + 12, ts[roots.look],
              ts[roots.look+4]]
        
      end
    end
  end
  
  if get( :chordmode ) == 'intro'
    
    with_fx :reverb, room: 0.7, mix: 0.5 do
      with_fx :rhpf, cutoff: cutoffs.look, res: 0.7 do
        
        with_fx :ixi_techno, min_cutoff: 50, max_cutoff: 70, res: 0.3 do
          
          play [ts[roots[0]], ts[roots[0]+2],
                ts[roots[0]+4], ts[roots[0]+6]]
        end
      end
    end
  end
end

live_loop :bass do
  sync :loop
  use_synth :dpulse
  use_synth_defaults pulse_width: 0.25, dpulse_width: 0.25, amp: 1, cutoff: 90, res: 0.9, sustain: 0, attack: 0.01, release: 0.2, decay: 0.2
  tick
  
  if get( :bassmode ) == 'normal'
    
    with_transpose -24 do
      with_fx :eq, low_shelf: 2 do
        if fills.look
          sleep 0.5
          play ts[roots.look], pan: pans.look
          sleep 0.25
          sleep 2
        else
          sleep 2.5
        end
        
        play ts[roots.look], pan: pans.look
        sleep 0.75
        play ts[roots.look], pan: pans.look
        sleep 0.5
        play ts[roots.look], pan: pans.look
      end
    end
  else
    if get( :bassmode ) == 'pulse'
      with_transpose -24 do
        with_fx :eq, low_shelf: 2 do
          sleep 0.5
          play ts[roots.look], pan: pans.look
          sleep 1
          play ts[roots.look], pan: pans.look
          sleep 1
          play ts[roots.look], pan: pans.look
          sleep 1
          play ts[roots.look], pan: pans.look
        end
      end
    end
  end
end

live_loop :melo do
  sync :loop
  tick
  use_random_seed seeds.look
  
  if get( :melomode ) == 'normal'
    
    sleep 1.25
    use_synth :fm
    use_synth_defaults amp: 0.5, divisor: 0.125, depth: 7, attack: 0.02, sustain: 0, decay: 0.2, release: 0.2
    with_fx :reverb, room: 0.9 do
      
      with_fx :echo, mix: 0.5, phase: 1, decay: 8 do
        8.times do
          with_transpose +12 do
            play ts[rand_i(16)+roots.look] if one_in( 2 )
            sleep 0.25
          end
        end
      end
    end
  end
  
  if get( :melomode ) == 'alternate'
    notes = [ ts[roots.look],
              ts[roots.look+2],
              ts[roots.look+4],
              ts[roots.look+8] ]
    
    use_synth :tb303
    use_synth_defaults  decay: 1, release: 1,
      divisor: 0.333333, depth: 5, sustain: 2,
      note_slide: 0.0625, res: 0.9, cutoff: 70, amp: 0.4
    
    sleep 2
    
    with_fx :reverb, room: 0.9 do
      
      with_fx :echo, mix: 0.5, phase: 1, decay: 8 do
        syn = play notes.choose
        
        with_transpose +36 do
          
          8.times do
            nnote = notes.choose
            control syn, note: notes.choose if one_in( 2 )
            sleep 0.25
          end
        end
      end
    end
  end
end

live_loop :drums2 do
  cue :loop
  tick
  
  print "bar: ", barCount
  barCount = barCount + 1
  
  if get( :drummode ) == 'normal'
    
    at [0, 0.5, 2.5 ] do
      sample :bd_haus, amp: 2
    end
    
    at [1, 3] do
      with_fx :reverb, mix: 0.2 do
        
        sample :sn_dolf, pan: 0.5
      end
    end
    
    if fills.look
      at [3.5, 3.75] do
        with_fx :reverb, mix: 0.2 do
          
          sample :sn_dolf, pan: 0.5
        end
      end
      
    end
    
    at [1.75] do
      with_fx :reverb, mix: 0.2 do
        sample :sn_dolf, amp: 0.5, pan: 0.5
      end
    end
    
    at [0.5, 0.75, 1, 1.5, 2.5, 2.75, 3, 3.25, 3.5] do
      with_fx :reverb, mix: 0.2 do
        
        sample :drum_cymbal_closed, pan: -0.5
      end
    end
  end
  
  if get( :drummode ) == 'intro'
    at [ 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5 ] do
      with_fx :reverb, room: 0.95 do
        
        sample :drum_cymbal_closed, amp: rrand( 0.3, 0.7 )
        
        if one_in( 3 )
          sleep 0.25
          sample :drum_cymbal_closed, amp: rrand( 0.2, 0.4 )
        end
      end
    end
    
    if fills.look
      at [3] do
        with_fx :reverb, mix: 0.2 do
          with_fx :echo, mix: 0.5, phase: 0.5, decay: 4 do
            
            sample :sn_dolf, pan: 0.5
          end
        end
      end
    end
  end
  
  if get( :drummode ) == 'pulse'
    at [ 0, 1, 2, 3 ] do
      sample :bd_haus
    end
    
    at [ 0.5, 1.5, 2.5, 3.5 ] do
      sample :drum_cymbal_closed
    end
    
    at [ 1, 3 ] do
      sample :sn_dolf
    end
  end
  
  sleep 4
end

# Arrangement for whole track

at 31 do
  set :chordmode, 'normal'
end

at 31 do
  set :bassmode, 'normal'
end

at 63 do
  set :drummode, 'normal'
end

at 127 do
  set :bassmode, 'pulse'
  set :drummode, 'pulse'
end

at 143 do
  set :bassmode, 'normal'
  set :drummode, 'normal'
end

at 207 do
  set :bassmode, 'pulse'
  set :drummode, 'pulse'
end

at 223 do
  set :bassmode, 'normal'
  set :drummode, 'normal'
  set :chordmode, 'alternate'
  set :melomode, 'alternate'
end

at 287 do
  set :chordmode, 'normal'
  set :melomode, 'normal'
end

at 351 do
  set :drummode, 'intro'
end

at 355 do
  set :bassmode, 'none'
end

at 359 do
  set :chordmode, 'none'
end

at 363 do
  set :melomode, 'none'
end


at 363 do
  set :drummode, 'none'
end

2 Likes

type three back tick characters on a single line. Paste your code in the next line. press return and on the following line type a further three back ticks You will then get everything nicely formatted in a window, with a copy button in the top right corner.

live this:

#start of formatted code
play 72
#end of code

you wont see the three `, except in the editor as you type them in

1 Like

Got it! Thanks.

Now as an exercise I’m going to code a genetic algorithm in Sonic Pi

Worth the listen, definitely. :slight_smile:

And ‘at’ is so very versatile, even
without set & get.

Eli…

use_bpm 120
live_loop :beat4 do
  sleep 8
end


define :hat do
  at [0, 2, 3,  6],
  [{:amp=>0.3}, {:amp=> 1}, {:amp=>0.5},{:amp=>0.3}] do |p|
    sample :drum_cymbal_pedal, p
  end
end

define :drum do
  at [1, rrand_i(2, 3), 4, 6],
  [{:amp=>1}] do |p|
    sample [:drum_bass_hard, :drum_bass_soft].choose, p
  end
end



live_loop :do_hat do
  sync :beat4
  hat
  sleep 1
end

live_loop :do_drum do
  sync :beat4
  drum
  sleep 1
end
2 Likes