Audacity 3.2.0
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
WaveClipTrimHandle::AdjustBorder Class Referencefinal
Inheritance diagram for WaveClipTrimHandle::AdjustBorder:
[legend]
Collaboration diagram for WaveClipTrimHandle::AdjustBorder:
[legend]

Public Member Functions

 AdjustBorder (const std::shared_ptr< WaveTrack > &track, const std::shared_ptr< WaveClip > &clip, bool leftBorder, const ZoomInfo &zoomInfo)
 
bool Init (const TrackPanelMouseEvent &event) override
 
UIHandle::Result Trim (const TrackPanelMouseEvent &event, AudacityProject &project) override
 
void Finish (AudacityProject &project) override
 
void Cancel () override
 
void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
 
wxRect DrawingArea (TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
 
- Public Member Functions inherited from WaveClipTrimHandle::ClipTrimPolicy
virtual ~ClipTrimPolicy ()
 
virtual bool Init (const TrackPanelMouseEvent &event)=0
 
virtual UIHandle::Result Trim (const TrackPanelMouseEvent &event, AudacityProject &project)=0
 
virtual void Finish (AudacityProject &project)=0
 
virtual void Cancel ()=0
 
virtual void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
 
virtual wxRect DrawingArea (TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
 

Private Member Functions

void TrimTo (double t)
 

Static Private Member Functions

static SnapPointArray FindSnapPoints (const WaveTrack *currentTrack, WaveClip *adjustedClip, const std::pair< double, double > range)
 

Private Attributes

std::shared_ptr< WaveTrackmTrack
 
std::vector< std::shared_ptr< WaveClip > > mClips
 
double mInitialBorderPosition {}
 
int mDragStartX { }
 
std::pair< double, double > mRange
 
bool mAdjustingLeftBorder
 
std::unique_ptr< SnapManagermSnapManager
 
SnapResults mSnap
 

Detailed Description

Definition at line 47 of file WaveClipTrimHandle.cpp.

Constructor & Destructor Documentation

◆ AdjustBorder()

WaveClipTrimHandle::AdjustBorder::AdjustBorder ( const std::shared_ptr< WaveTrack > &  track,
const std::shared_ptr< WaveClip > &  clip,
bool  leftBorder,
const ZoomInfo zoomInfo 
)
inline

Definition at line 121 of file WaveClipTrimHandle.cpp.

126 : mTrack(track),
127 mAdjustingLeftBorder(leftBorder)
128 {
129 auto clips = track->GetClips();
130
131 wxASSERT(std::find(clips.begin(), clips.end(), clip) != clips.end());
132
133 if (track->IsAlignedWithLeader() || track->GetLinkType() == Track::LinkType::Aligned)
134 //find clips in other channels which are also should be trimmed
135 mClips = FindClipsInChannels(clip->GetPlayStartTime(), clip->GetPlayEndTime(), track.get());
136 else
137 mClips.push_back(clip);
138
140 {
141 auto left = clip->GetSequenceStartTime();
142 for (const auto& other : clips)
143 if (other->GetPlayStartTime() < clip->GetPlayStartTime() && other->GetPlayEndTime() > left)
144 left = other->GetPlayEndTime();
145 //not less than 1 sample length
146 mRange = std::make_pair(left, clip->GetPlayEndTime() - 1.0 / clip->GetRate());
147
148 mInitialBorderPosition = mClips[0]->GetPlayStartTime();
149 }
150 else
151 {
152 auto right = clip->GetSequenceEndTime();
153 for (const auto& other : clips)
154 if (other->GetPlayStartTime() > clip->GetPlayStartTime() && other->GetPlayStartTime() < right)
155 right = other->GetPlayStartTime();
156 //not less than 1 sample length
157 mRange = std::make_pair(clip->GetPlayStartTime() + 1.0 / clip->GetRate(), right);
158
159 mInitialBorderPosition = mClips[0]->GetPlayEndTime();
160 }
161
162 if(const auto trackList = track->GetOwner())
163 {
164 mSnapManager = std::make_unique<SnapManager>(
165 *trackList->GetOwner(),
166 FindSnapPoints(track.get(), clip.get(), mRange),
167 zoomInfo);
168 }
169 }
std::vector< std::shared_ptr< WaveClip > > mClips
std::unique_ptr< SnapManager > mSnapManager
static SnapPointArray FindSnapPoints(const WaveTrack *currentTrack, WaveClip *adjustedClip, const std::pair< double, double > range)
std::pair< double, double > mRange
std::shared_ptr< WaveTrack > mTrack
std::vector< std::shared_ptr< WaveClip > > FindClipsInChannels(double start, double end, WaveTrack *track)

References Track::Aligned, anonymous_namespace{WaveClipTrimHandle.cpp}::FindClipsInChannels(), FindSnapPoints(), mAdjustingLeftBorder, mClips, mInitialBorderPosition, mRange, and mSnapManager.

Here is the call graph for this function:

Member Function Documentation

◆ Cancel()

void WaveClipTrimHandle::AdjustBorder::Cancel ( )
inlineoverridevirtual

Implements WaveClipTrimHandle::ClipTrimPolicy.

Definition at line 236 of file WaveClipTrimHandle.cpp.

References mInitialBorderPosition, and TrimTo().

Here is the call graph for this function:

◆ Draw()

void WaveClipTrimHandle::AdjustBorder::Draw ( TrackPanelDrawingContext context,
const wxRect &  rect,
unsigned  iPass 
)
inlineoverridevirtual

Reimplemented from WaveClipTrimHandle::ClipTrimPolicy.

Definition at line 241 of file WaveClipTrimHandle.cpp.

242 {
243 if(iPass == TrackArtist::PassSnapping && mSnap.Snapped())
244 {
245 auto &dc = context.dc;
246 SnapManager::Draw(&dc, rect.x + mSnap.outCoord, -1);
247 }
248 }
static void Draw(wxDC *dc, wxInt64 snap0, wxInt64 snap1)
Definition: Snap.cpp:330
wxInt64 outCoord
Definition: Snap.h:48
bool Snapped() const
Definition: Snap.h:52

References TrackPanelDrawingContext::dc, SnapManager::Draw(), mSnap, SnapResults::outCoord, TrackArtist::PassSnapping, and SnapResults::Snapped().

Here is the call graph for this function:

◆ DrawingArea()

wxRect WaveClipTrimHandle::AdjustBorder::DrawingArea ( TrackPanelDrawingContext ,
const wxRect &  rect,
const wxRect &  panelRect,
unsigned  iPass 
)
inlineoverridevirtual

Reimplemented from WaveClipTrimHandle::ClipTrimPolicy.

Definition at line 250 of file WaveClipTrimHandle.cpp.

251 {
252 if(iPass == TrackArtist::PassSnapping)
253 return MaximizeHeight(rect, panelRect);
254 return rect;
255 }
static wxRect MaximizeHeight(const wxRect &rect, const wxRect &panelRect)

References TrackPanelDrawable::MaximizeHeight(), and TrackArtist::PassSnapping.

Here is the call graph for this function:

◆ FindSnapPoints()

static SnapPointArray WaveClipTrimHandle::AdjustBorder::FindSnapPoints ( const WaveTrack currentTrack,
WaveClip adjustedClip,
const std::pair< double, double >  range 
)
inlinestaticprivate

Definition at line 77 of file WaveClipTrimHandle.cpp.

81 {
82 SnapPointArray result;
83
84 auto addSnapPoint = [&](double t, const Track* track)
85 {
86 if(t > range.second || t < range.first)
87 return;
88
89 for(const auto& snapPoint : result)
90 if(snapPoint.t == t)
91 return;
92 result.emplace_back(t, track);
93 };
94
95 if(const auto trackList = currentTrack->GetOwner())
96 {
97 for(const auto track : trackList->Any())
98 {
99 const auto isSameTrack = (track == currentTrack) ||
100 (track->GetLinkType() == Track::LinkType::Aligned && *trackList->FindLeader(currentTrack) == track) ||
101 (currentTrack->GetLinkType() == Track::LinkType::Aligned && *trackList->FindLeader(track) == currentTrack);
102 for(const auto& interval : track->GetIntervals())
103 {
104 if(isSameTrack)
105 {
106 auto waveTrackIntervalData = dynamic_cast<WaveTrack::IntervalData*>(interval.Extra());
107 if(waveTrackIntervalData->GetClip().get() == adjustedClip)
108 //exclude boundaries of the adjusted clip
109 continue;
110 }
111 addSnapPoint(interval.Start(), track);
112 if(interval.Start() != interval.End())
113 addSnapPoint(interval.End(), track);
114 }
115 }
116 }
117 return result;
118 }
std::vector< SnapPoint > SnapPointArray
Definition: Snap.h:43
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
std::shared_ptr< TrackList > GetOwner() const
Definition: Track.h:409
LinkType GetLinkType() const noexcept
Definition: Track.cpp:1347

References Track::Aligned, Track::GetLinkType(), and Track::GetOwner().

Referenced by AdjustBorder().

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

◆ Finish()

void WaveClipTrimHandle::AdjustBorder::Finish ( AudacityProject project)
inlineoverridevirtual

Implements WaveClipTrimHandle::ClipTrimPolicy.

Definition at line 217 of file WaveClipTrimHandle.cpp.

218 {
219 if (mClips[0]->GetPlayStartTime() != mInitialBorderPosition)
220 {
222 {
223 auto dt = std::abs(mClips[0]->GetPlayStartTime() - mInitialBorderPosition);
224 ProjectHistory::Get(project).PushState(XO("Clip-Trim-Left"),
225 XO("Moved by %.02f").Format(dt), UndoPush::CONSOLIDATE);
226 }
227 else
228 {
229 auto dt = std::abs(mInitialBorderPosition - mClips[0]->GetPlayEndTime());
230 ProjectHistory::Get(project).PushState(XO("Clip-Trim-Right"),
231 XO("Moved by %.02f").Format(dt), UndoPush::CONSOLIDATE);
232 }
233 }
234 }
XO("Cut/Copy/Paste")
Abstract base class used in importing a file.
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)

References CONSOLIDATE, ProjectHistory::Get(), mAdjustingLeftBorder, mClips, mInitialBorderPosition, ProjectHistory::PushState(), and XO().

Here is the call graph for this function:

◆ Init()

bool WaveClipTrimHandle::AdjustBorder::Init ( const TrackPanelMouseEvent event)
inlineoverridevirtual

Implements WaveClipTrimHandle::ClipTrimPolicy.

Definition at line 171 of file WaveClipTrimHandle.cpp.

172 {
173 if (event.event.LeftDown())
174 {
175 mDragStartX = event.event.GetX();
176 return true;
177 }
178 return false;
179 }

References TrackPanelMouseEvent::event, and mDragStartX.

◆ Trim()

UIHandle::Result WaveClipTrimHandle::AdjustBorder::Trim ( const TrackPanelMouseEvent event,
AudacityProject project 
)
inlineoverridevirtual

Implements WaveClipTrimHandle::ClipTrimPolicy.

Definition at line 181 of file WaveClipTrimHandle.cpp.

182 {
183 const auto eventX = event.event.GetX();
184 const auto dx = eventX - mDragStartX;
185
186 const auto& viewInfo = ViewInfo::Get(project);
187
188 const auto eventT = viewInfo.PositionToTime(viewInfo.TimeToPosition(mInitialBorderPosition, event.rect.x) + dx, event.rect.x);
189
190 const auto offset = sampleCount(floor((eventT - mInitialBorderPosition) * mClips[0]->GetRate())).as_double() / mClips[0]->GetRate();
191 const auto t = std::clamp(mInitialBorderPosition + offset, mRange.first, mRange.second);
192 const auto wasSnapped = mSnap.Snapped();
193 if(mSnapManager)
194 mSnap = mSnapManager->Snap(mTrack.get(), t, !mAdjustingLeftBorder);
195 if(mSnap.Snapped())
196 {
197 if(mSnap.outTime >= mRange.first && mSnap.outTime <= mRange.second)
198 {
199 //Make sure that outTime belongs to the adjustment range after snapping
202 }
203 else
204 {
205 //Otherwise snapping cannot be performed
206 mSnap = {};
207 TrimTo(t);
208 }
209 }
210 else
211 TrimTo(t);
212 //If there was a snap line, make sure it is removed
213 //from the screen by redrawing whole TrackPanel
215 }
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:234
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
double as_double() const
Definition: SampleCount.h:46
double outTime
Definition: Snap.h:47

References sampleCount::as_double(), ViewInfo::Get(), anonymous_namespace{TimeTrack.cpp}::GetRate(), mAdjustingLeftBorder, mClips, mDragStartX, mInitialBorderPosition, mRange, mSnap, mSnapManager, mTrack, SnapResults::outTime, TrackPanelMouseEvent::rect, RefreshCode::RefreshAll, RefreshCode::RefreshCell, SnapResults::Snapped(), and TrimTo().

Here is the call graph for this function:

◆ TrimTo()

void WaveClipTrimHandle::AdjustBorder::TrimTo ( double  t)
inlineprivate

Definition at line 59 of file WaveClipTrimHandle.cpp.

60 {
61 t = std::clamp(t, mRange.first, mRange.second);
63 {
64 for (auto& clip : mClips)
65 clip->TrimLeftTo(t);
66 }
67 else
68 {
69 for (auto& clip : mClips)
70 clip->TrimRightTo(t);
71 }
72 }

References mAdjustingLeftBorder, mClips, and mRange.

Referenced by Cancel(), and Trim().

Here is the caller graph for this function:

Member Data Documentation

◆ mAdjustingLeftBorder

bool WaveClipTrimHandle::AdjustBorder::mAdjustingLeftBorder
private

Definition at line 54 of file WaveClipTrimHandle.cpp.

Referenced by AdjustBorder(), Finish(), Trim(), and TrimTo().

◆ mClips

std::vector<std::shared_ptr<WaveClip> > WaveClipTrimHandle::AdjustBorder::mClips
private

Definition at line 50 of file WaveClipTrimHandle.cpp.

Referenced by AdjustBorder(), Finish(), Trim(), and TrimTo().

◆ mDragStartX

int WaveClipTrimHandle::AdjustBorder::mDragStartX { }
private

Definition at line 52 of file WaveClipTrimHandle.cpp.

Referenced by Init(), and Trim().

◆ mInitialBorderPosition

double WaveClipTrimHandle::AdjustBorder::mInitialBorderPosition {}
private

Definition at line 51 of file WaveClipTrimHandle.cpp.

Referenced by AdjustBorder(), Cancel(), Finish(), and Trim().

◆ mRange

std::pair<double, double> WaveClipTrimHandle::AdjustBorder::mRange
private

Definition at line 53 of file WaveClipTrimHandle.cpp.

Referenced by AdjustBorder(), Trim(), and TrimTo().

◆ mSnap

SnapResults WaveClipTrimHandle::AdjustBorder::mSnap
private

Definition at line 57 of file WaveClipTrimHandle.cpp.

Referenced by Draw(), and Trim().

◆ mSnapManager

std::unique_ptr<SnapManager> WaveClipTrimHandle::AdjustBorder::mSnapManager
private

Definition at line 56 of file WaveClipTrimHandle.cpp.

Referenced by AdjustBorder(), and Trim().

◆ mTrack

std::shared_ptr<WaveTrack> WaveClipTrimHandle::AdjustBorder::mTrack
private

Definition at line 49 of file WaveClipTrimHandle.cpp.

Referenced by Trim().


The documentation for this class was generated from the following file: