Repository navigation
Resample clips moved to a track with a different sample rate - #12436
Conversation
Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Defer the horizontal mutation until vertical resampling… · au3clipsinteraction.cpp:957-974
src/trackedit/internal/au3/au3clipsinteraction.cpp:957-974
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winDefer the horizontal mutation until vertical resampling succeeds.
When both offsets are nonzero,
moveClipschanges the original clip start time beforemoveSelectedClipsUpOrDownbegins resampling. Cancellation returns failure before the temporary track list replaces the original, but no rollback restores the start time. This violates the Cancel-leaves-clip-untouched contract.Apply the horizontal change after the successful vertical move, using the updated clip keys.
Suggested fix
- changeClipsStartTime(clipKeyList, timePositionOffset, false); - muse::Ret moveRet = muse::make_ok(); const bool needsDownmixing = trackPositionOffset != 0 && moveSelectedClipsUpOrDown(newClipKeyList, trackPositionOffset, moveRet) == NeedsDownmixing::Yes; if (!moveRet) { return muse::RetVal<ClipKeyList>::make_ret(moveRet); } + changeClipsStartTime(newClipKeyList, timePositionOffset, false); + const muse::Ret makeRoomRet = makeRoomForClips(newClipKeyList);
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI (base), Organization UI (inherited)
- Review profile: CHILL
- Plan: Advanced
- Run ID:
99e098c3-880c-48ad-9213-564a17df6e4c
📒 Files selected for processing: 3
src/projectscene/view/tracksitemsview/trackitemsmovecontroller.cppsrc/trackedit/internal/au3/au3tracksinteraction.cppsrc/trackedit/tests/au3tracksinteraction_tests.cpp
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
87edeec to
d3a6bc3
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI (base), Organization UI (inherited)
- Review profile: CHILL
- Plan: Advanced
- Run ID:
35d54ec6-07c2-49ef-92f9-42dbfddd246a
📒 Files selected for processing: 4
src/trackedit/internal/au3/au3clipsinteraction.cppsrc/trackedit/internal/au3/au3interactionutils.cppsrc/trackedit/internal/au3/au3interactionutils.hsrc/trackedit/internal/au3/au3tracksinteraction.cpp
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| // A destination with clips keeps its rate: convert the pasted data before the project is changed | ||
| std::vector<std::pair<Au3WaveTrack*, int> > tracksToResample; | ||
| std::vector<std::pair<std::shared_ptr<Au3WaveClip>, int> > clipsToResample; | ||
| for (size_t i = 0; i < dstTracksIds.size(); ++i) { | ||
| const Au3WaveTrack* dstWaveTrack = DomAccessor::findWaveTrack(projectRef(), Au3TrackId(dstTracksIds[i])); | ||
| const auto trackToPaste = std::static_pointer_cast<Au3WaveTrack>(copiedData.at(i)->track()); | ||
| if (dstWaveTrack && !dstWaveTrack->IsEmpty() && trackToPaste->GetRate() != dstWaveTrack->GetRate()) { | ||
| const int rate = static_cast<int>(dstWaveTrack->GetRate()); | ||
| tracksToResample.emplace_back(trackToPaste.get(), rate); | ||
| for (const auto& clip : trackToPaste->Intervals()) { | ||
| clipsToResample.emplace_back(clip, rate); | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- pasteClips and insertBlankSpace references ---'
rg -n -F --glob '*.cpp' --glob '*.h' \
-e 'pasteClips' -e 'insertBlankSpace' -e 'IsPlaceholder' -e 'SetIsPlaceholder' \
-e 'GetRate()' -e 'SetRate(' \
src/trackedit/internal/au3/au3tracksinteraction.cpp \
au3/libraries/au3-wave-track/WaveTrack.cpp \
au3/libraries/au3-wave-track/WaveTrack.h \
src/trackedit/tests/au3tracksinteraction_tests.cpp || test "$?" -eq 1
printf '%s\n' '--- pasteClips block ---'
sed -n '250,370p' src/trackedit/internal/au3/au3tracksinteraction.cpp
printf '%s\n' '--- paste caller and insertBlankSpace block ---'
sed -n '180,235p' src/trackedit/internal/au3/au3tracksinteraction.cpp
printf '%s\n' '--- WaveTrack emptiness and placeholder-related definitions ---'
rg -n -F --glob '*.cpp' --glob '*.h' \
-e 'bool WaveTrack::IsEmpty' -e 'IsEmpty() const' -e 'IsPlaceholder' -e 'SetIsPlaceholder' \
au3/libraries/au3-wave-track src/trackedit | head -120
printf '%s\n' '--- WaveTrack implementation excerpts ---'
sed -n '930,975p' au3/libraries/au3-wave-track/WaveTrack.cpp
sed -n '1760,1910p' au3/libraries/au3-wave-track/WaveTrack.cpp
printf '%s\n' '--- nearby tests and rate-related assertions ---'
rg -n -F --glob '*test*' \
-e 'moveAllTracks' -e 'paste' -e 'GetRate' -e 'SetRate' -e 'sample rate' -e 'sampleRate' \
src/trackedit/tests src/trackedit || test "$?" -eq 1Repository: audacity/audacity
Length of output: 35227
Treat placeholder-only destinations as empty in both rate checks.
moveAllTracks inserts a placeholder before pasteClips(). WaveTrack::IsEmpty() counts that placeholder, so an originally empty destination enters the resampling branch. The later empty-track branch also remains skipped. WaveTrack::Paste() then resamples the new clip to the destination’s existing rate.
Use non-placeholder occupancy for both checks. This lets the destination adopt the pasted track’s rate while preserving the existing behavior for destinations with real clips.
Suggested fix
if (!ret) {
return ret;
}
+ const auto hasRealClips = [](const Au3WaveTrack* track) {
+ if (!track) {
+ return false;
+ }
+ for (const auto& clip : track->Intervals()) {
+ if (!clip->GetIsPlaceholder()) {
+ return true;
+ }
+ }
+ return false;
+ };
+
// A destination with clips keeps its rate: convert the pasted data before the project is changed
std::vector<std::pair<Au3WaveTrack*, int> > tracksToResample;
std::vector<std::pair<std::shared_ptr<Au3WaveClip>, int> > clipsToResample;
for (size_t i = 0; i < dstTracksIds.size(); ++i) {
const Au3WaveTrack* dstWaveTrack = DomAccessor::findWaveTrack(projectRef(), Au3TrackId(dstTracksIds[i]));
const auto trackToPaste = std::static_pointer_cast<Au3WaveTrack>(copiedData.at(i)->track());
- if (dstWaveTrack && !dstWaveTrack->IsEmpty() && trackToPaste->GetRate() != dstWaveTrack->GetRate()) {
+ if (hasRealClips(dstWaveTrack) && trackToPaste->GetRate() != dstWaveTrack->GetRate()) {
const int rate = static_cast<int>(dstWaveTrack->GetRate());
tracksToResample.emplace_back(trackToPaste.get(), rate);
for (const auto& clip : trackToPaste->Intervals()) {
clipsToResample.emplace_back(clip, rate);
}
@@
- if (dstWaveTrack->IsEmpty()) {
+ if (!hasRealClips(dstWaveTrack)) {Co-Authored-By: [email protected] Assisted-by: Claude Code (Claude Opus 5.5)
A multi-clip paste into a track with clips at another rate inserted the clips without resampling. As a result they played at the wrong pitch, and might be removed on the next load (audacity#12513) Co-Authored-By: [email protected] Assisted-by: Claude Code (Claude Opus 5.5)
Assisted-by: Claude Code (Claude Opus 5.5)
1ad89a5 to
10d1f7e
Compare
Resolves: #11930
Resolves: #12512
Resolves: #12513
Do a resampling when moving or copying clips between projects/tracks of different sample rate
QA checklist, oh boy, there we go
Moving
given:
One clip move:
Multiple clip move
given:
same as above plus a Clip T2 on A1
Cross project move
given:
Same as above in two separate project P1 and P2
Import (yes, unfortunately import is also might be affected)
and the original issues:
Recommended: