BPM Duration Calculator
Stop guessing seconds — work in beats and bars
- duration
- info
MusicGen doesn't know what a bar is. It generates in seconds and tokens, and if you type "10" into the duration box you get a clip that lands wherever it lands - awkwardly mid-phrase, more often than not. BPMDurationInput fixes that by letting you think like a musician: set a tempo, set a number of beats, and get back a duration in seconds that MusicGen will actually respect. Displayed as "BPM Duration Calculator", it's the small node that turns a random-length snippet into something with musical structure.
The math is boring and it's worth understanding because it's the whole node: duration = (beats / bpm) * 60. 120 BPM × 16 beats = 8 seconds. 174 BPM × 8 beats ≈ 2.76 seconds. That's it - no fancy estimation, just the one formula.
How it works
Three inputs: bpm (60–200), beats (1–64, in 0.25 steps so you can do half-beats), and time_signature (4/4, 3/4, 6/8, 2/4). It computes the duration, then checks it against MusicGen's hard limits: ~50 tokens per second, 1503 tokens max, so anything beyond ~30.06 seconds gets capped. Over that ceiling, the info string tells you the duration was capped and what the actual beat count came out to.
The honest gotcha: time_signature does not change the duration. It only appears in the info output as a "measures" calculation (16 beats in 4/4 = 4 measures). It's informational - the actual seconds come purely from BPM and beats. Don't expect 6/8 to give you different timing than 4/4 at the same BPM and beats.
Outputs: duration (FLOAT, in seconds) and info (STRING) with beats, measures, and an estimated token count.
Where it fits
Wire the duration output into HuggingFaceMusicGen's duration_override input. That's the whole pattern:
BPMDurationInput (120 BPM, 16 beats, 4/4) → duration_override
↓
HuggingFaceMusicGen
With duration_override set, the generation node ignores its manual duration field and uses your beat-based length instead. Pair it with the pack's ProfessionalLoopTransition and you can generate one-bar or four-bar clips that actually sit on the grid - the difference between a loop and a loop that syncs.
Install
It's one of the ten nodes in ebrinz/ComfyUI-MusicGen-HF; install the pack once. ComfyUI Manager → search "ComfyUI-MusicGen-HF", or:
cd ComfyUI/custom_nodes
git clone https://github.com/ebrinz/ComfyUI-MusicGen-HF
cd ComfyUI-MusicGen-HF
pip install -r requirements.txt
Restart ComfyUI.
Troubleshooting
If your generated audio is always ~30 seconds no matter what beats you enter, you've hit the token cap - the info string says so explicitly; drop the beats or raise the BPM. If the duration never seems to affect output, check you wired into duration_override, not the regular duration input, and remember an override of 0.0 means "use manual duration" - the node treats 0 as "not set". And don't panic when the calculator returns 7.5833 instead of 7.5; MusicGen's token grid is ~0.02s, so you want to pair this with SmoothAudioQueue's target_duration if you need sample-exact sync on the far end.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| bpm | FLOAT | 120.060–200 | — |
| beats | FLOAT | 16.001–64 | — |
| time_signature | COMBO | 4/4 | 4 options: 4/4, 3/4, 6/8, 2/4 |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| duration | FLOAT | — |
| info | STRING | — |