GithubHelp home page GithubHelp logo

bpm-counter's Introduction

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

bpm-counter's People

Contributors

johanbaaij avatar semantic-release-bot avatar

Watchers

 avatar  avatar

bpm-counter's Issues

Passing timestamp that breaks chronological order

Describe the bug
When passing a timestamp that breaks chronological order the calculated BPM is incorrect.

To Reproduce

counter.taps
// -> [0, 500, 1000, 1500]

counter.bpm
// -> 120

counter.tap(250)
counter.bpm
// -> 960

Expected behavior
reset() should be called.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.