Audacity 3.2.0
Public Types | Public Member Functions | Public Attributes | List of all members
ClipMoveState Struct Reference

#include <TimeShiftHandle.h>

Collaboration diagram for ClipMoveState:
[legend]

Public Types

using ShifterMap = std::unordered_map< Track *, std::unique_ptr< TrackShifter > >
 

Public Member Functions

 ClipMoveState ()=default
 
 ClipMoveState (const ClipMoveState &) PROHIBITED
 
ClipMoveStateoperator= (const ClipMoveState &) PROHIBITED
 
 ClipMoveState (ClipMoveState &&)=default
 
ClipMoveStateoperator= (ClipMoveState &&)=default
 
void Init (AudacityProject &project, Track &capturedTrack, TrackShifter::HitTestResult hitTestResult, std::unique_ptr< TrackShifter > pHit, double clickTime, const ViewInfo &viewInfo, TrackList &trackList, bool syncLocked)
 Will associate a TrackShifter with each track in the list. More...
 
const TrackIntervalCapturedInterval () const
 Return pointer to the first fixed interval of the captured track, if there is one. More...
 
double DoSlideHorizontal (double desiredSlideAmount)
 Do sliding of tracks and intervals, maybe adjusting the offset. More...
 
void DoHorizontalOffset (double offset)
 Offset tracks or intervals horizontally, without adjusting the offset. More...
 
void clear ()
 

Public Attributes

std::shared_ptr< TrackmCapturedTrack
 
bool initialized { false }
 
bool movingSelection {}
 
bool wasMoved { false }
 
double hSlideAmount {}
 
ShifterMap shifters
 
wxInt64 snapLeft { -1 }
 
wxInt64 snapRight { -1 }
 
int mMouseClickX {}
 

Detailed Description

Definition at line 205 of file TimeShiftHandle.h.

Member Typedef Documentation

◆ ShifterMap

using ClipMoveState::ShifterMap = std::unordered_map<Track*, std::unique_ptr<TrackShifter> >

Definition at line 214 of file TimeShiftHandle.h.

Constructor & Destructor Documentation

◆ ClipMoveState() [1/3]

ClipMoveState::ClipMoveState ( )
default

◆ ClipMoveState() [2/3]

ClipMoveState::ClipMoveState ( const ClipMoveState )

◆ ClipMoveState() [3/3]

ClipMoveState::ClipMoveState ( ClipMoveState &&  )
default

Member Function Documentation

◆ CapturedInterval()

const TrackInterval * ClipMoveState::CapturedInterval ( ) const

Return pointer to the first fixed interval of the captured track, if there is one.

Pointer may be invalidated by operations on the associated TrackShifter

Definition at line 416 of file TimeShiftHandle.cpp.

417{
418 auto pTrack = mCapturedTrack.get();
419 if ( pTrack ) {
420 auto iter = shifters.find( pTrack );
421 if ( iter != shifters.end() ) {
422 auto &pShifter = iter->second;
423 if ( pShifter ) {
424 auto &intervals = pShifter->MovingIntervals();
425 if ( !intervals.empty() )
426 return &intervals[0];
427 }
428 }
429 }
430 return nullptr;
431}
ShifterMap shifters
std::shared_ptr< Track > mCapturedTrack

References mCapturedTrack, and shifters.

Referenced by anonymous_namespace{TimeShiftHandle.cpp}::AdjustToSnap(), and TimeShiftHandle::Click().

Here is the caller graph for this function:

◆ clear()

void ClipMoveState::clear ( )
inline

Definition at line 249 of file TimeShiftHandle.h.

250 {
251 initialized = false;
252 wasMoved = false;
253 movingSelection = false;
254 hSlideAmount = 0;
255 shifters.clear();
256 snapLeft = snapRight = -1;
257 mMouseClickX = 0;
258 }

Referenced by TimeShiftHandle::Click().

Here is the caller graph for this function:

◆ DoHorizontalOffset()

void ClipMoveState::DoHorizontalOffset ( double  offset)

Offset tracks or intervals horizontally, without adjusting the offset.

Definition at line 118 of file TimeShiftHandle.cpp.

119{
120 if ( !shifters.empty() ) {
121 for ( auto &pair : shifters )
122 pair.second->DoHorizontalOffset( offset );
123 }
124 else {
125 for (auto channel : TrackList::Channels( mCapturedTrack.get() ))
126 channel->Offset( offset );
127 }
128}
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1417

References TrackList::Channels(), mCapturedTrack, and shifters.

Referenced by TimeShiftHandle::Drag().

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

◆ DoSlideHorizontal()

double ClipMoveState::DoSlideHorizontal ( double  desiredSlideAmount)

Do sliding of tracks and intervals, maybe adjusting the offset.

Returns
actual slide amount, maybe adjusted toward zero from desired

Definition at line 433 of file TimeShiftHandle.cpp.

434{
435 auto &state = *this;
436 auto &capturedTrack = *state.mCapturedTrack;
437
438 // Given a signed slide distance, move clips, but subject to constraint of
439 // non-overlapping with other clips, so the distance may be adjusted toward
440 // zero.
441 if ( !state.shifters.empty() ) {
442 double initialAllowed = 0;
443 do { // loop to compute allowed, does not actually move anything yet
444 initialAllowed = desiredSlideAmount;
445
446 for (auto &pair : shifters) {
447 auto newAmount = pair.second->AdjustOffsetSmaller( desiredSlideAmount );
448 if ( desiredSlideAmount != newAmount ) {
449 if ( newAmount * desiredSlideAmount < 0 ||
450 fabs(newAmount) > fabs(desiredSlideAmount) ) {
451 wxASSERT( false ); // AdjustOffsetSmaller didn't honor postcondition!
452 newAmount = 0; // Be sure the loop progresses to termination!
453 }
454 desiredSlideAmount = newAmount;
455 state.snapLeft = state.snapRight = -1; // see bug 1067
456 }
457 if (newAmount == 0)
458 break;
459 }
460 } while ( desiredSlideAmount != initialAllowed );
461 }
462
463 // Whether moving intervals or a whole track,
464 // finally, here is where clips are moved
465 if ( desiredSlideAmount != 0.0 )
466 state.DoHorizontalOffset( desiredSlideAmount );
467
468 //attempt to move a clip is counted to
469 wasMoved = true;
470
471 return (state.hSlideAmount = desiredSlideAmount);
472}

References shifters, and wasMoved.

Referenced by anonymous_namespace{ClipMenus.cpp}::DoClipMove(), and TimeShiftHandle::Drag().

Here is the caller graph for this function:

◆ Init()

void ClipMoveState::Init ( AudacityProject project,
Track capturedTrack,
TrackShifter::HitTestResult  hitTestResult,
std::unique_ptr< TrackShifter pHit,
double  clickTime,
const ViewInfo viewInfo,
TrackList trackList,
bool  syncLocked 
)

Will associate a TrackShifter with each track in the list.

Parameters
hitTestResultmust not be `Miss`
pHitIf null, implies `Track`, overriding previous argument

Definition at line 282 of file TimeShiftHandle.cpp.

290{
291 shifters.clear();
292
293 initialized = true;
294
295 auto &state = *this;
296 state.mCapturedTrack = capturedTrack.SharedPointer();
297
298 switch (hitTestResult) {
300 wxASSERT(false);
301 pHit.reset();
302 break;
304 pHit.reset();
305 break;
307 break;
309 state.movingSelection = true;
310 break;
311 default:
312 break;
313 }
314
315 if (!pHit)
316 return;
317
318 state.shifters[&capturedTrack] = std::move( pHit );
319
320 // Collect TrackShifters for the rest of the tracks
321 for ( auto track : trackList.Any() ) {
322 auto &pShifter = state.shifters[track];
323 if (!pShifter)
324 pShifter = MakeTrackShifter::Call( *track, project );
325 }
326
327 if ( state.movingSelection ) {
328 // All selected tracks may move some intervals
329 const TrackInterval interval{
330 viewInfo.selectedRegion.t0(),
331 viewInfo.selectedRegion.t1()
332 };
333 for ( const auto &pair : state.shifters ) {
334 auto &shifter = *pair.second;
335 auto &track = shifter.GetTrack();
336 if (&track == &capturedTrack)
337 // Don't change the choice of intervals made by HitTest
338 continue;
339 if ( track.IsSelected() )
340 shifter.SelectInterval( interval );
341 }
342 }
343 else {
344 // Move intervals only of the chosen channel group
345
346 auto selectIntervals = [&](const TrackShifter::Intervals& intervals) {
347 for (auto channel : TrackList::Channels(&capturedTrack)) {
348 auto& shifter = *state.shifters[channel];
349 if (channel != &capturedTrack)
350 {
351 for (auto& interval : intervals)
352 {
353 shifter.SelectInterval(interval);
354 }
355 }
356 }
357 };
358 if (capturedTrack.GetLinkType() == Track::LinkType::Aligned ||
359 capturedTrack.IsAlignedWithLeader())
360 //for aligned tracks we always match the whole clip that was
361 //positively hit tested
362 selectIntervals(state.shifters[&capturedTrack]->MovingIntervals());
363 else
364 {
365 TrackShifter::Intervals intervals;
366 intervals.emplace_back(TrackInterval { clickTime, clickTime });
367 //for not align, match clips from other channels that are
368 //exactly at clicked time point
369 selectIntervals(intervals);
370 }
371 }
372
373 // Sync lock propagation of unfixing of intervals
374 if ( syncLocked ) {
375 bool change = true;
376 while( change ) {
377 change = false;
378
379 // Iterate over all unfixed intervals in all tracks
380 // that do propagation and are in sync lock groups ...
381 for ( auto &pair : state.shifters ) {
382 auto &shifter = *pair.second.get();
383 if (!shifter.SyncLocks())
384 continue;
385 auto &track = shifter.GetTrack();
386 auto group = SyncLock::Group(&track);
387 if ( group.size() <= 1 )
388 continue;
389
390 auto &intervals = shifter.MovingIntervals();
391 for (auto &interval : intervals) {
392
393 // ...and tell all other tracks in the sync lock group
394 // to select that interval...
395 for ( auto pTrack2 : group ) {
396 if (pTrack2 == &track)
397 continue;
398
399 auto &shifter2 = *shifters[pTrack2];
400 auto size = shifter2.MovingIntervals().size();
401 shifter2.SelectInterval( interval );
402 change = change ||
403 (shifter2.SyncLocks() &&
404 size != shifter2.MovingIntervals().size());
405 }
406
407 }
408 }
409
410 // ... and repeat if any other interval became unfixed in a
411 // shifter that propagates
412 }
413 }
414}
static Return Call(This &obj, Arguments &&...arguments)
Invoke the method – but only after static initialization time.
double t1() const
Definition: ViewInfo.h:36
double t0() const
Definition: ViewInfo.h:35
static TrackIterRange< Track > Group(Track *pTrack)
Definition: SyncLock.cpp:161
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:232
LinkType GetLinkType() const noexcept
Definition: Track.cpp:1245
bool IsAlignedWithLeader() const
Returns true if the leader track has link type LinkType::Aligned.
Definition: Track.cpp:1250
A start and an end time, and mutative access to optional extra information.
Definition: Track.h:142
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1313
std::vector< TrackInterval > Intervals
@ Selection
Shift chosen intervals of this track; may shift other tracks' intervals.
@ Intervals
Shift intervals only of selected track and sister channels.
@ Track
Shift selected track and sister channels only, as a whole.
@ Miss
Don't shift anything.
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:219

References Track::Aligned, TrackList::Any(), AttachedVirtualFunction< Tag, Return, This, Arguments >::Call(), TrackList::Channels(), Track::GetLinkType(), SyncLock::Group(), initialized, TrackShifter::Intervals, Track::IsAlignedWithLeader(), TrackShifter::Miss, ViewInfo::selectedRegion, TrackShifter::Selection, Track::SharedPointer(), shifters, size, NotifyingSelectedRegion::t0(), NotifyingSelectedRegion::t1(), and TrackShifter::Track.

Referenced by TimeShiftHandle::Click(), and anonymous_namespace{ClipMenus.cpp}::DoClipMove().

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

◆ operator=() [1/2]

ClipMoveState & ClipMoveState::operator= ( ClipMoveState &&  )
default

◆ operator=() [2/2]

ClipMoveState & ClipMoveState::operator= ( const ClipMoveState )

Member Data Documentation

◆ hSlideAmount

double ClipMoveState::hSlideAmount {}

Definition at line 243 of file TimeShiftHandle.h.

Referenced by TimeShiftHandle::Drag(), and TimeShiftHandle::Release().

◆ initialized

bool ClipMoveState::initialized { false }

◆ mCapturedTrack

std::shared_ptr<Track> ClipMoveState::mCapturedTrack

◆ mMouseClickX

int ClipMoveState::mMouseClickX {}

◆ movingSelection

bool ClipMoveState::movingSelection {}

Definition at line 241 of file TimeShiftHandle.h.

Referenced by TimeShiftHandle::DoSlideVertical(), and TimeShiftHandle::Drag().

◆ shifters

ShifterMap ClipMoveState::shifters

◆ snapLeft

wxInt64 ClipMoveState::snapLeft { -1 }

◆ snapRight

wxInt64 ClipMoveState::snapRight { -1 }

◆ wasMoved

bool ClipMoveState::wasMoved { false }

Definition at line 242 of file TimeShiftHandle.h.

Referenced by DoSlideHorizontal(), and TimeShiftHandle::WasMoved().


The documentation for this struct was generated from the following files: