audiocn

useTapTempo

Tap tempo with a rolling average and idle reset.

useTapTempo powers the tempo control. Use it with your own input, sound pad or keyboard shortcut.

$ pnpm dlx shadcn@latest add @audiocn/use-tap-tempo

Usage

import { useTapTempo } from "@/hooks/use-tap-tempo";

const tempo = useTapTempo({ defaultValue: 120 });

Call tempo.tap() once per beat. The second tap produces a BPM value; later taps average the last four intervals. A gap longer than two seconds starts a fresh sequence without changing the current value on its first tap. Taps less than 80 ms apart are ignored.

BPM values are always whole numbers. Tapped tempos, value, defaultValue and setValue() round to the nearest integer.

Call tap() from your app's keyboard handler or hotkey library.

Options

Prop

Type

Returns

Prop

Type