Skip to content

Instantly share code, notes, and snippets.

@rnmeow
Last active April 21, 2023 14:42
Show Gist options
  • Save rnmeow/f0f01730524dadc429c9d1a41219644c to your computer and use it in GitHub Desktop.
Save rnmeow/f0f01730524dadc429c9d1a41219644c to your computer and use it in GitHub Desktop.
Modern JavaScript code of music timer for Adobe After Effects.
/* 1. Timer */
function padZero (n) {
if (n < 10) return '0' + n;
else return n.toString()
}
t = Math.floor(Math.max((time - inPoint), 0));
min = Math.floor((t % 3600) / 60);
sec = padZero(Math.floor(t % 60));
`${min}:${sec}`
/* 2. Timer with 2-digit Milisecond */
function padZero (n) {
if (n < 10) return '0' + n;
else return n.toString();
}
t = Math.floor(Math.max((time - inPoint), 0));
min = Math.floor((t % 3600) / 60);
sec = padZero(Math.floor(t % 60));
ms = Math.max(time - inPoint, 0).toFixed(2).substr(-2);
`${min}:${sec}.${ms}`
/* 3. Timer with Hour */
function padZero (n) {
if (n < 10) return '0' + n;
else return n.toString();
}
t = Math.floor(time - inPoint);
hr = padZero(Math.floor(t / 3600));
min = padZero(Math.floor((t % 3600) / 60));
sec = padZero(Math.floor(t % 60));
`${hr}:${min}:${sec}`
/* 4. Timer Countdown */
const TOTALTIME = 200; // Modify this value! (unit: seconds)
function padZero (n) {
if (n < 10) return '0' + n;
else return '' + n;
}
let t;
t = Math.floor(Math.max(TOTALTIME + -1 * (time - inPoint), 0));
let min, sec;
min = Math.floor((t % 3600) / 60);
sec = padZero(Math.floor(t % 60));
`-${min}:${sec}`
/* 5. Timer Countdown with 2-digit Milisecond */
const TOTALTIME = 200; // Modify this value! (unit: seconds)
function padZero (n) {
if (n < 10) return '0' + n;
else return '' + n;
}
let t;
t = Math.floor(Math.max(TOTALTIME + -1 * (time - inPoint), 0));
let min, sec;
min = Math.floor((t % 3600) / 60);
sec = padZero(Math.floor(t % 60));
ms = Math.max(100 - (time - inPoint), 0).toFixed(2).substr(-2);
`-${min}:${sec}.${ms}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment