fix(metronome): 修复第二拍延迟两倍间隔的 bug
drift correction 逻辑写反了: drift = now - nextTickAt (此时为负数,下一拍还在未来) nextDelay = intervalMs - drift ❌ = 2 × intervalMs 正确做法直接计算"目标时刻距现在还有多久": nextDelay = nextTickAt - now ✅ 现象:点击开始,第一拍立即响,但第二拍要等两倍拍间隔才响。 现在第一拍响完就立刻按 BPM 节奏进入第二拍。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -142,8 +142,7 @@ export function useMetronome(options: MetronomeOptions = {}) {
|
|||||||
beatIndex.value++
|
beatIndex.value++
|
||||||
|
|
||||||
nextTickAt += intervalMs.value
|
nextTickAt += intervalMs.value
|
||||||
const drift = Date.now() - nextTickAt
|
const nextDelay = Math.max(0, nextTickAt - Date.now())
|
||||||
const nextDelay = Math.max(0, intervalMs.value - drift)
|
|
||||||
|
|
||||||
timer = setTimeout(tick, nextDelay)
|
timer = setTimeout(tick, nextDelay)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user