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

Public Member Functions

 AdjustBetweenBorders (WaveTrack *track, std::shared_ptr< WaveClip > &leftClip, std::shared_ptr< WaveClip > &rightClip)
 
bool Init (const TrackPanelMouseEvent &event) override
 
UIHandle::Result Trim (const TrackPanelMouseEvent &event, AudacityProject &project) override
 
void Finish (AudacityProject &project) override
 
void Cancel () 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)
 

Private Attributes

std::pair< double, double > mRange
 
std::vector< std::shared_ptr< WaveClip > > mLeftClips
 
std::vector< std::shared_ptr< WaveClip > > mRightClips
 
double mInitialBorderPosition {}
 
int mDragStartX { }
 

Detailed Description

Definition at line 258 of file WaveClipTrimHandle.cpp.

Constructor & Destructor Documentation

◆ AdjustBetweenBorders()

WaveClipTrimHandle::AdjustBetweenBorders::AdjustBetweenBorders ( WaveTrack track,
std::shared_ptr< WaveClip > &  leftClip,
std::shared_ptr< WaveClip > &  rightClip 
)
inline

Definition at line 277 of file WaveClipTrimHandle.cpp.

281 {
282 auto clips = track->GetClips();
283
284 wxASSERT(std::find(clips.begin(), clips.end(), leftClip) != clips.end());
285 wxASSERT(std::find(clips.begin(), clips.end(), rightClip) != clips.end());
286
287 if (track->IsAlignedWithLeader() || track->GetLinkType() == Track::LinkType::Aligned)
288 {
289 //find clips in other channels which are also should be trimmed
290 mLeftClips = FindClipsInChannels(leftClip->GetPlayStartTime(), leftClip->GetPlayEndTime(), track);
291 mRightClips = FindClipsInChannels(rightClip->GetPlayStartTime(), rightClip->GetPlayEndTime(), track);
292 }
293 else
294 {
295 mLeftClips.push_back(leftClip);
296 mRightClips.push_back(rightClip);
297 }
298
299 mRange = std::make_pair(
300 //not less than 1 sample length
301 mLeftClips[0]->GetPlayStartTime() + 1.0 / mLeftClips[0]->GetRate(),
302 mRightClips[0]->GetPlayEndTime() - 1.0 / mRightClips[0]->GetRate()
303 );
304 mInitialBorderPosition = mRightClips[0]->GetPlayStartTime();
305 }
LinkType GetLinkType() const noexcept
Definition: Track.cpp:1347
bool IsAlignedWithLeader() const
Returns true if the leader track has link type LinkType::Aligned.
Definition: Track.cpp:1352
std::vector< std::shared_ptr< WaveClip > > mLeftClips
std::vector< std::shared_ptr< WaveClip > > mRightClips
WaveClipHolders & GetClips()
Definition: WaveTrack.h:338
std::vector< std::shared_ptr< WaveClip > > FindClipsInChannels(double start, double end, WaveTrack *track)

References Track::Aligned, anonymous_namespace{WaveClipTrimHandle.cpp}::FindClipsInChannels(), WaveTrack::GetClips(), Track::GetLinkType(), anonymous_namespace{TimeTrack.cpp}::GetRate(), Track::IsAlignedWithLeader(), mInitialBorderPosition, mLeftClips, mRange, and mRightClips.

Here is the call graph for this function:

Member Function Documentation

◆ Cancel()

void WaveClipTrimHandle::AdjustBetweenBorders::Cancel ( )
inlineoverridevirtual

Implements WaveClipTrimHandle::ClipTrimPolicy.

Definition at line 346 of file WaveClipTrimHandle.cpp.

References mInitialBorderPosition, and TrimTo().

Here is the call graph for this function:

◆ Finish()

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

Implements WaveClipTrimHandle::ClipTrimPolicy.

Definition at line 336 of file WaveClipTrimHandle.cpp.

337 {
338 if (mRightClips[0]->GetPlayStartTime() != mInitialBorderPosition)
339 {
340 auto dt = std::abs(mRightClips[0]->GetPlayStartTime() - mInitialBorderPosition);
341 ProjectHistory::Get(project).PushState(XO("Clip-Trim-Between"),
342 XO("Moved by %.02f").Format(dt), UndoPush::CONSOLIDATE);
343 }
344 }
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(), mInitialBorderPosition, mRightClips, ProjectHistory::PushState(), and XO().

Here is the call graph for this function:

◆ Init()

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

Implements WaveClipTrimHandle::ClipTrimPolicy.

Definition at line 307 of file WaveClipTrimHandle.cpp.

308 {
309 if (event.event.LeftDown())
310 {
311 mDragStartX = event.event.GetX();
312 return true;
313 }
314 return false;
315 }

References TrackPanelMouseEvent::event, and mDragStartX.

◆ Trim()

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

Implements WaveClipTrimHandle::ClipTrimPolicy.

Definition at line 317 of file WaveClipTrimHandle.cpp.

318 {
319 const auto newX = event.event.GetX();
320 const auto dx = newX - mDragStartX;
321
322 auto& viewInfo = ViewInfo::Get(project);
323
324 auto eventT = viewInfo.PositionToTime(viewInfo.TimeToPosition(mInitialBorderPosition, event.rect.x) + dx, event.rect.x);
325 auto offset = sampleCount(
326 floor(
327 (eventT - mInitialBorderPosition) * mLeftClips[0]->GetRate()
328 )
329 ).as_double() / mLeftClips[0]->GetRate();
330
332
334 }
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

References sampleCount::as_double(), ViewInfo::Get(), anonymous_namespace{TimeTrack.cpp}::GetRate(), mDragStartX, mInitialBorderPosition, mLeftClips, TrackPanelMouseEvent::rect, RefreshCode::RefreshCell, and TrimTo().

Here is the call graph for this function:

◆ TrimTo()

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

Definition at line 266 of file WaveClipTrimHandle.cpp.

267 {
268 t = std::clamp(t, mRange.first, mRange.second);
269
270 for (auto& clip : mLeftClips)
271 clip->TrimRightTo(t);
272 for (auto& clip : mRightClips)
273 clip->TrimLeftTo(t);
274 }

References mLeftClips, mRange, and mRightClips.

Referenced by Cancel(), and Trim().

Here is the caller graph for this function:

Member Data Documentation

◆ mDragStartX

int WaveClipTrimHandle::AdjustBetweenBorders::mDragStartX { }
private

Definition at line 264 of file WaveClipTrimHandle.cpp.

Referenced by Init(), and Trim().

◆ mInitialBorderPosition

double WaveClipTrimHandle::AdjustBetweenBorders::mInitialBorderPosition {}
private

Definition at line 263 of file WaveClipTrimHandle.cpp.

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

◆ mLeftClips

std::vector<std::shared_ptr<WaveClip> > WaveClipTrimHandle::AdjustBetweenBorders::mLeftClips
private

Definition at line 261 of file WaveClipTrimHandle.cpp.

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

◆ mRange

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

Definition at line 260 of file WaveClipTrimHandle.cpp.

Referenced by AdjustBetweenBorders(), and TrimTo().

◆ mRightClips

std::vector<std::shared_ptr<WaveClip> > WaveClipTrimHandle::AdjustBetweenBorders::mRightClips
private

Definition at line 262 of file WaveClipTrimHandle.cpp.

Referenced by AdjustBetweenBorders(), Finish(), and TrimTo().


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