5 Sonic Pi Tips


3 min read

Here are five tricks I reach for when making music with Sonic Pi.

1. :sync to a metronome

Keep your live loops in sync by creating a metronome:

live_loop :click do
  sleep 1

Use :sync to keep all your loops together with the :click:

live_loop :kick, sync: :click do stop
  sample :bd_808
  sleep 1

2. move things along with .tick

Increment the default tick by 1 and return value. Successive calls to tick will continue to increment the default tick.

.tick is a handy shorthand for playing melodies. Essentially, it can be used to "tick" through an array of values, moving to the next item in the array on the next repeat.

Let's say you have a simple melody consisting of four notes: [:c3, :a2, :c3, :e3]

You can play these notes in order using tick:

play [:c3, :a2, :c3, :e3].tick

I also like to use this to set sleep values for varied but predictable rhythms:

sleep [0.5, 0.75, 0.25, 0.25, 0.5].tick

3. make the computer .choose for you

IMO, randomization is probably the most important aspects of creating algorithmically generated music. .choose is a simple way to get the computer to "choose" something for you. It will randomly pick a value from the provided array. Here is an example of a bassline I created with this method:

live_loop :earth, sync: :met do
  with_fx :echo do
    use_synth :beep
    play [:c3, :a2].choose, attack: 2, decay: 3, release: 2
    sleep 6

You'll never know if this is going to play a C or an A until it actually happens -- it really helps add a mysterious, unpredictable, and constantly evolving vibe.

4. dice things up

Throws a dice with the specified num_sides (defaults to 6) and returns the score as a number between 1 and num_sides.

More randomization! Instead of choosing from a set of pre-specified values, this function literally acts like a throw of a die.

I like to use this to trigger random percussion samples to add some ear candy or variation to the beat.

live_loop :perc do
  if dice == 1
    with_fx :ping_pong do
      sample :perc_snap, amp: 0.5
  sleep 1

5. Get Euclidian with spread

Creates a new ring of boolean values which space a given number of accents as evenly as possible throughout a bar.

Ok this one is sick AF. This will create Euclidian rhythms based on the parameters provided. Essentially, this is a fancy way of saying that x number of notes will be spread as evenly as possible across y number of beats. This concept is named after the ancient homie Euclid, who described the mathematical relationship performed here.

This is a super easy way to generate interesting polyrhythms:

live_loop :bd do
  sample :bd_808 if (spread 2, 5).tick
  sleep 0.25

This will perform two kicks across the space of 5 sixteenth notes. There are so many cool possibilities to find here by rearranging these numbers. Just go play around with this one and make some IDM. Have fun!