One of the things I was shown at Picademy, was Sonic Pi. At the time I thought it was a great resource, but too difficult for me. Since then, I was lucky enough to meet creator, Sam Aaron and persuade (ok..bully) him to visit my school and run an all day workshop about the software.
Sam’s goal is to make coding accessible to all, with real, tangible results quickly and easily; this, of course, appeals greatly to children – even one line of code in Sonic Pi can generate a simple sound that can be expanded and extended easily.
Sonic Pi was initially created for the Raspberry Pi, but is now available on both Mac and PC. It is free and easy to install and you can get started straight away.
So, how does Sonic Pi work – the first thing you need to get to grips with is the tutorial at the bottom left of the page – clicking on the tutorial tab will open a collection of tutorials which will allow you to get to grips with how the system works.
You can see in the first picture that there is a middle bar which allows you to select one of 8 workspaces where you can input your code.
The most simple thing you can do is play notes and ‘compose’ a tune using simple commands – to play a middle C, all you need to do is type:
If you’re musical, you may recognise that middle c is the 4th octave so yes, you could try ‘play :c5’ and play a different c. I’m not musical, so I’m content to say that these notes all make the same nice sound. Notice that there is a colon before the letter, but not before the number. It is important to remember this as it is one of the common errors that children will make.
You can obviously also put different notes in by using different numbers with the play command e.g. play 75 would play a higher note. The children in our workshop liked to see just how high you could get and soon found that somewhere over 100 the notes become too high to hear.
At this point, you could try play a selection of notes one after the other –
Guess what, this is code, things are never as simple as that – playing all of the notes laid out like this basically plays them all at once since there is no wait command between each note – the computer tries to play them all together. In this instance, they will play a chord because the notes complement each other, but if you try other notes you will simply make a cacophony.
So, by adding in a sleep command you can put a pause between notes.
One of the children I teach got this far and then carefully composed the Ride of the Valkyries in his own time, however, composing individual notes is not what Sonic Pi is really all about. The most interesting feature is to do with samples – as Sam explained to the children, in a musical context, a sample is a short snippet of sound which has been used to enhance a piece of music. It can be a complete piece of music or a simple drum beat. Sonic Pi has a large selection of built in samples which can easily be sped up, slowed down, cut short or looped and it is very simple to combine these for a lovely music effect.
So let’s say we want to play the sample :loop_amen
As soon as I type in ‘sample :’ then I get a drop down menu of all of the different samples – the children in the workshop absolutely loved having the opportunity to just play with each of the different samples and combine them to make new sounds.
The next thing you can do is play with the rate of the sample:
By adding in a rate you can make the sample either faster or slower – in this instance, the play back is half its usual speed so it sounds a bit like a Groove Armada track, but if you go the other way and speed it up to a rate of 1.5 it sounds much more like a jungle beat. Already our track is sounding pretty cool. You can also use negative numbers to play samples backwards…
So, now I added in a few notes to play with along with some sleep commands :
Suddenly I have actual music coming out of my speakers and, as I’ve already said, I’m about as musical as a dead fly. You can imagine the excitement of children who have quickly and easily managed to make lots of music with a few simple instructions.
I’m going to finish the what you can do section here – there are so many other things you can do with Sonic Pi, but really the best way to find out is to have a play yourself – there are simple instructions for looping bits of music- either for a certain amount of times or indefinitely:
You can alter the sound of the beeps with “use_synth” e.g.
The ultimate goal is to live code by using live loops which constantly play while the user updates small bits of code to alter the pitch or pace of the song.
So, why is Sonic Pi valuable?
As I’ve already mentioned, children love instant results and Sonic Pi more than allows that – one line of code and you have a nice little sample of music playing. It’s easy for children to make simple tweaks to code which have broad and obvious results. It’s also really easy to debug – the code is clearly coloured which gives children a clue as to whether their code is going to work. The children must make sure their code is correct – a lot of the children made mistakes with the sample command because when you type in the word sample it automatically loads a drop down menu:
They also frequently forgot to use a colon before listing the name of the sample so that, even when copying information from the board, they made errors. So, importantly, Sonic Pi can help with the important skill of debugging and the fact that children constantly need reminding to test their code frequently as part of the debugging process. Unfortunately, the current version of Sonic Pi doesn’t clearly let the user know what the error in their code is, but Sam is already working on making the error codes more clear for children (and their teachers) in future versions.
In terms of it’s musical usefulness, it can help children to gain a better understanding of pitch and pace and it can be surprising to see which children are particularly successful at writing phat drum & base tunes!
Key for me was that all of the children that took part in the workshop with Sam enjoyed themselves, enjoyed coding and left excited and eager to create their own music. Some of the children even emailed themselves their code to carry on working on it at home. These children were Year 4 and so only 8 or 9 years old, they were of mixed ability with many of them struggling with learning difficulties, however, they were all involved and they were all coding confidently. What surprised me most of all was that the most able children were not necessarily the most competent and in fact the two who produced the most eloquent pieces of music were both average ability children, only one of whom even played a musical instrument.
It takes a bit of playing and getting used to, but I really think Sonic Pi is an excellent resource for getting kids to learn how to code and to make them more confident and comfortable with the language of code. So, why not give it a go and remember, Sam is probably one of the most approachable people in this community and is more than happy to receive weird twitter questions in the middle of the night (trust me, I know this from experience).