Introduction:

In this project you will learn how to code a live music performance, that you can add to and edit without having to stop the music!

Press the play button below to hear how your music will sound:

Step 1: Drums

Let’s start by creating a simple drum loop.

Activity Checklist

  • Start by creating a live_loop called :drums.

    screenshot
    screenshot

    Any code added to a live_loop will repeat until ‘Stop’ is pressed.

  • Add an alternating drum and snare, that play for one beat each.

    screenshot
    screenshot
  • Press ‘Run’ to test your drum loop.

  • If your drum loop is too fast/slow, you can change the beats per minute (bpm).

    screenshot
    screenshot

    You’ll need to stop and start your live_loop to speed it up or slow it down.

Save your project

Challenge: Changing the drum loop

Can you use different samples in your drum loop?

To see what samples are available, you can go to jumpto.cc/sonic-pi-samples, or just type sample :drum and choose from the list that appears.

screenshot
screenshot

Save your project

Step 2: Adding a sample

Let’s add a looping sample over the basic drum loop.

Activity Checklist

  • To play a sample in time with your drums, create another live_loop called :sample.

    screenshot
    screenshot
  • Add the sample :loop_compus, making it play every 8 beats.

    screenshot
    screenshot
  • If you test your sample, you’ll notice that it doesn’t match the drums at all!

  • The first thing you’ll need to do is sync your sample with the drum beat.

    screenshot
    screenshot
  • This still doesn’t sound right! Add code to print the duration of the sample:

    screenshot
    screenshot
  • If you scroll back through the log, you’ll see that although the sample is repeating every 8 beats, the sample doesn’t quite last 8 beats.

    screenshot
    screenshot

    (You can now remove the code to print the sample duration.)

  • To match your sample with the drums you’ll need to stretch the sample so that it lasts exactly 8 beats as well.

    screenshot
    screenshot
  • Test your code by pressing ‘Run’ again – you don’t need to stop and restart the music! You should now hear that your sample plays in time with your drum beat.

Save your project

Challenge: Changing the sample

Can you change the sample used?

To see what loop samples are available, you can go to jumpto.cc/sonic-pi-samples, or just type sample :loop and choose from the list that appears.

screenshot
screenshot

You might also need to change the numbers in your code for different samples. You can use the following code to find out the sample of a duration:

puts sample_duration(:sample_name)

To loop a sample without a gap, make sure that both numbers match.

screenshot
screenshot

Save your project

Step 3: Adding bass

Now let’s add some bass notes to your music.

Activity Checklist

  • Start by creating a new live_loop called :bass. This new loop should also sync with the drums.

    screenshot
    screenshot
  • Add code to play a single note every 8 beats. The note played uses the :chipbass synth.

    screenshot
    screenshot
  • Press ‘Run’ (no need to stop and restart your music). You should hear a note play every 8 beats.

  • A chord is a group of notes played together.

    Instead of playing the same note every 8 beats, you can choose a random note from a chord. In this case, the chord is C Minor.

    screenshot
    screenshot
  • ‘Middle’ C is actually :c4. To play lower bass notes, add a number lower than 4 after the chord name.

    screenshot
    screenshot
  • Use a sustain to choose how many beats the note is held for.

    screenshot
    screenshot
  • You can also use amp to choose the loudness of the bass. A number lower than 1 will be quieter, and higher than 1 will be louder.

    screenshot
    screenshot
  • You can also add a (louder) sample to play at the start of each note.

    screenshot
    screenshot
  • Press ‘Run’ to test your code. There’s no need to stop and restart your music.

Save your project

Challenge: Changing the bass

Can you change the bass notes in your music. You could change:

  • The name of the chord played, e.g. f2 instead of c2
  • The type of chord, e.g. :major instead of :minor
  • The synth used
  • The sample played
screenshot
screenshot

Save your project

Step 4: Adding sound effects

Finally, let’s add some sound effects to your music.

Activity Checklist

  • Add another live_loop called :effects, which syncs with the drums.

    screenshot
    screenshot
  • Add this code to play the :elec_blip2 sample every 2 beats.

    screenshot
    screenshot
  • Click ‘Run’ to test your code (there’s no need to stop and restart your music). You should hear a beep effect every 2 beats.

  • Instead of playing the same effect each time, you could instead choose randomly from a list of 2 effects.

    screenshot
    screenshot
  • Click ‘Run’ to test your random effects (there’s no need to stop and restart your music).

Save your project

Challenge: Changing the effects

Can you add even more sound effects to your music?

screenshot
screenshot

Save your project

Challenge: Show off your DJ skills!

Use everything you’ve learnt to be a DJ for your friends! Remember that you can add to your music, as well as change notes and samples without having to stop the music.

Save your project