foreign
who has sent in a
introduction to beat making with python
and foxdot
hey everyone I'm sangushnan and thank
you for coming to my talk which is beat
making with python and Foxton so during
the course of this talk I will introduce
Fox Dot and how you can you know use the
flexibility of python to make really
good music and in the process we will
also you know write some code make some
good music with code and you know it'll
end with like a really cool song that
I'm going to demo in the end so stick
around it's going to be fun so before I
get started with this talk I just want
to acknowledge some of the other really
cool talks that were given in the same
topic which kind of inspired me to
explore Fox Dot and also give this talk
uh so shout out to Ryan kirkbride whose
talk was at pycon UK and a shout out to
Jessica Garson who saw picon talk was in
2019. so these two are really cool talks
so even after this talk if you feel
inspired to kind of you know know more
about it and learn more about it you
should check out both of their talks
cool so here are some mandatory links
that I want to attach uh so the first
one is to my repo which has all the
slides and the code that I'm going to
demo during the course of this talk and
the second two optional links uh are to
my Instagram and my SoundCloud where I
uh kind of upload my Live code music to
uh so I would appreciate any feedback
positive negative what you think let me
know uh good
what is live coding code live coding is
uh like this really awesome improvised
performance art where you write code and
use live coded tools uh like Fox dot you
also have tools like Hydra p5.js Sonic
Pi title Cycles you use all these
amazing live coding tools uh to actually
create music and visuals by writing code
that's kind of projected on a screen so
people can actually see what you're
doing and as you do it live people kind
of interact with it so uh it's a it's a
really Niche it started off as this
really Niche thing but now there are
like live coding communities around the
world and the movement is only getting
like a lot bigger
so what is foxtrot uh Fox start is a
live coding environment uh where you can
actually write python to make code so
what fox dot kind of lets you do is it
it gives you uh like a
computerized synthesizer uh or what is a
synthesizer how much time do you have uh
synthesizer is not it's just an
electronic musical instrument that kind
of looks like a keyboard but it has a
bunch of like you know uh tuner knobs uh
where you can actually generate
waveforms uh and you can tune those
waveforms to sound different so you have
sine waves you have square waves you
have Sawtooth waveforms and all of these
waveforms just sound different and you
can use synthesizer to just create all
these different waveforms so it becomes
like an infinite musical instrument you
know you can do like a lot of things and
fox dot gives you the power of a
synthesizer uh with python so you can
just write python to code up whatever
you would do with your synthesizer which
is awesome uh but how is foxtrot doing
it it's doing git with the help of this
other really amazing software called
super collider uh and it what fox dot is
is just an abstraction on top of super
collider uh with like a GUI it has its
own IDE but in there this is an
abstraction on super collider uh and
super collider is the real hero uh it is
an amazing platform which is made up of
like an audio server it has its own
interpreted programming language which
is also called super collider and it
also comes up with its own editor and it
has a whole bunch of plugins that you
can install you can build your own
synthesizer with super collider it's
like super powerful and it's it it's
also the base of a lot of uh live coding
tools like you know foxtor title Cycles
uh Sonic Pi all of these kind of use
super collider uh it's also like
free and open source so
it's awesome that's awesome uh good so
how do you install Fox start uh first
you need python which I'm guessing all
of you would already have in your laptop
apart from python you also need Super
collider so you just go on to the
website of super collider downloads
install uh the latest version so 3.8 or
above and then you also need tick enter
which is the GUI which kind of opens up
of fox.ui and along with that you also
just pip install foxtort uh and after
you have everything set up you open up
super collider super collider opens up
an interface and over there you just
install uh this package called Fox dot
uh and then so packages or extensions in
super collider is called coax so you
just do quarks.install fox Dot and then
you just do a fox dot dot start which
starts like a server which means now you
have Fox dot plugin installed and ready
to connect on super collider and now all
you have to do is open your terminal and
just go python hyphen M fox dot or type
Fox Dot if you're not in a virtual
environment and then you get you get
this like nice IDE where you can write
python code to play around with
uh so
it kind of looks
something like this so this is the ID
that pops up when I do you know python
fnm Foxton
cool
so uh the basic of kind of everything in
Fox dot is a player right a player is
what you can use to play anything you
want uh so we can define a player say
let's say P1 and you define a player
object and you can name a player
whatever you want it and then you can
hook it up to things so over here we are
hoving it up to like a synthesizer uh
it's like straight up and our synth is
called profit so we have P1 which is a
player we're hooking it up to profit and
we are playing zero one two three which
are the notes uh that have to play and
then we can just stop this player by
just doing P1 dot stop that's it super
easy
uh and then you can do like print synth
devs to actually get like the list of
synthesizers that are available for you
so it's not just profit you have like
pads you have saw you have like a bunch
of the sizes that bunch of synthesizers
you can play around with in foxtrot
so actually let's come to the notes you
know you see zero one two three here so
what do these mean right uh so uh so
over here the number zero uh is actually
the first or the root node which is C
and it's followed by d e f g a b uh and
going back by one will uh give you the
notes that are below middle C so -2 is
the a that's actually below the middle C
so think of it like a piano where you
know uh node 0 is the middle C and then
you can count the white keys up or the
white keys down right
so what about the Black Keys uh so you
can actually just you know it's actually
very intuitive 0.5 is going to be C
sharp and 1.5 is going to be like you
know uh the black key over here uh so
it's like super in intuitive where you
just represent your piano as just
integers
cool uh so now that we have a player uh
players have a bunch of attributes uh so
actually to describe this better I'm
going to move ahead to my uh
editor
cool so we have defined a player and we
have defined you have we have hooked up
the synth to the player and I'm going to
just play it
and now I stopped it uh so very cool so
it's just playing c d e f right which is
the c major scale so I can just switch
the scale and I can play a different
scale if I want to uh so these are all
the available synthesizers which I don't
think is going to be really clear to you
uh but yeah it has like a whole bunch of
exercises that you can use uh it's not
just going to be profit so I can just do
pluck
and
it's gonna sound different it's a
different deciser
good uh so now coming up to player
attributes that we just saw on the slide
before so uh a player is going to have
like a bunch of attributes that you can
pass that can control things when uh
synth is playing right like these knobs
that you tune uh cool so here are some
of the player attributes there are a lot
of them as I showed you on the slide but
these are some of them I'm going to
explore the first one is notes of course
it's going to be integers so it's going
to be like you know D E F so I'm just
playing these notes and then it's going
to be the duration which here is one so
it gives like our a 1B duration in
between all these notes uh but what do
you mean by like a 1p duration uh that
is decided by the BPM which I am setting
here as 120 which is like the tempo so
there's going to be like 120 beats per
minute that's what they're going to be
playing uh and here is the octave so if
I play this
so it's octave 4 I make it octave 5.
it's gonna be it's gonna be one octave
higher so there are like a bunch of
these parameters that I can tune so like
there's going to be delay where you know
how much should I wait before I play and
I go I can also mention my route uh and
a lot of other things so this is like a
really powerful way uh to just play a
synthesizer any synthesizer by just
writing code and passing an array and
passing parameters so how you write
python you can just use the same way to
make music I find that really amazing uh
cool uh but actually the basis of making
music is going to be patterns right
patterns are super important when you're
making music
cool and uh Fox dot offers like a lot of
ways where you can create patterns uh
because it's just a list right so there
are a bunch of intuitive ways where you
can create patterns so you can do a
shuffle a reverse swap a rotate a
stretch trim you can also say like you
know in this pattern for every three uh
beats just reverse it you know and for
like Fox dot can do all that so let's
say I have this player and I have to
play zero one two three zero one two
three as notes and I don't want to type
all of this out so I'm just going to
Define like a pattern object and I'm
going to say you know what play from
zero to three like how you would do list
slicing it's the same thing it's python
list uh so on top of python list you can
also do a shuffle which is going to just
randomly Shuffle uh whatever notes that
you have and you're going to also be
able to do this every operation you know
so let's say I want eight but after
every your three bars I want to just
like reverse it
so I can just do that also like so the
third one is going to be reverse the
first two is going to be like one to
eight one to eight and then eight to one
so one to eight one two eight eight one
so you know after every three iterations
you just reverse it
and there is also like other things you
can do swap I can I can rotate I can
stretch I can trim and I can another
very cool thing is I can also call a
Lambda function uh so what I can do is I
can just say you know what pads I have
pads my synth here is my pattern which
is going to be eight notes so and I'm I
say like you know what uh if
the if if my note is an even number
which means is divisible by 2 then
increase it by like an octave
it's like a very weird function and I
can just write a Lambda function for it
and I can display it
[Music]
cool I really like that uh so you can do
this gives you like a lot of power
because it's just Python and you can
write really complex functions which you
can execute by just mapping it across
your pattern so you can create really
cool patterns out of it uh but how do
you make sure like the pattern sounds
good right so you can do that by playing
the scale uh so scales give you like a
blueprint or a pattern uh of how node
should be ordered right so what we
played initially the keyboard that I
showed you with just the white keys were
zero one two three men c d e f g a b c
that's like the c major scale right
which is like the default scale uh in
like western music and it's also the
default scale in Fox dot but you can
also switch your skill which means you
can start from a different note and the
Order of your notes is also going to be
different so your zero one two three is
not always going to be cdef it's going
to change depending on what scale you're
on so let's say I am playing the lydian
scale
[Music]
so this is a much different scale than
what uh the c major scale is and scales
can also be used to represent emotions
uh so we would just say maybe a major
scale sounds really happy to you A minor
scale might sound somber or like sad but
actually that's debatable it depends on
how you play the scale you can make a
minor scale sound really happy by just
playing the notes in the right order uh
but scales have emotions associated with
it inherently uh so you can use scales
to control uh the those emotions that
you evoke with your music uh uh but you
know what let's say like for me
personally I don't really know a lot of
Music Theory so I'm oblivious as to like
you know how do I play notes uh so what
I do is I actually
look at all of the scales that are there
right and I just pick a scale and I
create melodies by actually randomizing
my choice uh over a loop so I just say
you know what pick a random note uh in a
particular octave uh in a Dorian scale
and just randomize my duration between
zero to one right and
oh
[Music]
this is just a Melody it's a Melody that
I just it's just random Melodies and
it's going to be random every time you
play it
nice so this is awesome so you can just
randomize things and play notes and
rather than doing this random.choice uh
across with the list comprehension we
can actually do
a random pattern so Fox dot also has you
know a abstractions for things that you
would commonly do so rather than doing
this you can just type a random pattern
among four notes just pick something
random and what I'm doing here is I'm
changing synth every time I'm playing
and I'm taking from the list of sense
definitions so every time I play this
I'm going to have a different synth so
let's try it out
[Music]
so every time I play it it's going to
play the same kind of notes but in like
a different sense so again I'm
increasing the possibilities of
Randomness here and you can just make
just layer it on top of each other and
you can make really cool stuff uh right
awesome so now we know what patterns are
now we know how to play notes now we
know how to play since now we also know
some of the attributes randomizations
Melodies and stuff uh and now comes one
of the one of my most favorite Parts
about Fox Dot and why I think foxtrot is
as powerful as it is which is time
variables
so time variables are kind of are these
variables that you define by just
defining a variable you pass a list of
values and you pass a list of durations
and these values change after a pretty
predefined number of Beats which is set
by the duration right so let's say I
have this a which I'm defining as a
variable which is going to be 0 and 4
and my duration is 2. so after every
second beat uh my variable is going to
switch to four so it's going to be 0
after 2 beats four right so I can
actually do this uh to do live coding
because that's what live coding is you
know progressively change things as time
moves ahead so time variables kind of
let you do these things you can do this
to create like you know uh chord
progressions uh way or if you want to
like uh switch to a new scale after like
uh every 16 beats or every 8 Bits you
can to do these things like that by time
variables uh which I think is like
really awesome so let's check out how we
do that uh cool so let's say that we
have defined this variable uh where the
integers are going to be 0 5 1 2 which
are notes uh but 0 will play
uh after two beats five after one beat
one after two beats and three after one
beat so these are gonna be like the
durations after which the variable
should trigger you know these things
these notes so if I'm going to just play
this
[Music]
so you hear notes kind of played
multiple times because there's like gap
between those beats and the ones that
kind of play more frequently you're
going to hear them multiple times right
like say five and three are what you're
hearing you know multiple times uh so
this is just a simple way to tune time
variables but there are also like
Advanced uh time variables like you have
linear uh variables where you can
actually linearly increase the value uh
by just doing a linvar of zero to one uh
for I think eight bars so you can just
increase it gradually from zero to one
you know uh so let's say I'm playing
notes three to five and I want to just
linearly increase you know as I go to
eight Beats from zero to one it's gonna
sound something like this
I kind of think this sounds like an
ambulance like an effect of like you
know a thing that's kind of moving in
front of you and the fact that you can
do this with uh linear variables is like
super cool then you don't have to kind
of manually you know have a for Loop for
I in every iteration of the particular
beat linearly increase incremented by
some value and then again decrement is
like you don't have to do all that and
you can just do a linware and foxtort
inherently handles that for you I think
that's pretty cool uh cool uh so again
time variables awesome utilities but
what I think also makes uh foxtrot
really powerful is the ability to use
samples
uh
so foxdot has inherently like a bunch of
samples that you can use out of the box
cool uh so you come to samples when uh
we have just explored these nodes and we
want to add some Juju to our music uh
that's when we come to samples and fox
dot has like a bunch of samples that we
just printed right now uh so I think you
cannot see a lot of all these samples uh
but you can have uh things like a kick a
snare a hi-hat a random voice some
random noise a metal clanking uh you
know
you know just random noises uh so what
you can do now is let's say I want to
play a kick
right
uh let's say I want to play a cake and a
snare
cool now I want to add a hi-hat
now let's add another hi-hat
so this is actually the 4x4 4 on the
floor disco beat that you hear in like a
lot of disco songs uh from the 80s and
even now actually uh but then a 4x4
doesn't play as it is so right now we
have just played one players but you can
actually layer uh players on top of each
other and you can have two players so
let's say D1 is playing four by four and
with D2 I want to add like some magic
you know add some layers to a four
fourth to a generic four by four beat
right so let me just try to do some of
that
so 4x4 B I'm adding
an open symbol
so you can you can just add some layers
on top of beads and just keep on adding
layers and removing them and that's what
makes foxtrot so powerful and amazing to
make beats
cool so this is just these are just
really simple beats right so I want to
do I want to go a little bit more
complex right so you have these uh
brackets round brackets so you use these
round brackets when you want to play
things as if they were one character
which doesn't really make sense maybe uh
so let me just sonically show you how
that works
so you have okay I've got something
weird you have
right uh so if you want to do
right so let's say you have this one
note and you have two nodes here and
there you don't want to play them
linearly you want to play them uh like
they were individual notes right so
that's what you can do with a round
bracket uh so let me just show you how
it happens and now that you I think
you'll get it
this is before this is after
so uh this is how you can just create
patterns uh without even
with just minimal amount of code right
and another bracket that you can use
brackets are what it uses to actually
create these patterns there's actually
also this square bracket and square
bracket can be used to play things twice
as fast uh so let's say I have these two
hi-hats that play at normal pace and
three of these hi-hats that play kind of
double the speed
cool so this kind of thinks sounds like
a trap beat right so I'm gonna add some
drum to it
foreign
[Music]
stuff and uh make it like a trap beat
cool uh so now that we explored uh you
know round bracket and square bracket
there is also these uh conical brackets
that you can use to play multiple
sequences uh using just one string so
let's say you have this beat right
and you have this beat
so they sound really well together right
but you have to write two different
lines to actually execute them and if
you want to play them in the same line
you can just use these brackets and just
write them together and they will play
independently as you know two separate
sequences
now to add some Juju to it
cool uh this is how you kind of make uh
beats in uh Fox dot so you can just add
more complex patterns rhythms notes
beats bass and all of this is
is what makes up a live coded musical
performance
now that we covered most of it let's
actually make a cover right uh so I'm
going to set my BPM to 120 uh and I'm
going to play like
a basic
drum beat
cool so now uh I have my base that I
have already defined my notes for
I'm going to play it
foreign
good uh
all right uh this is me uh thank you so
much for attending this talk I hope you
had fun I hope you learned something new
and I hope you explore foxtrot to make
some music of your own and if you do
please share it with me I would love to
hear it uh and uh thank you so much
thank you thank you if you've enjoyed
this talk uh you'll be able to find
sengashnan on the Discord to ask any
questions that you have
we've got a bit of a break but then
coming up down in room c will be the
lightning talks