Skip to content

feat(editor): track regions — the data model + migration (no UI yet) - #332

Merged
byrongamatos merged 2 commits into
mainfrom
track-regions-p1
Jul 21, 2026
Merged

feat(editor): track regions — the data model + migration (no UI yet)#332
byrongamatos merged 2 commits into
mainfrom
track-regions-p1

Conversation

@ChrisBeWithYou

@ChrisBeWithYou ChrisBeWithYou commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

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, 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.
  • src/track-session.js — threads regions[] through _trackSessionNormalizePure (attached only when non-default), bumps editor_track_session to v3, teaches _trackSessionIsDefaultPure about regions.
  • routes.py_coerce_track_regions mirrors 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)

  • Migration is invisible — a v2 pack (no regions) resolves to exactly one full-span region per track, identical to today.
  • 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; the bump gates nothing.

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

    • Added support for optional regions on audio and transcription tracks.
    • Regions can define timeline positions, labels, mute state, and audio trimming.
    • Existing content continues to resolve to a single full-track region when no regions are specified.
  • Bug Fixes

    • Improved validation, ordering, deduplication, and handling of invalid region data.
    • Preserved compact, byte-identical saves when only default regions are present.
  • Tests

    • Added comprehensive coverage for region normalization, persistence, migration, and timeline boundaries.

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>
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ChrisBeWithYou, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 206e9df6-c408-4075-bb7c-f44cc22d6554

📥 Commits

Reviewing files that changed from the base of the PR and between 7b7e716 and 86854bb.

📒 Files selected for processing (3)
  • routes.py
  • src/region.js
  • tests/track_regions.test.mjs
📝 Walkthrough

Walkthrough

Adds a region data model for tracks, normalizes and persists authored regions[] on audio and transcription tracks, bumps editor_track_session to v3, omits implicit default regions, and adds backend and JavaScript coverage.

Changes

Track regions

Layer / File(s) Summary
Region model and normalization
src/region.js
Defines default-region resolution, validation, trimming and label normalization, deduplication, sorting, default detection, and beat containment.
Track-session persistence
routes.py, src/track-session.js
Sanitizes and persists non-default regions for audio and transcription tracks, omits default regions, preserves default-tree detection, and emits schema version 3.
Region and persistence validation
tests/test_track_regions.py, tests/track_regions.test.mjs, CHANGELOG.md
Adds coverage for normalization, migration, persistence, YAML round trips, idempotency, and documents the v3 groundwork.

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
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the core change: track regions data model and migration, with no UI work yet.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch track-regions-p1

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/region.js (1)

34-37: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Allow 0 to evaluate as valid rather than relying on the fallback.

Both _nonNegNumPure and _region_num_pos are designed to ensure non-negative numbers, but their strict > 0 checks reject valid zero inputs and rely on their default fallbacks (which happen to be zero) to produce the correct result. Using >= 0 avoids this logic quirk and prevents bugs if a non-zero fallback is ever used.

  • src/region.js#L34-L37: change the condition in _nonNegNumPure to Number.isFinite(n) && n >= 0.
  • routes.py#L556-L562: change the condition in _region_num_pos to math.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

📥 Commits

Reviewing files that changed from the base of the PR and between b0bf875 and 7b7e716.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • routes.py
  • src/region.js
  • src/track-session.js
  • tests/test_track_regions.py
  • tests/track_regions.test.mjs

Comment thread src/region.js
@byrongamatos
byrongamatos merged commit 2d8ea40 into main Jul 21, 2026
3 of 4 checks passed
@byrongamatos
byrongamatos deleted the track-regions-p1 branch July 21, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants