BeatTimer: Synchronize with the beat
In the previous my entry, I introduced the dotFes Clock. I used some tricks to synchronize with the BGM strictly in it. One is a BeatTimer.
It is a timer to synchronize with the beat. If you create an instance of the BeatTimer and call the start method with a tempo by BPM, it starts time counting since the current time.
var timer:BeatTimer = new BeatTimer();
timer.start(140);
And it updates some properties based on the time lapsed since the time of the timer has started if you call the update method.
timer.update();
Then, you can get some useful values.
- beatPosition: Indicates how many beats have been passed. For example, when three quarter notes and an eighth note are passed, the property returns 3.5.
- phase: Indicates a position on the beat. If the new beat started, it indicates 0.0 and if the beat finished, it indicates 1.0.
- isOnBeat: Indicates whether it has been in the new beat by the update method call this time.
For example, you can trace a message with 4 beat kicks by the following code:
if (timer.isOnBeat) {
trace('Kick!');
}
In the dotFes Clock, I used it to change motion parameters synchronizing the rhythm.
1 Comment
[...] BeatTimer: Synchronize with the beat [...]