DEV Community

Giang Pham Truong
Giang Pham Truong

Posted on AI-assisted

Why a score's printed beat and playback BPM need separate units

A printed tempo mark can say eighth note = 120, while a playback timeline measures speed in quarter notes per minute. Treating both numbers as the same BPM would double the intended playback rate. Pianory keeps the score's beat unit for display and converts to a canonical quarter-note rate for timeline math.

In tempo.ts, a TempoMark stores the printed unit, whether it is dotted, the printed per-minute value, and quarterBpm. beatQuarters maps half, quarter and eighth notes to 2, 1 and 0.5 quarter notes respectively, then multiplies by 1.5 for one dot. So an eighth-note mark at 120 beats per minute becomes 60 quarter notes per minute. The label function reverses that conversion for the player UI, leaving the score's printed ♪ = 120 intact.

readTempoMark deliberately accepts only the first simple MusicXML <metronome> mark. Unsupported beat units, more than one dot, note-to-note relations and non-positive rates return no mark. The OSMD iterator supplies tempo points; buildTimeline scales those points against the parsed mark's quarter-note rate and retains the printed beat for display. A focused test checks that eighth note = 120 produces 60 quarter BPM at the start and converts a later point of 60 to 30 quarter BPM. The UI also uses the preserved beat when displaying the tempo slider's accessible value.

This design keeps arithmetic in one unit while showing musicians the beat the score actually printed. The focused conversion and timeline tests passed locally, but they do not measure playback accuracy in a real browser or establish how every MusicXML file behaves. I make Pianory; this example comes from its score player. AI assisted with drafting this article, and I checked the claims against the source and focused tests.

Top comments (2)

Collapse
 
officialmailkr profile image
오피셜메일 •

표시용 박자와 계산용 quarter BPM을 따로 둔 덕분에 단위 혼동이 드러나네요. 지원하지 않는 점음표나 관계 표기를 조용히 추정하지 않고 거절하는 테스트도 중요한 계약이겠습니다. UI에서 원래 단위가 보존되는지까지 확인한 점이 좋습니다.

Collapse
 
ptrgiang profile image
Giang Pham Truong •

Thanks for reading it closely. Returning no parsed mark for notation we do not support is intentional: a plausible but incorrect tempo would be harder to catch than an explicit absence. Preserving the printed beat in the player's accessible label is the other half of that contract.