Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions If Else with built in decay and no markers/keyframes?

  • If Else with built in decay and no markers/keyframes?

    Posted by Caleb Mclaughlin on October 8, 2015 at 2:34 pm

    tl;dr
    How can I trigger a value that decays without keyframes or markers to calculate decay time.

    I’m in pre-production for a music video using MIDI to trigger visuals. There will be a controller layer with keyframes generated from MIDI representing pitch and velocity from the MIDI file. I know how to map the opacity of a layer with a certain value from the control layer but can’t make it decay without using keyframes or markers. I want to avoid this because I plan to have 70+ layers (each mapped to a value from the controller layer).

    Here’s an example applied to a layer opacity:

    if (thisComp.layer(“Control”).effect(“Slider Control”)(“Slider”) ==5) 100 else 0

    This accomplishes the revealing of the layer every time the control value is 5, but strictly in an On/Off fashion.

    I tried using *time* to facilitate a decay:

    if (thisComp.layer(“Control”).effect(“Slider Control”)(“Slider”) ==5) 100/time else 0

    This won’t work because if the triggering happens later in the timeline, the decay has already begun.

    All the methods of decay I’ve seen use keyframes and markers to calculate time offset etc, but with 70 layers being triggered over and over, I don’t think that’s an option for me.

    Any ideas? I’m afraid I’ll have to go back to the drawing board pretty soon. Thanks guys!

    —————————–

    Caleb

    Caleb Mclaughlin replied 10 years, 7 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    October 8, 2015 at 4:33 pm

    You have to loop back in time until you find the most recent time where the note was on, and use the time since that event as the input to your decay formula. Probably something like this:


    myNote = 5;
    decayTime = .25;
    t = time;
    s = thisComp.layer("Control").effect("Slider Control")("Slider");
    while (t >= 0){
    if (s.valueAtTime(t) == myNote) break;
    t -= thisComp.frameDuration;
    }
    if (t > 0){
    easeOut(time-t,0,decayTime,100,0);
    }else
    0

    Dan

  • Caleb Mclaughlin

    October 8, 2015 at 6:46 pm

    How would you modify this to begin the decay as soon as the myNote value becomes 5? Not when it ceases to be 5?

    Looks like I have some reading ahead of me to understand how this works. Do you mind giving me a quick breakdown of how this works to point me in the right direction? Mainly the “break” and “while” and “t-“.

    Thank you, Dan, for all the help you give the AE community.

    —————————–

    Caleb

  • Dan Ebberts

    October 8, 2015 at 7:00 pm

    That’s a more complicated event detector. Basically, you have to find the most recent frame where the note went from not being the target value to being the target value. I don’t have time to set it up for you right now, but it will be very similar in concept to this:

    https://www.motionscript.com/design-guide/audio-trigger.html

    Dan

  • Caleb Mclaughlin

    October 9, 2015 at 2:29 pm

    Excellent, thank you. I’m eager to understand this myself and this is a great starting point.

    Again, thanks for your help.

    —————————–

    Caleb

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy