 Thank you for having me, first time in Buffalo ever. My name is David Padea, you can find me on the internet as David on Twitter, GitHub, etc. And I work for a company called Crowd Interactive, which is a web development consultancy based in Mexico, more specifically a small town by the Pacific called Colima. And I'm here to talk a little bit about how to make music with Ruby, as you saw. So what I was using there is a little gem that I created called Banjo. But before I go down in details, I want to talk a little bit about what inspired me to write Banjo. Right, so I've always been interested in sort of mixing music and code, my two passions. So this is me a lot of pounds earlier, and I used to play at a band and I used to play the bass, and also I played sort of innovative instrument. This is back in around 2009, and it's barely noticeable, but I have a pedal down here. And this pedal, if you're a musician, you'll probably recognize it as one of the basic distortions that you can use on a guitar, except that mine, I removed the guts of it and I just kept the switch. And then I plugged in a cable that connected to the parallel port of my laptop, which I had right by my side. And then I wrote this little program so that every time I press that pedal, a sound file will sound on the speakers. So as I was playing, I hit the pedal and the sampling will begin. And so that complimented the music of my band, sort of like a DJ, but I was just using my feet to actually trigger the sounds, right? So this is, I rescued some of the code. That program was written in Beesol Basic. That's how old I am. And I rescued some of the code, and I don't know, to be honest, I don't know what's going on except that there's a bunch of fifths and elves. I guess the important part is that IMP call that actually read the parallel port, and if it was 254, what you read, then do stuff, right? And I'm trying to remember why 254. It's probably because the parallel protocol, it's backwards, and when you actually put a current on one of the data pins, it probably goes into a zero so that the easier numbered get is 254 as I press the pedal, right? So later on, last year, I was invited to speak at a conference in Israel, Rails Israel last year. And while I was speaking there, there was this guy called John Krutisch. And at one of the parties at Rails Israel, this guy did almost the same thing that I just did. He plugged it on his computer, and he displayed code on a projector, and he started sort of coding music. So that was the performance. You can see P.J. on the drums right there. That's P.J. And there was, I don't remember his name. This guy with the accordion. So they were all playing, and John will be sort of live coding music. And this was his code. And so when I saw it, I was like, whoa, I want to do that because that's awesome, and I love music, and I love coding, and I want to do something like that. So I went on and figured out what was he using. And he has his own library, which is called LiveCoder, and that's what he was using. And I tried to set it up, except that there was a little problem, which was that it's written in JavaScript, and I suck at JavaScript, like real bad. I'm a Ruby developer. I still tried to figure it out, but I just couldn't. So I just said, screw it. Let's just write something in Ruby and make it happen. So I did, and that's how Banjo came to be. So I analyzed what he was doing, first of all. I was fortunate enough to take this video, so I was looking at, I know what you're doing, John. And by looking at it, I tried to analyze this code and figure out what he was doing, and all these modellers happening. And then it hit me, like, oh, I know what he's doing. He's sort of doing maybe some sort of scanning to a lot of integers. And if that integer seems to be, like, the result is one of these modellers, then he will play, like, the base drum or the snare or some sample or something like that. So it looks something like this. So let's say, at least this is the way Banjo works. So you have, like, a sweeping that goes from zero to 15, like, all the time. And then if you want to play a note or something that only you only wanted on a certain pattern, then you do something like this, right? Like, if I modellers four equals zero, then play the note. And so in this case, only the green ones will play, and the other ones will be totally silent. Same if you change it to seven and so on. So let me talk a little bit about music theory, just a little bit. I don't know if you're familiar with music sheet, sorry, with sheet music. And you usually have something like this, like, you have the staff, and then you see, like, a number, a couple of numbers here. So this is basically just telling you how music is measured, like, on this particular sheet. So this basically means that every period will be composed of four quarter notes, which are these ones, right? So this is the measure of every period, and it's sort of the principle behind of banjo. So if we wanted to do, except that I added a little bit more control, if you wanted to do something like this, like, that plays a quarter note, you will use the actual modellers four, and then it will be, like, boom, boom, boom, boom. Right, like, it will be, like, every quarter note. So let me do a little demo of that. So what I meant is, like, say, for example, here, I'm playing the C3 note, sorry, and then I will say every four, right, so. ["C3 Note"] ["C3 Note"] Inside of the code, every function is just calling that modellers thing. So if you wanna do it every eight, that would be, like, half. So what I was thinking of it, so I had the basic idea, and I was thinking, like, how can I do it with Ruby, and to do something like what was described there, where you will have, like, some sort of timer, and then call it every time, and then maybe play the note, maybe don't, maybe don't. And the first thing I thought was maybe an infinite loop and use a thread and then a counter, but yeah, that didn't work out very well. So I stumbled upon Event Machine, and I've used it before, Event Machine, to sort of do basic web servers, but I've never thought of it that it actually had a timer sort of functionality. So that's what I used for Banjo. So inside the code, you basically just declare an Event Machine to run, and then you add a periodic timer. So if you had this code on a console, this would just happen every second, right? Because I'm telling you, I'm telling here, Event Machine, add a periodic timer that every second just do this. Let me show you, just in case you don't believe me. So that's all it does, basically. It's just the basics are that it's just telling us every time a second has passed, and that's the basics. So when I found that out, then that's interesting, that might work for me. So the next thing to do was to actually do stuff with that periodic timer, right? So what I sort of did with Banjo is that what happens on that specific time, that poll rate, is that it loads all the classes that are in the folder called channel, and those classes are basically your instruments, your different instruments like drums or piano or whatnot, and then just call the perform method. That's how it works. You load all the classes and then call it perform method. Why am I loading them? Because that way you can change them live and then save, and that's why Druby reloads them, and then the music just changes, right? But obviously you can't do it every second, so you sort of need to calculate some sort of poll rate for that to happen. So internally Banjo calculates the poll rate like this. So if you know a little bit about what tempo is, it measures the speed of a song, right? So if you had a song that's 60 bits per minute, that means there's gonna be a bit every second basically, right? So in Banjo terms, that means that I will have, the green ones will happen every second, right? But I need to poll for the smaller periods and that's gonna happen every quarter of a second, right? And a more upbeat song or more regular songs are on 120 and the range between 100 or 140. And that means I need to poll and co-perform for those classes every quarter of a second, right? And like I said, the classes themselves are just very basic Ruby objects and the only thing that you need to do is just inherit from this class, which is Banjo channel, and it will give you all those methods to play and to do the whole music thing. So on the perform method, you just need to tell basically MIDI how to play some notes, right? So what I use for that, I did a little bit more research, like how can I use my computer to send MIDI messages and stuff? So I found this gem, which is called UD MIDI, which is basically that. You just use it to use your Ruby code to send MIDI messages and turn off the lights. Now I'm kidding. You use it to send MIDI messages and then you just set it up on your computer MIDI interfaces and then you just choose one and just send it to software like Logic or GarageBand or whatever your music software preferences. So I learned a little bit about MIDI and didn't become a super expert, but at least I knew this, is that you have to send a message for when the note is on, like when you press a key on the piano and then sometime after that, you need to send a message to turn it off, like key down, key up, right? And then you need to send obviously the key number and the velocity, which is like how much pressure you actually put on a key. And that's all it does, that's all Banger does, it has something like this, it doesn't have a sleep, but you get the feeling like, I only declare a UD MIDI output and then by using puts, I send the message note on, this is the key and then velocity that can be 100 or can be all the way to 127 and then sleep a little bit and just release the key. So, demo zone again. How do I get out of here? Unlocked, something happened. I'm sorry, something happened to my computer. I'm locked on this thing. I need to get out of here, so just help, it's frozen. Thank you, Team Cook. So I guess I just unplug it and see if that helps. I don't know what's going on here. It's just dead. No. Sure, I restarted. Will that help? Let's do this. So I'll just turn it on and turn it on real quick if I can. Computers. Yeah, it should turn on pretty quick. So, it's all a matter of doing, you know, mixing a little bit of poll timing and making your computer sort of send media messages to an external software. In my case, I use Logic and so on Logic, that's where I decide, you know, this channel is going to be the drums, this channel is going to be like the piano and so on. And that's Unimidi just helped me through that. It's very raw, but still helps you send those messages. Anyway, so the purpose of this talk is to invite you to collaborate in Banjo, and here's a little to-do list of things that I want to do with it. And one of them is test does it work on Linux? To be honest, I don't know. But since the Unimidi gem claims to do so, then I'm pretty sure that Banjo works on Linux. So, it will be nice if someone could just collaborate that. The other thing, there's a change. I want to change the duration of notes because right now it's in seconds, but sheet music tells you that it should be in sort of fractions of the period. So, I want to change that. I want to write a CLI, you know, to just do Banjo in it and then you get like the bare bones of a Banjo song and then just create, you know, Banjo channel piano and then you get the bare bones of one of the channels. And just as every junk open source project needs, I want to improve the documentation because right now there's not a lot of it in the repo. So, if you want to help or if you want to play with it, this is the address, it's on my account under David Banjo. So, just fork it, play around and if you need help setting up what we'll hear, just find me and I can help you. And that's it. So, thank you. Thank you, sir.