Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trying to linearly map markers to keyframes

  • Trying to linearly map markers to keyframes

    Posted by Andrew Davies on July 22, 2012 at 6:34 pm

    I’m trying to link the value of an expression slider to the index of the layer’s markers so that I don’t need to adjust the keyframes of the slider, just the layer markers.

    So far I have this applied to the slider:

    m=thisLayer.marker.nearestKey(time);
    m.index;

    which works so far. But what this does is snaps the value of the slider to each index (e.g. 1 to 2 to 3) and I want it to linearly move from one index to the next (e.g. 1 to 1.1 to 1.2… until it gets to 2).

    I thought it would be something simple, but don’t know enough about how the linear function and layer markers works to know exactly what to do, if it’s possible.
    Any help or suggestions on reading materials would be greatly appreciated.

    Thanks.

    Andrew Davies replied 13 years, 10 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    July 22, 2012 at 8:31 pm

    This should be close:


    m = marker;
    if (m.numKeys > 0){
    if (time > m.key(m.numKeys).time){
    m.key(m.numKeys).index;
    }else if(time <= m.key(1).time){ 0; }else{ i = m.nearestKey(time).index; if (time <= m.key(i).time) linear(time,m.key(i-1).time,m.key(i).time,i-1,i) else linear(time,m.key(i).time,m.key(i+1).time,i,i+1); } }else value

    Dan

  • Andrew Davies

    July 23, 2012 at 4:33 am

    That works! amazing, thanks so much.
    I understand the top few lines; checking if there are any markers and setting the values if the CTI is before or after the marker range, but if you have time could you explain what the last bit is doing?

    Namely:

    linear(time,m.key(i-1).time,m.key(i).time,i-1,i)
    else
    linear(time,m.key(i).time,m.key(i+1).time,i,i+1);

    Thanks again.

  • Dan Ebberts

    July 23, 2012 at 5:12 am

    Basically that part checks to see if the current time is before the nearest marker, if so it interpolates between the previous and nearest markers, otherwise (current time is after nearest marker) it interpolates between the nearest and next markers.

    Dan

  • Andrew Davies

    July 23, 2012 at 1:07 pm

    Thanks Dan. Much appreciated.

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