Music Software Development

Online metronome

Set a tempo, press Start, and practise. Tap a steady beat on the Tap button (or the T key) to match a song you are hearing. Space starts and stops the metronome when the cursor is not in a form field.

Metronome controls

Tap at least twice.

The metronome needs JavaScript and Web Audio.

Why this metronome stays steady

A browser timer such as setTimeout fires when the page's main thread is free, which can be several milliseconds late while the page redraws or garbage collects. Clicks played straight from a timer wobble by that much, and the error is easy to hear. This metronome uses the timer only to look ahead: every 25 ms it checks which clicks fall in the next 100 ms and books each one at an exact time on the Web Audio clock (AudioContext.currentTime). The audio hardware then plays them on time even if the timer itself runs late, because each click was booked before it was due.

A tempo change is picked up at the start of the next beat, so the beat you are in finishes at its old length and nothing jumps. The flashing beat indicator reads the same clock: each animation frame compares the booked click times with the current audio time, so the lights follow the sound rather than the timer. The guide to scheduling audio in JavaScript explains the technique in code.

How tap tempo works

Each tap is timed, and the tempo is the average of up to the last eight gaps between taps, so one uneven tap does not throw it off. Pause for more than two seconds and the next tap starts a new count. The result is rounded to a whole BPM.

Need the tempo as delay times? The BPM to milliseconds calculator converts it into straight, dotted and triplet note lengths.

Keep this tab in the foreground for the steadiest timing: some browsers slow timers in background tabs, so the metronome books clicks further ahead while the tab is hidden.