1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

Bug 2534 - Change Speed merges selected clip with adjacent clips

This commit is contained in:
Leland Lucius 2020-09-18 09:00:50 -05:00
parent 5bca69ca31
commit 3605d73d12

View File

@ -32,6 +32,7 @@
#include "../widgets/valnum.h" #include "../widgets/valnum.h"
#include "TimeWarper.h" #include "TimeWarper.h"
#include "../WaveClip.h"
#include "../WaveTrack.h" #include "../WaveTrack.h"
enum enum
@ -551,9 +552,42 @@ bool EffectChangeSpeed::ProcessOne(WaveTrack * track,
double newLength = outputTrack->GetEndTime(); double newLength = outputTrack->GetEndTime();
if (bResult) if (bResult)
{ {
// Silenced samples will be inserted in gaps between clips, so capture where these
// gaps are for later deletion
std::vector<std::pair<double, double>> gaps;
double last = 0.0;
auto clips = track->SortedClipArray();
auto front = clips.front();
auto back = clips.back();
for (auto &clip : clips) {
auto st = clip->GetStartTime();
auto et = clip->GetEndTime();
if (st >= mCurT0 || et < mCurT1) {
if (mCurT0 < st && clip == front) {
gaps.push_back(std::make_pair(mCurT0, st));
}
if (mCurT1 > et && clip == back) {
gaps.push_back(std::make_pair(et, mCurT1));
}
if (last >= mCurT0) {
gaps.push_back(std::make_pair(last, st));
}
}
last = et;
}
LinearTimeWarper warper { mCurT0, mCurT0, mCurT1, mCurT0 + newLength }; LinearTimeWarper warper { mCurT0, mCurT0, mCurT1, mCurT0 + newLength };
track->ClearAndPaste(
mCurT0, mCurT1, outputTrack.get(), true, false, &warper); // Take the output track and insert it in place of the original sample data
track->ClearAndPaste(mCurT0, mCurT1, outputTrack.get(), true, true, &warper);
// Finally, recreate the gaps
for (auto gap : gaps) {
auto st = track->LongSamplesToTime(track->TimeToLongSamples(gap.first));
auto et = track->LongSamplesToTime(track->TimeToLongSamples(gap.second));
track->SplitDelete(warper.Warp(st), warper.Warp(et));
}
} }
if (newLength > mMaxNewLength) if (newLength > mMaxNewLength)