RubyConf 2015

Aprende a crear música con Ruby

Darin Wilson  · 

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

- OK, good morning. Thank you all for coming. We know you have a choice in conference talks, and we appreciate you flying Sonic Pi airlines. So today I'd like to talk about making music with Ruby, and specifically using a software system called Sonic Pi. Sonic Pi was created by a guy named Sam Aaron who was a programmer working over in the UK and one of his primary motivations when he made it was to try to give people a creative experience with code.

That sounds a little funny because a lot of times people think of code as just something for making very serious business applications or big crazy government databases or sharing pictures of your food on the internet. These are all very important, but for Sam, code could be a lot more than that.

It could be a vehicle for self expression and creativity. And he wanted everyone to have an experience of that, including and especially people who had never coded before. So he tried to make Sonic Pi as accessible as possible. It's completely free and open source, it runs on Mac, Windows, and Linux, and it was specifically designed to run on the Raspberry Pi computer which we saw a little bit of in the last talk if you were here.

This is about a credit card sized computer, costs about 35 dollars. You plus in a USB keyboard and mouse, plug it into a monitor or even TV, and you're ready to go. Sonic Pi was written in Ruby, actually, and the language it uses for creating the music is a very elegant and very approachable Ruby DSL.

And after seeing Betsy's talk yesterday, I'm not even sure it's a DSL. For the most part it's straight-up Ruby with a really really nice API, so it's easy for just about anybody to get started with it. And in fact, Sam collaborated with a school teacher in the UK to develop a curriculum for bringing Sonic Pi into primary schools and teach 10 year old kids the basics of coding.

But the real miracle of the system for me, is that on the one hand, it's simple enough for 10 year old kids to play around with and do bleeps and bloops and all kinds of interesting things, but it's also sophisticated enough that Sam and other folks have taken it into live performance in night clubs, coding up there while people are dancing.

Dancing to code. Think about that for a minute. So here's an excerpt of one of his performances, if the gods of the wireless are smiling on us at this moment. So it's a little dark, but there's a camera on Sam in the upper right hand corner, having fun. Oh.

A slight delay. And he usually has the code projected on the screen behind him so people can see what's going on. And we're getting a good look at the loading. All right. Well, it gives you a taste of it, anyway. By the way, that's running on the Raspberry Pi.

So you don't even necessarily need, thank you to our sponsor, you don't even necessarily need a super powerful computer to run this. So all this is fantastic and it's a really cool system, but one of the things that got me really excited about it when I first found out about it is that it's a nice way not only to get people started coding, but to get people started making music.

I've been a musician for most of my life and I earned my living as a musician for a few years until I turned bad and became a programmer. My poor parents have still haven't gotten over that. And I often meet people who say that they would like to learn to make music, but they don't because it seems too daunting or too expensive or it would just take too long for them to get to the point where they could make something interesting.

But Sonic Pi provides a really nice friendly on ramp to this and you can get something kind of fun going up quickly so when I meet people like this now I can say, try out Sonic Pi. So in this talk I'm gonna give you a quick music lesson with Sonic Pi, and hopefully convince you to give it a try yourself.

Now we've seen this slide a lot, and I'm sorry to say there's gonna be a little bit of this in this talk. There will be moments where it will seem perfectly clear, and then it's gonna seem like I take some weird logical leap, put in a couple numbers and I have a, an owl.

And I apologize for that. So if you don't grasp every single aspect of it, don't worry about it. Obviously I can't turn you all into musical masters in 30 minutes or whatever remains, but what I hope to do is just give you a few things to start, a few ideas that you can approach the system with, and just give you a little nudge across the starting line so that hopefully you can take it and run with it yourself.

So with that, let's talk about music. Music can be a little daunting if you've never worked with it before. It seemed very vast, it seems very rich, and it's also very very abstract. So how do you even get started? How do you approach it? How do you start to wrap your head around it? Well, as programmers, we learn that if you have a big, complex, seemingly insurmountable problem, the way to attack it is to break it down into smaller, more manageable problems.

And it turns out, you can do that with music, too. One way to think of music is that it consists of four different elements: melody, harmony, rhythm, and timbre. The first three of these you probably have at least an instinctive sense of. Timbre you may not have heard before.

But really it just talks about the sound of the instruments producing the music. So if you think about the difference between a flute and guitar and a kazoo, the difference between those three is what timbre is all about. So I'll go through each one of these and show how they manifest in Sonic Pi, and hopefully give you enough to go on.

So let's switch over to Sonic Pi. I also want to point out, this is what Sonic Pi looks like when you first install it and run it. You download it as a binary and you're up and ready. You don't need to worry about installing Ruby, you don't have to get your bundler file just right, you don't have to install gems, you don't have to worry about your version of Mac has Lib zero eight point six of whatever the hell is broken this week.

You're ready to go right away. You don't even have to open a terminal. This main window is where you enter the text and then you click the run button to start the music, stop button stops it, and kind of that's all you need to know to get started. There are lots of other things you can do, adjusting the size, adjusting the colors, saving your work, but really just type in text and go.

So for beginners, it's a really really nice experience to start with. So let's start with melody. What is a melody? A melody is really just a series of single notes played in succession. That's all a melody is. And it's usually the most forward-facing part of a piece of music.

So if you're driving down the road, you've got your iPod on, you're singing along to your favorite song, chances are you're singing the melody, cause that's the thing that's most forward. Unless you're strange like me and you're singing anything but the melody, but that's my own problem.

So how do we play a melody in Sonic Pi? Well, let's start by playing a single note. To do that, we use the play command. And see, I love this software already. The first thing I do is type, "play. " That makes me happy. So what do we pass to play? The note that we want to play.

How do we do that? Well, with a number. And we're off and running. Now what does this number mean? Well, it's the equivalent of middle C on the piano, if that means anything to you, but the truth is, you don't really need to know what it means. All you really need to know is that with higher numbers, you get a higher pitch.

With lower numbers, you get a lower pitch. And as you increment one integer at a time, that is exactly the equivalent of walking up to a piano and just going up all the notes one by one. Or going fret by fret on a guitar. Now you can also do some things that you can't do on a piano that will work.

[ ... ]

Nota: se han omitido las otras 3.953 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.