Skip to content

Preserve metadata when trimming, support WAV smpl loops, and trim/tag fixes - #3

Merged
Xehanort88 merged 2 commits into
masterfrom
claude/confident-dijkstra-zdi0od
Sep 26, 2026
Merged

Xehanort88 merged 2 commits into
masterfrom
claude/confident-dijkstra-zdi0od

Conversation

@Xehanort88

@Xehanort88 Xehanort88 commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Trimming keeps all metadata

  • WAV files are now trimmed at the chunk level: every chunk is copied verbatim (tags, smpl sampler loops, cue points, bext, the exact fmt chunk). Only the data chunk is shortened, and the fact sample count is updated. The audio is no longer rewritten. A data size left as a placeholder (0 or past the end of the file) by an interrupted writer is handled.
  • FLAC audio is still re-encoded losslessly, but the source's metadata blocks are restored onto it: tags, cover art, application blocks, padding, and surrounding ID3 tags. Only the seek table and cue sheet are dropped, since they point into the old audio. If this fails, it falls back to copying text tags, with a warning.
  • Ogg Vorbis streams whose granule positions start past 0 (e.g. recorded from a live stream) are now cut at the right sample. Decoders number samples from the stream's start granule.
  • Failures to copy tags (used by trim and extend) are now logged as warnings instead of being silently ignored.

WAV smpl loop points

  • A WAV file with no loop tags has its first forward smpl loop used as the embedded loop: it is the first choice for all commands, and is used by play-tagged when no tag names are given. Text tags take precedence, and explicitly named tags never fall back to smpl.
  • tag on WAV files also writes the loop to the smpl chunk (as a forward loop with an inclusive end, repeating forever). An existing chunk keeps its header, its other loops and its sampler-specific data.
  • WAV chunks are found by reading only their headers, so looking for a smpl loop doesn't load the whole file.

Other fixes

  • The interactive trim prompt is no longer shown when export-points only prints to the console.
  • Detected loops within 5 ms of the embedded loop points are left out, so the same loop isn't listed twice.
  • trim --keep-after now defaults to 100 samples, the same as the interactive prompt (one shared constant). The Python API's MusicLooper.trim() still defaults to 0.

Behaviour change

Running trim without --keep-after now keeps 100 samples after the loop end instead of 0. Pass --keep-after 0 to cut exactly at the loop end.

Testing

  • 129 tests pass locally. The 2 FFmpeg decoder tests were skipped because FFmpeg wasn't installed.
  • The Tests workflow passed on both commits (Ubuntu and Windows, Python 3.10 and 3.13).
  • End to end, trim and tag were run on WAV files that have tags and a smpl chunk.

…rt offset

- Trim WAV files at the chunk level: every chunk is copied verbatim (tags,
  sampler loops, cue points, bext, the exact format chunk), only the data
  chunk is shortened and the fact sample count updated.
- Restore the source's FLAC metadata blocks (tags, cover art, application
  blocks, padding, surrounding ID3 tags) onto the re-encoded audio, dropping
  only the seek table and cue sheet, which point into the old audio.
- Log a warning instead of silently ignoring failures to copy tags.
- Trim Ogg Vorbis streams whose granule positions start past 0 at the right
  sample, as decoders number samples from the stream's start granule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QTLaHUDYw58dcfrK65spTz
…pe embedded loops

- Read loop points from a WAV file's sampler (smpl) chunk when it has no loop
  tags (tag names auto-detected), so they are used as the first loop choice
  and by play-tagged; write them to the smpl chunk when tagging WAV files,
  keeping any existing sampler data and other loops.
- Parse WAV chunks from their headers with seeks, so looking for the smpl
  chunk does not read the whole file.
- Do not offer to trim when export-points only prints to the console.
- Leave out detected loops within 5 ms of the embedded loop points, which
  would otherwise be listed twice.
- Default `trim --keep-after` to the same 100 samples as the interactive
  prompt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QTLaHUDYw58dcfrK65spTz
@Xehanort88
Xehanort88 merged commit fc07205 into master Sep 26, 2026
8 checks passed
Xehanort88 added a commit that referenced this pull request Sep 26, 2026
Preserve metadata when trimming, support WAV smpl loops, and trim/tag fixes
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