0:03
So the final core area of the EarSketch API that I wanna look at in this module is
effects.
And so in this video, we're gonna look at the setEffect function and
we're gonna look at a number of different ways to use it to add effects to tracks
to set the values of effect parameters and also to create effects
envelopes that gradually change those effects parameter values over time.
And so I wanna start with the simplest things that we can do with setEffect.
setEffect is a kind of unusual function.
You can define functions in Python that can have different numbers of arguments,
depending on what you wanna do with them.
So setEffect can have two arguments like in the example we see here, but
it can also have as many as six.
So we're going to start with a simple two argument version and
kind of build our way up to more complex operations.
So what we see in this simple incarnation is that there's just two arguments.
First, there's a track we wanna add the effect to and
then the second one is the name of the effect and
all the effects in your sketch are referenced by constants.
So like DISTORTION is the constant for DISTORTION.
Here's a list of them just so you can see them on a slide, but
we've also included documentation on the course website.
It has all kinds of information about all of these effects and what they are and
what they can do and how to use them.
As you look through this list, you'll see there's several that you're probably
familiar with from things we did with module two of the course.
Things like dynamic range compression and DELAY and
DISTORTION and PANNING and VOLUME.
And there might be some others that you haven't used before, but are easy to
experiment with and play around with and kind of see what they can do.
So I have a simple script already open here in EarSketch that simply takes
a sound, House_Deep_PIANO_001 and
uses fitMedia to place it on the first four measures of track one.
So we can run this We can listen to this.
This is a dry sound with no effects supplied to it yet.
[MUSIC]
So now if I want to add an effect to this say, distortion,
all I have to do is type in SetEffect, a track I want it to go on,
track 1 in this case and the effect, DISTORTION.
And then I can go ahead and run this again and
you'll see it's added an effect lane for us just like we would see in reaper,
if we added an effect or any other dol that shows us that distortion has been
applied to this track and go ahead and play it and I'll hear a lot of distortion.
[MUSIC]
Now I can also do other things that you're use to doing in digital audio workstations
like Reaper.
I can bypass the effect, if I want to temporarily disable it.
[MUSIC]
And then I can turn it back on.
[MUSIC]
Also if I'm running out of space in my view, I can always hide my code.
But still if I have five, ten tracks and lot of effects,
I'm gonna have to do a lot of vertical scrolling.
So if you wanna save some space, you can press this effects button to show or
hide all the effects lanes.
This won't disable the effects, it'll just hide them from the view, so
you can fit in more tracks in a single vertical slice.
The other thing I can do is you may remember in Reaper,
there was a master track.
And if we apply the effects to the master track, then apply them to our entire
mix and not just to a single track and we can do that in your sketch as well.
There's a special constant we give, so instead of giving a track number,
we simply type in the constant MASTER_TRACK.
So if I do that right now, we can go ahead and
see what this looks like on the master track and I run this again.
Now it's not going to sound any different in this case, cuz we only have one track
in this particular example, but there is an important difference in that you can
see the effect lane and the effect is being applied as MASTER_TRACK,
which just showed up as opposed to being applied to track one like it was before.
4:44
So that's the most basic way to had add an effect,
which is all of it's default parameters to a track or the MASTER_TRACK in EarSketch.
As you listen to that, I don't know if your thinking the same thing as me, but
I thought that was a lot of distortion for piano.
It's pretty nasty.
So what if I wanna reduce the amount of distortion?
Well, then I can set a parameter value and this akin to what we did In Reaper.
When we opened up the effects style of box and there were a bunch of sliders and
we could change the values of the sliders to set them to new values for
that effect to configure it.
And that those would stay fixed for the entire piece of music, but
we could set them to whatever we wanted.
And so if we're gonna do that,
we add two additional arguments to our setEffect call.
We start again with the track that we wanna apply this to and
the effect constant that we wanna use, but
then we give it a parameter constant, which represents the parameter,
the slide essentially we wanna change and the value that we wanna take that on.
And again, if you look at the supplementary effects documentation,
it lists.
For every effect, it explains what all the different parameter constants are and
what their values can be.
So for instance, for PITCHSHIFT, our parameter is PITCHSHIFT_SHIFT or
at least one of our parameters available to us is PITCHSHIFT.
How much do we wanna shift the pitch by and then we specify that in semitones.
So the negative 2 here means down 2 semitones or a whole step.
So, I wanna change the amount of distortion applied to the track.
So, it's not just that fixed amount for the whole track.
I wanna change it to a different level.
So, I can go ahead and I can add in on of these DISTORTION parameters here.
In this case, I'm gonna choose DISTO_GAIN.
The gain on my distortion.
So DISTO_GAIN is my next parameter.
What is the amount?
Well, it tells me here that the default amount is 20, the minimum is 0 and
the maximum is 50.
So I had the default value before, which was 20, which was maybe too much, so
I'm gonna reduce that say, to 5 instead.
I'll run this again.
You can see that line showing me the distortion level went down quite a bit
since I put a lower number and I can hear what this sounds like.
I'll switch this back to track one, as well.
[MUSIC]
6:59
And then if that's too little, maybe I wanna bump it up to ten.
Let's say, so I can do that.
I can run this again and I can play with it.
[MUSIC]
And then I can stack effects, as well.
I'm not limited to just one effect per track.
So if I wanted to add say, a volume effect here to change the volume of
the overall track, I can come down here.
I can see volume, so I can go setEffect, also on track one.
My effect is VOLUME and then I wanna control the game here.
And we can see that the game goes from a default of zero,
which means it doesn't change the volume at all and this is in decibels.
A minimum value is -60, which would make it silent, basically and
a maximum value would be a gain of 12 dB.
So I can go ahead and make this maybe just a little bit softer, so
I'll just do maybe -5 dB and I can go ahead and run that again.
Now we see a second lane here with my VOLUME, GAIN, as well in my track and
we can hear that.
[MUSIC]
I wanna go back and talk about this notion of effects envelopes.
So we spent a lot of time on effects envelopes in module two of the course
where we were looking at ways that you could essentially define by clicking
different points in the effects lanes, you could control automations for
changes to these parameters over time.
And it was typically done in the form of drawing dots and so
you are defining essentially a starting time and value and ending time and value.
And you can do this, again,
with another starting point and ending point from there.
And you can define as many of these as you want
on a track to start doing very complex curves, if you want.
So each of these ramps from a starting point in value to an ending
point in value is defined by a single call to setEffects.
So if i wanna do these more complicated ramps,
I just call setEffect a bunch of times.
So, it starts off the same way with the track and the effect name and
the parameter name and then I just give it the values for these two points.
What is the starting value?
What is the starting time?
What is the ending value?
And what is the ending time?
So as an example, if I wanted to do a glosanda with my PITCHSHIFT to have it
change gradually over time.
I can say, well, I wanted to start a -2 semitones in measure 1 and
then go up to 0 semitones, the original pitch by the time we get to measure 5.
So now, let's take what we learned about adding envelopes to our effects and
then apply it to this example here.
So we'll add some envelopes to change the values of the DISTORTION_GAIN parameter
and the VOLUME, GAIN parameter over the course of these four measure of music.
So we'll go ahead and start with the volume and we'll start
with -60 dB of silence and have it fade in over the first two measures.
We'll be at -60 at measure one and we'll increase to 0,
that's the original volume at measure 3.
Now we'll go ahead and run this and
you'll see the curve here where it's starting at -60 in measure 1.
By the time it get to measure three, it's at zero dB and then it's just a straight
line after that, because I haven't told it to change it anymore.
So, it just keeps it at zero dB.
Now let's look at the distortion and I'm gonna go ahead and
have no distortion until measure three while we're doing the fade in.
So I'm gonna say, my DISTORTION should be DISTO_GAIN of 0 in measure 1 and
it should still be a DISTO_GAIN of 0 at measure three.
So if I run this, you'll see I've gone from zero distortion,
still zero distortion in measure three.
Now, I wanna do something else.
So you can go ahead and copy and past this.
Put in another line and so starting at measure three,
it's still gonna have a value of zero.
But by the time we get to measure 4, I want it massively destroyed, so
put in a level of 20.
So I go ahead and run that and you can see how could this curve goes up very
quickly here to measure three at 0 to measure 4, 20 and
then while I bring it back down to no distortion by the end that last measure.
So, I'll copy and paste this line one more time.
11:25
And I can say that at the beginning of measure 4,
I want it to be at just a 20 where we left off, but
by the beginning of measure 5 I want it back down to zero distortion.
So I can run that and you can see how that curve comes down in this last part.
So, it starts off at zero, still at zero at measure three, that's our first line.
Our second setEffect command sends it from 0 at measure 3 to 20 at
the beginning of measure 4.
And then our file one goes ahead and takes it back down to zero by the time
we get to the beginning of measure five where the sounds ends.
So let's go ahead and listen to all of that.
[MUSIC]
So at this point, I wanna recap all the things that we've done in module four as
we've introduced Python and EarSketch API.
We've looked at the concepts of algorithmic composition.
We looked at it specifically in terms of EarSketch and Python.
And then we covered some basic concepts in Python looking at variables, Functions,
Constants, Strings, Loops and Lists.
And we've covered basic ideas in the EarSketch API, functions to place audio
audio in our multi track dot timeline to do pattern sequencing by defining our own
rhythms with each strings and adding effects, controlling effects parameters
and envelopes to change those effects parameters over time.
In module five of the course,
we're gonna kind of take everything that we've learned here and go a step further,
really looking at the notion of not just writing sequential instructions for
the computer to follow, but writing musical algorithms and
take fundamentally different approaches through code of how we make music.