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

Public Types

using AdjustHandler = std::function< void(WaveTrack::Interval &, double)>
 

Public Member Functions

 AdjustClipBorder (AdjustHandler adjustHandler, std::shared_ptr< WaveTrack > track, std::shared_ptr< WaveTrack::Interval > interval, bool adjustLeftBorder, bool isStretchMode, const ZoomInfo &zoomInfo)
 
bool Init (const TrackPanelMouseEvent &event) override
 
UIHandle::Result Drag (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 WaveClipAdjustBorderHandle::AdjustPolicy
virtual ~AdjustPolicy ()
 
virtual bool Init (const TrackPanelMouseEvent &event)=0
 
virtual UIHandle::Result Drag (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, const std::pair< double, double > range)
 

Private Attributes

std::shared_ptr< WaveTrackmTrack
 
std::shared_ptr< WaveTrack::IntervalmInterval
 
int mDragStartX { }
 
const bool mAdjustingLeftBorder
 
const bool mIsStretchMode
 
const double mInitialBorderPosition
 
double mBorderPosition
 
const std::pair< double, double > mRange
 
AdjustHandler mAdjustHandler
 
std::unique_ptr< SnapManagermSnapManager
 
SnapResults mSnap
 

Detailed Description

Definition at line 125 of file WaveClipAdjustBorderHandle.cpp.

Member Typedef Documentation

◆ AdjustHandler

using AdjustClipBorder::AdjustHandler = std::function<void(WaveTrack::Interval&, double)>

Definition at line 128 of file WaveClipAdjustBorderHandle.cpp.

Constructor & Destructor Documentation

◆ AdjustClipBorder()

AdjustClipBorder::AdjustClipBorder ( AdjustHandler  adjustHandler,
std::shared_ptr< WaveTrack track,
std::shared_ptr< WaveTrack::Interval interval,
bool  adjustLeftBorder,
bool  isStretchMode,
const ZoomInfo zoomInfo 
)
inline

Definition at line 190 of file WaveClipAdjustBorderHandle.cpp.

196 : mTrack { std::move(track) }
197 , mInterval { std::move(interval) }
198 , mAdjustingLeftBorder { adjustLeftBorder }
199 , mIsStretchMode { isStretchMode }
200 , mInitialBorderPosition { adjustLeftBorder ? mInterval->Start() :
201 mInterval->End() }
203 , mRange { GetLeftAdjustLimit( *mInterval, *mTrack, adjustLeftBorder, isStretchMode),
204 GetRightAdjustLimit(*mInterval, *mTrack, adjustLeftBorder, isStretchMode) }
205 , mAdjustHandler { std::move(adjustHandler) }
206 {
207 assert(mRange.first <= mRange.second);
208 if(const auto trackList = mTrack->GetOwner())
209 {
210 mSnapManager = std::make_unique<SnapManager>(
211 *trackList->GetOwner(),
213 zoomInfo);
214 }
215 }
std::shared_ptr< WaveTrack::Interval > mInterval
const std::pair< double, double > mRange
std::shared_ptr< WaveTrack > mTrack
static SnapPointArray FindSnapPoints(const WaveTrack *currentTrack, const std::pair< double, double > range)
std::unique_ptr< SnapManager > mSnapManager
double GetRightAdjustLimit(const WaveTrack::Interval &interval, const WaveTrack &track, bool adjustingLeftBorder, bool isStretchMode)
double GetLeftAdjustLimit(const WaveTrack::Interval &interval, const WaveTrack &track, bool adjustingLeftBorder, bool isStretchMode)

References FindSnapPoints(), mRange, mSnapManager, and mTrack.

Here is the call graph for this function:

Member Function Documentation

◆ Cancel()

void AdjustClipBorder::Cancel ( )
inlineoverridevirtual

Implements WaveClipAdjustBorderHandle::AdjustPolicy.

Definition at line 288 of file WaveClipAdjustBorderHandle.cpp.

References mInitialBorderPosition, and TrimTo().

Here is the call graph for this function:

◆ Drag()

UIHandle::Result AdjustClipBorder::Drag ( const TrackPanelMouseEvent event,
AudacityProject project 
)
inlineoverridevirtual

Implements WaveClipAdjustBorderHandle::AdjustPolicy.

Definition at line 227 of file WaveClipAdjustBorderHandle.cpp.

228 {
229 const auto eventX = event.event.GetX();
230 const auto dx = eventX - mDragStartX;
231
232 const auto& viewInfo = ViewInfo::Get(project);
233
234 const auto eventT = viewInfo.PositionToTime(
235 viewInfo.TimeToPosition(mInitialBorderPosition, event.rect.x) + dx,
236 event.rect.x
237 );
238
239 const auto offset = sampleCount(floor((eventT - mInitialBorderPosition) * mTrack->GetRate())).as_double()
240 / mTrack->GetRate();
241 const auto t = std::clamp(mInitialBorderPosition + offset, mRange.first, mRange.second);
242 const auto wasSnapped = mSnap.Snapped();
243 if(mSnapManager)
244 mSnap = mSnapManager->Snap(mTrack.get(), t, !mAdjustingLeftBorder);
245 if(mSnap.Snapped())
246 {
247 if (mSnap.outTime >= mRange.first && mSnap.outTime <= mRange.second)
248 {
249 //Make sure that outTime belongs to the adjustment range after snapping
252 }
253 mSnap = {};
254 }
255 TrimTo(t);
256 //If there was a snap line, make sure it is removed
257 //from the screen by redrawing whole TrackPanel
259 }
const auto project
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
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
bool Snapped() const
Definition: Snap.h:52

References sampleCount::as_double(), ViewInfo::Get(), mAdjustingLeftBorder, mDragStartX, mInitialBorderPosition, mRange, mSnap, mSnapManager, mTrack, SnapResults::outTime, project, TrackPanelMouseEvent::rect, RefreshCode::RefreshAll, RefreshCode::RefreshCell, SnapResults::Snapped(), and TrimTo().

Here is the call graph for this function:

◆ Draw()

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

Reimplemented from WaveClipAdjustBorderHandle::AdjustPolicy.

Definition at line 293 of file WaveClipAdjustBorderHandle.cpp.

294 {
295 if(iPass == TrackArtist::PassSnapping && mSnap.Snapped())
296 {
297 auto &dc = context.dc;
298 TrackArt::DrawSnapLines(&dc, rect.x + mSnap.outCoord, -1);
299 }
300 }
AUDACITY_DLL_API void DrawSnapLines(wxDC *dc, wxInt64 snap0, wxInt64 snap1)
Definition: TrackArt.cpp:775
wxInt64 outCoord
Definition: Snap.h:48

References TrackPanelDrawingContext::dc, TrackArt::DrawSnapLines(), mSnap, SnapResults::outCoord, TrackArtist::PassSnapping, and SnapResults::Snapped().

Here is the call graph for this function:

◆ DrawingArea()

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

Reimplemented from WaveClipAdjustBorderHandle::AdjustPolicy.

Definition at line 302 of file WaveClipAdjustBorderHandle.cpp.

303 {
304 if(iPass == TrackArtist::PassSnapping)
305 return TrackPanelDrawable::MaximizeHeight(rect, panelRect);
306 return rect;
307 }
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 AdjustClipBorder::FindSnapPoints ( const WaveTrack currentTrack,
const std::pair< double, double >  range 
)
inlinestaticprivate

Definition at line 152 of file WaveClipAdjustBorderHandle.cpp.

155 {
156 SnapPointArray result;
157
158 auto addSnapPoint = [&](double t, const Track* track)
159 {
160 if(t > range.second || t < range.first)
161 return;
162
163 for(const auto& snapPoint : result)
164 if(snapPoint.t == t)
165 return;
166 result.emplace_back(t, track);
167 };
168
169 if(const auto trackList = currentTrack->GetOwner())
170 {
171 for(const auto track : as_const(*trackList))
172 {
173 if(track == currentTrack)
174 {
175 //skip track that interval belongs to
176 continue;
177 }
178
179 for (const auto &interval : track->Intervals()) {
180 addSnapPoint(interval->Start(), track);
181 if(interval->Start() != interval->End())
182 addSnapPoint(interval->End(), track);
183 }
184 }
185 }
186 return result;
187 }
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:110
std::shared_ptr< TrackList > GetOwner() const
Definition: Track.h:230

References Track::GetOwner().

Referenced by AdjustClipBorder().

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

◆ Finish()

void AdjustClipBorder::Finish ( AudacityProject project)
inlineoverridevirtual

Implements WaveClipAdjustBorderHandle::AdjustPolicy.

Definition at line 261 of file WaveClipAdjustBorderHandle.cpp.

262 {
263 const auto dt = std::abs(mInitialBorderPosition - mBorderPosition);
264 if (dt != 0)
265 {
266 if (mIsStretchMode)
267 {
269 project, 100.0 / mInterval->GetStretchRatio());
270 }
271 else if (mAdjustingLeftBorder)
272 {
273 /*i18n-hint: This is about trimming a clip, a length in seconds like "2.4 seconds" is shown*/
274 ProjectHistory::Get(project).PushState(XO("Adjust left trim by %.02f seconds").Format(dt),
275 /*i18n-hint: This is about trimming a clip, a length in seconds like "2.4s" is shown*/
276 XO("Trim by %.02fs").Format(dt));
277 }
278 else
279 {
280 /*i18n-hint: This is about trimming a clip, a length in seconds like "2.4 seconds" is shown*/
281 ProjectHistory::Get(project).PushState(XO("Adjust right trim by %.02f seconds").Format(dt),
282 /*i18n-hint: This is about trimming a clip, a length in seconds like "2.4s" is shown*/
283 XO("Trim by %.02fs").Format(dt));
284 }
285 }
286 }
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)
void PushClipSpeedChangedUndoState(AudacityProject &project, double speedInPercent)

References ProjectHistory::Get(), mAdjustingLeftBorder, mBorderPosition, mInitialBorderPosition, mInterval, mIsStretchMode, project, WaveClipUIUtilities::PushClipSpeedChangedUndoState(), ProjectHistory::PushState(), and XO().

Here is the call graph for this function:

◆ Init()

bool AdjustClipBorder::Init ( const TrackPanelMouseEvent event)
inlineoverridevirtual

Implements WaveClipAdjustBorderHandle::AdjustPolicy.

Definition at line 217 of file WaveClipAdjustBorderHandle.cpp.

218 {
219 if (event.event.LeftDown())
220 {
221 mDragStartX = event.event.GetX();
222 return true;
223 }
224 return false;
225 }

References TrackPanelMouseEvent::event, and mDragStartX.

◆ TrimTo()

void AdjustClipBorder::TrimTo ( double  t)
inlineprivate

Definition at line 144 of file WaveClipAdjustBorderHandle.cpp.

145 {
146 mBorderPosition = std::clamp(t, mRange.first, mRange.second);
148 }

References mAdjustHandler, mBorderPosition, mInterval, and mRange.

Referenced by Cancel(), and Drag().

Here is the caller graph for this function:

Member Data Documentation

◆ mAdjustHandler

AdjustHandler AdjustClipBorder::mAdjustHandler
private

Definition at line 139 of file WaveClipAdjustBorderHandle.cpp.

Referenced by TrimTo().

◆ mAdjustingLeftBorder

const bool AdjustClipBorder::mAdjustingLeftBorder
private

Definition at line 134 of file WaveClipAdjustBorderHandle.cpp.

Referenced by Drag(), and Finish().

◆ mBorderPosition

double AdjustClipBorder::mBorderPosition
private

Definition at line 137 of file WaveClipAdjustBorderHandle.cpp.

Referenced by Finish(), and TrimTo().

◆ mDragStartX

int AdjustClipBorder::mDragStartX { }
private

Definition at line 133 of file WaveClipAdjustBorderHandle.cpp.

Referenced by Drag(), and Init().

◆ mInitialBorderPosition

const double AdjustClipBorder::mInitialBorderPosition
private

Definition at line 136 of file WaveClipAdjustBorderHandle.cpp.

Referenced by Cancel(), Drag(), and Finish().

◆ mInterval

std::shared_ptr<WaveTrack::Interval> AdjustClipBorder::mInterval
private

Definition at line 132 of file WaveClipAdjustBorderHandle.cpp.

Referenced by Finish(), and TrimTo().

◆ mIsStretchMode

const bool AdjustClipBorder::mIsStretchMode
private

Definition at line 135 of file WaveClipAdjustBorderHandle.cpp.

Referenced by Finish().

◆ mRange

const std::pair<double, double> AdjustClipBorder::mRange
private

Definition at line 138 of file WaveClipAdjustBorderHandle.cpp.

Referenced by AdjustClipBorder(), Drag(), and TrimTo().

◆ mSnap

SnapResults AdjustClipBorder::mSnap
private

Definition at line 142 of file WaveClipAdjustBorderHandle.cpp.

Referenced by Drag(), and Draw().

◆ mSnapManager

std::unique_ptr<SnapManager> AdjustClipBorder::mSnapManager
private

Definition at line 141 of file WaveClipAdjustBorderHandle.cpp.

Referenced by AdjustClipBorder(), and Drag().

◆ mTrack

std::shared_ptr<WaveTrack> AdjustClipBorder::mTrack
private

Definition at line 131 of file WaveClipAdjustBorderHandle.cpp.

Referenced by AdjustClipBorder(), and Drag().


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