https://github.com/sam-parsons/tempo-tap
measure speed of successive invocations
https://github.com/sam-parsons/tempo-tap
games music tap-tempo
Last synced: 5 months ago
JSON representation
measure speed of successive invocations
- Host: GitHub
- URL: https://github.com/sam-parsons/tempo-tap
- Owner: sam-parsons
- Created: 2019-07-02T23:41:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T03:27:50.000Z (over 2 years ago)
- Last Synced: 2023-03-07T19:58:43.481Z (about 2 years ago)
- Topics: games, music, tap-tempo
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/tempo-tap
- Size: 513 KB
- Stars: 5
- Watchers: 0
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tempo tap
tap tempo object to measure speed of successive invocations
## install
`npm install tempo-tap`
## example
```js
const { tapTempo } = require('tempo-tap');let tempo = 0;
// programmatically simulate one tap per second
tapTempo.tap();
setTimeout(() => (tempo = tapTempo.tap()), 1000);
setTimeout(() => (tempo = tapTempo.tap()), 2000);
setTimeout(() => (tempo = tapTempo.tap()), 3000);
setTimeout(() => (tempo = tapTempo.tap()), 4000);console.log(tempo); // 60 taps per second
```## api
#### Methods & Properties
* `.tap()` records a tap with Date.now(), stores inside TimeContainer
returns current tempo or -1 for insufficient data
* `.getLastTempo()` returns the last calculated tempo as a number
* `.clear()` clears TimeContainer, reinitiates the object
* `.setThreshold()` sets how many values TimeContainer must contain until it can make a tempo calculation - default is 3## license
Dual-licensed under the MIT License or the Apache License, version 2.0