FORUMS: list search recent posts

Crossing Keys and changing values...

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ed Nudnick
Crossing Keys and changing values...
on May 25, 2013 at 1:43:11 am

I have a project with a text layer displaying text spoken by a narrator.
The current word being spoken changes its Fill Color as a narrator speaks.

That much of the script works beautifully... (I must thank the amazing Mr. Dan Ebberts for posting his snippets of wisdom on these forums for making this much possible).

The layer, "transcribedSOUND.wav" is an audio layer, peppered with transcription markers as processed by Adobe Premiere and Adobe Media Encoder.

Now, here's my issue...

The text layer has an animated sourceText value.
So, every time I encounter a text keyframe, I'd love to be able to set my variable, HLword back to one (1).

Though, I seem to be getting lost every time I include this in a similar if...else statement.

I think it should go like this:

xx = 0;
if (text.sourceText.numKeys > 0)
{xx = text.sourceText.nearestKey(time).index;
if (text.sourceText.key(xx).time > time) xx--;
}
if (xx > 1)
{if (xx%2)
{SOMETHING}
else
{SOMETHING}
}
else
{SOMETHING_ELSE}

transSOUND = thisComp.layer("transcribedSOUND.wav");
HLword = 0;
n = 0;
if (transSOUND.marker.numKeys > 0)
{n = transSOUND.marker.nearestKey(time).index;
if (transSOUND.marker.key(n).time > time) n--;
}
if (n > 0)
{if (n%2)
{HLword = n;}
else
{HLword = n;}
}
else
{HLword;}


Return to posts index

Dan Ebberts
Re: Crossing Keys and changing values...
on May 25, 2013 at 5:17:53 am

I'm not sure, but it sounds like you're trying to create a persistent variable (something that survives from one frame to the next), which you can't do. If what you're really after is the number of markers that have occurred since the last keyframe, your expression will have to count them. I can help you with that, if that's indeed what you're trying to do.

Dan



Return to posts index

Ed Nudnick
Re: Crossing Keys and changing values...
on May 25, 2013 at 2:19:37 pm

That sounds about right...
Though, I realize I forgot all about the value of poor little "n," which is really where the magic happens.

I think the logic behind what I'm after (at this point) is to reduce n to 1 (one) in the following manner:

Subtract the value of the marker index from the current value of n each time the index value of the sourceText keyframes increases.

To achieve this, I don't think I need to embed my original (and most importantly), working expression into another IF... ELSE statement.

But, I just have to parse the logic into another javascript/Adobe-speak hybrid.


Return to posts index


Ed Nudnick
Re: Crossing Keys and changing values...
on May 25, 2013 at 3:06:55 pm

Ok. I'm getting MUCH closer.

Though, I'm having some difficulty in remembering how to prevent a value from changing until the current time actually crosses the time at the marker.

The function of "Nearest" seems to be giving me a rounding error.

transSOUND = thisComp.layer("transcribedSOUND.wav");
HLword = 0;
n = 0;
nn = 0;
xx = 0;
xxt = 0;

if (text.sourceText.numKeys > 0)
{xx = text.sourceText.nearestKey(time).index;
xxt = text.sourceText.key(xx).time;
if (xxt > time) {xx--;
}}

if (xx > 0)
{if (xx%2)
{x = xx;}
else
{x = xx;}
}
else
{x;}

if (transSOUND.marker.numKeys > 0)
{nn = transSOUND.marker.nearestKey(time).index;
n = (transSOUND.marker.nearestKey(time).index - transSOUND.marker.nearestKey(xxt).index + 1);
if (transSOUND.marker.key(nn).time > time) nn--;
}

if (n > 0)
{if (n%2)
{HLword = n;}
else
{HLword = n;}
}
else
{HLword;}


Return to posts index

Ed Nudnick
Re: Crossing Keys and changing values...
on May 25, 2013 at 3:28:49 pm

Sorry. Sorry...

The expression below is where I'm currently stuck

transSOUND = thisComp.layer("transcribedSOUND.wav");
HLword = 0;
n = 0;
nn = 0;
xx = 0;
xxt = 0;

if (text.sourceText.numKeys > 0)
{
xx = text.sourceText.nearestKey(time).index;
xxt = text.sourceText.key(xx).time;

if (xxt > time) {xx--;
}}
if (transSOUND.marker.numKeys > 0)
{nn = transSOUND.marker.nearestKey(time).index;
n = ((transSOUND.marker.nearestKey(time).index - transSOUND.marker.nearestKey(xxt).index )+1);
if (transSOUND.marker.key(nn).time > time) nn--;
}
if (n > 0)
{if (n%2)
{HLword = n;}
else
{HLword = n;}
}
else
{HLword;}


Return to posts index

Dan Ebberts
Re: Crossing Keys and changing values...
on May 25, 2013 at 4:30:20 pm

I think this is closer to what you're after:


count = 0;
t = 0;
n = 0;
if (text.sourceText.numKeys > 0){
n = text.sourceText.nearestKey(time).index;
if (text.sourceText.key(n).time > time)n--;
}
if (n > 0) t = text.sourceText.key(n).time;
m = thisComp.layer("transcribedSOUND.wav").marker;
k = 0;
if (m.numKeys > 0){
k = m.nearestKey(time).index;
if (m.key(k).time > time)k--;
}
if (k > 0){
while ((k >= 1) && (m.key(k).time >= t)){
k--;
count++;
}
}
count



Dan



Return to posts index


Ed Nudnick
Re: Crossing Keys and changing values...
on May 25, 2013 at 4:41:25 pm

Perfect!

I keep forgetting about while functions and wind up concocting a bunch of IF's embedded into IF's.

Thanks, Dan!


Return to posts index

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