 Welcome to my talk, I'm Julian Chill, I'm British, I like Tweed as you can tell by my three-piece Tweed suit. You can get one of these too if you just come to the UK, it's great. So I live in a small little town called Bath and just so you know it's not London, I don't live in London, I live in Bath. It's called Bath because it's got a giant bath and yes we also do have baths and showers in our homes. I work for a small, as you can see I like clothes, I work for a small clothing company called Red Hat. We do some open source software, you may have heard of us. At Red Hat I work on a team called ManageIQ where we manage clouds. Again being British we've got lots of clouds so I'm good at managing them and if you'd like to come and manage clouds and get a sweet red hat then come speak to me afterwards and we can try and hire you and you do get a red hat working at Red Hat, it's really cool. So this talk is called It's More Fun to Compute which those of you who were born like over 30 years ago will know the band Kraftwerk, a German synthesizer band and this is a track taken from their album Computer Vault. So what we're going to talk about today are synths. Not these cool synths from Fallout 4, but these kind of synths, oh there's some feedback, is that me or is that you? So these are analog synthesizers. So to get started with analog synthesizers, oh yeah first of all I should mention on stage here I've got a few of my synthesizers, I've got my Arturia Mini Brute, I've got a Korg Volca Keys, so this is a monophonic synthesizer, this is a polyphonic synthesizer so it's got more than one synth, which makes it pretty cool. This is a Volca Beats, it's a drum machine and unfortunately I didn't bring these today, these are little bits which are these little magnetic connectors that you can connect up and build all sorts of cool circuits. They teamed up with Korg to make the Korg synth kit so you can give it to your kids, they can plug them in and they can make such annoying noises, it's so cool. So if you don't have kids buy it for your friends for Christmas, they'll love you. Right, so to get started with synthesizers we need to learn about oscillators and I don't know much about oscillators except that they oscillate and so they basically just go around many many times oscillating and then when we take the output of the oscillator that makes stuff happen and you can look on Wikipedia and it will tell you exactly what oscillators are but they're just like these little analog components that ended up being so so amazing that a chap called Moog put lots of them into a machine like almost as big as this room and made sweet sweet music. So the things that these oscillators create are called waves and it can create a few different types of waves so as a software engineer you may know about square waves you know like on and off, that's sort of one type of wave. We can also create sine waves, these are more like as we think about analog type things where there's multiple variables between the sort of the up and the down. Synthesizers can also create triangle waves which I think kind of look pretty cool. We can also create sawtooth or as I think it really should be called no kogori waves and the cool thing with saw waves is they can go one direction and they can also go the other direction. I just switched the picture but isn't that cool right? Like depending on which way you do it we can hear some of these in a moment. The sound will sound different depending on which way the saw is facing and of course there's the dearly beloved Google wave. May it rest in peace. And the final sound that we can make is noise. So back in the day before Netflix and Hulu we used to watch this thing called television where we'd receive radio waves from the sky and in between channels or when they turn the channels off this is what you would get. This is noise, it's just everything, all of the waves of just everything and some people believe it originates from the Big Bang and we can use this noise to make kind of cool music. So let's have a little demo. So I've got a little app here which I'm running in something called Ruby Processing which is an audio, sorry, which is a graphics library that you can use to create. Hang on a second. See this should be coming in from input. Everything's trying to work here in a second. So as you can hear, as I talk we're getting the waves on the top and then at the bottom is the frequency, so the higher the frequencies the more on the one side of the screen the lower the more it is on the other side. This should be coming in via this. Let's just change this over. So if we play a triangle wave, the demo guards against me, so unfortunately it seems to be picking up the computer microphone as opposed to, let's try again, it could be, everyone be quiet, okay let's try that, don't use, okay let's try again, whoa, sorry, right. So you can see it's kind of, actually this is meant to be the sawtooth and then if we change it to a square wave, pardon, I need that, I mean maybe GarageBand is getting in the way, go away GarageBand, ah thanks Andrew, right, so then this is a triangle wave, why do you hate me today, ah it's too low that's why, ah there we go, sorry, I apologize, yes I knocked the cable on my device, that's why, okay quickly, photo booth, right, now you can see what I'm doing, I don't like computers, they don't like me, right, so now you can kind of see, pick this up, right, let's try that again, so let's play a sawtooth, square wave, now this is just a little bit of Ruby code that's reading this, so you can see it's still kind of more analog looking, but you know if we added more processing power and took more samples we could probably get a finer grain square, so if Tom and Charlie around, make JRuby better, so this works better, then the triangle wave, and the cool thing is, if we just move this out, the cool thing with waves is that the, if any of you went to Joan and Salk earlier, you'll already know all this, this is amazing, the higher the frequency, the more stuff there is in a small amount of space, so if we go all the way down to the very bottom octave, you can see that we can only fit like two waves, so if we go all the way up to a higher octave, there's lots of them, and then for those wondering this is what noise sounds like, doesn't that just take you back to the television not being on, having to wait for the cartoons to start, and then we can also mix all of the waves together, anyway, right, great, yes that worked, we're doing good, okay, let's see what else we got, right, so then we're good, so the next thing we need to learn, so we can now make sounds by pressing buttons, and we can have the different waves, but we can also change the way the wave is generated using what's called envelopes, we've got attack, delay, a decay, sustain, and release, I know you're thinking that's probably some kind of sweet move on some like arcade fighter, but actually it's more simpler than that, so when we're playing the sound, say for instance the sawtooth, you can just hear that it's just sort of like a constant sound from the very beginning that I pressed the note to the time I take it off, so if we increase the attack, that means that increases the amount of time it takes to go from zero to the highest point that that sound can make, decay is the amount of time it takes to go from that highest point down to the level that you have set, so all of these are time, all except sustain, which is an amplitude, so then sustain is the level that the sound is playing, and then release is the amount of time it takes after you've taken your finger off the button, so if we can just see that with our super sweet JRuby app, so if we were for instance to increase the attack and delay, it will take a little bit longer to make the sound, so you can hear it gradually gets to the sound, and then if we were to add some release, when I take my finger off, the sound will still keep going, so you can see that the sounds are sort of carrying on with each other, so that's really cool, so that with using just the different waveforms and the different envelopes, you can basically create any musical sound that you've ever heard of, which is why these are called synthesizers, because they synthesize sound, three-blind mice, cool, so you're thinking this is all really interesting, we would love to hear you playing your musical day Julian, I'm like I know, but you're like this is a ruby comfort, so let's talk about ruby, so I don't know if any of you heard of a application called sonic pie, or as I prefer, sonic pie, it's a ruby application to make music, and it runs on top of something called super-collider, which is a digital synthesizer, so all of these instruments here are analog, everything is created via circuits, and you're actually changing the electricity as it goes through, and it's all really, really cool, whereas digital synthesizers all live inside my laptop, and I don't know how any of it works, because computers, anyway, with that kind of little bit of knowledge we had about the different waves, the different notes like on the keyboard, and using the envelopes, we can now see there's this little bit of sonic pie code, so when sonic pie came out, I was like cool, I'm a musician, I love playing instruments, I love code, let's go and do these two things together, and I was like, ah, how do you make actual good music with code, this is really, really hard, so let's have a little, let's close this so it doesn't eat computer, right, so here's sonic pie, so you start it off by writing play 60, so 60 is just a note, I think it should be middle C, possibly, and you can also use the literal names, and so if we run this, if we turn it up, yes, that's playing middle C, and then this is the code that we had in that slide, where we're using the sawtooth wave, and we're playing it for 16, we've got a slight attack, slight decay, slight sustain, and slight release, so as you can see, that's basically what we were doing on the synthesizer, but with controls and stuff, and so you can do this in code, and I'm thinking, this is so cool, now I've gone and bought my really expensive instruments, I can now play sonic pie, and then this was as far as I got, because it's really hard, so let me show you what can possibly be done, I don't know if any of you recognize this little tune, this was written by one of the sonic pie contributors, and as you can see, it's just Ruby code, and the great thing with sonic pie is it's meant to be able to, so like 10 year olds can write this, so if a 10 year old can write threaded Ruby code, then I don't know why we can't, so there's not much to this, it's just some notes playing, and changing like the envelopes, and the volume, and all sorts, and so this is what we can eventually get up to, but as you can see, so far I'm just here, okay what's next, let's have a look, oh yeah, I did the demo, right, okay, so you're thinking, okay that's totally sweet, so now we can go over here and play instruments, we can go over here on the computer and write code in sonic pie, but wouldn't it be cool if we could write code on the computer to talk to the instruments, I wonder if that's possible, when it turns out it is, there's a protocol called MIDI, so as I was saying these are all analog instruments, and back in the oldie days you used to connect them with basically electrical cables, and you would send either like plus 12 or minus 12 or anything in between, and that would tell them to do different things with different manufacturers, use different voltages, different cables, so the music industry standardised on MIDI, which stands for musical instrument digital interface, but before I talk about MIDI, I'd like to talk about this lady, Wendy Carlos, she is an amazing musician, she jumped on the synthesiser bandwagon when it came out and wrote some phenomenal music, her first album which really brought synthesisers to the mainstream was switched on Bach, it's classical music but made with synthesisers, so you might not be so much into Bach, so you might not have heard of this, but you've probably seen or heard of the film Clockwork Orange, she also wrote the music for this, and if you're not into dystopian government futures, then she also wrote the music for Tron, so this is all just amazing films with amazing music that you can do with these instruments and hopefully sonic pie, so that's really cool, back to MIDI, so MIDI is a serial protocol, it's like you need two cables, one to send data one way, one to get it the other way, and it's a five pin cable, because this is the 80s, we didn't have USB, you can now run it on USB, but it still acts as if it's these two individual cables, so MIDI message is pretty simple, you have the status byte which is the note, so whether it's on or off, and you can control various other things as well, that's basically whether someone, because all of MIDI is based on keyboards, so it's like if you press a note and you take it off, you get two messages for that, then you have the note number, that's where in the keyboard you're playing, which is what we saw earlier from sonic pie 60, or C3, is the note, and the last one is velocity, some keyboards, the harder you press it, the louder the sound and the softer you press it, the gentler and quieter the sound, so some keyboards support that, so you can just send this data across the wire, so let's see what we can do with that, so I've written a couple of Ruby gems, so I have, where is it gone, so as I said, I have these, I named them already, here I go, yes, excellent, so let's get the camera on so you can see, oh yeah, ignore my cat photos, don't look at those, so this is my synthesizers here, this is the Korg Volca Beats, sorry Korg Volca Beats, and this is the Korg Volca Keys, and Korg have got like five different instruments, all of this size, and they all support MIDI, and so I've written a Ruby library that wraps these, oh can you see that code is a big enough? So we create a new device, we find the first one that is available, and then we can set the sustain to maximum, we can play the note C4, then we can play the note C4 and actually change the envelope, because even though these are analog synthesizers, all of the controls are digital, so we can actually change that via Ruby code, and then we can play a chord, so if I just tinker about with all of this stuff, change this there, hopefully if we play this code it should make some noises, let's go to the right folder, right CD, Korg Volca, so this is available on GitHub, and I would love poor requests to add all of the other instruments, and I'd love poor requests to get rid of all of my terrible code, and bad spellings, because I'm British so everything has extra use in it, and Ss, so right, so if we run this, let's see what happens, hopefully something will, nothing happened, yay, oh was it you could hear it, cool, okay, then let's fix that, thank you, I thought I'd messed up then, right, yay, that wasn't very musical, but we basically sent music notes to an actual instrument via Ruby code that I wrote, and I'm a terrible developer, let's just do that again, so that's really, really nice and simple, but you don't really want to be writing code in Atom to make music, because it's very sequential, and then you've got to then have loops, and you've got to then deal with threads and timing and computers, and so I was like, what can I do, instead of writing code in Atom, which is a great editor for writing code and then shipping it off to Heroku, but it's not great interface for writing music, then I remembered that Sonic Pi is a really good application for writing code to write music, and I wonder if we could get Sonic Pi to talk to my instruments using MIDI, so I had a look at Sonic Pi and unfortunately it does not yet support, does not yet have MIDI support, because it turns out that's quite complicated, so what I did being a true hacker, an elite hacker at that, is I wrote some more code, which I can show you now, which, let's go to Sonic Pi, so in Sonic Pi you write normal Sonic Pi Ruby code, where's it gone, like this, but instead of sending the note data to SuperClyder that's running underneath Sonic Pi, we send it to DRB, and then from DRB that comes all over here, and we take that information and we do stuff with it, so the cool thing is, at the moment we've got three instruments, and so I need to know what those instruments are, so if we just comment this out, and do this, when I rerun this, it will tell me which devices I've got, can you see this, so I've got my mini-brutes, and as you can see I've got two mini-brutes there, that's because I was saying time, that time, the data goes both in and out, whereas the corgs are only inputs, but you're thinking there's no corg Volcker keys on here, that's because I've got a tiny little MIDI switch, and so the problem is, every time you plug in more and more MIDI devices, they all change their names, and where they are in the order, and you could have them connected via multiple switches, so in our library what we do first is we run this command here to see which devices there are, we're coming that out, then, because this is Ruby, we then stick it in a YAML file, so now I know what the devices are, so we give it a name and a key, so we can call it later what the device is and which port it's on, so that's pretty cool, so all this does is just create a DRB server that basically reads the YAML file, takes the data from Sonic Pi and sends it off to whichever device, cool for, so let's go back to Sonic Pi, so there's a slightly famous song that is included in Sonic Pi, which you may recognize, so this is still written in Sonic Pi sending data to Super Clidder, and this is kind of cool, you know, you can write pop songs, this was coded by Sonic Pi's inventor Sam Aaron, I mean that's pretty cool, but as I said let's see if we can get it to talk to our instruments, so it's the same kind of code, but instead of sending using like the drum samples and whatnot, we're actually sending it to the Volca beats, and this is the drum beat, so hopefully if, oh we're gonna get this running again, glad I remember that, if we run this this should work, so this is now running in Sonic Pi sending MIDI notes to my MIDI instruments, and if you don't believe me we can comment out this bit here, and the drum, and the drum stopped, then we can put this back again, so now we've got a really really nice interface to send to our instruments, and then over here on the output you'll see we're getting the note information and which device that we're sending it to, and the next step of the library would actually be to hook this up to my called Volca beats library, so then we could actually change the envelopes and which instruments we're playing, and because this polyphonic synth is multiple instruments, which we can play with, but wouldn't it be more fun to do it with code as opposed to having to twiddle knobs, right that's enough of that, so we can now control music via code, which is pretty pretty musical instrument sorry via code, which is pretty really cool, so now you're thinking right that's cool, we can write some pop songs, go on America's Got Talent, but what that's gonna be useful for my day job, and I'm like yeah that's true, so what else can we do, well then I thought about mini test, mini test has this option of creating what's called a reporter, where you can take the data from your your tests and do something with it, like either make them really pretty output, or send it all to dev null, so you don't know about your tests, and so I thought wouldn't it be cool to have like an audio system in your office that would let you know of the status of your tests, so let's have a look at that, so where is it, musical reporter, so first of all I've just written a very basic test a set of tests, so like all good programmers, my test part I just write a cert true when I want my test to pass, and a cert fail when I want my test to fail, because otherwise it'd be really hard, right, you'd have to write actual code, so if you do this your tests will always pass, it's so much better, then I have a reporter that grabs the MIDI device, something like these, and then when the test passes it sends one note, when it fails it sends another note, let's see if that works, let's close this, where are we, CD, demos, CD, musical reporter, right, test, is that it, is that how you do it, oh no, oh you are, you should try it again, should we, you're just hearing things Andrew, maybe, ah, anyway, this should be sending notes which it appears not to be, oh yeah, there is something there, it's just super super quiet, wasn't it, well that could be buzzing, anyway, we can play with this afterwards, so the cool thing is you'd think, oh I know, if my tests can play a song every time a test is run maybe you could write a song in mini-test, because you know you could set it up so when they pass they make this, when they fail they make this, there's only one slight problem with that, is mini-test and R-spec and all the other testing libraries, they randomize your tests which is so annoying because it means you can't make a nice sequential piece of music in your Ruby testing framework, maybe they weren't built for that, I don't know, but maybe that's why, okay, so we should have hopefully played some music but we didn't, the next thing is, you know, you go to work on Monday after this conference and they'll be like, hey what did you learn about Ruby, because we want to make our code faster, more performant, I'm like, don't worry about any of that, anyone can go off and learn how to make code faster, Aaron Patterson did it really well by deleting all his code, it was super super fast, what we want to know is how our code actually sounds, whether you know the algorithms we choose does it sound better than a different algorithm and so have you ever thought what does quicksort and bobble sort sound like, like we know we've seen graphs of how they look and we know kind of vaguely how they work, but wouldn't it be cool to know how they sound, so if we go over to Sonic Pi, we've got two simple bits of code there, one's bubble sort, one's quicksort, so we're piping in the numbers 50 to 100, that way they're in the audible human range, then we're shuffling them, then we're sorting them, so this is how quicksort, sorry bubble sort should sound, so every time you run bubble sort on your computer, that's what it's got to listen to, and we know it's not the fastest, but let's see what quicksort sounds like, I mean sorry bubble sort's not the fastest, so you would obviously then normally use quicksort, let's see how that sounds, I don't know about you, but to me that just doesn't sound, I know they're vaguely similar, but I think I much prefer bubble sort, so now you know that when it comes to choosing which algorithm you use or or method, just maybe pipe it through Sonic Pi to see you know how the poor computer feels when it's having to listen to this code, okay, right, let's see if, so if we go back here, run in slightly ahead, right, so, ah yes, so we've, let's see, let's have a recap, we've played music on our instruments, we've played music with Sonic Pi, we've used Sonic Pi to control our instruments, and you're thinking I've obviously left out the most important thing, can we control Sonic Pi from our instruments, because as you remember I said that I started playing with Sonic Pi, but I wasn't very good at codes, and then I went back and played with my instruments, and when I got a bit better at them, I was able to come back to Sonic Pi and write a bit of code to control my instruments, but I really prefer playing my instruments than writing codes, so I wrote some code so that I could play my instruments to play Sonic Pi, so I didn't have to write code to make music, that makes sense, right, so let's plug this in instead, so here I have a USB MIDI keyboard, so this doesn't actually generate any audio, it just sends MIDI notes, so if we plug that in, so if we run this code, let me show you the, oops, wrong file, that's why Ruby, Sonic MIDI, right, so if I show you this code, what do I call it, ah Sonic MIDI, here we go, is that it, oh MIDI, there it is, right, so what we're doing, we're grabbing MIDI instrument, and then we're sending that MIDI note using a kind of unofficial hacked API of Sonic Pi, and we're sending that data to Sonic Pi, so hopefully if I press my keyboard, we should be able to get Sonic Pi to play music, but without having to write any code, so we can now make Sonic Pi play music without having to write code, so now I can hopefully play some actual music, yes, but as you can see there's a tiny bit of a delay from pressing the keys, and it's sending it to Sonic Pi, and then Sonic Pi playing the music, and there's also a lot of code and cables, when really I could just do the same thing on an instrument, but that wouldn't be fun, so there's that, so now, but then that got me thinking, I haven't done this yet, but it made me think, if you can control the computer via a keyboard, you could do programming with a keyboard to write code, I don't know if anyone's thought of this yet, but I think that could be really really cool, so that's my idea, don't steal it, I'll share the proceeds with you, okay, right, so now that I've got slightly better at writing code and playing my instrument, I made a little dance song, if I can find it, there it is, which is really really simple, it's not doing anything complicated, it's just sending some different drum beats, and then, is it this one, yes, yeah, and then it's sending some different instrument notes to my three synths, my Volca keys, and then, oh is this not, no it's not the file, is it this one, oh maybe I deleted the wrong thing, aha this is it, right, yes, um sorry, so I send my um my my drum beats to the synth, the bass synth, drum synth, I then send some more notes to the Volca keys, and some more notes to the mini-brute, so if we go back over here, and we run our DRB file again, so most of this code is up on github, and the rest of it, if it isn't, and you want it, I will put it up there, right, so this is our DRB server, so that's running, so hopefully if we run this, this should be able to control three instruments at the same time, fingers crossed, which means then I can just come over here and then play with my instruments, which is what I wanted to do anyway, so basically what we've done with free and open source software is basically make Ableton live, and all those other really expensive pieces of hardware, or software even, for a little bit of time questions, or should we just go outside in the hall and play with these, ah so in Sonic Pi, I, I've got this one line here which sends the, Sonic Pi can set the BPM, so Sonic Pi is regulating the BPM, however the problem is, because DRB returns data back, it being Ruby, you'll see over, if I extend this out, there's all these timing warnings running slightly behind, because Sonic Pi is just sending data so fast that it's then, DRB's trying to respond back, and Sonic Pi's waiting, so this is why MIDI's hard, but yeah, not MIDI, so yeah, MIDI and Sonic Pi, but yeah, so I'm controlling the BPM via Sonic Pi, yeah that was actually a project, so the question was, could you just play music on these and have Ruby kind of capture all of the note information, and then you can use that to play that back afterwards, yeah I was thinking that would be a really cool project, so I've got another MIDI device, that's just a load of buttons, I was thinking that would be really cool to set up as like a, with a record key, so then the record sets Ruby to start listening the input, so then as I play on here, that would then yeah, generate Ruby code, that's also really cool, so we should also work on that later in tomorrow, yes, any other questions, oh sorry there's one over there, oh yeah, so there's a whole suite of gems from a chap called Ari, I think his name is, I can, it's all on my github, you'll see which gems, but he's basically written a whole suite of MIDI libraries that work on both Mac and Linux, and I believe Windows, and he not only does like the raw communications, he then wraps them in really nice DSLs so that you can then write more idiomatic Ruby to send the messages, so I've basically, all of my code is just sitting on top of his, so he's done all the hard work, cool, all right thank you very much