Live Coding Music with Sonic Pi
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Aarons, Sam
Sonic Pi is a Ruby DSL & IDE for live coding music with a specific focus on education. In this demo-heavy talk, we’ll cover its history - why it was created, how it evolved and what it can do today. We’ll also take a quick technical nosedive into some of the more interesting linguistic innovations that were necessary to perform live with code. For example, we’ll see how we can rhythmically sync multiple threads, use lexical blocks to close over time, accurately sleep without drifting and deterministically manipulate global state concurrently. Expect noise!
 How do you program? Actually, because the problem is that my audience, my golden audience, people I really want to talk to, people I want to actually have some kind of impact on are not programmers. But maybe you can help me out, right? So, how do you go to parties? Have you been to parties recently? I mean, I've got three kids, so I've been for a while. But when I did go to parties, you meet people, Ty, how's it going? What's your name? Sam? I'm having a conversation. This is quite unusual for me. Normally I'm programming all day. And they ask me, what do you do? And I say, I'm a programmer. Silence. You must have had that experience. And then there's Walker. Let's do a programming party, then that's fine. But normal parties, people don't normally tend to go to a program. I don't know about you, but I find that deeply frustrating. Because there's so much beauty, so much joy in programming to share with everybody, that the inability to even start talking about it to people who don't have a direct experience with it is really frustrating. I find it deeply frustrating. So now, I lie. So if I go to a party now, people say, what do you do? I tell them musician, oh great, what do you play? And I've got this. At least we have any conversation. So what I'm trying to do, hopefully, is to give you maybe a tool that you can use to help have that conversation with other people. But actually, the real problem isn't you guys and your party experience. I think the real problem is how do we engage everybody else. And not just people I range, but people older and ideally much younger. And so I think that if we say to people, and people say, well why do you need a program? Why do we need a program? That's a really good question. In the UK, we've just started to introduce computer science in schools. And that's fabulous. But when people talk about why they need a program, the same standard things come up. Because you can get a job. And I don't know, most of you, probably all of you here have jobs because you could program. But you're all probably, like me, quite weird. You probably discover programming for its own beauty, its own joy, and you spend time in your own time just learning about these things. So you're all quite weird people. And I think that the things that we, that got us started by programming, are necessarily the same things that we should use to excite other people. And also that our motivations are the same motivations that probably other people might have to start programming. So I think to look beyond our own cultures and look beyond our own small programming communities to think about how do we engage everybody else. And so when we talk about engagement, and we talk about using how to have a good job to load a program, I think that's a bad start. How many people learn sports at school to become professional sports people? Some people, but not all, should we only teach sports to the people who are going to be the professional sports people? Of course not. There's so many beautiful and positive things to get from studying sports that are beyond just getting a job. And I think the same is programming, it's true. And just to think about an analogy of this, how many people think that reading and writing is only for business? Do we do reading and writing for other things than making rich people richer? Yes, of course we do, right? And this is a point as well, I would never talk to programmers. You've got unbelievably great skills, all of you. Why is it, not all I'm saying is all you do, but many programmers use it to make rich people richer, and this makes me a bit sad. And I think there are more things we can do, and I think engaging, broader audiences, especially young people, showing people that the code is much more than writing a business application or business website. I think that's a really good way to start. So maybe it's really, it's fine, right? And you can talk to me afterwards and tell me why you're just here. But if you do agree, then maybe we need to start having a conversation about what other things can be done with code. Where are they? What are the domains? And ideally, why are we only doing this? If it's not for making jobs? And my thing is, I think that code is an amazing new tool that humans can use to express themselves. Just like we use the technology of language to express ourselves, computing code is also a technology that also is an amazing powerful expression at all. We just haven't really learned how to use it as such yet. It's so nascent, so young. I can give you, you start with who's watched the structure and terminations of computer programs lectures. All of you need to go watch those things. They will be really cool. From the 80s, Susan and Jonathan, and they talk about the scheme. But they open it up by talking about programming being extremely new. And they talk about, in other technologies, other fields of study. And they come and they come towards geography. They said, geography came around from the Egyptian periods where they were looking at the Nile, and they were worried about where the flooding might be. So they created tools and compasses, maps, to actually figure out where they were safe to pot the lands. Do we call geography compassing? Do we call astronomy telescoping? So why do we call computing computing? Obviously we're still very, very young. So we haven't figured out what we could do with it. I think there's lots more stuff. And I think music is one of the many things you could do in computing that's really interesting, expressive, and, let's go back to what I was saying earlier, it's something we can use to engage with more and more people who aren't, programming is already. And I think that this is where it gets really exciting. So this is what I've created, it's called Sonic Pi. It's a Ruby DSL that like Rails, but it doesn't make websites, it makes stacks. And in the same way that Rails was trying to make all of the sort of hard, complicated enterprise tech stacks a bit more simple and engaging and easy to start with, this has exactly the same properties. And I developed this in schools with school kids. And I don't know if anyone's been to schools recently, but it's a different experience. They're like the teachers just trying, basically, they're trying to get the kids to this. They've got all these technologies, techniques to use, cutting the hands or counting down or putting fitness and waggling. And whatever technique they're using, at some point, hopefully, the children are still in their list, and they, the teachers, have no time to talk to the school children. So if you think about it, they've got time to maybe two or three sentences before the kids are fined at one date. What are your two or three sentences to engage kids in programming? If you were in that school, is it opening apps? I would like that, but yeah, even then, it's like, is it create a project or a workspace or a far system entity with all these things that take many lessons? You can understand. So you need to find ways to actually get them straight away. This is why Sonic Pi is also a text editor. I built my own text editor to make this experience which is also an app. So you just download it from that. You download it from PC, you have a Raspberry Pi, or it's called Sonic Pi. It's also installed by default. So you just open the application, and you get this kind of environment, and you can just type text, and you can run, and you get errors. Great. So this is my first program. Thread, death. And so I'm identifying local variable method, good and low, fine. So what can we call? Well, I've got sort of auto-completion thing going on, so call play, give me a number, and I can hear sound. Is it possible to turn that up? Good, there we are. And this point, I've spent hours, so I've only got 30 minutes left, so I'm going to go just quickly. But at this point, there's a lot of opportunities for learning to do abstractions, but numbers have its properties. You can go up and go down, which is great. What else in the world could a document go down? And can we then go use numbers to model those things? Clearly, pitch, the music goes up. So if I do something like this, give it higher notes, and if I do something like this, give it a lower note. I can also do something like this and get notes between notes, so I'm free to choose whatever note I want. And at this point, kids do this, don't they? What about this? They play this note. You're a rat, maybe you could hear that. And then this one, this is a really fun, like... So I did this talk to have some job developers, and it was in a cinema, and I did this line of code, thinking maybe you might hear a little bit, and the facts just... People are sick, right? It was amazing. So you could throw, like, the one line of code, you can get people engaged and trusted. So you can play any note at this point. Oh, yeah, you can hear that. Just the background. So there's a cinema, and you could be scared. So there we are. This is the first programme in Sonic 9. You don't have to think about objects and classes and any of that stuff. You just write it in the function, give it a parameter, press the root button, or hit the shortcut, and you get immediate outputs, and you can even visualise what's going on in the scope of it. And then at this point, you think, well, okay, I want to make a melody. So that's 60, then 65, say. And I don't know what your expectations are, but I'm probably not the same as what actually happens here. Because this is where it deviates from traditional programming languages. Although it's a Ruby DSL, there's lots of weirdness going on. It's not quite Ruby. It's mostly Ruby. Here, you might... One way to think about it is the computer's crazy fast. So it plays notes 60, then notes 65, pretty much at the same time as one after the other. But actually, I've got this insane clock system underneath. And this plays both these notes sample-active at the same time. One, 44,100 per second, in terms of accuracy. Because you need this, and I'll get onto this in a moment, when you actually move on from doing beeps and bleeps like this to performing on stage at useful venues, when you're doing music, you can care about time, you can care about sound. And so one of the challenges of something like this is not just to make something that I can go into the classroom and do this kind of thing, but also the same tool I could go on stage at the pool. I mean, that sounds ridiculous, but that's what a guitar is, right? You go to school, pick up a guitar, you start learning, but then there are an amazing guitarist professional using his same instruments. So could we imagine Sonny Pius, that sort of a code-leaving guitar, where people can both learn, pick it up very simple, but also take it to a crazy level. So if you want to make a melody with one more command... There you have it. I know, look at that. Now, I don't know about you, but that excites me to believe the members. But I think about it, right? What is Western music? It's mostly which notes played when they're played. But I have the ability to make any melody with these two bands, any bass line, any riff, any notes on, any dark punk. With these two bands, I could do that, but more importantly, you could do that. And even more importantly, your children could do that. And they do. It's so fun to watch. And so this is the thing, right? So at this point, I'd basically... I was trying to make a computer science curriculum, but I couldn't do that. So I did this. You could obviously then use your standard favourite Ruby things. So I could use this ratio. A bit of repetition going on. You could do a bit of function calling, so you can make abstractions. You can have first part, second part, you can do randomization. And that can go into detail about that. Of course, spend time talking, spend a lot of time on randomization stuff. It's not standard Ruby randomization. But the question then is, where do you go from here? You have your own programs. You have this starting point, which is making some basic views. But if I want to go on stage and load them, where have I taken this? And this is where I guess it'll be interesting. So first of all, what you do is you can change the sound. So that gives it a boring... So I can use synths. There's a bunch of built-in synths. So let's start with Ghibli. Or a little bit of piano. So you can do an obviously changing thing. And it affects the curve below it, so I can switch between that and that, and I can sort where you want it. So you can modify the sounds. Now these synthesizers, this huge synth piano, it adds documentation about it, and it has all those black things in it, which you can copy as well. They're all in options. They can be changed. Each of the synthesizers has up to 20 or 30 different controls. So the tommorow sound is fully programmable. And this is where you can start to see how much time it's pouring this out, figuring out what creating you can do, which is a design. And this is to me where it gets really exciting. But what do I mean by this? Well, let's have a look. So I have a used synth prophet. And I use it also to use root cymbals, to represent notes. And I let it go for at least 8 seconds. You can use that, right? But you can pass these options as opposed to these options. You can change the mode cluster, is it? Oh, no, that's not true. Here, actually, it's less crunchy. So you can start to mess around these things. You notice that the sounds are very controversial. So every time you press the wrong button, it breaks me to press, it's broken through. And your credit is still running. It's still being reduced to this. It's throwing more sounds at the top. So already we're dealing with a concurrency. Which is a lot of fun. And why do we need that? Well, I can explain in a moment. But before I do that, I'll say what else. So you can play to the notes. You can wait time to the notes. You can change the sounds. You can modify the sounds, and there's many more conditions to make. I really encourage you to download this. Just explore and play. But you can also play samples. So this is like the R&M break. Most famous drop break. It was just formed like a hit bar. And drum and bass. Gather, get the juggle. What do we know about that? So like NWM used the same sample. And they just played out hard to the back on top. And then you've obviously got the sound of the drum and bass sound. Yeah? And then the juggle, which is the same thing, but faster, right? So you can take the same sample. You can change the strings, right? This is a lot of fun. You can even do this, right? What do you think this is going to do? That's what that is. Brackets. Brackets are hard to read, forward, whatever. So you can play around with it. You like that? That's great. That's good. Yeah, if you like that, you can have no mix. There's so much more you can do that. I've got 30 minutes to explain to you. And I'll get to the way I can explain that. Tonight, please come to the Digital Ocean Party. And that'll be for you. So you'll be able to see that. That's the way you can take it. Right? That's looking at other things. So before I continue, it's really important just to make sure you understand. This is free. It's open source. You can download all of these systems. And if you press the help button here, that's the information button. Help button here. There's a full tutorial. And this is a full book. It's like 40,000 books. It's written and streaming. You know nothing about programming. So if you don't live like that, either you can whip through it, but you don't even silk it through. And children have taught them sounds on the code. Adults have taught them sounds on the code. So you can totally get it in the computer. I've spent a lot of time documenting everything and seeing the products on the code. It's building something which is useful, is one thing. That's a beautiful thing. But if it's not something you have to mean, just download and use. That's not too often. And maybe there, if you're a programmer, you can download both the thing or the general thing, and you can probably do some things. You put this directory and then you run this break script, and then you look at this file. If you're a programmer, you can follow a tutorial for the half an hour of doing the language or the build. But if you're my son, my son, you're not going to be able to do that. If you're a computer science teacher, you don't have to do that. I don't have enough time. So you just have to work with the computer and also have to have really good documentation. So it doesn't work as you expect. You can know if you have a why. So it's important to put it down as it's really well documented. And my promise to you, and it's a real promise, it's not just a password and password. It's not your fault, right? No one's too stupid to code. No one's too stupid to code. We are too stupid to be rushing to play this in a simple way. So if you read the tutorial, it doesn't make sense. That's a good, please tell me how I really do my best to fix this in the next person, one person at a time. So that's again, that's a good promise. But where did you do this? I've got a sample, we've got a sense. The next thing is, you might want to write like a HouchTrack, right? That's amazing. So let's leave for half a second. And I'll do this. And we've got the basement part. It's great. Within a couple of hours, children are doing this. So let's just come with this, and then let's create another one of these things. I'll show you. Let's just go. And I'll do it. Instead of doing this, let's leave for a second. And let's just call one of the other ones. Let's just call one of the other banks. There you are. And obviously, this is also, now, we're going to play the both at the same time. So let's do this, and... It's not quite what I wanted to do. Where is the base end? Now, obviously, your program is actually the key to see what's going on here. But most people don't realize this. And kids, they want this. They write this code. And all that stuff is a number of children doing exactly this and saying, seriously, why can't I get both things at the same time? And this is a bit depressing, because if you care, the answer is, you can't do this. Because you've got to wait until you're the university. Because you need this thing called concurrency in France, and we don't teach that in school. Sorry. Seriously, and now, if you don't, it's good to teach, you know what I'm saying? The kids, they want to teach. It's good to teach, you know what I'm saying? The kids, they want to do this. And it's not the same as having a lot of time. We can't mark it. It's just double-check when we can't teach that. And so this is where, you know, you just talk the hair out of it, and it's depressing. How do I fix this? And this is the beautiful thing about programming. Some programming in general. It says, we don't have to stop at this. Loops, they're green, crap. They're rubbish. They're just engine Xs and they just just wait to be used in case people press. Then they're using it. That's all they're going to do at the same time. Or if you don't have the game, you're just saying, but if you ever wanted to do two things at the same time, or if you want to change the behavior, then you just don't give you anything to talk to. So, as a programmer, that's what you do. You invent new things. So, I'm afraid this is for a live loop. So you just add live to the front, and on the code, and it gets you there. So, as a programmer, it's a live loop, and it's having a unique name. These are now no longer a multiple-separate loop. This is my band. And I've got Sarah playing drums. Sreddy playing the bass. And then when I run the code, I'll forget. So, now we've got Sarah playing the drums. We've got three other characters. There's one more thing. At this point, people have been quite happy. They've got things going at the same time. But, if I played that for more than a few minutes, it would all be... Yeah, it's not going to be something good. So, what I really want to be able to do is, I mean, this is a static programming thing. So, if you have an idea of what the build would definitely be, just write it down first. And seriously, unless you know exactly what it's going to build, then you can't do it. So, you can write the test and you can go to the frame of the music and see what the test is like. But, other than that, I'm not sure what the things are. But, here we run the code. We then run the test. In this case, we listen to music. And then, so, okay. I want to change the bass drum. It's a bit less distant. Sorry, I want to stop dancing. I'm going to change the code. So, I still have 70... There we are, I get the call. I'm going to change the code. It can be a bit less distant. Off-speed. But, that's not going to work. It's a performance. That's programming. That's totally cool. When you always tear down the code, and again, you want the test to tear it down. When you do this, it's a performance, right? But, when you perform any code, what you really want to be able to do is just change the code. Have it just automatically change the code. Just change it, right? So, this live-in thing doesn't just give you concurrency. It gives you the ability to save the code. And, just like that. This is already like a lot of fun. Just enough time to give you enough stuff to go away and have some fun. But, I want to just go in and train more to get the code done. See? Even if you want to have a square push. It's like, cool, like, you can be an UK artist. You can go on to that. I need to get a lot of stuff with the arm-end-brain things. So, let's just go back to look at that. And then, let's change time. Let's change the speed of time. So, you use PPM. Because this path-step is not all set in a live. It's actually all the beats. And, time is like the train local variables which my wife leaves. And, we're on motion time. So, you're crazy part of the stuff. You also stretch time based on the length of samples. Again, don't listen to what I'm saying. It's just crazy science. But, the effect here is that you can now basically see if you've won a limited number of samples. And, you can do that. Which is fun. But, what's rather stupid is you basically put that sample as a round file. It looks for all the trends and it's around the drum that it takes from. And, then carefully using the citizens from the all-you-are, took them out and then copy and pasted them from time to time. And, spent days doing the beats. Could we do this in a slightly better way? What we could actually do is just stick for a short amount of time to get rid of this. And, then just use onset command. Which is just an option to do some action. Here, I'm just pulling out that drum here. And, like now, you want three bits. Or, like you did. Or, after. You put a random instance, three drummers. I think that this is just like a whole-star pop genre music in all lines of code. So, that's fun. You can do that with any sample. I can take the guitar sample, do the same thing. Guitar, that's right. That's right. Pick. Pick. It's awesome. I've got a type of show. You can even pull in audio in some words. I have a guitarist today. I built the live loop. And, then started to sing in an octave. So, you can play up the bass. You can play it back. It's much more fun than this. We're taking this in the end. This is where we combine two things out of randomization. So, it's quite deterministic. It's best that we make it. So, with all the randomization stuff, it's deterministic. So, if I would do puts, rounds, three values, puts, and 5, 0, 0, 6, I'd call it again. And, if I do this twice, I'd consider getting two different values. Look, get this. We do this with all of them. Rounds, back. And, then, I can do randomization. Which actually says I'd do very useful and make music. It's now a tool. What would I do with this? So, if I did the live loop stuff. And, I've got this here. I'd do 8 times. Do. Use random seeds. So, remember that. We've got repetition. So, we've got the random seeds. We've got repetition. So, we start building melodies by changing this buildup to here and there. To make it a box. To make it a stage here. To make it a small block. So, you see now, I can just by changing that seed, get me thinking of different things. This is a really talented post. I build a structure like this, and then I make a change in the seed. And, then, I make a change in the seed. Well, where I'm going to take that, if I move this. It's on the buildup example. So, we're going to do this. To do exactly that, I've got some scale of E minor kind of type. So, I'm putting up. Oh, I do this cool thing here. Right, this is an outside. This is for two reasons. One is, this is a special kind of data structure. It's a really useful data structure that gives you a pretty good background. So, it's kind of like a list. So, it's sort of square brackets, round. But also, I want to make sure that the kids aren't scared of lists. Because lists are the most exciting programming language there is. If you have a time to do this, you can do it right away. I know that's a retro thing, but I can still do it. Anyway, listen to this. There's a riff going on, right? I didn't say thing again. I didn't say text. This is really cool. So, I'm doing this user-brand foundation system to talk out around the riff. I did the same thing at the time. I didn't get to change the scene to a license. And it doesn't go to all the craters. Look at this. Sleep from minus to T. Backwards in time. You go backwards in time to me, right? I'll leave that as an exercise for you to grow where why doesn't that fit in? But it's really cool. I've got a warm-in lens. I want to show you one more thing. So, you, if you have a guitar and you have an audio pedal, as an audio card in your system, you just read as if you've found some questions. You call it a fool. And you run the code. And you pull the audio in for your guitar. You now get on with the guitar. I haven't shown you this, but you can also do this thing where you say with effects, reverb, or whatever. Wrap that around. And now you've got your guitar with you. And you add another one. Distortion, say. And now you've got your guitar passing the distortion, passing the reverb. You can feel that we've changed the effect of those things. I can show you very quickly, but for 30 seconds, let's just do it in a short time. But there's one more thing you can do. I'll just MIDI. So I can call MIDI E1. You can't see that. I might have made it by a single. Just hit and wait for it. It's a little mode. It just flashes. That's no use for you. I'll just put this in here. See for a short amount of time. I'm flashing the lights. But if I let it say live, audio, you can now hear this change the amplitude. So now what I'm doing here is I'm using Ruby to trigger my filter to the side. So you're practically in time. It extends the MIDI message to the device. The device then put it into my audio card. And then the live audio bring it back to the side. Which then you can use to MIDI to base the code. That all sounds complicated, but it's fine by the code. I have the reverb here. Actually, let's just use a cross. You can hear that. Is it the cross you're wearing? Do something here, then. It's the light. And then you can use a ring here. Put it on. E3, into the boat. It's a 5% I've been playing for a while now. And I can see the light in it. It's been pretty bright. So it's a good touch. I want things to be at the same time. So if I see that it's a clean very sample bass drum and I can finish it off by adding a kick drum. So please, see if it's a good approach. I can hear some clouds. Off we go. We're out of time. Thank you.
 How do you program?  Actually, because the problem is that my audience, my golden audience, people I really want to  talk to, people I want to actually have some kind of impact on are not programmers.  But maybe you can help me out, right?  So, how do you go to parties?  Have you been to parties recently?  I mean, I've got three kids, so I've been for a while.  But when I did go to parties, you meet people, Ty, how's it going?  What's your name? Sam?  I'm having a conversation.  This is quite unusual for me.  Normally I'm programming all day.  And they ask me, what do you do?  And I say, I'm a programmer.  Silence.  You must have had that experience.  And then there's Walker.  Let's do a programming party, then that's fine.  But normal parties, people don't normally tend to go to a program.  I don't know about you, but I find that deeply frustrating.  Because there's so much beauty, so much joy in programming to share with everybody,  that the inability to even start talking about it to people who don't have a direct  experience with it is really frustrating.  I find it deeply frustrating.  So now, I lie.  So if I go to a party now, people say, what do you do?  I tell them musician, oh great, what do you play?  And I've got this.  At least we have any conversation.  So what I'm trying to do, hopefully, is to give you maybe a tool that you can use  to help have that conversation with other people.  But actually, the real problem isn't you guys and your party experience.  I think the real problem is how do we engage everybody else.  And not just people I range, but people older and ideally much younger.  And so I think that if we say to people, and people say, well why do you need a program?  Why do we need a program?  That's a really good question.  In the UK, we've just started to introduce computer science in schools.  And that's fabulous.  But when people talk about why they need a program, the same standard things come up.  Because you can get a job.  And I don't know, most of you, probably all of you here have jobs because you could program.  But you're all probably, like me, quite weird.  You probably discover programming for its own beauty, its own joy, and you spend time in your own time  just learning about these things.  So you're all quite weird people.  And I think that the things that we, that got us started by programming, are necessarily the same things  that we should use to excite other people.  And also that our motivations are the same motivations that probably other people might have to start programming.  So I think to look beyond our own cultures and look beyond our own small programming communities  to think about how do we engage everybody else.  And so when we talk about engagement, and we talk about using how to have a good job to load a program,  I think that's a bad start.  How many people learn sports at school to become professional sports people?  Some people, but not all, should we only teach sports to the people who are going to be the professional sports people?  Of course not.  There's so many beautiful and positive things to get from studying sports that are beyond just getting a job.  And I think the same is programming, it's true.  And just to think about an analogy of this, how many people think that reading and writing is only for business?  Do we do reading and writing for other things than making rich people richer?  Yes, of course we do, right?  And this is a point as well, I would never talk to programmers.  You've got unbelievably great skills, all of you.  Why is it, not all I'm saying is all you do, but many programmers use it to make rich people richer,  and this makes me a bit sad.  And I think there are more things we can do, and I think engaging, broader audiences,  especially young people, showing people that the code is much more than writing a business application or business website.  I think that's a really good way to start.  So maybe it's really, it's fine, right?  And you can talk to me afterwards and tell me why you're just here.  But if you do agree, then maybe we need to start having a conversation about what other things can be done with code.  Where are they? What are the domains?  And ideally, why are we only doing this?  If it's not for making jobs?  And my thing is, I think that code is an amazing new tool that humans can use to express themselves.  Just like we use the technology of language to express ourselves,  computing code is also a technology that also is an amazing powerful expression at all.  We just haven't really learned how to use it as such yet.  It's so nascent, so young.  I can give you, you start with who's watched the structure and terminations of computer programs lectures.  All of you need to go watch those things.  They will be really cool.  From the 80s, Susan and Jonathan, and they talk about the scheme.  But they open it up by talking about programming being extremely new.  And they talk about, in other technologies, other fields of study.  And they come and they come towards geography.  They said, geography came around from the Egyptian periods where they were looking at the Nile,  and they were worried about where the flooding might be.  So they created tools and compasses, maps, to actually figure out where they were safe to pot the lands.  Do we call geography compassing?  Do we call astronomy telescoping?  So why do we call computing computing?  Obviously we're still very, very young.  So we haven't figured out what we could do with it.  I think there's lots more stuff.  And I think music is one of the many things you could do in computing that's really interesting,  expressive, and, let's go back to what I was saying earlier,  it's something we can use to engage with more and more people who aren't,  programming is already.  And I think that this is where it gets really exciting.  So this is what I've created, it's called Sonic Pi.  It's a Ruby DSL that like Rails, but it doesn't make websites, it makes stacks.  And in the same way that Rails was trying to make all of the sort of hard,  complicated enterprise tech stacks a bit more simple and engaging and easy to start with,  this has exactly the same properties.  And I developed this in schools with school kids.  And I don't know if anyone's been to schools recently, but it's a different experience.  They're like the teachers just trying, basically,  they're trying to get the kids to this.  They've got all these technologies, techniques to use,  cutting the hands or counting down or putting fitness and waggling.  And whatever technique they're using, at some point, hopefully,  the children are still in their list,  and they, the teachers, have no time to talk to the school children.  So if you think about it, they've got time to maybe two or three sentences  before the kids are fined at one date.  What are your two or three sentences to engage kids in programming?  If you were in that school, is it opening apps?  I would like that, but yeah, even then, it's like,  is it create a project or a workspace or a far system entity  with all these things that take many lessons?  You can understand.  So you need to find ways to actually get them straight away.  This is why Sonic Pi is also a text editor.  I built my own text editor to make this experience which is also an app.  So you just download it from that.  You download it from PC, you have a Raspberry Pi,  or it's called Sonic Pi.  It's also installed by default.  So you just open the application, and you get this kind of environment,  and you can just type text, and you can run, and you get errors.  Great. So this is my first program.  Thread, death.  And so I'm identifying local variable method, good and low, fine.  So what can we call?  Well, I've got sort of auto-completion thing going on, so call play,  give me a number, and I can hear sound.  Is it possible to turn that up?  Good, there we are.  And this point, I've spent hours, so I've only got 30 minutes left,  so I'm going to go just quickly.  But at this point, there's a lot of opportunities for learning  to do abstractions, but numbers have its properties.  You can go up and go down, which is great.  What else in the world could a document go down?  And can we then go use numbers to model those things?  Clearly, pitch, the music goes up.  So if I do something like this, give it higher notes,  and if I do something like this, give it a lower note.  I can also do something like this and get notes between notes,  so I'm free to choose whatever note I want.  And at this point, kids do this, don't they?  What about this? They play this note.  You're a rat, maybe you could hear that.  And then this one, this is a really fun, like...  So I did this talk to have some job developers,  and it was in a cinema, and I did this line of code,  thinking maybe you might hear a little bit,  and the facts just...  People are sick, right? It was amazing.  So you could throw, like, the one line of code,  you can get people engaged and trusted.  So you can play any note at this point.  Oh, yeah, you can hear that. Just the background.  So there's a cinema, and you could be scared.  So there we are. This is the first programme in Sonic 9.  You don't have to think about objects and classes and any of that stuff.  You just write it in the function,  give it a parameter, press the root button, or hit the shortcut,  and you get immediate outputs,  and you can even visualise what's going on in the scope of it.  And then at this point, you think,  well, okay, I want to make a melody.  So that's 60, then 65, say.  And I don't know what your expectations are,  but I'm probably not the same as what actually happens here.  Because this is where it deviates from traditional programming languages.  Although it's a Ruby DSL, there's lots of weirdness going on.  It's not quite Ruby. It's mostly Ruby.  Here, you might...  One way to think about it is the computer's crazy fast.  So it plays notes 60, then notes 65,  pretty much at the same time as one after the other.  But actually, I've got this insane clock system underneath.  And this plays both these notes sample-active at the same time.  One, 44,100 per second, in terms of accuracy.  Because you need this, and I'll get onto this in a moment,  when you actually move on from doing beeps and bleeps like this  to performing on stage at useful venues,  when you're doing music, you can care about time, you can care about sound.  And so one of the challenges of something like this  is not just to make something that I can go into the classroom  and do this kind of thing, but also the same tool I could go on stage at the pool.  I mean, that sounds ridiculous, but that's what a guitar is, right?  You go to school, pick up a guitar, you start learning,  but then there are an amazing guitarist professional  using his same instruments.  So could we imagine Sonny Pius, that sort of a code-leaving guitar,  where people can both learn, pick it up very simple,  but also take it to a crazy level.  So if you want to make a melody with one more command...  There you have it.  I know, look at that.  Now, I don't know about you, but that excites me to believe the members.  But I think about it, right?  What is Western music?  It's mostly which notes played when they're played.  But I have the ability to make any melody with these two bands,  any bass line, any riff, any notes on, any dark punk.  With these two bands, I could do that,  but more importantly, you could do that.  And even more importantly, your children could do that.  And they do. It's so fun to watch.  And so this is the thing, right?  So at this point, I'd basically... I was trying to make a computer science curriculum,  but I couldn't do that.  So I did this. You could obviously then use your standard favourite Ruby things.  So I could use this ratio.  A bit of repetition going on.  You could do a bit of function calling,  so you can make abstractions.  You can have first part, second part,  you can do randomization.  And that can go into detail about that.  Of course, spend time talking,  spend a lot of time on randomization stuff.  It's not standard Ruby randomization.  But the question then is, where do you go from here?  You have your own programs.  You have this starting point, which is making some basic views.  But if I want to go on stage and load them,  where have I taken this?  And this is where I guess it'll be interesting.  So first of all, what you do is you can change the sound.  So that gives it a boring...  So I can use synths. There's a bunch of built-in synths.  So let's start with Ghibli.  Or a little bit of piano.  So you can do an obviously changing thing.  And it affects the curve below it,  so I can switch between that and that,  and I can sort where you want it.  So you can modify the sounds.  Now these synthesizers, this huge synth piano,  it adds documentation about it,  and it has all those black things in it,  which you can copy as well.  They're all in options.  They can be changed.  Each of the synthesizers has up to 20 or 30 different controls.  So the tommorow sound is fully programmable.  And this is where you can start to see  how much time it's pouring this out,  figuring out what creating you can do,  which is a design.  And this is to me where it gets really exciting.  But what do I mean by this? Well, let's have a look.  So I have a used synth prophet.  And I use it also to use root cymbals,  to represent notes.  And I let it go for at least 8 seconds.  You can use that, right?  But you can pass these options as opposed to these options.  You can change the mode cluster, is it?  Oh, no, that's not true.  Here, actually, it's less crunchy.  So you can start to mess around these things.  You notice that the sounds are very controversial.  So every time you press the wrong button,  it breaks me to press, it's broken through.  And your credit is still running.  It's still being reduced to this.  It's throwing more sounds at the top.  So already we're dealing with a concurrency.  Which is a lot of fun.  And why do we need that? Well, I can explain in a moment.  But before I do that, I'll say what else.  So you can play to the notes.  You can wait time to the notes.  You can change the sounds.  You can modify the sounds, and there's many more conditions to make.  I really encourage you to download this.  Just explore and play.  But you can also play samples.  So this is like the R&M break.  Most famous drop break.  It was just formed like a hit bar.  And drum and bass.  Gather, get the juggle.  What do we know about that?  So like NWM used the same sample.  And they just played out hard to the back on top.  And then you've obviously got the  sound of the drum and bass sound.  Yeah?  And then the juggle, which is the same thing,  but faster, right?  So you can take the same sample.  You can change the strings, right?  This is a lot of fun.  You can even do this, right?  What do you think this is going to do?  That's what that is.  Brackets.  Brackets are hard to read, forward, whatever.  So you can play around with it.  You like that?  That's great. That's good.  Yeah, if you like that, you can have no mix.  There's so much more you can do that.  I've got 30 minutes to explain to you.  And I'll get to the way I can explain that.  Tonight, please come to the Digital Ocean Party.  And that'll be for you.  So you'll be able to see that.  That's the way you can take it.  Right?  That's looking at other things.  So before I continue, it's really important  just to make sure you understand.  This is free. It's open source.  You can download all of these systems.  And if you press the help button here,  that's the information button.  Help button here.  There's a full tutorial.  And this is a full book.  It's like 40,000 books.  It's written and streaming.  You know nothing about programming.  So if you don't live like that,  either you can whip through it,  but you don't even silk it through.  And children have taught them sounds on the code.  Adults have taught them sounds on the code.  So you can totally get it in the computer.  I've spent a lot of time documenting everything  and seeing the products on the code.  It's building something which is useful,  is one thing.  That's a beautiful thing.  But if it's not something you have to mean,  just download and use.  That's not too often.  And maybe there, if you're a programmer,  you can download both the thing  or the general thing,  and you can probably do some things.  You put this directory and then you run this  break script, and then you look at this file.  If you're a programmer, you can follow a tutorial  for the half an hour of doing the language  or the build.  But if you're my son,  my son, you're not going to be able to do that.  If you're a computer science teacher,  you don't have to do that.  I don't have enough time.  So you just have to work with the computer  and also have to have really good documentation.  So it doesn't work as you expect.  You can know if you have a why.  So it's important to put it down as it's really well documented.  And my promise to you,  and it's a real promise,  it's not just a password and password.  It's not your fault, right?  No one's too stupid to code.  No one's too stupid to code.  We are too stupid to be rushing to play this in a simple way.  So if you read the tutorial, it doesn't make sense.  That's a good, please tell me how I really do my best  to fix this in the next person,  one person at a time.  So that's again, that's a good promise.  But where did you do this?  I've got a sample, we've got a sense.  The next thing is, you might want to write  like a HouchTrack, right?  That's amazing.  So let's leave for half a second.  And I'll do this.  And we've got the basement part.  It's great.  Within a couple of hours, children are doing this.  So let's just come with this,  and then let's create another one of these things.  I'll show you.  Let's just go.  And I'll do it.  Instead of doing this, let's leave for a second.  And let's just call one of the other ones.  Let's just call one of the other banks.  There you are.  And obviously, this is also, now,  we're going to play the both at the same time.  So let's do this, and...  It's not quite what I wanted to do.  Where is the base end?  Now, obviously, your program is actually  the key to see what's going on here.  But most people don't realize this.  And kids, they want this.  They write this code.  And all that stuff is a number of children  doing exactly this and saying,  seriously, why can't I get both things at the same time?  And this is a bit depressing,  because if you care,  the answer is, you can't do this.  Because you've got to wait until you're the university.  Because you need this thing  called concurrency in France,  and we don't teach that in school.  Sorry.  Seriously, and now, if you don't,  it's good to teach, you know what I'm saying?  The kids, they want to teach.  It's good to teach, you know what I'm saying?  The kids, they want to do this.  And it's not the same as having a lot of time.  We can't mark it.  It's just double-check when we can't teach that.  And so this is where,  you know, you just talk the hair out of it,  and it's depressing.  How do I fix this?  And this is the beautiful thing about programming.  Some programming in general.  It says, we don't have to stop at this.  Loops, they're green, crap.  They're rubbish.  They're just engine Xs and they just  just wait to be used in case people press.  Then they're using it.  That's all they're going to do at the same time.  Or if you don't have the game, you're just saying,  but if you ever wanted to do two things at the same time,  or if you want to change the behavior,  then you just don't give you anything to talk to.  So, as a programmer,  that's what you do.  You invent new things.  So, I'm afraid this is for a live loop.  So you just add live to the front,  and on the code, and it gets you there.  So, as a programmer,  it's a live loop, and it's having a unique name.  These are now no longer  a multiple-separate loop.  This is my band.  And I've got  Sarah playing drums.  Sreddy playing the bass.  And then when I run the code,  I'll forget.  So, now we've got Sarah playing the drums.  We've got three other characters.  There's one more thing.  At this point,  people have been quite happy.  They've got things going at the same time.  But, if I played that  for more than a few minutes,  it would all be...  Yeah, it's not going to be something good.  So, what I really want to be able to do  is, I mean, this is a static programming thing.  So, if you have an idea of what the build  would definitely be,  just write it down first.  And seriously,  unless you know exactly what it's going to build,  then you can't do it.  So, you can write the test  and you can go to the frame of the music  and see what the test is like.  But, other than that,  I'm not sure what the things are.  But, here we run the code.  We then run the test.  In this case, we listen to music.  And then, so, okay.  I want to change the bass drum.  It's a bit less distant.  Sorry, I want to stop dancing.  I'm going to change the code.  So, I still have 70...  There we are, I get the call.  I'm going to change the code.  It can be a bit less distant.  Off-speed.  But, that's not going to work. It's a performance.  That's programming. That's totally cool.  When you always tear down the code,  and again, you want the test to tear it down.  When you do this, it's a performance, right?  But, when you perform any code,  what you really want to be able to do  is just change the code.  Have it just automatically  change the code.  Just change it, right?  So, this live-in thing doesn't just give you concurrency.  It gives you the ability to save the code.  And, just like that.  This is already like a lot of fun.  Just enough time to give you enough stuff to go away and have some fun.  But, I want to just go in  and train more to get the code done.  See?  Even if you want to have a square push.  It's like, cool, like, you can be an UK artist.  You can go on to that.  I need to get a lot of stuff with the arm-end-brain things.  So, let's just go back to look at that.  And then,  let's change time.  Let's change the speed of time.  So, you use PPM.  Because this path-step is not all set in a live.  It's actually all the beats.  And, time is like the train local variables  which my wife leaves.  And, we're on motion time.  So, you're crazy part of the stuff.  You also stretch time based on the length of samples.  Again, don't listen to what I'm saying.  It's just crazy science.  But, the effect here is that you can now basically  see if you've won a limited number of samples.  And, you can do that.  Which is fun.  But, what's rather stupid is  you basically put that sample as a round file.  It looks for all the trends  and it's around the drum that it takes from.  And, then carefully using the citizens  from the all-you-are,  took them out and then copy and pasted them  from time to time.  And, spent days doing the beats.  Could we do this in a slightly better way?  What we could actually do is just  stick for a short amount of time  to get rid of this.  And, then just use onset command.  Which is just an option to do some action.  Here, I'm just pulling out that drum here.  And, like now,  you want three bits.  Or, like you did.  Or, after.  You put a random instance, three drummers.  I think that this is just like a  whole-star pop genre music  in all lines of code.  So, that's fun.  You can do that with any sample.  I can take the guitar sample,  do the same thing.  Guitar,  that's right.  That's right.  Pick.  Pick.  It's awesome.  I've got a type of show.  You can even pull in audio  in some words.  I have a guitarist today.  I built the live loop.  And, then started to sing in an octave.  So, you can play up the bass.  You can play it back.  It's much more fun than this.  We're taking this in the end.  This is where we combine  two things out of randomization.  So, it's quite deterministic.  It's best that we make it.  So, with all the randomization stuff,  it's deterministic.  So, if I would do  puts, rounds,  three values,  puts, and 5, 0, 0, 6,  I'd call it again.  And, if I do this twice,  I'd consider getting two different values.  Look, get this.  We do this with all of them.  Rounds, back.  And, then, I can do randomization.  Which actually says I'd do very useful  and make music.  It's now a tool.  What would I do with this?  So, if I did the live loop stuff.  And, I've got this here.  I'd do 8 times.  Do.  Use random seeds.  So, remember that.  We've got repetition.  So, we've got the random seeds.  We've got repetition.  So, we start building melodies  by changing this buildup to here and there.  To make it a box.  To make it a stage here.  To make it a small block.  So, you see now, I can just by changing that seed,  get me thinking of different things.  This is a really talented post.  I build a structure like this,  and then I make a change in the seed.  And, then, I make a change in the seed.  Well, where I'm going to take that,  if I move this.  It's on the buildup example.  So, we're going to do this.  To do exactly that, I've got some scale  of E minor kind of type.  So, I'm putting up.  Oh, I do this cool thing here.  Right, this is an outside.  This is for two reasons.  One is, this is a special kind of data structure.  It's a really useful data structure  that gives you a pretty good background.  So, it's kind of like a list.  So, it's sort of square brackets, round.  But also, I want to make sure  that the kids aren't scared of lists.  Because lists are the most exciting  programming language there is.  If you have a time to do this,  you can do it right away.  I know that's a retro thing, but I can still do it.  Anyway, listen to this.  There's a riff going on, right?  I didn't say thing again.  I didn't say text.  This is really cool.  So, I'm doing this user-brand foundation system  to talk out around the riff.  I did the same thing at the time.  I didn't get to change the scene to a license.  And it doesn't go to all the craters.  Look at this. Sleep from minus to T.  Backwards in time.  You go backwards in time to me, right?  I'll leave that as an exercise for you to grow  where why doesn't that fit in?  But it's really cool.  I've got a warm-in lens. I want to show you one more thing.  So, you, if you have a guitar  and you have an audio pedal,  as an audio card in your system,  you just read as if you've found some questions.  You call it a fool.  And you run the code.  And you pull the audio in for your guitar.  You now get on with the guitar.  I haven't shown you this, but you can also do  this thing where you say  with effects, reverb, or whatever.  Wrap that around.  And now you've got your guitar with you.  And you add another one.  Distortion, say.  And now you've got your guitar  passing the distortion, passing the reverb.  You can feel that we've changed the effect of those things.  I can show you very quickly,  but for 30 seconds, let's just do it  in a short time.  But there's one more thing you can do.  I'll just MIDI.  So I can call MIDI E1.  You can't see that. I might have made it by a single.  Just hit and wait for it.  It's a little mode.  It just flashes.  That's no use for you.  I'll just put this in here.  See for a short amount of time.  I'm flashing the lights.  But if I let it say live,  audio,  you can now hear this  change the amplitude.  So now what I'm doing here  is I'm using Ruby to trigger  my filter to the side.  So you're practically in time.  It extends the MIDI message to the device.  The device then put it into my audio card.  And then the live audio bring it back to the side.  Which then you can use to MIDI to base the code.  That all sounds complicated, but it's fine by the code.  I have the reverb here.  Actually, let's just use a cross.  You can hear that.  Is it the cross you're wearing?  Do something here, then.  It's the light.  And then you can use a ring here.  Put it on.  E3, into the boat.  It's a 5%  I've been playing for a while now.  And I can see the light in it.  It's been pretty bright.  So it's a good touch.  I want things to be at the same time.  So if I see that it's a clean  very sample bass drum  and I can finish it off by adding a kick drum.  So please,  see if it's a good approach.  I can hear some clouds.  Off we go.  We're out of time.  Thank you.
Live_Coding_Music_with_Sonic_Pi_0_47.png Live_Coding_Music_with_Sonic_Pi_48_131.png Live_Coding_Music_with_Sonic_Pi_132_11315.png Live_Coding_Music_with_Sonic_Pi_11316_11663.png Live_Coding_Music_with_Sonic_Pi_11664_12083.png Live_Coding_Music_with_Sonic_Pi_12084_13043.png Live_Coding_Music_with_Sonic_Pi_13044_13595.png Live_Coding_Music_with_Sonic_Pi_13596_14543.png Live_Coding_Music_with_Sonic_Pi_14544_14663.png Live_Coding_Music_with_Sonic_Pi_14664_16307.png Live_Coding_Music_with_Sonic_Pi_16308_17183.png Live_Coding_Music_with_Sonic_Pi_17184_18215.png Live_Coding_Music_with_Sonic_Pi_18216_18275.png Live_Coding_Music_with_Sonic_Pi_18276_18647.png Live_Coding_Music_with_Sonic_Pi_18648_21287.png Live_Coding_Music_with_Sonic_Pi_21288_23279.png Live_Coding_Music_with_Sonic_Pi_23280_23339.png Live_Coding_Music_with_Sonic_Pi_23340_26159.png Live_Coding_Music_with_Sonic_Pi_26160_26771.png Live_Coding_Music_with_Sonic_Pi_26772_29471.png Live_Coding_Music_with_Sonic_Pi_29472_43367.png Live_Coding_Music_with_Sonic_Pi_43368_45083.png Live_Coding_Music_with_Sonic_Pi_45084_45251.png Live_Coding_Music_with_Sonic_Pi_45252_45277.png