Activity › Forums › Adobe After Effects Expressions › expression needed to count time while song plays
-
expression needed to count time while song plays
Posted by Michael Mazur on April 30, 2007 at 10:41 pmI am making a DVD for a band and they want a live “player” with a counter on it while the songs are playing. How can I animate a counter to count seconds and minutes acurately while these songs play? Obviously I know that it can be done manually, but that would be a rediculously long task. Please help.
Andrew Morgan replied 13 years, 2 months ago 5 Members · 9 Replies -
9 Replies
-
Colin Braley
May 1, 2007 at 12:00 amPaste this expression into the sourceText property of a text layer and you will have a nice minutes and seconds counter:
//begin expression
amtOfDigits = 2;
seconds = Math.round( time % 60 );
minutes = Math.floor( time / 60 );
function addLeadingZeroes( v ){
for( i = 0; i < Math.abs( amtOfDigits - (v + "").length ); i++) v = "0" + v; return v; } addLeadingZeroes(minutes) + ":" + addLeadingZeroes(seconds) //end expression~Colin
-
Lord Scales
May 1, 2007 at 12:45 am[Colin Braley] “{
for( i = 0; i < Math.abs( amtOfDigits - (v + "").length ); i++) v = "0" + v; return v; }"I understood almost nothing there =(.
Could you explain what “++” does? And “”? And the “return”?
Sorry I don’t know this very weel.You can add a Text > Timecode or this expression in the Source Text: timeToTimecode(t = time + thisComp.displayStartTime, timecodeBase = 30, isDuration = false), but the Colin’s is much better!
Lord Scales
-
Michael Mazur
May 1, 2007 at 12:55 amWhat is in the original text layer? Also, could you write the expression exactly how I need to put it in? I am new to this and I am confused. Thanks.
-
Filip Vandueren
May 1, 2007 at 1:02 amThe content of the original textlayer is not important. Only it’s font, color, size etc. will be retained, the actual text will be replaced by a clock.
After creating a Textlayer twirl open the layer in the Timeline and you’ll see a property called sourceText.
Option- or Alt-Clic on it’s stopwatch icon, and you’ll be in the expression editor.Paste Colin’s entire expression there (everything inbetween the // lines).
No change is needed. -
Colin Braley
May 1, 2007 at 1:03 amAlright, heres a more step by step description of what to do:
-Import your song into AE
-Drag your song onto the “Create new comp” button at the bottom of the project window, and you will have a comp that is the same duration as your song
-Create a new text layer by going to Layer>New>Text.
-Select this new text layer, and twirl down the little trianges until you see a property called “Source Text”
-Select the “Source Text” property and goto Animation > Add Expression, or just alt+click on the stopwatch.
-In the little text are that is created for your expression copy and paste in the following code:
amtOfDigits = 2;
seconds = Math.round( time % 60 );
minutes = Math.floor( time / 60 );
function addLeadingZeroes( v ){
for( i = 0; i < Math.abs( amtOfDigits - (v + "").length ); i++) v = "0" + v; return v; } addLeadingZeroes(minutes) + ":" + addLeadingZeroes(seconds)~Colin
-
Michael Mazur
May 1, 2007 at 1:13 amI got it to work. One last question, why does it count up to 60 and then quickly change to one minute? Can I make it go from :59 to 1:00?
-
Colin Braley
May 1, 2007 at 1:17 am[Lord Scales] “I understood almost nothing there =(.
Could you explain what “++” does? And “”? And the “return”?”Lord Scales, heres a quick explanation:
the following section of code:
function addLeadingZeroes( v ){
for( i = 0; i < Math.abs( amtOfDigits - (v + "").length ); i++) v = "0" + v; return v; } is just creating a custom function to add leading zeroes to a number. Functions like this aren't really necessary, they are just a handy way to keep you from writing the same code multiple times throughout an expression. Once you have "declared" this function, you can use it just like any other function built into AE like random(), Math.round(), etc. This function takes in 1 "argument," which will be referred to as "v" within the function itself. It takes this number v, converts it into a String (a series of letters) and then adds some zeroes to the front of it. The code: for( i = 0; i < Math.abs( amtOfDigits - (v + "").length ); i++) v = "0" + v; is something called a "for loop." It is just a looping structure, similar to other loops you may have head of like a "while loop." You could use a while loop in this situation, I just like using for loops because they are more concise. All this loop is doing is adding zeros to the front of "v" until the number of digits in the number is equal to the variable amtOfDigits. If you want a more detailed description of how this loop is actually working, let me know, but I reccommend you learn about basic for loops and while loops in javascript first. And by the way, the line with "return v" is just saying "the result form this function to be given back is v." ~Colin -
Lord Scales
May 1, 2007 at 2:02 amThanks, Colin!!
I am going to do some tests here but I didn’t get the “i++” yet.
Lord Scales
-
Andrew Morgan
March 6, 2013 at 7:42 amYes, just change both the “60”‘s to “59”‘s in the expression.
Reply to this Discussion! Login or Sign Up