Skip to content

Stretch ratio simplification attempt - #12290

Merged
saintmatthieu merged 4 commits into
audacity:masterfrom
saintmatthieu:stretch-ratio-simplification-attempt
Oct 1, 2026
Merged

saintmatthieu merged 4 commits into
audacity:masterfrom
saintmatthieu:stretch-ratio-simplification-attempt

Conversation

@saintmatthieu

@saintmatthieu saintmatthieu commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Resolves: #12209 (resolves it on master - ticket is already resolved for 4.0.1)
Resolves: #12266

A clip's stretch ratio is now stored as one variable.

It used to be based on mRawAudioTempo, mClipStretchRatio and mClipTempo
(the latter being the current project's tempo or a freeze of it if the user
unchecked the "Stretch to match project tempo" box).

This simplification lumps those three in just one variable, mStretchRatio.
It's based on the belief (reviewers please challenge this) that the raw tempo,
issued from the detection, really only is needed once at import.

The PR also adds a plethora of test cases: that's because a wrong parsing of the stretch ratio from a legacy project file can lead to many bugs (clips cutting each other, trim boundaries not respected, etc). They are largely based on those in @kryksyh 's PR #12213

  • I signed CLA
  • This PR includes AI assistance
  • If the PR is AI-assisted, I have read, understood and complied with the guidelines for AI-assisted contributions
  • The title of the pull request describes an issue it addresses
  • If changes are extensive, then there is a sequence of easily reviewable commits
  • Each commit's message describes its purpose and effects
  • There are no behavior changes unnecessary for the stated purpose of the PR

Recommended:

  • Each commit compiles and runs on my machine without known undesirable changes of behavior

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

WaveClip now stores stretch as an absolute ratio instead of combining raw-audio tempo, clip tempo, and clip stretch ratio. During deserialization, it converts legacy tempo attributes using the project tempo when needed. Serialization no longer writes those legacy attributes. Tempo-matching workflows now handle project tempo changes, imported loops, and changes to the clip matching setting. New tests cover legacy clip conversion, clip operations, XML persistence, and tempo-matching behavior.

Priority: ➖ Normal

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

Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant TempoDetection
  participant ITrackeditProject
  participant Au3TrackeditProject
  participant WaveClip
  TempoDetection->>ITrackeditProject: Set time signature with noStretch
  ITrackeditProject->>Au3TrackeditProject: Update time signature
  Au3TrackeditProject->>WaveClip: Temporarily disable and restore tempo matching
Loading

Merge Risk: 🟡 Moderate · up to 93517

Tempo changes can misalign a clip’s volume automation, and direct track XML loading can fail. Address these before merging.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 93517

Valid legacy tempo data has a defined conversion path and the changed workflows have targeted tests. The remaining design risk is that a failed project-tempo update could leave clips in a different tempo-following state; coverage of invalid import tempos and external users of the replaced APIs is also incomplete. No introduced security vulnerability was established.

Retained concerns

  • Low · reliability · inferred: If the synchronous project-tempo update exits before restoration, clips temporarily disabled for the no-stretch operation can retain the wrong tempo-following setting. The new path applies that transition across project clips rather than only the imported clips handled by the prior import workflow. A concrete throwing or interrupted execution was not demonstrated.
Security review details

Security Blast Radius

  • inferred — The evidenced effects concern clips and project tempo in the opened or imported project. No changed service or privilege boundary was identified in the examined paths; broader caller coverage remains incomplete.

Trust Boundaries and Controls

  • observed — Project XML remains on the WaveTrack-to-WaveClip deserialization path. The new context setter does not itself parse XML, and legacy tempo conversion applies finite-positive checks; the examined paths did not establish a new parser bypass.

Resilience and Maintainability Implications

  • inferred — Because tempo notification is synchronous, restoration of temporarily changed clip flags depends on the tempo update completing and returning to the caller.

Hardening Proposals

  • proposed — Restore each clip's prior tempo-following flag through a failure-safe scope, and define valid tempo preconditions for the import quotient before it is stored.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue [#12209] is closed and provides historical context only. It supplies no active coding requirements for this pull request. The pull request adds stretch-ratio conversion, tempo-handling changes, …
Out of Scope Changes check ✅ Passed The reviewed changes remain connected to [#12209]. WaveClip, tempo detection, project tempo handling, clip interaction, and the added tests all support stretch-ratio persistence or clip timing behav…
Title check ✅ Passed The title clearly identifies the main change: simplifying clip stretch-ratio storage. It is concise and related to the pull request.
Description check ✅ Passed The description includes issue references, motivation, implementation summary, test coverage, and all required checklist items.

Warning

Linked repositories: Public OSS repositories can only analyze public repositories installed in this organization. No linked repositories were analyzed; skipped musescore/musescore.


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: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: 4f34923d-aa7b-457a-8554-76e732a6ab80

📥 Commits

Reviewing files that changed from the base of the PR and between c921664 and 24569cf.

📒 Files selected for processing (9)
  • au3/libraries/au3-wave-track/WaveClip.cpp
  • au3/libraries/au3-wave-track/WaveClip.h
  • au3/libraries/au3-wave-track/WaveTrack.cpp
  • src/importexport/import/internal/au3/tempodetection.cpp
  • src/importexport/import/internal/au3/tempodetection.h
  • src/project/tests/CMakeLists.txt
  • src/project/tests/cliptempopersistence_tests.cpp
  • src/trackedit/internal/au3/au3clipsinteraction.cpp
  • src/trackedit/tests/au3clipsinteraction_tests.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@saintmatthieu
saintmatthieu force-pushed the stretch-ratio-simplification-attempt branch 2 times, most recently from ef60dba to 9351725 Compare September 25, 2026 17:11

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: 2d2c17fa-0834-48d3-bab9-fbf62bcf3ab7

📥 Commits

Reviewing files that changed from the base of the PR and between ef60dba and 9351725.

📒 Files selected for processing (10)
  • au3/libraries/au3-wave-track/WaveClip.cpp
  • au3/libraries/au3-wave-track/WaveClip.h
  • au3/libraries/au3-wave-track/WaveTrack.cpp
  • src/importexport/import/internal/au3/tempodetection.cpp
  • src/importexport/import/internal/au3/tempodetection.h
  • src/trackedit/internal/au3/au3trackeditproject.cpp
  • src/trackedit/internal/au3/au3trackeditproject.h
  • src/trackedit/itrackeditproject.h
  • src/trackedit/tests/au3clipsinteraction_tests.cpp
  • src/trackedit/tests/mocks/trackeditprojectmock.h

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@ianalarina ianalarina moved this to Ready for Qa in Audacity 4.1 Sep 28, 2026
@ianalarina ianalarina added this to the Audacity 4.1 milestone Sep 28, 2026
Assisted-by: Claude Opus 5 (1M context)
Assisted-by: Claude Opus 5 (1M context)
It used to be based on `mRawAudioTempo`, `mClipStretchRatio` and `mClipTempo`
(the latter being the current project's tempo or a freeze of it if the user
unchecked the "Stretch to match project tempo" box).

This simplification lumps those three in just one variable, `mStretchRatio`.
It's based on the belief (reviewers please challenge this) that the raw tempo,
issued from the detection, really only is needed once at import.

Assisted-by: Claude Opus 5 (1M context)
@saintmatthieu
saintmatthieu force-pushed the stretch-ratio-simplification-attempt branch from 9351725 to 83b31d2 Compare October 1, 2026 19:21
@saintmatthieu
saintmatthieu merged commit 8de3891 into audacity:master Oct 1, 2026
5 of 10 checks passed
@saintmatthieu
saintmatthieu deleted the stretch-ratio-simplification-attempt branch October 1, 2026 19:22
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.

Refactor clips stretching Conversion from aup3 to aup4 results in messed up clips

3 participants