Audacity 3.2.0
Functions
PasteOverPreservingClips.cpp File Reference
#include "PasteOverPreservingClips.h"
#include "WaveClip.h"
#include "WaveTrack.h"
Include dependency graph for PasteOverPreservingClips.cpp:

Go to the source code of this file.

Functions

void PasteOverPreservingClips (WaveTrack &oldTrack, sampleCount start, sampleCount len, WaveTrack &newContents)
 Substitute new contents into existing track, preserving clip boundaries. More...
 

Function Documentation

◆ PasteOverPreservingClips()

void PasteOverPreservingClips ( WaveTrack oldTrack,
sampleCount  start,
sampleCount  len,
WaveTrack newContents 
)

Substitute new contents into existing track, preserving clip boundaries.

Parameters
startbeginning position to paste over in oldTrack
lenlength to paste over in oldTrack
newContentsbegins at offset 0

Definition at line 18 of file PasteOverPreservingClips.cpp.

21{
22 // now move the appropriate bit of the output back to the track
23 // (this could be enhanced in the future to use the tails)
24 double lenT = oldTrack.LongSamplesToTime(len);
25 // 'start' is the sample offset in 't', the passed in track
26 // 'startT' is the equivalent time value
27 // 'newContents' starts at zero
28 double startT = oldTrack.LongSamplesToTime(start);
29
30 //newContents has one waveclip for the total length, even though
31 //oldTrack might have whitespace separating multiple clips
32 //we want to maintain the original clip structure, so
33 //only paste the intersections of the NEW clip.
34
35 //Find the bits of clips that need replacing
36 std::vector<std::pair<double, double> > clipStartEndTimes;
37 //may be truncated due to a clip being partially selected
38 std::vector<std::pair<double, double> > clipRealStartEndTimes;
39 //Used to restore clip names after pasting
40 std::vector<wxString> clipNames;
41 for (const auto &clip : oldTrack.GetClips()) {
42 auto clipStartT = clip->GetPlayStartTime();
43 auto clipEndT = clip->GetPlayEndTime();
44 if ( clipEndT <= startT )
45 continue; // clip is not within selection
46 if ( clipStartT >= startT + lenT )
47 continue; // clip is not within selection
48
49 //save the actual clip start/end so that we can rejoin them after we paste.
50 clipRealStartEndTimes.emplace_back(clipStartT, clipEndT);
51
52 if ( clipStartT < startT ) // does selection cover the whole clip?
53 clipStartT = startT; // don't copy all the NEW clip
54 if( clipEndT > startT + lenT ) // does selection cover the whole clip?
55 clipEndT = startT + lenT; // don't copy all the NEW clip
56
57 //save them
58 clipStartEndTimes.emplace_back(clipStartT, clipEndT);
59 clipNames.push_back(clip->GetName());
60 }
61 //now go through and replace the old clips with NEW
62 for (unsigned int i = 0; i < clipStartEndTimes.size(); ++i) {
63 //remove the old audio and get the NEW
64 auto [start, end] = clipStartEndTimes[i];
65 oldTrack.Clear(start, end);
66 auto toClipOutput = newContents.Copy(start - startT, end - startT);
67 //put the processed audio in
68 oldTrack.Paste(start, toClipOutput.get());
69
70 //Restore original clip's name
71 auto newClip = oldTrack.GetClipAtTime(start + 0.5 / oldTrack.GetRate());
72 newClip->SetName(clipNames[i]);
73
74 //if the clip was only partially selected, the Paste will have created a
75 // split line. Join is needed to take care of this
76 //This is not true when the selection is fully contained within one clip
77 // (second half of conditional)
78 auto [realStart, realEnd] = clipRealStartEndTimes[i];
79 if ((realStart != start || realEnd != end) &&
80 !(realStart <= startT && realEnd >= startT + lenT) )
81 oldTrack.Join(realStart, realEnd);
82 }
83}
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:48
void SetName(const wxString &name)
Definition: WaveClip.cpp:858
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1428
void Join(double t0, double t1)
Definition: WaveTrack.cpp:1573
WaveClip * GetClipAtTime(double time)
Definition: WaveTrack.cpp:2193
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:713
double GetRate() const override
Definition: WaveTrack.cpp:421
WaveClipHolders & GetClips()
Definition: WaveTrack.h:322
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Definition: WaveTrack.cpp:646
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References WaveTrack::Clear(), WaveTrack::Copy(), PackedArray::end(), WaveTrack::GetClipAtTime(), WaveTrack::GetClips(), WaveTrack::GetRate(), WaveTrack::Join(), SampleTrack::LongSamplesToTime(), WaveTrack::Paste(), and WaveClip::SetName().

Referenced by EffectEqualization::ProcessOne().

Here is the call graph for this function:
Here is the caller graph for this function: