I'm Mark evansen with music.i and in these videos I'm going to be showing you how to connect python to Ableton so that you can make music like [Music] this so in this first part we get to kick it off with the most exciting part setting things up and adjusting your computer settings so to start with if I go over at Ableton right here I've got a blank Ableton session with three midi Parts what I'm going to do is I'm going to put drum kit on the first a beautiful ethereal theorin whistle on the second track and an electric base on the third track next I'm going to go over here and record enable all three of those tracks so that I can hear whatever they're playing okay having done this we need to set things up so that python can talk to Ableton and it's going to do so using midi now on a Mac if you want to have programs talk to each other via midi you do so via something called IAC so to get AC setup we want to go to audio midi setup and it's a little bit hidden you have to actually go into the window show midi studio and here is the IAC driver notice it's grayed out so double click on that and over here make sure to click device is online then add a few midi ports we only really need one for this but might as well make you know three or four buses why the heck not you can close this up and now that the IAC driver has been connected we can go into Ableton and for each of these parts we can say listen to MIDI from I driver bus one and then we're going to put each of the instruments on a different midi channel so we'll have the drums on channel one the thein on channel 2 and the base on Channel 3 this is pretty much everything we need to do to be set up in Ableton now let's make sure we're set up in Python so all of the Python stuff I'm going to be doing is in this simple IDE called th I like to use th to teach python because it's a really simple uncluttered interface and to do all of the musical stuff we do in Python we're going to use this library that I created called Scamp suite for computer assisted music in Python now Scamp is available freely you can install it via pip if you know what that means and if you don't know what that means in th there's a tool called manage packages which uses pip under the hood and I can search for Scamp click on it here and click install of course it's already installed on my computer you also might want to install Scamp extensions I don't think we're going to use that but sometimes I do use that in my videos okay having installed Scamp I've got a simple script right here which basically works like this the first Line Imports everything from the Scamp libraries the second line creates what's called a session object you use the session to create instruments to advance time all of this good stuff so we're creating a session object here with Tempo equals 100 and storing it in the variable s next we create our instruments so this line right here creates a drum part so we ask the session s to create a new midi part we call it drums we want it to send midi messages over IAC bus one that virtual MIDI cable in the computer that we just set up we want it to start on channel one and use just one channel um if this is a bit confusing to you the reason that we have to specify this is that in Scamp normally instruments use like eight channels and the reason for this is that is trying to manage complicated things like microtonality and Pitch bends in a polyphonic setting okay so great we've got a drum part A thein Part is also going to be over IC Bus one but use Channel 2 and the base part is going to use channel 3 and then in order to play some notes and actually hear them from Ableton all we have to do is ask one of the instruments to play a note so this script while true means do this forever so forever it's going to play a note on the drums play a note on the thein and play a note on the base the play note function takes pitch volume and duration pitch is a midi pitch volume goes from 0 to 1 and it kind of corresponds roughly to MIDI velocity which is 0 to 127 and then duration is in Beats at the current Tempo which is 100 by the way on the drum part pitch actually is going to correspond to which drum instrument it's using so is it a kick is it a snare is it a high hat so let's take a listen to this and see how it sounds so you can see the midium messages are going exactly where they need to go channels one 2 and three by the way if you're intrigued by this combination of python and music consider taking my course on cad.com it's a totally beginner friendly way of learning python while making music in the process because this video was so boring let's just add in one thing to make it more interesting let's do some randomization so I'm going to import the random library in Python and then for the pitch of the drum I'm going to do random. randint 3645 so this is going to choose a random integer from 36 to 45 so bunch of different possible drum sounds I'm actually going to do the exact same thing for the base part and then for the therin part I'm going to give it a list of 80 comma 78 this is going to do a glissando from 80 down to 78 whatever actual pitches those correspond to finally let's randomize the durations as well we can do this with random. uniform so that takes two numbers let's say. 2 and 1.3 and it's going to give us a floating Point random number in between those two numbers so it could be any decimal so I'm going to copy this I'm going to have all of the notes use a uniform random duration and let's take a listen to [Music] this he let's just make it slightly more interesting and add an acceleration so I say s. set Tempo Target 1,000 over the course of 50 beats let's take a [Music] listen okay I didn't quite think that through but I think that's a good stopping place for today hope you all enjoyed this really boring setup video and next time we're going to get into the meat of it by creating a slap base [Music] part see you there by the way you can find all the code for this video series in the description and you can get early access to the whole series as well as other fun stuff at my patreon although of course the real reason to subscribe to my patreon is to support the years of work I've put into Scamp but hey bonus stuff is nice too [Music] n