Skip to content

Fix au3 project loading - #12213

Merged
kryksyh merged 2 commits into
audacity:release-4.0.1from
kryksyh:fix-au3-project-loading
Sep 23, 2026
Merged

kryksyh merged 2 commits into
audacity:release-4.0.1from
kryksyh:fix-au3-project-loading

Conversation

@kryksyh

@kryksyh kryksyh commented Sep 18, 2026

Copy link
Copy Markdown
Member

Resolves: #12209

After the change introduced in ff3dcf4, the track added notification is emitted before any clip is created.
therefore project tempo is never set for the clip, which results in miscalculation of clip's timing.

There is another issue that could not be solved by reverting: the envelope points are calculated at clip loading time, if we set the tempo after that, some envelope points may be already removed. This is also present in au3.

  • 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 18, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

WaveClip now stores project tempo and receives it during deserialization. Stretch-ratio calculation uses clip tempo or project tempo according to the matching mode. Tempo changes, copy operations, range copies, and pastes preserve or initialize tempo metadata. New tests cover loading, playback boundaries, envelopes, toggling, copying, pasting, save/reload behavior, and serialized XML.

Priority: ➖ Normal

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

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 7aaba

Legacy projects with tempo-matched clips can lose hidden audio when a cut line is expanded, because the restored cut line's speed no longer matches its clip. The rest of the tempo-persistence change looks sound; this single construction site should be fixed before merge.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing AU3 project loading. It is concise and related to the tempo and clip-timing changes.
Description check ✅ Passed The description includes the issue reference, motivation, change context, and required checklist. The recommended local build-and-test item is unchecked, but the required information is otherwise comp…
Linked Issues check ✅ Passed The changes address #12209. WaveTrack::HandleXMLChild passes the project tempo to each deserialized WaveClip. WaveClip::GetStretchRatio uses that tempo when project-tempo matching is enabled. Th…
Out of Scope Changes check ✅ Passed The changes stay within #12209. The production changes modify clip tempo state, clip creation during project loading, tempo matching, and copy or paste persistence. The added tests directly verify the…

Warning

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


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.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Pass the project tempo to deserialized cut lines. · WaveClip.cpp:1238

au3/libraries/au3-wave-track/WaveClip.cpp:1238
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Pass the project tempo to deserialized cut lines.

NewShared leaves mProjectTempo unset. XML restores the raw tempo and tempo-match flag, but not the project tempo. Therefore, with the default stretch ratio, the cut line can use 1.0 while its parent uses rawAudioTempo / projectTempo.

ExpandCutLine calls Paste on the non-empty parent, so the new empty-clip derivation does not apply. Paste rejects ratios that differ by more than 1e-6. ExpandCutLine then erases the cut line even when Paste returns false, which can delete the hidden audio without pasting it.

Proposed fix
-        mCutLines.push_back(WaveClip::NewShared(1, pFirst->GetFactory(), format, mRate));
+        mCutLines.push_back(
+            WaveClip::NewShared(
+                1, pFirst->GetFactory(), format, mRate, mProjectTempo));

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: ab3896da-b2a9-42c9-bce3-9de3d2c37997

📥 Commits

Reviewing files that changed from the base of the PR and between de2e43d and 7aabaf8.

📒 Files selected for processing (6)
  • au3/libraries/au3-wave-track/WaveClip.cpp
  • au3/libraries/au3-wave-track/WaveClip.h
  • au3/libraries/au3-wave-track/WaveTrack.cpp
  • src/project/tests/CMakeLists.txt
  • src/project/tests/cliptempopersistence_tests.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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I will suggest some improvements for the unit tests, but in the meantime it may move on to QA.

EXPECT_DOUBLE_EQ(clips[i]->GetEnvelope().GetTrackLen(), 1.0);
}

// Loading must not mistake the inflated legacy durations for overlaps.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having a hard time understanding this ... Is this a setup thing? GIVEN/WHEN/THEN would actually be helpful here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Commenting it out doesn't fail the test either.

{
ASSERT_TRUE(readProject());
auto& track = *firstTrack();
track.LinkConsistencyFix(true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can kind of understand why this is needed for the test with a stereo clip, but for the three others ?.. and indeed, commenting these three out don't fail the test.

Comment on lines +33 to +34
// Exercise the project reader's track-addition notifications and clip XML
// handlers, using silent blocks so no recorded audio fixture is needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A comment on this factory describing what the project coming out of it looks like would be helpful.


for (size_t i = 0; i < clips.size(); ++i) {
EXPECT_DOUBLE_EQ(clips[i]->GetStretchRatio(), 1.0);
EXPECT_NEAR(clips[i]->GetPlayStartTime(), 0.2 + 0.5 * i, 1e-9);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's really tedious here. I have to go check the impl of readProject to understand this expectation. A helper function like testClipStartTime(i), also used in readProject for the construction, would be helpful.

@kryksyh
kryksyh changed the base branch from master to release-4.0.1 September 23, 2026 13:33
@kryksyh
kryksyh force-pushed the fix-au3-project-loading branch from 7aabaf8 to c2aa4e0 Compare September 23, 2026 13:34
@kryksyh
kryksyh merged commit 82afea9 into audacity:release-4.0.1 Sep 23, 2026
1 of 3 checks passed
@kryksyh
kryksyh deleted the fix-au3-project-loading branch September 23, 2026 13:35
@saintmatthieu saintmatthieu mentioned this pull request Sep 24, 2026
8 tasks done
saintmatthieu added a commit that referenced this pull request Oct 1, 2026
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

<!-- Use "x" to fill the checkboxes below like [x] -->

- [x] I signed [CLA](https://www.audacityteam.org/cla/)
- [x] This PR includes AI assistance
- [x] If the PR is AI-assisted, I have read, understood and complied
with the [guidelines for AI-assisted
contributions](https://github.com/audacity/audacity/blob/master/AI_POLICY.md)
- [x] The title of the pull request describes an issue it addresses
- [x] If changes are extensive, then there is a sequence of easily
reviewable commits
- [x] Each commit's message describes its purpose and effects
- [x] There are no behavior changes unnecessary for the stated purpose
of the PR

Recommended:
- [x] Each commit compiles and runs on my machine without known
undesirable changes of behavior
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.

Conversion from aup3 to aup4 results in messed up clips

2 participants