ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to target multiple keyframe to check their values from Slider Control

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Shah Raz
How to target multiple keyframe to check their values from Slider Control
on Jan 24, 2017 at 10:53:54 am
Last Edited By Shah Raz on Jan 25, 2017 at 12:49:57 am

First post here! Hello everyone ☺

If you are on the AfterEffects subreddit, you may have seen:

https://www.reddit.com/r/AfterEffects/comments/5pdszq/replicating_synthesia...

I am stuck at the part where chords come in (see multiple keyframes in some of the frames which represent a set of chords):

https://s29.postimg.org/xnn5bf7kn/midi_chord_keyframes.png

I have a bunch of layers in the comp (underneath the 'midi' layer using the following expression on the opacity property:

midiNote = thisComp.layer( 'midi' ).effect( 'ch_0_pitch' )( 'Slider' );
if ( midiNote == parseInt(X) ) 100 else 0; // where X = an integer


I need a hand in targeting the keyframes at any given time marker instead of the Slider value number.

How can I target all the keyframes instead of the one value that's showing in the Slider Control?

Thanks.


Return to posts index

Projectile Creative
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 26, 2017 at 1:26:54 am

I've changed the code slightly to this now per .ai file's layer in the comp:


midiNote = thisComp.layer( 'midi' ).effect( 'ch_0_pitch' )( 'Slider' );
noteActive =thisComp.layer("midi").effect("ch_0_vel")("Slider");
midiNumber = parseInt(name.split("/")[0]);
if ( midiNote == midiNumber && noteActive > 0 ) 100 else 0;


Still need to figure out how to target the multiple keyframes.

Hope someone can give me a hand here... Thanks :)


Return to posts index

Dan Ebberts
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 26, 2017 at 10:45:58 pm

Just curious--in your graph of the keyframe data, where are those keyframes?


Dan



Return to posts index


Shahid Raza
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 27, 2017 at 9:12:32 pm

Hi Dan!

Here's what those keyframes are if this is what you meant...







Thanks, looking forward to your reply!


Return to posts index

Dan Ebberts
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 27, 2017 at 9:52:47 pm

No, I meant what properties are they on?

DaN



Return to posts index

Shahid Raza
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 27, 2017 at 10:25:02 pm

Sorry, I'm not quite sure what you mean -- might be that I'm new to After Effects and all (like literally a week of proper messing about with it).

The keyframes were created by using the om_midi script from here: http://omino.com/pixelblog/2011/12/26/ae-hello-again-midi/

After importing the midi file, it created a null layer named midi with several Slider effects full of keyframes.

So those keyframes you are seeing are only on the midi layer's ch_0_pitch, ch_0_vel and ch_0_dur effects.

Would this be of help? I'm sorry if I'm sounding too noobish!


Return to posts index


Dan Ebberts
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 27, 2017 at 10:58:41 pm

I'm at a loss as to what you mean by "target multiple keyframes". The pitch slider can only have one note value at a time. Unless there are multiple channels--is that the case?

Dan



Return to posts index

Shahid Raza
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 27, 2017 at 11:02:46 pm

Hm, that's really odd. I have only one channel (ch_0) and the pitch slider has 2-3 or more in some cases within the same slider...

Could this be a bug with om_midi script or am I doing something wrong?

If you see this image from my previous post you'll see I have only highlighted the midi layer's ch_0_pitch slider:



There are no other layers down selected here. Just the midi layer.


Return to posts index

Dan Ebberts
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 28, 2017 at 12:02:30 am

I'm not quite sure what's going on there. A given frame can only have one keyframe value. It looks like you have some in quick succession, where maybe a chord is played, but each particular note value is held for only one frame. I'm not sure how an expression would know whether a particular note is still playing or not.

Dan



Return to posts index


Dan Ebberts
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 28, 2017 at 12:29:51 am

It would interesting to compare the midi data to the resulting keyframes. I wonder if each note duration is bookended by a pair of keyframes, one signifying note on and the other note off. if that's the case, the expression for each key would have to look at all the keyframes up to the current time to see how many times the value for his particular key shows up. If it's an odd number that note is on, if it's a even number the note is off. Definitely do-able if that's how it's set up.


Dan



Return to posts index

Dan Ebberts
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 28, 2017 at 7:31:16 am

OK, so if that's how it operates (keyframe pairs to designate note on/off) something like this should work:


midiNote = thisComp.layer( 'midi' ).effect( 'ch_0_pitch' )( 'Slider' );
midiNumber = parseInt(name.split("/")[0],10);
n = 0;
for (i = 1; i <= midiNote.numKeys; i++){
if (midiNote.key(i).time > time) break;
if (midiNote.key(i).value == midiNumber) n++;
}
if (n%2) 100 else 0



Dan



Return to posts index

Shahid Raza
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 28, 2017 at 6:11:26 pm

Awesome stuff! Works like a charm! However, the render times are really slow with it.

Is there anyway I make my code and structure efficient? I can send you the .aep file if needed.

I have 216 layers this code is applied to and it's taken 2hrs 30mins to get 50% through the render on 720p settings whereas the one I had previous expression was exporting at the same settings in 30 mins max.

Maybe my hopes of this template being something similar to Synthesia won't really work well... =/

But thanks for your help on this!


Return to posts index


Dan Ebberts
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 28, 2017 at 6:31:55 pm

How long is the comp? The issue is that for the expression to get the info it needs, at each frame it has to process all previous keyframes, which becomes more and more work as the comp progresses.

It would probably be much faster to have a script analyze the data and keyframe the keyboard keys on and off, because the script should only have to make one pass through the data.

Dan



Return to posts index

Shahid Raza
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 28, 2017 at 6:35:21 pm

Depending on the MIDI piece, it can vary. This comp is 3min 30sec and it does look like the estimated time keeps increasing.

How would I go about writing a script for the keyframe analysis on the midi layer or would you have something handy to do this kind of stuff?

Thanks again.


Return to posts index

Dan Ebberts
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 28, 2017 at 6:44:23 pm

It would be a pretty straightforward script if you have some scripting experience. If you haven't written a script before, it will take a while to get used to the AE object model, but this would be a good first script since it probably doesn't need a UI or any file I/O (depending on how much you want the script to do). This would be a fun one to learn on.

Dan



Return to posts index

Shahid Raza
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 29, 2017 at 12:17:39 am

I've never scripted before, so challenged accepted ☺

Worse case, I'm going to try and develop my own program / app like Synthesia if the rendering becomes an issue (which is even more of a challenge lol).

Thanks for the help with the keyframe stuff though.


Return to posts index

Dan Ebberts
Re: How to target multiple keyframe to check their values from Slider Control
on Jan 29, 2017 at 12:35:55 am

Ask questions if you get stuck.

Dan



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]