In this tutorial we'll finish our MIDI controlled animation in After Effects.
In this video we build on the fundamentals we learned in Part 1 (watch this first if you haven’t already) and learn how to actually TRIGGER animations that begin playing when After Effects detects a MIDI keyframe. The only way to do this is to write an expression that does some fancy tomfoolery. Joey is going to walk you step-by-dorky-step through the process.Make sure you check out the resources tab for everything you'll need to complete this lesson.
Tutorial Full Transcript Below 👇:
[Toto - Africa]
Joey Korenman (00:00:29):
This is up Joey here at school of motion and welcome to day six of 30 days of after effects. This is part two of the tutorial series where we take MIDI information and we bring it into after effects. And then we use it to trigger animations. Now I have to warn you that this might be the geekiest tutorial I've ever made in my entire life it's expression city. We're really going to get our hands dirty. And at the end, we're all just going to feel really filthy. But if you can hang with it, if you can just bear with me, let your brain absorb it by the end of this, hopefully you'll have a pretty good understanding of how this thing is actually set up. And that'll give you some really cool ideas about what you can do with this knowledge later. Now don't forget to sign up for a free student account so you can grab the project files and expressions from this lesson, as well as assets from any other lesson on the site. All right. Let's hop into after effects and check it out. All right, here we go. Down the rabbit hole. So we are in logic and, um, this is the track that I recorded for the demo for this video. So I'll just play a little bit of it. You can see the MIDI information down here,
Joey Korenman (00:01:36):
And then, uh, I did find Backing tracks for this song.
Joey Korenman (00:01:48):
You know, one of the things I hope this tutorial does, is it, it, you know, I want it to give you guys ideas, um, and kind of create, you know, there's, this is kind of something that hasn't been done a whole lot, and it would be really sweet to see, you know, what some really, really creative, amazing designer person could do with this technique. You know, uh, you know, programming MIDI that goes along with a cool song and then using that to trigger animations, um, I'm really excited that it's working and sort of, so anyway, so we've got the media information here and obviously this is a lot more complicated than what we had in the first example. Okay. I mean, you know, Hey, I recorded, you know, the first, third of the song, there's just a ton of data here. Um, and on top of that, there's a whole lot of different instruments, right? There's high hats, kick snare, um, there's different symbols, there's Toms, you know, there's probably eight or 10 different instruments actually, um, being played in here, you know, if we go to like something like this, right. There's a little drum fill in there. Um, let's see what else we got, like sort of over here in the chorus.
Joey Korenman (00:03:05):
All right. So if you want to be able to have each instrument sort of trigger a different thing, you kind of need access to that instrument independently. Okay. By default, you're not really getting that out of your MIDI file. So, uh, let me show you what happens. Um, if I just select this MITIE and I say export selection as mini file. Um, there, I'm getting that error again. So, uh, let me first come down here and say, delete mini events outside locators. All right. And then I'm going to make sure I don't have any, any drum hits happening too early. That all looks good. And now export that mini file.
Joey Korenman (00:03:49):
All right. Cool. Um, and let me just make a new folder here. We'll call it demo too. And this is called Africa raw. So the first thing I'm gonna do is I'm gonna grab the, uh, the audio file, just the, uh, the bounced audio. Okay. And then I'm going to grab that mini file that we just made. So let's grab Africa raw mini file. Make sure I have something selected in here and I'm just going to rename. So this is the old, this is the actual MIDI file, um, from the demo. So I'm just going to rename that old for a minute and let's import this one we just made. Okay. It takes a little longer than in the last tutorial, because there's a lot more going on. And if I hit you, you can see, wow. There's a ton of data in there. Now, here is the problem. Um, let's look at channel zero velocity and let's go into the graph editor and let's kind of jump in there. Okay. And you can see there's peaks and there's hard hits and then weaker hits and let's play the audio and see how it syncs up.
Joey Korenman (00:04:56):
Okay. So listen to just the kick drum, The kick drum. Doesn't exactly line up with, with this. Okay. It's like, it lines up with some hits, but not other hits and then listen to the snare drum.
Joey Korenman (00:05:15):
Right? So it lines up with some hits, but not other ones. So what happens is by default, all of these mini notes, they get placed kind of Willy nilly onto some channels. Okay. And what you really want is you want the kick on its own channel, the snare on its own channel, the high hat on its own channel. You want all of these things separated out. Um, that way you'll be able to more easily kind of control like trigger, you know, a certain animation on the cake, a certain animation on the snare with this, it's going to be a lot harder cause you're going to kind of have to manually tell it, which of these hits goes with which instrument, okay. If everything's happening on the piano, it doesn't really matter, but this a drum set. And so you've got multiple instruments happening at the same time. So this Mitty information we brought in, isn't going to be too useful. Let's delete it. And let's hop back into logic. I'll show you how to fix this. Okay. So we are back in logic and let's take a look at the MIDI information one more time. So here is our hero drums.
Joey Korenman (00:06:17):
All right. Now let me show you. Each of these notes is placed into a MIDI channel and the way you find out which channels you can open up your event list. All right. So in logic you have this kind of manager window over here and this, uh, this has a few different modes, but in event mode, it's showing you every single mini event in your song. Each of these notes is considered a MIDI event. Um, and if I select one of them, it will highlight that event over here in the list. And it will show me in this column, which channel it's in. Okay. So this note is in channel three. OK. This snare hit is in channel two. Okay. This snare hit is in channel one. Now that's obviously going to screw us up. Okay. And what we want is we want every instrument in its own channel.
Joey Korenman (00:07:04):
Okay. This kick drum is in channel three, this kick drums in channel two. Right. And that snare hits in channel two. So that's why in aftereffects, when we were looking at the data, it looked like, you know, the kick was lining up with some of those hits, but not others. And then the snare would line up with some of those hits, but not others it's cause of the kick and the snare. Sometimes we're in the same channel. Sometimes we're in different channels and that's not very useful. So what we want to do is put every instrument in its own channel. If I select, for example, a high hat notes. Okay. Um, it'll show me over here. All right. Which key on the software keyboard is actually corresponding to that note. You know, I'm, I'm playing on a sort of a drum shaped mini controller, but all it's doing is it's sending notes to the computer and it's interpreting, you know, this note is a kick, right?
Joey Korenman (00:07:59):
And this note is a snare. So this is the note for high hat. And when I select it, it highlights every single hat hit and you can see that, you know, they kind of all look like they all look like they're on channel one. So the hi-hats actually look like they might be set up. Right. But just to make sure once you've highlighted everything, you can come over here and you can actually sort of batch adjust all of them. Okay. And make sure they're all on the same channel. So now they are all on channel one. That's great. So now we just have to do that for the rest of the instruments. All right. So I'm not going to do all of them, but I'll do a couple more. Um, cause there's a couple of things that kind of tripped me up and maybe I can save some people, some hassle.
Joey Korenman (00:08:40):
So here's the kicks, right? I'll select all of them by clicking that little key. And I can look in the list and I see that, um, you've got some are on channel three, some are on channel two and you want them all on the same channel. So let's try to put them all on channel two. And if I click over here, um, at first it doesn't let me change it at all. If I hold shift, it does let me change it. Okay. And I'm honestly not sure why. Um, but just know if you're using logic does now here's the problem. If I move it up like this, right? So now it's channel eight, this one's on channel seven and the problem is it's incrementing them all the same and I want to change them all. So they're all on the same channel. So this is a trick I figured out you select all the notes.
Joey Korenman (00:09:21):
You come over to your edit menu, uh, sorry, your functions menu. And you want to say set MIDI channel to voice number and the F and what that will do is it will set every note to the same channel. Now, if I hold shift, I can move these up to channel two. Okay. So now I've got high hats, all on channel, one kick on channel two, let's set the snare. Okay. And you can see are on channel two summer on channel one. And I want them all to go to channel three. So I'm going to do the same thing, set mini channel to voice number. So it sets all of them to the same channel and then hold shift and move this up to channel three.
Joey Korenman (00:10:07):
There you go. Cool. You just do that for every instrument that's in here. Okay. And it doesn't even take that long. Here's my cow bell. Right. And even the cow bell, this makes no sense to me summer on three summer on two. So yeah. So you just do the same thing, set mini channel to voice number and then hold shift and move that up to four. There you go. All right. So once that's done, then you can export that MIDI. And when it comes into after facts, it's going to be much more useful. So let's hop back in there. All right. So let's import that MIDI. Um, and I had already, uh, already imported this previously. Um, all right. So let me make sure that I've got my, uh, I've got, you know, something in this sequence selected, hit apply, and it's going to take a little while, but this time you're going to see a whole lot more channels come through. Okay. Um, what's strange to me is that I, it seems as though the channels that you assign things to in logic, don't always match what, what comes through here, but that's not such a big deal, right. Because, um, you know, what you can do is hit you and you can see a whole bunch of key frames here, but there are a lot more spread out because we've separated instruments onto their own channels. If I just hit, you know, audio preview here, right. Watch, watch this column right here.
Joey Korenman (00:11:39):
Obviously that's the kick drum channel 11 is the kick drum. Okay. So it's easy to figure out, you want to figure out high hat. Um, it looks to me like this is the high hat up here. 1, 2, 3, 1, 2, 3. All right. So it's a lot easier to figure out when, when they're separated into their own channels like that. So, uh, first thing I'm gonna do is clean this up a little bit and what I decided to do, um, as opposed to trying to work with the velocities of these, right. I mean, there is some change in the velocity. This is the high hat track. Remember. Um, and so, you know, I've kind of got varying, you know, hardness of my, my hi-hat hits here, but I wanted to just actually make this simpler. And every time I hit a drum or a high hat or a symbol, I want it to trigger something.
Joey Korenman (00:12:28):
So that's what we're going to do. And to do that, all we need is this duration property here. Okay. You can see there's one key frame for each hit and I simplified the playing so that, um, you know, I could make sure that all of my hits kinda end up, um, you know, triggering and registering. So we have a key frame for every single drum hit and all I'm going to need are these duration column, uh, these duration rows, I don't need the velocity. I don't need the pitch. So I'm just going to quickly go through and I'm going to delete everything. Let me just do select all here and all I want to keep are the durations. Okay. So I'm just going to, de-select, I'm holding command. I'm just going to, de-select all of the durations here for all of the channels and then I'm delete everything else.
Joey Korenman (00:13:20):
Okay. So now we literally just have key frames where every single hit is, and this is going to be a lot easier to deal with. Okay. And if you zoom out, this isn't even the whole song. The song is actually the part I recorded like a minute and a half long, but let's just deal with this part. Okay, cool. So here's the, here's where, here's where it gets crazy, frankly. Um, you know, and I want to just level with you guys that this is some pretty dense, uh, expression stuff here. And, um, you know, I'm, I'm, I'm going to walk you through it as best I can. What I suggest is if you really want to understand this, don't just watch this tutorial actually apply it. Um, I'll have the expression that you can copy and paste right off of this tutorials page. Um, and I'm going to walk you through them, but until you actually get in there and you type these things in, and you literally, I want you to type in the code yourself because your brain needs to sort of internalize it, wrap itself around.
Joey Korenman (00:14:21):
Okay. So how do we trigger something with a key frame? All right. This is just kind of a fundamental problem with after effects is how, how can I ant make an animation and then have it triggered really simply, um, based on key frames. So the, the main idea behind this actually comes from Dan Ebberts page motion script. If you get on there, he has a great tutorial. Now, the way he does it is he basically uses layer markers, right? These little to trigger animations. It's the exact same principle though. Okay. You using an expression to figure out based on the current time. All right. So let's here. Let me close this down and we'll just focus on, let's not use the high hat. Let's figure out which one is the kick. This is the kick right here. Okay. Channel one, actually, this is the snare, but good enough.
Joey Korenman (00:15:16):
We use the snare. Okay. If we want something to happen every time, boom, we hit one of these key frames. We need to know the current time of our comp. Right. And we need to know where the closest key frame is to the current time. Okay. And basically we're doing a little bit of checking on each frame, we're saying, Hey, am I on a key frame? Am I on a key frame? Am I on a key frame? Hey, I'm on a key frame on that frame that we're on a key frame. We're going to set the value of something to its initial value. All right. And then I'm not on a key frame anymore. I'm still not on a key from a slot on a key frame. Every time it's not on a key frame, it's going to figure out what should my current value be based on where the last key frame was.
Joey Korenman (00:16:03):
Okay. So for example, if I wanted a here we'll, we'll just use a circle. We'll start simple. Oh boy, people, here we go. Here we go. All right. So let's say here's a circle right on every snare hit. I want it to jump like, grow really fast and then slowly shrink down. Okay. So let's just animate that real quick. So you, you have to start your animations with kind of the idle pose. Okay. So this is the idol posts, just sitting there, put a key frame there as soon as it gets triggered. Right. I want it to be much bigger. And then over 12 frames, I want it to end up back at its initial value and let's just easy. Ease that. Okay. All right. So that's what a snare head's going to look like. Boom. Okay. And I want that animation to be triggered every single time we see a snare hit.
Joey Korenman (00:17:06):
Okay. So here's what we're going to do. We're going to write an expression to trigger this animation. Every time we hit the snare. Um, now the easiest way to do this is to sort of create your animation like this, right. And then pre comp the whole thing. All right. We'll just call this snare circle. Now, why are we pre comping it? Well, here's why, what we're going to be doing is we're going to have to sort of manually be controlling some property. Right. And if it was scale, uh, you know, that wouldn't be that hard if we only had a couple of key frames, but we have three key frames here and it's going to just get a lot more complicated if we try to, you know, have to decide, should the circle be at this value at this value or this value it's trickier with more than two values.
Joey Korenman (00:17:58):
So the great thing is once you've, pre-com something you can just time remap it. So I'm going to enable time remapping and I'm going to go forward and figure out like, okay, how much of this animation do I need? I really only need half a second. Right? Let's see, this is a 24 frames per second comp, the thing is done by frame 13. All right. So let's just call it a second. All we want is for the first second of this animation to be triggered every time there's a snare hit. Okay. So we basically need to write an expression for this. Um, that's going to figure out w you know, what frame should we be showing of this animation based on, uh, you know, where these key frames are? All right. So let's jump right in. Uh, so first we need to know, um, the beginning and ending value of that time remap, um, that we want to sort of interpolate between.
Joey Korenman (00:18:53):
Okay. So why don't we say start value equals zero. Cause we're going to start at the first frame, which is frame zero, and then the end value is going to be one. All right. Now, why is it one? Why isn't it 24 frames? Well, even though this time remapped property is showing you frames internally, it's working in seconds. It's just one of those confusing gotchas that you need to know when you're writing expressions on things that need a time you're going to, you're going to actually work in seconds, not frames. And if you want to work in frames, you need to convert and maybe divide the result by 24 or 30 based on the frame rate. All right. So now we know that, uh, we also need to know, um, what the current comp time is. So wherever our play head is, we need to know where that is.
Joey Korenman (00:19:38):
We don't need to do anything because after effects has a built in variable called time. Um, and so all you do is type in time and it will return whatever the current time is. But we do need to know where the nearest key frame is after effects has a, um, has a function built in that will let you figure out where the closest key frame is to anything. Okay. So, um, the way it works is this, I first need to tell after effects, which property I'm looking at to figure out where the closest key frame is that property in this case is this slider. So I'm going to make a variable. So our reference property equals, and then I'm just going to pick whip that slider. Cool. Next, um, I want to figure out where the closest key frame is. Okay. Um, and so what I'm gonna do, I'm gonna make a variable.
Joey Korenman (00:20:31):
I'm going to call it N right for nearest, and this is how it works to find the nearest key frame. You first type in the name of the property that you want to find the nearest key frame form. Then you add a period and you're going to add the function nearest key in parentheses. You then have to give after effects a time. And the T and the reason you can do that is because what if I wanted to know where the nearest key frame is to the beginning of my layer, right? And not necessarily the nearest key frame to my play head, but the nearest key frame to something else. So, because I want the nearest key frame to my play head, I'm just going to type in time and close that off. Okay, now this doesn't do anything yet, but I want to stop for a minute to show you a little trick.
Joey Korenman (00:21:19):
I use some times when I'm doing expressions to help me figure stuff out, I'm just going to make a type layer here, and I'm going to come up here. I'm going to open up the type layer and reveal the source, text, property source tax, lets you actually change what the type layer says. And you can put expressions on that. So if I copy this expression and I hold option, click the stopwatch and paste it in there. Uh, there we go. Um, what I want to do is I actually want this type layer to show me, uh, the current TA or sorry, not the current time. I want it to show me the time of the closest key frame. Like where in time is the closest key frame. Um, so I've got this variable here and right. And N you might think it's what it's actually going to return.
Joey Korenman (00:22:09):
Like the value event is going to be a time, but it's not what it's actually going to be is. And this may be weird if you have no programming experience, but N actually becomes a key frame. Okay. This nearest key function, it doesn't give you the time of the nearest key frame. It gives you a key frame. Once you have the key frame, you can ask the key frame, Hey, what time are you at? Right? Or what index number do you have, right. And the way you do that, you take the variable N and you put a dot and then you can ask it a question. My question to you then is what time are you at? Okay. And so now this type layer is going to show me the value of the nearest key frame, or, sorry, not the value, the time of the nearest key frame.
Joey Korenman (00:23:00):
So the nearest key frame, you can see this hasn't changed because if I'm at the beginning, this is the nearest key frame. If I'm here, it's the nearest key frame. And as I go forward, it changes right there because now the nearest key frame is here. And this is where we run into a little bit of a curve ball. Um, the value of the nearest key frame is going to change when we get to the middle. It, we, you know, there's not like a simple way to just say, okay, I want to know where the next key frame is. Right. It only can give you the nearest one. Um, another thing you can ask the key frame is what index are you right? And the index is literally, what number are you? You're the first key frame. You're the second, third, fourth, fifth. Right. Um, so that's going to be very useful too.
Joey Korenman (00:23:47):
All right. So let's just keep that up. It's just kind of nice to know, like when you're writing expressions and sometimes you're, you're having trouble figuring out what they're doing. Um, you can, you can just make a type layer and just use it almost like a little debugging thing. So let's lock that. All right. So let's hop back into our time remap expression. So Andy is actually the key frame. What I actually want him to be though is the index of the nearest key frame. And you'll see why in a minute. Okay. So, um, what we need to do is, so, so let me try to talk you through this. This is gonna be very hard to explain, but what I want this, this expression to do is check to see, Hey, are we on a key frame? If we're on a key frame, I want time remapped to be zero.
Joey Korenman (00:24:39):
And then as we get further and further away from the key frame, I want the time remapped to, to increase right, to play the animation that we've created in this pre-camp. And so if we're one second in front of this key frame, I want that animation to stop and let, and then we'll just wait until the next key frame. Boom, here's another key frame, go back to zero. And then as we get further and further away play and play, play up another key frame. So what we need to do, what we need to know in order to make that happen is we need to know what the differences between the current time and the time of the last key frame. Okay. So at the last key frame, you know, was a second ago, right. Then I know that a second has passed. So this time remapped should be one second, right?
Joey Korenman (00:25:30):
If it's a half second, this time remaps should be one second. So what I'm going to do is I'm going to subtract the current time or sorry, I'm going to subtract the time of the last key frame from the current time. And that'll basically give me the value of the time remap. Okay. Um, but then, uh, we have a wrinkle here because the only variable I have so far is the index of the nearest key frame, not the previous key frames. So in order to make sure we're always looking at the previous key frame, we need to check to see where we are in time and think of it this way. If we are, if the, if the current time right, is greater than the time of the nearest key frame, then that means we are in front of, of the key frame that we're focusing on, right.
Joey Korenman (00:26:19):
Once we get to here. Well, now that the time of the nearest key frame is actually greater than the current time. And in that case, we want to look back one key frame and make sure we're still focused on the right one. So that's why this variable N is now the index of the key frame, because what that's going to let me do is make a little condition. Okay. If this play is on or in front of the nearest key frame, then I want to use, I want to find out, okay, look right now, the nearest key frames index is one, and we know that our time is in front of this. Okay. Uh, then what I need to make sure is that I'm asking the key frame with the index of one, what time are you at? But as soon as we get closer to this key frame, well, now my index is switching.
Joey Korenman (00:27:11):
And so now the condition is the conditions being met that now the time of the key frame with index two is actually later than the current time. Well, in that case, I don't care about key frame index two. I still want key frame index one. So here's what we're going to do. This N is the index of the nearest key frame. And what I'm going to do is type in an if statement. Okay. And, and this is how it works. If parentheses, and then in parentheses, what condition are we checking is the current time. Uh, and I want to know, is it greater than or equal to the nearest key frame time? Okay. So is it greater than or equal to, and this is how you type that in greater than or equal to that's what that means. The time of the nearest key frame.
Joey Korenman (00:28:05):
Okay. Um, and so what I'm going to do, actually, let me quickly come up here and copy this and paste it. And I'm just going to make another variable called end time to make this easier to check. Okay. And all I'm doing is instead of getting the index, I'm getting the time of the nearest key frame. Okay. So if the time is greater than or equal to N time, right. Then what needs to happen? Um, well, in that case actually know what I'm doing this backwards. I screwed up, but I'm going to let you see it. I'm gonna let you see me squirm. Uh, here's what we're going to do. We are going to check if the time is less than or equal to the nearest key frame time now, why are we doing that? Okay. Okay. Here's why, if the, if the time is equal to, or greater than one of these key frames, then we don't have to worry about it.
Joey Korenman (00:29:03):
Okay. Uh, because all we need to do is ask the nearest key frame, Hey, what time are you at? And then subtract that time from the current time. And we'll get, we'll get our answer. The problem happens when we are, when the current time is less than the nearest key frame. And when that happens, we do need to deal with it. We do need something to happen. So that's why I'm going to deal with that condition. First, if that's the condition, the current time is less than or equal to the near ski frames time. If that is the case, um, you notice I just tabbed over, um, you don't have to do that. It just makes your code a little bit easier to read. Um, but if that happens, then I want to make sure that I am no longer looking at the key frame with index of two.
Joey Korenman (00:29:48):
I want to look at the key frame with index of one. So what I'm going to, what I want to do is basically take this variable N right, which is the index of the near ski frame. And I want to subtract one from it. So there's a sh that, you know, you could just say N equals N minus one, there's a shorter way to do it. Um, the shortcut is just N minus minus that just increments and by one, and you can also do N plus plus, right. But end minus, minus, and then go to next line. And I close the little curly brackets. Okay. So what that has done is we have a variable, N N is the index of the nearest key frame one or two in this case, it's two, but because the time of key frame two is actually ahead of our play head, we're going to increment and down by one.
Joey Korenman (00:30:42):
So now we're looking at this key frame again, what this ensures is that we're always looking at the key frame behind us. Okay, cool. So now that we've done that, what we need to do is figure out what is the difference in time between our current time and this key frames time. So what we need to do is now figure out the exact time of this key frame. Okay. So, so if we are here or we are here, what we want to use is this end variable. Okay. So what I'm going to do is just put the play head here, and let's say, um, that the, the near key time equals N okay. Uh, sorry. That's what we want to do. And is the index of, um, and is the index of this key frame? It is not actually the key frame. So what we're going to do is we have to type a slightly different expression here.
Joey Korenman (00:31:36):
We are going to start with this ref property Vale variable. So remember that ref property is referring to this slider here, and we're going to put a period and we're going to use the term key. What this allows us to do is actually access all the key frames on that layer. And if you type in key, and then in parentheses put a number like that, it will actually refer to the first key frame, right. Or the second key frame, if we put a variable in there, N it's referring to the N key frame, right? Whatever this number is, right. Whatever the value of N is, that's the key frame it's looking at. So, because we have this little [inaudible] in there, it's always going to be referring to the key frame just behind the plan. Okay. And now that we figured out what key frame we want, we can also ask that key frame.
Joey Korenman (00:32:28):
So dot time, Hey, so let me, let me try to put this in English for you. We are saying the near key time variable equals this property right here. And then we're asking that property. Hey, I want to know about the key frame with the index. N N right now is one. So I'm asking about this key frame, and then we're asking that key frame, Hey, what time are you at? And when that's the result, that's what this variable is gonna gonna get. Okay. And so then what we want to do, um, is we want to, why don't we just say D D is, uh, I w I always use D when I'm like doing a subtraction, because D is for Delta or like deltas in other words for change. Right? So the change D is the current time minus the near key time. Cool.
Joey Korenman (00:33:19):
So if we are here at one second, the time is one. And the key frame here is, uh, is at, you know, a little after half a second. Okay. So it's like 0.6. So D is going to equal 0.4. If the play head was right on this key frame D would equal zero. Okay. Because if, if we're sitting here at 0.6 seconds, and this is at 0.6 seconds, this key frame, then at zero, and as we get further away, that value will increase. So we have an increasing value, and we want to interpolate that value between zero and one seconds to play this animation. Okay. Hopefully it's starting to click, I know this is pretty, pretty wacky. So I'm gonna use the linear expression like we did in part one of this tutorial. So I'm going to say linear. We are looking at the variable D we know it's going to, it's going to go between zero.
Joey Korenman (00:34:20):
Um, and we actually don't know, um, you know, what value it's like, what the maximum value of it's going to be, but it really doesn't matter the way the linear expression works is if I give this a value of zero and one, and at some point, the value of D ends up being two, right. Greater than this range, what it does is it caps it, right? So this kind of clamps your values. Um, so since my start value is zero, and my end value is one, I want to make sure that I'm looking for zero and one. All right. Um, and an easier way to do this would just be, just use those variables, the start value and the end value. Okay. So we're looking at variable D looking for numbers between zero and one, and then we just want to, um, return values between zero and one.
Joey Korenman (00:35:09):
So in this case, this is actually kind of a unique case for this linear expression. Um, you know, we're, we're, we're using the same two variables here, and actually, I got to make sure these are case sensitive. So make sure that you use the same case when you do this. Um, you know, w we're basically interpret interrelating values of this variable from zero to one to zero to one. So that's why these are the same. Okay. Um, it won't be like that. Um, but for using, you know, for using linear to trigger animations, a lot of times you are using the same variables. All right. So let's, let's see what happens. All right. Let's see. This thing actually works. Okay. Um, so let's turn on our layer here. Alright. Now here is the problem. Okay. We're getting an error and this is where I had to, I had to look this up for help, cause I wouldn't have known how to do this either.
Joey Korenman (00:36:08):
Um, so th there's a problem. Uh, the first problem is if we, if we open up, I keep closing this, which I shouldn't, let's just leave it up. But if you look at this, uh, you're going to have a problem, um, at the beginning of the animation, right? Because there is no key frame back here. And the nearest key frame is, is in front of us, which means that we're actually gonna take the, this end variable and subtract one from it. The problem is this is the first key frame. So if we do that, we're going to have a problem. So what you can do is you can have another if statement saying, Hey, if the, if the nearest key frame to me is in front of me, and it's the first key frame, then don't do anything yet. Okay. Um, so why don't we try that?
Joey Korenman (00:36:53):
Let me just try that and see if that, if that does it, but, uh, I believe I'm still gonna have problems. So, um, so here's what we need to do. Okay. We're going to change this if then statement just a little bit. If the current time is less than or equal to the time of the next key frame. Well, that's, that's the case right now. Uh, the next thing we need to do is add one more F okay. So if that's the case, we'll then also check for this is N greater than one. Okay. Now the reason we're asking if N is greater than one is because there's this one case at the beginning of the animation, where the nearest key frame is in front of us. And normally what we want to do is make sure that we subtract one from men, so that we're looking at the previous key frame. Well, in this one, case B at the beginning, there is no key frame. So we don't want to do anything yet. Okay. So if N is greater than one, right. If we're already, um, if we're looking past this cool. Right. Um, but if not, don't do anything. Okay. And let's see here. So let's see, Hey, look at that. All right. So let's do [inaudible].
Joey Korenman (00:38:17):
Well, holy bud. Geez. Look at that. We have a working expression now. It's interesting. This is actually slightly different than the expression that I, that I use to actually make the demo. Um, if we look at that expression, let's see here. Um, I've actually had to include some other stuff, um, because I was getting errors and there's actually ways in after effects, expressions to check. Is there an error? And if there's an error, do this and if not do this, um, but it looks like right now everything's working. So I'm not going to look the gift horse in the mouth. All right. So hopefully you understand what's happening. Okay. We are, we're doing w you know, we're kind of doing a couple things where we're checking to see where the nearest key frame is. If it's in front of us, look back one key frame. So let's figure out how far we are from the previous key frame. And let's use a linear expression to trigger this animation. Now, here's, now this is great. Right. And, and, you know, for a kick drum or something like that, or, or something, that's just kind of repeating. Um, and you're not playing too many notes too close together. This is great. Okay. But let's go to here. This part where we have four snare hits in a row.
Joey Korenman (00:39:41):
Okay. Okay. You see how it gets a little funky in there. It gets a little funky in there. Okay. And the reason it's getting funky is because these are so close together and the animation starts to play boom, but then it has to then start over again. And it would be really nice if, if you could sort of have overlapping animations and not just have something that, you know, just basically it starts playing at the first frame and it plays until it hits another key frame. Then it jumps back to the first frame. You want it to be a little smoother and maybe have some overlapping notes and stuff, just to show you though how cool this is. So that's the snare circle, right? Um, if I, let me, let me scale this down a little bit, and then let's duplicate it and let's make this the kick circle, okay.
Joey Korenman (00:40:39):
Make this a hundred percent. And then let's just fill this with a different color. Right. So one will be to make a little darker. So one is going to be the kick one is going to be the snare. Um, and actually this is a good time to talk about sort of some of the other things I did with these expressions to make this a little bit easier to deal with. Right. Because what I want to do now is I want to use this exact same expression, except I want to reference a different property. Okay. And, you know, if I have to, if I have eight instruments or 10 instruments, and I want to keep coming in here, um, and, you know, changing this every single time, it gets a little bit annoying. Um, and it also could be a problem if I, you know, decided to tweak the media a little bit and reexport a new one.
Joey Korenman (00:41:30):
Um, and I just want to like, just bring in a new mini, but have all this stuff lined right up to it. Um, so what I did was I did a couple of things, right? So actually, let me turn this off for a minute. Um, let me actually delete this. And we're going to do a quick tweak to this snare expression. Uh, I'm going to add a new null and I'm going to call this a song control. And I'm just going to use this Knoll to tell every single layer in my comp that needs to know which layer has the MIDI information. Okay. And so I'm going to use an expression control called layer control, and this is going to be renamed to Mitty layer and this expression control it lets you pick any layer in your comp and then other layers can pick whip to that.
Joey Korenman (00:42:18):
Right? So my Mitty layer is, uh, is layer four MIDI. Okay. So first thing I could do is open up my expressions here and I can change the first part of this reference property equals. And instead of doing this right, this comp the layer called MITIE, um, I can pick whip if I open this up, I can pick whip to this. Okay. So now it's saying this comp the layer song control the effect MIDI layer. Okay. And what that's actually doing is it's going to pick the layer. It's going to pick, you know, your after effects layer from this. Okay. So that didn't mess anything up. Okay. It didn't change anything, but now if I ever needed to, I could pick a different Mitty and this would automatically update. Okay. The next thing I want to make easier on myself is I know that, um, you know, each of these, each of each of the instruments is on a different channel.
Joey Korenman (00:43:26):
Okay. And I want to easily be able to pick channels zero channel eight, channel 11, channel 10. I want to make this easy on myself. So on the actual snare circle layer, I'm going to add an expression control. That's a slider control. Uh, and I'm going to call that channel. Okay. And what I'm going to do here. Um, so first off, let's see. So we are currently using channel one. Okay. So let me make sure that this is set to channel one. And what I'm going to do is I'm going to make a new variable in this expression and I'm just going to call it channel and I'm going to set it to this. Okay. Um, and what I'm going to do is, uh, I'm going to change the, this part of the expression a little bit. Okay. So right now the reference property VA variable is being set to whatever layer is being picked here.
Joey Korenman (00:44:18):
And then on that layer, it's looking for an effect called channel one duration. And I don't want it to always look for that. I want it to look for channel, whatever is set to duration. Okay. So what I'm going to do is I'm actually going to close my quotes here. All right. And I'm going to close my quotes here. I'm gonna delete this one. That's hard-coded in there. Okay. And so what I'm going to do you see how I've separated these two parts of the, of the string C H underscore and underscore dur. And what I, what you can do is you can just add another part to this string and it'll sort of create the new, the new type for you, right. So C H underscore, and then I'm going to add whatever number that is. All right. So that number is whatever this channel variable is.
Joey Korenman (00:45:14):
And then I'm going to add the last part of that and hit enter. Um, and we are getting a, an error, um, and what it's, let's see. Error line four. Okay. So, so something here with the syntax isn't working, um, I think what it might be is, um, I need to make sure that this variable right now, you know, it's, it's giving me a number, but, uh, I need to make sure that it's actually giving me the value of that number and not like, uh, you know, some representation of that number. So I'm actually just going to add a dot value to the end of the channel. All right. So that fixed it. So channel equals that slider value and then that, that variable basically just gets plugged in there. And what's cool is if I duplicate this now, so that's my snare circle. So now let's make my kick circle. All right. And let's, uh, let's generate a fill and make it, you know, some kinda color and let's scale it back up to a hundred. Okay. So now what we have, we have two layers reacting to the snare, but I want this one to react to the kick. So let's figure out what channel the kicks on go into MITIE and let's just play it.
Joey Korenman (00:46:36):
All right. So it's this it's channel 11. Okay. So now if I just go here and I type in 11, Awesome. That cool. And now you could really easily, um, you know, if you wanted to do the high hats, you know, just like maybe scoot it over here. Let's figure out what channels, the high hat. It's this one channel zero. So you can just set this to channel zero. All right, right. And make this one much smaller. Let's make this a 20%
Joey Korenman (00:47:24):
Greatness. Okay. So now let's, let's talk about another way that you use this MIDI information. Okay. Because this is cool. And sometimes this is what you want, but sometimes you want things that can overlap. Um, and the best way to do that is with particles. Okay. So let's, uh, let's do this. Let's turn all this stuff off and let's, um, let me, let me find out where is this, uh, where is this pre comp it's here right here. Snare circle. Let's duplicate this and let's call this snare particle and let's, if this was going to be a particle, um, then what I would want is for eventually that to disappear. Okay.
Joey Korenman (00:48:10):
So why don't we say, um, let's do it this way. Okay. Let's have it start at scale zero. Um, and then really quickly grow fast. Okay. And then fade back over maybe a second, fade back to zero. All right. So that's the particle that I want to be spawned every time there's a snare head. Okay. Um, and what I'm gonna do, I'm gonna, I'm gonna trim the comp like this when you're making a particle for a, you know, any particle, um, effect to use, you want to crop your comp so that it's only as big as it needs to be. So I'm going to click my region of interest button, and I'm just going to try and crop this. So it's only as big as it has to be.
Joey Korenman (00:49:07):
Cool. And then you go, um, composition, crop comp to region of interest. There you go. So there's our particle boom. Okay. And it's actually, this is probably much bigger than we needed it to be too. Um, so why don't we actually shrink this down a little bit. I'm just going to shrink it. Um, maybe 400. All right. And then I can just grab all these key frames and scale them down a little bit, make sure this starts at zero and ends at zero. Cool. So there's our particle. I'm going to bring this in here and I'm going to hide it. I'm going to make a new solid, and I'm going to put particular on it, which is one of the best plugins out there. All right. So particular that, um, so particular, you know, this is kind of the default thing it does. And so what I'm going to do is first tell it to emit this as its particle.
Joey Korenman (00:50:07):
So let's come here. Uh, we'll vote of the particle settings and tr I mean, particular, I could do 10 tutorials on there's a ton of settings, and I'm just going to show you the ones you need, um, to get this effect to work. So the particle I'm gonna change that to a Sprite. All right. And Sprite just means it's going to let you use another layer as its particle. Then I'm going to go into texture and I'm going to say the layer I want you to use is this snare particle layer. Okay. Um, and time sampling, I want it to start at birth and play once. And what that means is when the, when the particle is born, uh, I want, I want it to play this animation one time and then the particles dead. And that's it. Okay. Um, you, you could, there's other cases where maybe you want it to loop the animation over and over again, but not in this case.
Joey Korenman (00:50:56):
All right. So then I'm gonna come up here and let me name this layer. Um, let's see, new snare particle. Okay. Uh, and, um, I'm just realizing that actually actually made all those changes on this particle, which is not what I wanted to do. So let me, let me fix that real quick. So this is going to be a Sprite and the texture is going to be snare particle. Okay. Um, then I need to make the size bigger so I can actually see. Okay. So cool. So you can see what's happening, boom. Right. It makes those particles, uh, and then that's it. Right. That's pretty cool. And what I want is to let me turn this off too, so you won't need that anymore. Uh, what I want to happen is I want, um, I want these particles to be born every single time. There's a key frame.
Joey Korenman (00:51:58):
Uh, one thing I need to change real quick at the time sampling on here is supposed to be start at birth play once. There we go. Okay. So what it's doing right now is it's generating these particles constantly. Okay. Cause that's what the plugin does. And so what I want to do is I basically want to have a burst of particles and the way you have a burst is you change the emitter settings. So the particles per second right now is 100. And so what I can do is I can put a key frame here, right? Make that a hold key frame, and then go forward one frame and make this zero. Okay. And so what that will do is it will just make a bunch of particles and then stop. And then if I want, I can do the same thing, go to zero now.
Joey Korenman (00:52:42):
Okay. So it makes particles, it stops. And then it makes more particles and stops and they see the flickering that's happening there. Uh, this is one of the annoying things about particular. Um, it actually, it has a, it kind of has a bug. It's a known thing where if you're changing values, sometimes it doesn't delete the old frames. It rendered, it keeps showing you old friends. Um, an easy trick is you just go into the random seed here and you'd change it. Right. And so now we'll kind of force it to rerender. Right. So there's one burst and there's another burst. Cool. So if we can get this particles per second to basically flip on for frame, and then flip off, we can create bursts of particles. Right. So what I'm to do, let me grab the expression that we wrote for our here's, our kick and our snare.
Joey Korenman (00:53:33):
Okay. So let's grab it from this, copy it. And let's bring it in here. Okay. So I'm going to put an expression on particles per second. I'm going to paste that in there, and here's what we're going to change instead of the, the result that we're sort of returning being, you know, this linear property here. Um, what we need to do is we actually need to see, okay. If our play head is on a key frame, then I want a burst of particles. If we're not on a key frame, I want no particles. So the behavior's a little bit different. We're not interpolated between values. We're saying I want to be on for frame and then off on for frame then off. Okay. So really all we need to check is, are we touching a key frame? So, um, we actually don't need to mess with all of this stuff.
Joey Korenman (00:54:30):
All we need to know is where's the nearest key frame, are we touching it? That's it. Okay. So near key time, we're still concerned with that. We're still concerned. We're still concerned with, um, the difference between the current time and the near key time. Um, but what we actually really want to know is, you know, sometimes like, you know, if I'm having trouble kind of articulating to myself what I need to do, I'll just sort of walk through it and kind of talk myself through it. So think about it. Where's the nearest key frame it's here. Okay. Are we touching it now? So we get here. Okay. We're touching it now. Okay. So here here's the tricky thing, right? Um, the nearest key frame is, is going to be some times, all right, look right there. The play head is here. The key frame is slightly in front of it.
Joey Korenman (00:55:24):
The key frame, the key, the play heads here, the key frames slightly behind it. The problem with media information is sometimes things do not come in on an exact frame. Okay. So what I actually need to do is check to see if, um, if we're very close to the key frame. So if I just tried to do something like this, right? Uh, let me come up here. Oh boy, here we go. If I tried to do something like this, right? Uh, if time equals and if you're checking, if something's equal in after effects, you have to have two equal signs, something to keep in mind if time equals near key time, then, uh, I want the value of the particles per second to be 100.
Joey Korenman (00:56:18):
Otherwise that's what else? This is how the Ellis thing works. I close one set of curlicues. I say, else I open up another set and then I can say zero. Okay. Uh, effects J oh, right. And, uh, I, I forgot. So the air, it just gave me as it's looking for an expression slider called channel on this, uh, on the Slayer, which doesn't exist. So what I'm going to do is I'm just going to copy this channel slider, paste it on here. So now that should work. Okay. Um, all right, cool. So, so we are getting some particles, so let's, let's listen to this and see what happens.
Joey Korenman (00:57:14):
That's not really working well, is it right? And we're getting like some random stuff here and, and it's just, it's just not happening for us. Um, and the reason is right, because if we, if we look here, we're never actually hitting that key frame, we're getting really close, but we're never actually hitting it. And so what we need to do is actually check if the, if D if the difference between the current time and the nearest key time is less than the duration of one frame. Okay. Um, so here's the problem with that. Sometimes D is going to be positive and sometimes it's going to be negative. So, uh, if you think back to, you know, algebra or, uh, remember when you learn this stuff now, but, uh, the concept of absolute value, right? So if something is negative one, or if something is one, the absolute value of both of those numbers is one.
Joey Korenman (00:58:10):
Joey Korenman (00:59:42):
All right. You see all that flickering. That is that awesome problem. That particular has where we need to change the random seed, get rid of our old frames.
Joey Korenman (01:00:02):
And there it is beautiful burst of particles created by committee notes. All right. Um, and so what I wanted to do was actually not have it create a whole bunch of particles, but just create one particle. Um, and so to do that, um, I kind of had to mess around right now. What it's doing is every time it hits a snare, it's for one frame, it's turning the particles per second to a hundred, and that's too high. Now, if I turn it to one, uh, the problem is one particle. And of course, now we have to change the random seat again. So, all right. Um, one value of one particle per second, it can work. The problem is sometimes it doesn't trigger, right. It triggers there, but then it misses one. So one isn't enough. And I kind of played with the values and eight seemed to work pretty well. And of course, we need to change the random seed. So it resets, here we go. Cool. Um, and these particles are moving. Um, and if I don't want them to move, I just set the velocity of the zero and the velocity random to zero. And then let me just turn the, um, let me turn the size of these particles up to, right. And there you go. Okay. And now we have our snare particle and it's, you know, it's pretty close to the animation that we had before, except now they can overlap.
Joey Korenman (01:01:48):
All right. Let's do the same thing with a Kik. Um, now that we've got this set up, it should be pretty easy. So let's just duplicate this call, this new kick particle, um, and all I need to do. All right. So the kick is on channel 11. So, and let me just set this to 11. Um, and then let's put, um, let's generate a fill effect for that and make it, you know, let's make it green this time. All right. And let's kind of scrub through, so there's my kick. Um, and for, we can make this one a little bit bigger, or actually maybe what we'll do is we'll make the snare particles a little smaller. All right. And we'll do a, let's go particle size, a little smaller. So there's some differentiation between the kick and the snare, and let's see what that looks like.
Joey Korenman (01:02:45):
So it appears to be working. Um, now, you know, I know that right now, this whole process, it must seem really finicky and what a pain in the butt, and here's the thing, right. Um, you know, eventually I'm sure someone is going to, you know, create a script or a plugin or something that makes this much, much easier. Um, you know, MIDI is far from the cutting edge, but using MIDI with after effects, it hasn't really taken off. It hasn't been that popular. And that's why it was not easy to, to find information about how to even try to do it. Um, and you know, unfortunately right now it's just sort of this clunky process. I guarantee you, um, if enough people start doing this, someone out there with a gigantic brain is going to make this much, much easier, but I'm actually pretty happy with the way this is working.
Joey Korenman (01:03:40):
And what I really hope is that it's, you know, we've really gotten into some deep expressions here, but, um, it's also just kind of interesting to look at after effects as this tool that you can plug in with other tools and do other neat little things with, um, you know, let's, let's do one more little experiment here, right? So, I mean, the beauty of this is now we've kinda got two ways of triggering animations, right? Like we've got, um, we have our high hat over here, which is being, which is just an animation, right. That's being triggered. Um, and why don't we make it a little bit more interesting to why don't we sort of, um, you know, why don't we make another little ellipse here, but kind of make it do something like this. Right. And, and it can start like this and rotate. It can just sort of like jump 90 degrees and then rotate back to zero. Right. And, um, you know, you know, just, you can just play with it and just see what you can come up with. Um, but this technique here, right of time, remapping a layer based on the MIDI information that works great for stuff that you want to be a little bit more complex in the way it moves. Um, but you can trigger simple things with particles,
Joey Korenman (01:05:02):
Right? So that's the high hat and you can see, it feels jerky because of how quick those high hits are coming. Um, but you can, you know, you can use particles to trigger kind of simpler things. Um, and then, uh, know the last thing I'll show you guys is you can just use particular sort of as a particle system and not even as a way to trigger animations. Um, the, we know that channel 11 is channel 11 is the, um, the kit. Okay. Um, and we know that channel eight is cow bell, right? Cause it's just a constant coordinate pulse. So what that means is channel 10, it must be that symbol. So why don't we have that symbol trigger, a big burst of particles. Okay. So I'm going to duplicate this and I'm going to call this new symbol, oh one particle. I'm going to change the channel.
Joey Korenman (01:05:59):
Um, two channel, I believe it was 10. I've already forgotten. This has been a long tutorial. It's just double check. Yep. Channel 10 is that symbol. And I'm going to just change the settings on this. Okay. So, um, instead of having the particles be a Sprite, I'm just going to have them be spheres and they can be much smaller. Right. It'd be five or something like that. Um, and so when I play this and I know I'm just going to do it preemptively, I'm going to have to change the random seed. So it sort of forces a rerender there.
Joey Korenman (01:06:36):
Okay. Um, now we're not seeing anything. Oh, there's zero velocity. So let's put some velocity on those particles who can actually get some movement. All right. So you see there's one particle floating away there. If you actually want particles like a big kind of fireworks looking thing, then going to 100 particles, sorry, eight particles per second, isn't going to do it. We need that number to be much higher. Um, and you know, I, I knew this and being that I don't like to have to keep diving in and, you know, diving into the code and finding where that, you know, number is, okay, it's hidden down here eight. Um, what I'd rather do is give myself a slider control and say, okay, these little burst versus the particles, how many particles should there be? And I'm just going to use that slider to drive this value.
Joey Korenman (01:07:30):
So instead of eight, it's going to use whatever I have this set to. So if I set this to a hundred, right, and then of course a particular to make this easier on myself, I'm actually going to duplicate the slider and I'm going to call this random seed. And I am going to make a quick expression, linking the random seed to let me see if I can actually get to it way down here, this slider, there we go. So now I can just change the random seed just by messing with that. That's a lot quicker. Right. And so now if we look at this,
Joey Korenman (01:08:07):
Right, and it's it, you'll see, it'll start taking a little longer preview, still, not enough. Let's let's up. That let's make that burst 2000. There we go. Great. That's better. Okay. And these particles are kind of boring right now. I mean, it works, but it's kind of boring. And so let me solo these for a minute. Uh, what I did in the demo was I really cranked up the velocity, like really, really high. So they really like explode when they come out. Um, but then at the same time, I went into the physics tab into the air tab and I turned up the air resistance a little bit. Right. So what it does is it has the, it makes them shoot out a really fast, but then they slow down. Right. And boom, right about there I'd like them to dissolve. So I'm also going to go into the particle setting here and I'm going to set the life to just one second, give them a, give that a little bit of randomness. Um, but then I'm going to go to opacity over life and I'm just going to have it kind of fade out over the lifespan. Okay. So now that burst is going to look like this. Cool.
Joey Korenman (01:09:29):
All right. And so there you go here, let's duplicate that high hat, stick that over there and let that render out. And, oh man, this was a long dance, just geek Fest of a tutorial people. Thank you. If you made it all the way through this and you ever meet me in person, I'll buy you a beer because God bless you. I mean, whew, this must've been tough. Um, but hopefully you learned something here. Uh, and if nothing else, you now have a little bit of an understanding of how fricking powerful expressions are. Okay. I mean, you got to understand that, like, you know, if you came up with some setup of particles and animations and things, you're triggering with Mitty and you love it and it looks awesome and some band wants to hire you to do that for their entire concert set. All you have to do is update the MIDI and this will all be done for you.
Joey Korenman (01:10:33):
Um, it's, it's amazing time-saver for doing stuff like this. And this is just the tip of the iceberg. This was kind of an obvious, uh, you know, way of using the MIDI information. There's probably a lot of other really cool things you could do. I mean, you know, using, um, if you had a mini keyboard and I mean, you could, I mean, there's ways you could map this to actually literally be able to play an animation and then have after effects, create it for you. Um, so anyway, I'm going to copy and paste these expressions onto the site. So you guys can just grab them and paste them right on and use them. Okay. Um, and I'll put some links to free Mitty resources in case you don't have the ability to actually use to create your own mini files. But if you do, if you're a musician or if you, if you don't mind sort of getting your hands dirty and programming some stuff, oh my goodness. What a cool trick this is. And, and think of all the amazing things you could do with it. So thank you guys. I really appreciate all the troopers who made it through this territorial promise. The next one will not be like this, but every once in a while, I got to go off the deep end. Thank you guys. I'll see you on the next episode of 30 days of after effects.
Joey Korenman (01:11:47):
That was a lot. Thanks so much for hanging in there. I really hope that this lesson showed you the power of after effects, expressions, and what you can do with them. If you understand a little bit, and if you're willing to tinker and kind of be like a mad scientist, you can pretty much make the program, do whatever you want, which is awesome. If you have any questions, let us know. And we'd love to hear from you if you use this technique on anything. So please give us a shout on Twitter at school emotion. Thank you so much. I'll see you on the next one.