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

ClipData CollectClipData (const WaveTrack &oldTrack, sampleCount start, sampleCount len)
 Collect clip boundary and name information. More...
 
void PasteOverPreservingClips (const ClipData &data, WaveTrack &oldTrack, sampleCount start, sampleCount len, const WaveTrack &newContents)
 Substitute new contents into existing track, preserving clip boundaries. More...
 

Function Documentation

◆ CollectClipData()

ClipData CollectClipData ( const WaveTrack oldTrack,
sampleCount  start,
sampleCount  len 
)

Collect clip boundary and name information.

Parameters
startbeginning position to paste over in oldTrack
lenlength to paste over in oldTrack
Precondition
oldTrack.IsLeader()

Definition at line 18 of file PasteOverPreservingClips.cpp.

20{
21 assert(oldTrack.IsLeader());
22 ClipData results;
23 auto &[clipStartEndTimes, clipRealStartEndTimes, clipNames] = results;
24
25 double lenT = oldTrack.LongSamplesToTime(len);
26 // 'start' is the sample offset in 't', the passed in track
27 // 'startT' is the equivalent time value
28 double startT = oldTrack.LongSamplesToTime(start);
29
30 for (const auto &clip : oldTrack.GetClips()) {
31 auto clipStartT = clip->GetPlayStartTime();
32 auto clipEndT = clip->GetPlayEndTime();
33 if (clipEndT <= startT)
34 continue; // clip is not within selection
35 if (clipStartT >= startT + lenT)
36 continue; // clip is not within selection
37
38 //save the actual clip start/end so that we can rejoin them after we paste.
39 clipRealStartEndTimes.emplace_back(clipStartT, clipEndT);
40
41 if (clipStartT < startT) // does selection cover the whole clip?
42 clipStartT = startT; // don't copy all the NEW clip
43 if(clipEndT > startT + lenT) // does selection cover the whole clip?
44 clipEndT = startT + lenT; // don't copy all the NEW clip
45
46 //save them
47 clipStartEndTimes.emplace_back(clipStartT, clipEndT);
48 clipNames.push_back(clip->GetName());
49 }
50 return results;
51}
bool IsLeader() const override
Definition: WaveTrack.cpp:2449
WaveClipHolders & GetClips()
Definition: WaveTrack.h:690
double LongSamplesToTime(sampleCount pos) const

References WaveTrack::GetClips(), WaveTrack::IsLeader(), and WideSampleSequence::LongSamplesToTime().

Referenced by EffectEqualization::Process().

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

◆ PasteOverPreservingClips()

void PasteOverPreservingClips ( const ClipData data,
WaveTrack oldTrack,
sampleCount  start,
sampleCount  len,
const 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
Precondition
oldTrack.IsLeader()
newContents.IsLeader()
oldTrack.NChannels() == newContents.NChannels()

Definition at line 53 of file PasteOverPreservingClips.cpp.

56{
57 assert(oldTrack.IsLeader());
58 assert(newContents.IsLeader());
59 assert(oldTrack.NChannels() == newContents.NChannels());
60 const auto &[clipStartEndTimes, clipRealStartEndTimes, clipNames] = data;
61
62 //newContents has one waveclip for the total length, even though
63 //oldTrack might have whitespace separating multiple clips
64 //we want to maintain the original clip structure, so
65 //only paste the intersections of the new clip.
66
67 // now move the appropriate bit of the output back to the track
68 // (this could be enhanced in the future to use the tails)
69 double lenT = oldTrack.LongSamplesToTime(len);
70 // 'start' is the sample offset in 't', the passed in track
71 // 'startT' is the equivalent time value
72 double startT = oldTrack.LongSamplesToTime(start);
73
74 //now go through and replace the old clips with NEW
75 for (unsigned int i = 0; i < clipStartEndTimes.size(); ++i) {
76 //remove the old audio and get the NEW
77 auto [start, end] = clipStartEndTimes[i];
78 oldTrack.Clear(start, end);
79
80 auto toClipOutput = newContents.Copy(start - startT, end - startT);
81 oldTrack.Paste(start, *toClipOutput);
82
83 //Restore original clip's name
84 auto newClip = oldTrack.GetClipAtTime(start + 0.5 / oldTrack.GetRate());
85 newClip->SetName(clipNames[i]);
86
87 //if the clip was only partially selected, the Paste will have created a
88 // split line. Join is needed to take care of this
89 //This is not true when the selection is fully contained within one clip
90 // (second half of conditional)
91 auto [realStart, realEnd] = clipRealStartEndTimes[i];
92 if ((realStart != start || realEnd != end) &&
93 !(realStart <= startT && realEnd >= startT + lenT))
94 oldTrack.Join(realStart, realEnd);
95 }
96}
void SetName(const wxString &name)
Definition: WaveClip.cpp:1300
const WaveClip * GetClipAtTime(double time) const
Definition: WaveTrack.cpp:3374
void Join(double t0, double t1)
Definition: WaveTrack.cpp:2279
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:1222
void Paste(double t0, const Track &src) override
Definition: WaveTrack.cpp:2112
double GetRate() const override
Definition: WaveTrack.cpp:875
TrackListHolder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: WaveTrack.cpp:1154
size_t NChannels() const override
May report more than one only when this is a leader track.
Definition: WaveTrack.cpp:620
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References WaveTrack::Clear(), WaveTrack::Copy(), PackedArray::end(), WaveTrack::GetClipAtTime(), WaveTrack::GetRate(), WaveTrack::IsLeader(), WaveTrack::Join(), WideSampleSequence::LongSamplesToTime(), WaveTrack::NChannels(), WaveTrack::Paste(), and WaveClip::SetName().

Referenced by EffectEqualization::Process().

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