Transcript
Programming Those Beats!
Play the Beat With Your Melody
Do this
Create a live_loop
that plays at least one sound. Change the sample and press run without stopping the playback! You can start with the code below.
Loop example
live_loop :trythis do
sample :bd_ada
sleep 1
end
Which one of the statements is true?
Educator notes
Live loops are a good example of concurrency in programming. Concurrency means the ability of a computer program to perform more than one task at a time.
Please notice that you should have only one use_bpm command at the top to declare the song tempo. If you put the use_bpm command inside a live_loop, only the contents of the live_loop will be affected. This can be used for creative effects but is more of an advanced technique. (Try for example two identical live_loops with different names and slightly different tempi)
#Example of two live loops with different tempi
live_loop :loop1 do
use_bpm 120
sample :elec_blip
sleep 1
end
live_loop :loop2 do
use_bpm 122
sample :elec_blip
sleep 1
end
Let’s Add Some Cymbals
Do this
Make another live_loop that plays fast hi-hats with your original beat.
Crash the live_loop by removing the sleep value and then fix it!
Why is it a good idea to separate different percussive parts to different live_loops?
What happens to the program when there is a live_loop without a sleep?
Educator notes
Sometimes you may find that a learner is making a really complex live_loop with all of their sounds inside, and are struggling to make it sound the way they want. Encourage them to break the live_loops into several simpler loops to keep things more manageable.
When there is an error inside a live_loop, such as a missing sleep, it will only stop the playback of the live_loop in question. Sometimes learners have several live_loops happily running with error messages on the screen. It’s a good idea to help them understand where the errors are as they might not realize how they are affecting their compositions. Remember to look for the line number that the error message displays.
Happy Rhythmic Accidents
Do this
Experiment with different sleep values inside your cymbal live_loop. What kind of numbers give results you find interesting? What numbers don’t work so well?
Hint: You can try dividing the sleep value to get interesting results. Use a decimal number when dividing!
sleep 1/3.0
Experimentation is the key to success. It’s all too easy to get stuck in doing the same things over and over. Sometimes the best way to break free is to try something totally crazy and see what happens. With Sonic Pi you can easily try ideas that could be impossible with traditional instruments or music programs!
Educator notes
Sonic Pi is ideal for experimenting with complex rhythms as it will never play anything wrong no matter how complicated it gets.
You can encourage students to explore the mathematical ratios between two rhythms! A simple way of exploring this is having one live_loop play one sample with a sleep value of 1, and another loop where you change the sleep value. Placing two different rhythmic ratios against each other is known as a polyrhythm.
Examples:
sleep 1
against sleep 0.666666
(⅔) 3:2 (triplet)
sleep 1
against sleep 0.8
5:4 (quintuplet)
When you are making divisions in Sonic Pi, it’s important to use decimal numbers. If you use only integers, the result will be rounded down to the nearest integer as well. So to get the right ratios, always use a decimal number when dividing.
There is not really a clear consensus when a rhythm is called a polyrhythm and when it’s a cross rhythm. They both mean more or less the same thing. One explanation is that when a piece of music is based on the rhythmic difference of two or more parts its a cross rhythm and if the difference is more momentary, then it’s a polyrhythm.
Give Your Loop a Break
Do this
Create a fill in your drum beat that plays every four bars.
- Remember that in 4/4 time one bar has a total sleep time of 4
Add a comment to the beginning of the loop with your name and a description of the beat.
- Comments are made with the #-sign
Live code by commenting on a part of your code while it’s still running.
Comment example
#this is a comment
#MY SICK TUNE v 0.1
play 60
sleep 1
#the play below will not play
#play 67
sleep 1
Educator notes
Commenting is a really important skill in programming, as it allows us to communicate our intent to others more clearly. A good way to have your learners get familiar with the comment syntax is asking them to write their name and the name of the composition in the beginning of their code.
Some learners may try and make their beats faster by making the sleep arguments smaller. Remind them to use the use_bpm
command instead.
Halving or doubling the values of sleep arguments is a musical way of creating different rhythms. Note that faster rhythms don’t necessarily mean a faster tempo!