Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Triggering Opacity (and other things) with Markers

  • Triggering Opacity (and other things) with Markers

    Posted by Adam Prejean on February 13, 2013 at 3:59 pm

    Hey all,
    I’m fairly new to expressions and scripting in AE. I’ve been messing around with this, but I decided to ask here since I can’t seem to figure it out. Currently, I’m visualizing pieces of music in MIDI format. As far as I can tell, AE doesn’t work with MIDI directly. And I need something more accurate than Sound Keys (need to be able to visualize individual instruments/notes).

    I’m using a modified version of this script so that it breaks the MIDI down further into individual notes AND it creates markers on null layers instead of keyframes. This allows me to use the Markers to trigger animations I want for the different notes as described by Dan Ebberts.

    So in my main Comp, I’ll have a PreComp for each note that contains the animation and has Markers named “start” and “stop” (for the MIDI note’s In and Out points).

    The idea was to have the animation playback when the “start” marker was hit and end at the “stop” marker. But following Dan’s method I realize I probably can’t do this since the layer is being time remapped and could possible disrupt the space-time continuum. So I decided to have the “start” marker trigger the animation, and have the “stop” marker affect the layer’s opacity. Ideally, I’d like the opacity to start fading out and finish at 0% when it hits the “stop” marker.

    The problem now is once the opacity gets down to 0% at the first “stop” marker, it stays at 0% for the duration of the comp. Is it possible to force the layer to be at 100% opacity at the “start” marker, fade down to 0% at the “stop” marker, and then be back at 100% by the time the next “start” marker hits?

    So for example…
    frame 10 at “start” marker – animation starts and layer is at 100% opacity.
    frame 100 – opacity starts fading out.
    frame 110 at “stop” marker – opacity is at 0%
    frame 150 at next “start” marker – animation starts and layer is back at 100% opacity.

    Is this even possible, or is there a better (much easier) way that I’m missing?

    Thanks!

    Scott Green replied 10 years, 1 month ago 5 Members · 11 Replies
  • 11 Replies
  • Dan Ebberts

    February 13, 2013 at 8:42 pm

    I think this does what you want:


    fadeFrames = 10;
    n = 0;
    if (marker.numKeys > 0){
    n = marker.nearestKey(time).index;
    if (marker.key(n).time <= time){
    n++;
    if (n > marker.numKeys) n = 0;
    }
    }
    if (n > 0){
    if (marker.key(n).comment == "stop")
    ease (time,marker.key(n).time - framesToTime(fadeFrames),marker.key(n).time,100,0)
    else
    0;
    }else{
    0
    }

    Dan

  • Adam Prejean

    February 13, 2013 at 9:51 pm

    That is exactly what I needed!

    One more thing… Some animations actually start before the note “hits”. For example, if my main Comp has a cube move across the screen entering screen Left and exiting screen Right, but the Trigger Marker is when the cube is in the center. In my PreComp for the cube’s animation the null “action” layer would have a Marker when the cube is centered. Using your time remap script as is, the cube would “pop” into existence in the center.

    I changed the line…
    if (marker.key(n).time > time){

    to this…
    if ((marker.key(n).time)-1 > time){

    … to have the frames prior to the trigger marker be visible.

    This works for the animation before the marker, but the cube disappears if it’s still visible when the next marker hits. Is there a way around this?

    Also, using the same cube example, I would need the opacity expression to allow the layer to be at 100% if the animation starts before the “start” marker.

    I’m assuming it’s correct that I can’t have a “start” and “stop” animation since the preComp is being time remapped. If the cube went across the screen for note “C#” and the same note happens again before the cube is finished moving across the screen, the cube would appear to snap back to it’s “start” marker position (not what I wanted). My work around for this has been to just duplicate the layer and add/remove markers as needed so that both instances of that note’s animation can play close together.

    I know a LOT of this can be manually keyframed (but why?). I’m trying to streamline a workflow so that changing the piece of music is a simple matter of running the midi script to get my markers.

    Thanks so much Dan!

  • Dan Ebberts

    February 13, 2013 at 10:17 pm

    I think this is closer, but I don’t think it’s everything you’re looking for. I hope it helps though.


    fadeFrames = 10;
    n = 0;
    if (marker.numKeys > 0){
    n = marker.nearestKey(time).index;
    if (marker.key(n).time <= time){
    n++;
    if (n > marker.numKeys) n = null;
    }
    }
    if (n > 1){
    if (marker.key(n).comment == "stop")
    ease (time,marker.key(n).time - framesToTime(fadeFrames),marker.key(n).time,100,0)
    else
    0;
    }else{
    if (n == null) 0 else 100
    }

    Dan

  • Adam Prejean

    February 13, 2013 at 11:17 pm

    That works, but If I add a 2nd set of “start” and “stop” markers I run into the same problem with the opacity snapping back to 100% for the 2nd “start” marker.

    Is there a way to set opacity at 100% 20 frames prior to the “start” marker?

    Also, any ideas on the time remap portion to have it show the animation that happens before the hit? Similar to your audio sync example with the drummer, but if the arm’s animation was slower, it would disappear before reappearing for the next animation to start.

    Thanks so much for your help!

  • Adam Prejean

    February 14, 2013 at 3:39 pm

    This seems to be working the way I need. Not sure if it needs to be cleaned up a bit though.

    fadeFrames = 10;
    n = 0;
    if (marker.numKeys > 0){
    n = marker.nearestKey(time).index;
    if (marker.key(n).time &lt;= time){
    n++;
    if (n > marker.numKeys) n = 0;
    }
    }
    if (n > 0){
    if (marker.key(n).comment == "stop")
    ease (time,marker.key(n).time - framesToTime(fadeFrames),marker.key(n).time,100,0)
    }else{
    0
    }
    if (n > 0){
    if (marker.key(n).comment == "start")
    ease (time+.5,marker.key(n).time - framesToTime(1),marker.key(n).time,0,100)
    }else{
    0
    }

  • Erik Woodard

    February 21, 2014 at 4:43 pm

    I’m trying make one layer follow a leader layer after a marker trigger. And I want it to continue to follow until the next marker. But I can’t even get the first trigger to work.

    Any thoughts?

    n = 0;
    if (thislayer.marker.numKeys > 0){
    n = marker.nearestKey(time).index;
    if (marker.key(n).time > time){
    n--;
    }
    }

    if (n = 0){
    value;
    } else {
    (thisComp.layer("1claws")transform.position);
    }

  • Dan Ebberts

    February 21, 2014 at 5:00 pm

    Your test for a zero value of n should be like this:

    if (n == 0){

    Give that a try.

    Dan

  • Lukasz Pason

    January 22, 2015 at 8:06 pm

    If I wanted the numbers to be Whole numbers, can i just place a math.round at the end of the script? Also, can the numbers be random between say 1-50 until it reaches the Stop marker?

    Motion Designer / DJ / Father
    http://www.lukaszpason.com

  • Scott Green

    March 11, 2016 at 10:13 am

    Hi,

    I’m wondering if you can help me with something similar to this.

    I’ve used LayerMonkey to create a sort of slideshow between comps and on my final comp that I’ve named “OUTPUT” I’d like to trigger a blur value of 25 when each of the LayerMonkey markers in my pre-comp appears.

    So, in English it would say”

    In the comp named “OUTPUT” on the layer called “MASTER v002” give the FAST BLUR effect a BLURINESS value of 25 when the the comp named “MASTER v002” on the layer called “LM Master Control” has a marker.

    Can you help me to come up with a script I can try for that please?

    Many thanks,
    Scott.

    Motion Videos UK – We are creative video designers who bring pleasure, meaning and beauty to our small world through film, motion graphics and animation.

  • Dan Ebberts

    March 11, 2016 at 3:01 pm

    You didn’t mention the duration of the blur, so I took a guess. Try this:


    blurDur = .3;
    blurMax = 25;
    m = comp("MASTER v002").layer("LM Master Control").marker;
    n = 0;
    if (m.numKeys > 0){
    n = m.nearestKey(time).index;
    if (m.key(n).time > time) n--;
    }
    if (n > 0){
    t = time - m.key(n).time;
    linear(t,0,blurDur,blurMax,0)
    }else
    0

    Dan

Page 1 of 2

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