feat(editor): track regions — the data model + migration (no UI yet) - #332
Conversation
A track can now carry regions[]: its audio/MIDI content as placeable blocks
on the timeline. This first step ships the DATA MODEL only — no rendering,
playback, or build changes — so it de-risks the persistence round-trip before
any UI lands.
- src/region.js (new): the region shape {id, startBeat, lenBeat, srcIn?,
srcOut?, name?, muted?}, validation, the default full-span region, the
default-is-null rule, and the beat-window membership predicate. A notation
region is a WINDOW over the arrangement's one notes[] array, never a copy
(that would fork note.beat-as-truth); an audio region is a non-destructive
pointer into immutable media (a beat-grid start + an in/out trim in the
file's own seconds).
- track-session.js: threads regions[] through _trackSessionNormalizePure
(attached only when non-default), bumps the editor_track_session schema to
v3, and teaches _trackSessionIsDefaultPure about regions.
- routes.py: _coerce_track_regions mirrors src/region.js so authored regions
survive the save->build round-trip (the tree is rebuilt field-by-field, so
an unknown field would otherwise be stripped); version 2->3.
Two guarantees, both tested: migration is invisible (a v2 pack with no regions
resolves to one full-span region per track, identical to today) and
byte-identical (a lone default region writes no regions key, so untouched
packs don't churn on save). v3 is purely additive — v2 trees need no migration
and the bump gates nothing.
First of a sequenced arc: PR 2 renders the region strip + selection, PR 3 is
the import-into-existing-project driver (place/move/delete), PR 4 adds
non-destructive audio-region playback + trim.
Tests: tests/track_regions.test.mjs (11), tests/test_track_regions.py (7) —
all fail on main. Full suite green: JS 296/0, pytest 365/0, lint 0 errors.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xGPjDBF8NTwTK7VQvizix
Signed-off-by: ChrisBeWithYou <chris@rifflarr.local>
|
Warning Review limit reached
Next review available in: 55 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds a region data model for tracks, normalizes and persists authored ChangesTrack regions
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant TrackSession as track-session.js
participant RegionModel as region.js
participant Routes as routes.py
TrackSession->>RegionModel: normalize track regions
RegionModel-->>TrackSession: normalized non-default regions
TrackSession->>Routes: persist normalized track session
Routes->>Routes: sanitize regions and stamp version 3
Routes-->>TrackSession: session payload
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/region.js (1)
34-37: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAllow
0to evaluate as valid rather than relying on the fallback.Both
_nonNegNumPureand_region_num_posare designed to ensure non-negative numbers, but their strict> 0checks reject valid zero inputs and rely on their default fallbacks (which happen to be zero) to produce the correct result. Using>= 0avoids this logic quirk and prevents bugs if a non-zero fallback is ever used.
src/region.js#L34-L37: change the condition in_nonNegNumPuretoNumber.isFinite(n) && n >= 0.routes.py#L556-L562: change the condition in_region_num_postomath.isfinite(n) and n >= 0.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/region.js` around lines 34 - 37, Update _nonNegNumPure in src/region.js:34-37 and _region_num_pos in routes.py:556-562 to accept finite zero values by changing their positivity checks from strictly greater than zero to greater than or equal to zero, while preserving fallback behavior for invalid numbers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/region.js`:
- Around line 31-33: Update _regionIdPure to trim the string before validating
its length, and check the trimmed value against the 160-character limit.
Preserve the existing empty-string result for non-string, blank, or over-limit
values.
---
Nitpick comments:
In `@src/region.js`:
- Around line 34-37: Update _nonNegNumPure in src/region.js:34-37 and
_region_num_pos in routes.py:556-562 to accept finite zero values by changing
their positivity checks from strictly greater than zero to greater than or equal
to zero, while preserving fallback behavior for invalid numbers.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8e36b207-b20c-4151-9ab7-55b14d9e90cd
📒 Files selected for processing (6)
CHANGELOG.mdroutes.pysrc/region.jssrc/track-session.jstests/test_track_regions.pytests/track_regions.test.mjs
PR 1 of the track-regions arc — the data model + migration
Gives a track a region layer:
regions[]is its audio/MIDI content as placeable blocks on the timeline. This first step is data-model only — no rendering, playback, or build changes — so the persistence round-trip is proven before any UI.Output of a 7-seat design charrette (DAW / UX / host-compat / transcription / rhythm-meter / audio-engine / operability); the core design calls came back unanimous.
What's here
src/region.js(new) — the region shape{id, startBeat, lenBeat, srcIn?, srcOut?, name?, muted?}, validation/dedupe/sort, the default full-span region, thedefault-is-nullrule, and the beat-window membership predicate. A notation region is a window over the arrangement's onenotes[]array, never a copy (that would forknote.beat-as-truth); an audio region is a non-destructive pointer into immutable media.src/track-session.js— threadsregions[]through_trackSessionNormalizePure(attached only when non-default), bumpseditor_track_sessionto v3, teaches_trackSessionIsDefaultPureabout regions.routes.py—_coerce_track_regionsmirrors the frontend so authored regions survive the save→build round-trip (tracks are rebuilt field-by-field, so an unknown field would otherwise be stripped); version 2→3.Guarantees (both tested)
regionskey, so untouched packs don't churn on save.Tests
tests/track_regions.test.mjs(11) +tests/test_track_regions.py(7), all fail on main. Full suite green: JS 296/0 · pytest 365/0 · lint 0 errors.What's next
PR 2 renders the region strip + selection; PR 3 is the import-into-existing-project driver (place/move/delete); PR 4 adds non-destructive audio-region playback + trim.
🤖 Generated with Claude Code
https://claude.ai/code/session_017xGPjDBF8NTwTK7VQvizix
Summary by CodeRabbit
New Features
Bug Fixes
Tests