FORUMS: list search recent posts

# Trying to linearly map markers to keyframes

FAQ   •   VIEW ALL
 Trying to linearly map markers to keyframes on Jul 22, 2012 at 6:34:06 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.

 Re: Trying to linearly map markers to keyframeson Jul 22, 2012 at 8:31:14 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

 Re: Trying to linearly map markers to keyframeson Jul 23, 2012 at 4:33:35 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.

 Re: Trying to linearly map markers to keyframeson Jul 23, 2012 at 5:12:30 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