johanbaaij / bpm-counter

JavaScript library for calculating beats per minute.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bpm-counter

CI Workflow npm package MIT License semantic-release Maintainability Test Coverage

JavaScript library for calculating beats per minute.

⏱️ Uses performance.now() by default, override with your own timestamps if necessary
♻️ Automatically resets when pausing between taps

Usage

import { Counter } from 'bpm-counter';
const counter = new Counter();

Call the tap() method with a touch or click event.

counter.tap();

Optionally you can pass timestamps in ms.

counter.tap(0);
counter.tap(500);
counter.tap(1000);
counter.tap(1500);

Or initialize with an array of timestamps in ms.

const counter = new Counter([0, 500, 1000, 1500]);

To read the BPM:

counter.bpm;

Waiting 1.5 * average interval length will reset the counter. To reset manually:

counter.reset();

Installation

yarn add bpm-counter

or

npm install bpm-counter

Credits

  • TSDX – Zero-config CLI for TypeScript package development

About

JavaScript library for calculating beats per minute.

License:MIT License


Languages

Language:TypeScript 100.0%