Repository navigation
fix(triage): anch 8000 or each sliced piece on its own downbeat (no bar-0 ruler) - #54
Merged
Merged
Conversation
…uler) When slicing a chunk into N-bar pieces, some pieces' bar rulers started at bar 0 instead of bar 1 — at fractional BPMs, seemingly at random. Cut points are rounded to whole ms, so with a non-integer msPerBar a cut can land a hair past its exact grid line. anchorInRange then resolved the piece's anchor with a strict ceil and overshot by a full bar, placing the grid anchor one bar INTO the piece. Since the bar ruler numbers relative to the anchor (bar 1 = anchor), the piece's left edge fell before bar 1 and rendered as bar 0. Whether the rounding tipped over the line varied per piece, hence the mixed 0/1. At 120 BPM (msPerBar 2000, integral) it never triggered, so existing tests missed it. Interior pieces start exactly on a cut, which is a downbeat of the original grid by construction — so the piece's bar-1 anchor is simply its start. Set anchor = pieceStart for those instead of round-tripping through anchorInRange. The leading partial (i === 0) may start mid-bar and keeps the original grid anchor. TDD: new red test at 130 BPM asserting audioStartMs === startMs for every piece; full triage-store suite green, typecheck clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When slicing a chunk into N-bar pieces (the
SLICE TO BARSaction), some pieces' bar rulers started at bar 0 instead of bar 1 when a piece was selected — at fractional BPMs this looked random across pieces.Why it happened
The bar ruler numbers relative to a chunk's anchor (
audioStartMs): bar 1 sits on the anchor, and any beats before the anchor render as bar 0.In
sliceChunkIntoBarstwo roundings combined:Math.round(originalAnchor + n·step).anchorInRange, which returns the smallest grid boundary≥ pieceStartusingMath.ceil.With a non-integer
msPerBar(e.g. 130 BPM → 1846.15 ms) the rounded cut can land a hair past its exact grid line. The strictceilthen read it as "just past bar M" and returned bar M+1, placing the anchor a full bar into the piece. The piece's left edge fell before bar 1 → rendered as bar 0. Whether the rounding tipped over varied per piece, hence the mixed 0/1. At 120 BPM (msPerBar2000, integral) it never triggered, so existing tests missed it.The fix
Interior pieces start exactly on a cut, which is a downbeat of the original grid by construction — so the piece's bar-1 anchor is simply its start. Set
anchor = pieceStartfor those instead of round-tripping throughanchorInRange. The leading partial (i === 0) may start mid-bar and keeps the original grid anchor.Testing
audioStartMs === startMsfor every sliced piece (reproduced the full-bar overshoot: anchor 9231 vs piece start 7385), now green.triage-storesuite green (72 tests);tsc --noEmitclean.detectChunks"generous min-pause" test and the hardware-dependent WebGPU readback perf benchmark — not touched by this change.🤖 Generated with Claude Code