Skip to content

fix(audio): keep imported audio on its own clips through a clip reorder - #1045

Merged
EtienneLescot merged 2 commits into
mainfrom
fix/1011-audio-reorder
Oct 6, 2026
Merged

EtienneLescot merged 2 commits into
mainfrom
fix/1011-audio-reorder

Conversation

@EtienneLescot

@EtienneLescot EtienneLescot commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Audio is re-anchored per stretch that still hangs together, not per trackId. A take that a clip edit pulled apart becomes separate takes that keep their clip, length and offsetMs. Moving the clip back joins them again, loops included.
  • Cutting a fragment's head off (narrowing a clip) advances its offsetMs, so the file jumps where the footage was cut.
  • A clip join (move or delete) relabels takes without re-cutting them against the old layout. That re-cut dropped the audio on the absorbed clip: deleting a typed word under a music bed lost the rest of the bed.
  • Behaviour change: deleting or narrowing a clip under a take leaves the rest on its own footage (two takes, a jump in the file) instead of re-flowing the music. A duplicated or inserted clip gets no audio.

Related issue

Closes #1011

Type of change

  • Bug fix

Release impact

  • Patch

Desktop impact

  • Not platform-specific

Testing

  • New tests in timeline.test.ts (the report's three-clip project with its numbers, move and move back, swap, insert, duplicate, delete and narrow under a bed, the 521d0bd offset repair) and insertion.test.ts (typing, deleting and dragging away a word under a bed). 9 fail on main; the other 2 guard behaviour that must not change.
  • vitest on src/lib/ai-edition, electron/ai-edition, sceneDescription and the audio components: 1710 passed. Both tsc configs, Biome.
  • Not done: a reorder in the app, and how the preview and export sound.

🤖 Generated with Claude Code

Every structural clip edit folded all fragments of a trackId into one span,
first to last. After a reorder that span covered the clip now between the
pieces, ran offsetMs past the end of the file, and pushed the next take past
the programme end.

Fold per stretch that still hangs together instead. A stretch that came apart
becomes its own take and keeps its clip, length and offsetMs; moving the clip
back joins them again. A clip edit that cuts a fragment's head now advances
its offsetMs, so the file jumps where the footage was cut.
)

When a move or a delete joins two clips, reanchorRows re-cut every take
against the clips as they were. That put the absorbed clip's id back, and the
rederive after it dropped the audio that clip carried: deleting or dragging
away a word typed under a bed lost the bed after the word. Relabel only; the
rederive re-cuts against the joined clips.
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7872bd90-7d9b-4745-948a-756693e1df2f
📥 Commits

Reviewing files that changed from the base of the PR and between 2ac20cf and 972c174.

📒 Files selected for processing (4)
  • src/lib/ai-edition/document/audioTracks.ts
  • src/lib/ai-edition/document/insertion.test.ts
  • src/lib/ai-edition/document/timeline.test.ts
  • src/lib/ai-edition/document/timeline.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Audio re-anchoring now separates detached stretches into takes and joins compatible adjacent takes. Timeline handling adjusts offsets when clamping anchored regions. Tests cover imported-audio spans and offsets across insertion, reordering, and other clip edits.

Changes

Imported Audio Re-anchoring

Layer / File(s) Summary
Group and join audio takes
src/lib/ai-edition/document/audioTracks.ts
Re-anchoring groups fragments by timeline and source continuity before collapsing them into pills. Adjacent takes can join when their asset and playback properties match and their timeline edges and offsets meet the stated conditions. cutTakeHead advances offsets for positive cuts on non-looping regions with numeric offsets.
Apply take handling to timeline edits
src/lib/ai-edition/document/timeline.ts, src/lib/ai-edition/document/timeline.test.ts, src/lib/ai-edition/document/insertion.test.ts
Clamping anchored regions now adjusts offsets for the removed source head. Audio tracks are relabeled from the original document. Tests cover bed spans, offsets, and clip associations across insertion, reordering, swaps, duplication, deletion, source-range changes, and rebuilds.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: olamide226

Merge Risk: ⚪ Minimal · up to 972c1

No confirmed issue currently blocks merging. In-app reorder and preview/export audio remain untested and should receive normal validation.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: keeping imported audio with its clips through a clip reorder.
Description check ✅ Passed The description includes a clear summary, related issue, change type, release impact, desktop impact, and testing details. It also states which tests were not performed. The omitted screenshots sectio…
Linked Issues check ✅ Passed #1011 requires imported audio to follow its clips during reorder, retain fragment lengths and offsets, and avoid adding audio to clips that had none. splitDetachedTakes separates fragments that no l…
Out of Scope Changes check ✅ Passed The changes to audio take grouping, head-cut offsets, and relabeling address #1011's clip-edit behavior. The added timeline and insertion tests verify those behaviors and guard against audio appearing…
Docstring Coverage ✅ Passed Docstring coverage is 84.62% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 4 files.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@EtienneLescot
EtienneLescot merged commit cab5ad8 into main Oct 6, 2026
19 checks passed
@EtienneLescot
EtienneLescot deleted the fix/1011-audio-reorder branch October 6, 2026 19:57
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.

[Bug]: Reordering clips rewrites imported audio tracks (bed stretched over another clip, loop pushed past the end)

1 participant