ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Animation triggered by markers (once again...)

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Rafael Braz
Animation triggered by markers (once again...)
on Jun 23, 2019 at 8:30:36 pm
Last Edited By Rafael Braz on Jun 23, 2019 at 8:33:20 pm

Hello!

I've spent the last couple of days trying to solve this but I still lack of some javascript knowledge.
I searched the forums and tweaked some expressions. It almost worked the way I need except it stopped halfway(?). 😭



The thing is...

I have a text layer with notes, one by line, as you can see on the left. (It's for a music teaching project.)
The idea is to connect the marker index and the text line index (+1 because line counting starts from 0 and markers from 1).

Example:

The 3rd marker (marker index = 3) will get me the 3rd line on the text layer. In that case it's "A2".
If the layer name is "A2", its opacity goes to 100% until the next marker. (Unless the next marker calls the same note on the text layer).

This is the expression on the Fill effect on the layers called A2, F and D:
(The layer "notas" contain all the notes one by line. )

txt = thisComp.layer("notas").text.sourceText.split("r");
nota = thisLayer.name;

m = thisComp.marker;
n = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (m.key(n).time > time) n--;
}
if ((n > 0) && (txt[m.key(n).index+1] == nota)){
100;
}else
0


So... it worked until it doesn't as you can see on the gif. There are 9 lines of text for 9 markers.

It looks like a very specific doubt but the idea is simple.

The marker index defines the text line and if its content equals the layer name, opacity goes 100.
It must last until the next marker unless it's the same content.

I think I'm this close...

edit: I tried to understand and steal this code on Dan's page.
https://www.motionscript.com/design-guide/marker-sync.html
but I couldn't understand it properly...

Thanks in advance.


Return to posts index

Andrei Popa
Re: Animation triggered by markers (once again...)
on Jun 24, 2019 at 8:38:42 am

That split in line one should have "\r" as parameter, not "r". I think you missed something when copying the expression, because that should break it.

And your behaviour is due to the handeling of the array "txt". Subtract 1 from marker instead of adding. You are starting from row 3.

txt = thisComp.layer("notas").text.sourceText.split("r");
nota = thisLayer.name;

m = thisComp.marker;
n = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (m.key(n).time > time) n--;
}
if ((n > 0) && (txt[m.key(n).index-1] == nota)){
100;
}else
0


Andrei
My Envato portfolio.


Return to posts index

Andrei Popa
Re: Animation triggered by markers (once again...)
on Jun 24, 2019 at 8:40:02 am

I also messed up the "r" thing.

txt = thisComp.layer("notas").text.sourceText.split("\r");
nota = thisLayer.name;

m = thisComp.marker;
n = 0;
if (m.numKeys > 0){
n = m.nearestKey(time).index;
if (m.key(n).time > time) n--;
}
if ((n > 0) && (txt[m.key(n).index-1] == nota)){
100;
}else
0


Andrei
My Envato portfolio.


Return to posts index


Rafael Braz
Re: Animation triggered by markers (once again...)
on Jun 24, 2019 at 1:29:47 pm

The HTML always messes the "r" thing... in my code it is correct.
I couldn't find any difference between our codes except the "r" thing.

Anyway, after searching more in the forums, trying, tweaking, I found a way out!
I'll post when I get home.


Return to posts index

Andrei Popa
Re: Animation triggered by markers (once again...)
on Jun 24, 2019 at 1:49:12 pm

[Andrei Popa] "And your behaviour is due to the handeling of the array "txt". Subtract 1 from marker instead of adding. You are starting from row 3."

That was the difference in our code.

Andrei
My Envato portfolio.


Return to posts index

Rafael Braz
Re: Animation triggered by markers (once again...)
on Jun 25, 2019 at 9:45:05 pm

just tried but it didn't work ☹
on the 5th marker both "A2" and "D" opacities are 100

this is the code I wrote on a slider (actually I found reading old threads...):

m = thisComp.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;
m.key(n).index
}else
0


it gave me exactly what I needed.

if time is less than marker1 time, the slider value is 0.
if time is more than marker1 time and less than marker2 time, the slide value is 1.
and so it goes. it changes each time the needle pass over the next marker.


Return to posts index

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