This summer we did a whole show on computer programming in front of a live audience in Cambridge. Other than being more than a little stressful for just about everyone involved, it was also huge fun. It was particularly great when Kat got to explore her musical interests with Sam Aaron, the man behind Soni Pi; a programme that can be used to code music.
Sam - I mean, we've just heard about how important it is to get people to code. In my opinion, it's not just about getting people to be professional programmers but also use code to express themselves. In the same way we write and read, we write diaries, we write poems, we could also use code in the same way to express ourselves in really exciting new ways. And so, Sonic Pi is software which allows you to write code, basic words, press a special magic button and hear amazing sounds.
Kat - As a musician, I'm really excited by this and I know a lot of computer musicians, they're using programs like Ableton and things like that that cost hundreds and hundreds of pounds to make music and often, I play with them. So, how is this different? Why did you make this? I mean, I downloaded it earlier for free.
Sam - Absolutely. So, you heard Eben earlier talking about lowering the barrier to entry. I mean, part of the deal about the Raspberry Pi, it's extremely affordable. And so, the software I've written is also extremely affordable. It's entirely free. And so, the idea is, if you don't have any money, it doesn't matter. You can use the software. Also, it runs on all computers. It runs on a Raspberry Pi, but also runs on a Windows or a Mac. So, if you already have a computer, use that, but if you don't, then get one of these Raspberry Pis because they're really wicked fun.
Kat - Now, is this just a way of basically tricking kids and tricking even adults into doing a bit of coding or is it actually genuinely a musical tool? Could you make musical compositions that would stand up on this?
Sam - I mean, is writing poetry tricking kids into grammar? Right? Clearly not, right? So, this is not tricking people into making code.
Kat - Maybe a little bit.
Sam - Code is an amazing expressive form and it's just shown people that potential. And yes, Sonic Pi is a new musical instrument that you can use today to perform in nightclubs and venues to make music and it's a lot of fun.
Kat - Right. Well, enough talking about it. Let's see it. So, we've got a computer screen up. We got a little Raspberry Pi sort of naked circuit boards sitting there. And on the screen, I can see just some lines and lines, and lines of code. They look like words, sleep, bit, crusher, soul, sustain. What is this?
Sam - Yes. So, I'm showing you here one of the examples. So, when you start up Sonic Pi, you have a help system. The help system contains a bunch of examples. This is one of the pre-canned examples just to show you what you can do with the system. So, shall we hear it?
Kat - Yeah. Let's play something.
Sam - Let's give it a go.
Sam - So we're getting some of that dance music. This is all generated in real time on the Raspberry Pi using lots of fancy mathematics to make the sounds. The synthesisers are all real time generated. So, this little Raspberry Pi is an extremely capable machine, it's able to do this. So, I use the same system to perform on stage at night clubs.
Kat - That is incredible. It's kind of pumping. We're all like, "Come on. Hands on the air people!"
Sam - They're going wild.
Kat - Reach for the lasers.
Sam - Calm down people! Calm down!
Kat - Never thought I'd say on the radio. So, what have we got going on here? So it's making drums and synths and all sorts of things.
Sam - Absolutely. So, shall I show you how to get started?
Kat - Okay, let's have a go. Let's make a tune, banging tune.
Sam - So, the first word to learn in Sonic Pi is the word play because we're playing a note, but also playing. We're having fun, right? So I write the word 'play' and then I choose a number to play. Let's choose 80. We hear a little beep. That's it. That's your first programme. How easy is that to write?
Kat - Yeah, that was, even I, I think. As the kind of notes, a paper musician could do that
Sam - So, once you write your first programme, the next thing is how to change these things. So now, we can change this number 80 because numbers can go up and down. Notes can also go up and down. So, if I chose a lower number like 60, you get a low note, right?
Kat - Yes. It's much lower, okay.
Sam - If I'd said 90 I'd get a higher note, right? So, done. So now, we can play all the notes we can imagine then we need a way to make a melody. So, if I play note 60 then I need to have a way of saying, "Well, wait for a bit. Let's sleep for a second and then play another note. Play 65, say and then let's sleep for half a second and play 72." So this way, we're able to play different notes and make a little melody, right?
Kat - I like that.
Sam - At this point, with these two commands, 'play' and 'sleep', we can play pretty much all western notation. So, if you take any Bach, or Mozart, or Beethoven with two commands, you can reproduce those things. It's not slamming beats yet, but we've already done classical music.
Kat - Okay. Can we make it a bit more funky? Can we get it kind of going?
Sam - So, the next thing we do is once you got playing, we need some programming structures to help us to manipulate this stuff. So, I've invented something called the live loop. A live loop is just a thing which can loop. So, let's play a sample loop Amen which is Amen Break.
Kat - Is that the Amen Break? Very well known.
Sam - Sleep for the one length of that sample.
Kat - That's what drum and bass is made of fans.
Sam - And now we've got this loop going around, but whilst it's playing, I can now change the rate, say to be half, and now, we got it half and I can bring it back up to 1 again. I'm just changing one number here. Let's go reverse, minus one. Let's add some bass and then let's add some slicer to slice the volume in and out. So, I just choose where to start the slicer, where to end it. And so, just by adding a simple piece of code on top of another simple piece of code.
Kat - I think we've got a number one hit here already. I mean, it's fairly boring and repetitive, but there you go.
Sam - That's what dance music is.
Kat - Exactly.
Sam - You have to be able to dance to it. So, you say it's fairly boring and repetitive, but we've only got 9 lines of code here.
Kat - How long would it take someone like me to actually make a tune, a kind of a song with a beginning, a middle, an end, some structure?
Sam - It depends on how complicated the tune would be. I went to a school in New Castle, Benton Park Primary School where they have a Sonic Pi Orchestra and they've been teaching themselves, the kids have been teaching themselves. And the primary school kids have been teaching their local teachers how to do the stuff. This is 10-year olds. Okay, so you just need some time and some creativity and some fun and some patience. In a few days, you can get the basics down and then depending on how much time you want to put into it, in the same if you want to learn a violin, how much practice you put into it, you can get to do some wicked things pretty quickly.
Kat - Is there transferable skills from learning to write these kind of stuff?
Sam - Absolutely! This system is written in the same language that Twitter was originally written in.
Kat - And that's boring and repetitive.
Sam - Using exactly the same structures as Twitter was originally written in. All the UK government work is all written in the same language. This language called Ruby.
Kat - Also boring and repetitive.
Sam - Absolutely transferable. But code is not boring. It can be repetitive, but the computer does the repetition, not you.
Kat - So, we're going to have a little bit of time now. I want you to show me what you can do because you play in night clubs, don't you? You've played this stuff out and people do dance to it.
Sam - Absolutely, yes. So, let's choose one of the examples in a way to start. So, this is an example called ("Tilburg")(music playing). So, this is going and so, I've got my basic tune around. It's very hard to play that. I can't fully hear myself. Normally, these beats are bashing out. So, I can turn the randomization off.
Kat - I do like my house music and this sounds pretty good.
Sam - It's nice, yeah. I start and stop it. Sorry, I made a mistake. So, you can make mistakes all the time. It's totally fine. So turn off bits, turn of the bass drum and then get the rhythm going again, and then drop a kick in again. Now, off we go. So, all I'm doing there is editing some very simple lines to make that happen.