A simple javascript metronome.
CoffeeScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
src
.gitignore
Cakefile
LICENSE.md
README.md
package.json

README.md

Pendulum

Install with:

npm install pendulum

Simple metronome. You can include the script in your browser, or require it via Node.

Pendulum = require('pendulum').Pendulum;

In the browser, after including pendulum.js or pendulum.min.js, the Pendulum class will be available in the window object.

After that, creating a metronome is as simple as:

m = new Pendulum(80);

Where 80 is the beats-per-minute (BPM).

To start and stop the metronome:

m.start();
m.stop();

You may also want to change the BPM:

m.set(120);

Events

To register a callback function, use on.

m.on(event, callback);

The start event is fired when the metronome starts. The stop event is fired when the metronome starts. The bpm event is fired after calling set. The callback function takes two parameters: the old and the new BPM values.

m.on('bpm', function(oldBPM, newBPM) {
    console.log("BPM changed from " + oldBPM + " to " + newBPM);
});

Finally, the tick event is fired when the metronome ticks.

m.on('tick', function() {
    console.log("Tick!");
});

Todo

  • Set bpm using 'lento', 'adagio', etc.
  • Add musical meter notation ("3/4", etc) to stress different ticks