(Japanese | English)

BeatTimer

A utility for a developer who want to do something synchronizing the rhythm.

Source

Usage

Create a instance at first.

var timer:BeatTimer = new BeatTimer();

Next, call the start() method with a BPM that you want to synchronize.

timer.start(140); // Start with a BPM: 140

Call the update() method in arbitrary timing. Basically, this utility suppose usage that call the update() method every frame (ex: in Event.ENTER_FRAME).

timer.update();

If you call the update() method, the following properties will be updated based on the time lapsed since the time that the start method() has called and the BPM.

  • 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.

License

Licensed under the MIT License

Copyright (c) 2008 BeInteractive! (www.be-interactive.org) and Spark project (www.libspark.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Author