Coding Music with Sonic Pi - A 6-8 Part Scheme

Lesson Zero: Things you will need for this topic:

Your student choices should be made on wear and sound quality.

Your student choices should be made on wear and sound quality.

  1. Headphones - you will also be learning about listening 'comfort' and what Db (decibels) are and how this affects your ability to hear. You will also learn that listening to sound that is too loud is damaging to your hearing.

  2. Thing to note with headphones, is that the bluetooth connection on MacOS with Sonic Pi is problematic. Seen this Changelog on GitHub.

  3. Free Applications for both MacOS, Windows and iOS: Sonic Pi, Audacity and GarageBand.

  4. Understanding where your audio comes from on your computer and how to control this. See this tutorial for MacOS and this one for Windows.

  5. If you have a MacBook, I recommend that you will install GarageBand and the loops that come with it. Go to the Mac Store here. [You will need to do this at home as well as school, as the files are huge]. This will be to play with the tracks and the elements fo tracks you make such as bass-lines, melodies and, in some cases, harmonies.

  6. If you have an iPad at home, you can install GarageBand on this to be able to edit the music you will be making either at home or in school - importing all your sounds from Google Drive. This is free and great to use. See this for support.

Earphones or headphones. 

Earphones and headphones are not always the same. There are types that will be better for different jobs. 

Apple earphones are great for listening to vocals or podcasts/ Youtube tutorials. They are not good, though, for low or bass-heavy music - the things you will be hearing in this topic. The reason is, that the low-sounding parts to the music you will be making, needs a 'seal' on, in or around the ear to be able to hear this. 

Apple earphones, while a great product due to the build quality, rarely makes the 'seal' within the ear canal for us to hear the low sounds. They also allow sound from outside to 'bleed' past the earphones into your ears. This means that the outside sound mixes with the music you are creating and you hear an inaccurate piece of music.

These two things combined, means that, the hard plastic earphones last a long time but are not good for creating music on your device.

Try this link to see the range of cheap earphones available in Thailand from Lazada.

2. Apps.

MacOS/ Windows/ iOS (optional depending on your school)

This is Sonic Pi for Mac - This is Sonic Pi for Windows - This GarageBand for iOS
This is Audacity 2.3.1 or MacOS - This is Audacity 2.3.1 for Windows - This GarageBand for MacOS

One of the neater tricks in Sonic Pi is the save and record function. This allows students to export a .WAV file of their code to iCloud/ Google Drive and import to GarageBand for editing and collaborating if there is time to Jam in a team of 4.

Lesson 1

A lot of children may never have known that you can code anything other than Scratch, in a paid for platform or the ‘stuff’ websites and apps are made of. So to say we are going to code music is quite a unique concept and experience.

To introduce this I like to use Xavier Riley’s presentation at the Bath Ruby conference. I like to use the end portion because he has experience of using Sonic Pi in schools with children and draws directly from their initial experiences.\

Rocking Out In Ruby - A Playful Introduction to Sonic PI by Xavier Riley Help us caption & translate this video! http://amara.org/v/IG11/

Lesson 2 and 3 - Synths and Samples

In this round, the students continue with the direct instruction - this helps in the ‘getting to know’ the application and the general usefulness of Sonic Pi’s immediate feedback that the music offers. In this respect, coding languages don't really do this. Generally, you need to compile or at least load up a few files etc. Here, the kids enjoy the ‘this isn’t quite right and something needs fixing’ situation that immediately prompts a debugging session and, more importantly, a quick conversation with the person next to them.

Screen Shot 2019-07-20 at 13.30.50.png

Lesson 3 and 4: Loops and live_loops

Threading loops. This is one of th best things to learn in Sonic Pi. When the kids get here, they really come into their own. They instantly know that the music will automatically wrap each around each other and begin to experiment beyond: Play, sleep, play, sleep.

From the help section in Sonic Pi:

So you’ve made your killer bassline and a phat beat. How do you play them at the same time? One solution is to weave them together manually - play some bass, then a bit of drums, then more bass… However, the timing soon gets hard to think about, especially when you start weaving in more elements.

What if Sonic Pi could weave things for you automatically? Well, it can, and you do it with a special thing called a thread. See here in the Sonic-Pi.net help section.

Infinite Loops

To keep this example simple, you’ll have to imagine that this is a phat beat and a killer bassline:

loop do
  sample :drum_heavy_kick
  sleep 1
end
loop do
  use_synth :fm
  play 40, release: 0.2
  sleep 0.5
end 

As we’ve discussed previously, loops are like black holes for the program. Once you enter a loop you can never exit from it until you hit stop. How do we play both loops at the same time? We have to tell Sonic Pi that we want to start something at the same time as the rest of the code. This is where threads come to the rescue.

Threads to the Rescue

in_thread do
  loop do
    sample :drum_heavy_kick
    sleep 1
  end
end
loop do
  use_synth :fm
  play 40, release: 0.2
  sleep 0.5
end 

By wrapping the first loop in an in_thread do/end block we tell Sonic Pi to run the contents of the do/end block at exactly the same time as the next statement after the do/end block (which happens to be the second loop). Try it and you’ll hear both the drums and the bassline weaved together!

Now, what if we wanted to add a synth on top. Something like:

in_thread do
  loop do
    sample :drum_heavy_kick
    sleep 1
  end
end
loop do
  use_synth :fm
  play 40, release: 0.2
  sleep 0.5
end
loop do
  use_synth :zawa
  play 52, release: 2.5, phase: 2, amp: 0.5
  sleep 2
end 

Now we have the same problem as before. The first loop is played at the same time as the second loop due to the in_thread. However, the third loop is never reached. We therefore need another thread:

in_thread do
  loop do
    sample :drum_heavy_kick
    sleep 1
  end
end
in_thread do
  loop do
    use_synth :fm
    play 40, release: 0.2
    sleep 0.5
  end
end
loop do
  use_synth :zawa
  play 52, release: 2.5, phase: 2, amp: 0.5
  sleep 2
end 

Runs as threads

What may surprise you is that when you press the Run button, you’re actually creating a new thread for the code to run. This is why pressing it multiple times will layer sounds over each other. As the runs themselves are threads, they will automatically weave the sounds together for you.

Screen Shot 2019-07-21 at 11.19.58.png

A quick nod to the Amen Break that is so often used in Sonic Pi and referenced a lot by Sam Aaron and in the resources here too.

10 Songs that sample the famous 'Amen Break' from the song recorded by The Winstons called Amen Brother, there are thousands of examples, but I chose 10 from vastly different genres to mix it up a bit. Here's the history of the Amen Break. what is the Amen Break: Wikipedia

Lesson 4 and 5: Putting it Together

Screen Shot 2019-07-21 at 11.51.23.png

From this lesson on there is really very little left in this mini project for the kids to be directed too other than the tutorial section to help them with live explanations. The task I set them is to try and emulate a track and deconstruct a track. In this regard I set them Your Love, by Frank Knuckles and Jamie Principle.

As you an see, there are some extras here that is not in the resource above. This is because the lessons I run are based on discovery and the questioning of “How can this sample be shorter?’ “Which sample is this closest too?” “How can we edit this sample to make it sound more like the track in hand?” “What needs to be done to it?”

I must be clear here - the students I teach are already musically minded. They are taught music in specialist lessons from Foundation stage upwards and most have extra music lessons for an instrument such as piano, violin etc. So their knowledge of beats, bars/ Measures, timbre and newer language being introduced here such as decay and attack are easily absorbed and quickly understood.

This is by no means exclusive. A quick test of what decay, sustain and attack does in Sonic Pi is immediately obvious. So trialling the values as you play and re-play is quite easy to grasp.

The kids who are struggling to understand are not excluded. On the contrary, I offer nearly right answers for them to play with and try to create the code to give it a fix such as this below ( very nearly correct sample - breaking it up depending on the students varies the ‘correctness’ of the sample).

use_bpm 90
live_loop :Knuckles_Intro do
  with_synth :pluck do
    16.times do
      play [:c, :e, :g].ring, decay: 1, attack: 0.05
      sleep 0.25
    end
  end
end
Screen Shot 2019-07-21 at 12.39.16.png

Mehackit

Mehackit is possibly the place to learn sonic pi easily with simple tutorials as too Dave Conservatoire on Youtube. This gives the kids who are struggling to get a leg up with what they want to do without feeling left behind or left out. For us it’s a real boon because it’s in so many languages and caters for all the EAL students we have.

Lesson 5 and 6: Compositions, Exporting and Remixing


As the kids begin to build and rebuild the track, it’s important for the kids to try to collaborate on their work as well as showcase it. The issue with Sonic Pi is that it’s very single minded with a single user in mind - a musician. This is tough sometimes when you’re part of a team or a class that naturally shares and collaborates with other teams.

One of the options here is Google Keep. The kids can easily share and edit text from the Sonic Pi console straight into their notes and out again. You can do this in Classroom, however, Classroom isn’t really the arena for adding unedited snips of work - it’s for discussion and sharing prototypes and assignments.

Jiyong and Yoonhan are here sharing snips of code back and fourth to edit live as they play.

Jiyong and Yoonhan are here sharing snips of code back and fourth to edit live as they play.

You can see that Abigail is sharing to her class for people to play and offer guidance to ideas.

You can see that Abigail is sharing to her class for people to play and offer guidance to ideas.

Bear in mind that these sessions will probably run over time because more-often-than-not the kids will want to experiment and make many corrections. So plan for this and be as flexible as possible.

As the mine project come to a close where are you going to export these tracks too? What can you do with them?

Well, we ran out of time and were going to edit them in GarageBand (something for next year for sure) but some kids put them into Audacity and edited in the settings where parts were too quiet or stretched them out - or simply amplified the .WAV file to suit.

The classes all have pages on our intranet so there are embedded SoundCloud playlists there. Here is something you might want to do so that kids can play all tracks at once with the text alongside should you wish.



Coding Projects and Competitions

Preparing for the competition

Preparing for the competition

Coding takes up approximately a third of our total teaching time not including CCAs (this is year round). Within this there are 4 major projects across the year groups that includes the Singapore LEGO NXT competition.

One of the newer projects is the switch to Raspberry Pi for Sonic Pi music coding (this can be done on anything incidentally but the Pis add a certain 'WOW!' ferver), old school shape and letter building algorithms in Scratch and using MakeyMakeys, RPis, cartons and speakers to build 'Operation' games - as seen in the link below. Their game is here.

We won!

We won!

The projects lead our kids to, eventually, the kind of show reel in year 6. This is a term-long project that encompasses a portion of game design into the project. This is something I have learned about called 'Game Feel' while studying at California Institute.

The idea behind this is that games, while they can be graphically appealing (and this is something I like my students to be aware of too) should have a hook or draw much like a book or film has to bring you back to the environment and re-play or continue playing.

The materials we, as a team, read and use as a reference point are here.

1. Game Feel by Steve Swink

2. The Art of Game Design: A book of Lenses by Jesse Schnell

3. The Rules of Play: Game Design Fundementals by Eric Zimmerman and Katie Salen

4. Level Up: The Guide to Great Video Game Design by Scott Rogers

The show reel the Year 6 students create, builds on the WWII topic they are studying and splicing the locality, Singapore, into a historically engaging game based on events in the 1940s.

The success of this is largely determined on a few factors and this is down to wholesale student enthusiasm. The games that were the best were'nt built by the best coders. They were built by the kids whose determination levels higher. The boys who won the FLL on the right are testment to this.

FOBISIA Coding competion 2016

Following on from the success and fun we had at the FLL, I wanted to create a regional competiton that centered on games, music and general restrictiveness that kids don't really encounter in school projects. The games kids produce in Scratch are relatively simplistic in nature: a maze, a platform and some kind of element where they bump into things making a noise. All good and fine. However, when restrictions are put in place, children have to be a little creatve to bend the rules. The competition meant that the the entrants could only use regular polygons and creative soundscapes to enhance gameplay. Many rules were bent. The other rule was that it was hosted on a single day (live streams from all schools below) and students got points and prizes based on speed and accuracy of the final game.


Scratch Day (back in 2011)

This is the Scratch Day animation for Year2 and Year 3 Children on the day. They will have lots of fun making this and chanting the song.

If we have time we'll put their faces into the animation rather than Mr. Squirrel and Mr. Lobster.

Hope you enjoy it too.

Part 1

The complete file is here

Making a voice over in Scratch for Year 2 Children

Part 2

Making a voice over in Scratch for Year 2 Children

Part 3

Making a voice over in Scratch for Year 2 Children

Part 4

Making a voice over in Scratch for Year 2 Children

Part  5

Making a voice over in Scratch for Year 2 Children - Part 5

Part  6

Part 7

Making a voice over in Scratch for Year 2 Children - Part 7

Part 8

Making a voice over in Scratch for Year 2 Children - Part 8

Part 9

Part 10

Making a voice over in Scratch for Year 2 Children

Part 11

Making a voice over in Scratch for Year 2 Children

6 UNITS OF SCRATCH PROGRAMMING FOR THE PRIMARY SCHOOL (YEARS 1-6)

N.B. These lessons and resources are in no way finalised were very much a 'work inprogress for everyone to edit".

Needless to say but you are welcome to download and deconstruct.

This is a series of scratch programming lessons for every year group from Year 1 to 5. Year 6 will be coming shortly but the premise of this is that I work on it to get it a bit tighter in terms of progression and pitching it just right. The thing is, if your school doesn't have a specialist teacher then it might be best to rip them apart and mix and match as you see fit.

The whole school have been working on Scratch for the end of term 2 projects and these are a range of simple turns and effects/ key presses right through to a full scaled game with several levels focusing on paltform type games.

You and anyone are free to download and edit the files, videos, and slide shows as you see fit. I would like though, to have some kind of discourse should there be improvements made to any of the files. Should there be a clearer video or anything like that. 

You can contact me via the form inthe contact link above.

As there is a creative commons license attached to this it would great if, when you use these, you post or tweet where you got them from. Thanks and enjoy the games :)

Year 1