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 &)=delete
 
ClipMoveStateoperator= (const ClipMoveState &)=delete
 
 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 ChannelGroupIntervalCapturedInterval () 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 231 of file TimeShiftHandle.h.

Member Typedef Documentation

◆ ShifterMap

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

Definition at line 240 of file TimeShiftHandle.h.

Constructor & Destructor Documentation

◆ ClipMoveState() [1/3]

ClipMoveState::ClipMoveState ( )
default

◆ ClipMoveState() [2/3]

ClipMoveState::ClipMoveState ( const ClipMoveState )
delete

◆ ClipMoveState() [3/3]

ClipMoveState::ClipMoveState ( ClipMoveState &&  )
default

Member Function Documentation

◆ CapturedInterval()

const ChannelGroupInterval * 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 388 of file TimeShiftHandle.cpp.

389{
390 auto pTrack = mCapturedTrack.get();
391 if (pTrack) {
392 auto iter = shifters.find(pTrack);
393 if (iter != shifters.end()) {
394 auto &pShifter = iter->second;
395 if (pShifter) {
396 auto &intervals = pShifter->MovingIntervals();
397 if (!intervals.empty())
398 return intervals[0].get();
399 }
400 }
401 }
402 return nullptr;
403}
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 282 of file TimeShiftHandle.h.

283 {
284 initialized = false;
285 wasMoved = false;
286 movingSelection = false;
287 hSlideAmount = 0;
288 shifters.clear();
289 snapLeft = snapRight = -1;
290 mMouseClickX = 0;
291 }

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 127 of file TimeShiftHandle.cpp.

128{
129 if (!shifters.empty()) {
130 for (auto &pair : shifters)
131 pair.second->DoHorizontalOffset(offset);
132 }
133 else if (mCapturedTrack)
134 mCapturedTrack->ShiftBy(offset);
135}

References mCapturedTrack, and shifters.

Referenced by TimeShiftHandle::Drag().

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 405 of file TimeShiftHandle.cpp.

406{
407 auto &state = *this;
408
409 // Given a signed slide distance, move clips, but subject to constraint of
410 // non-overlapping with other clips, so the distance may be adjusted toward
411 // zero.
412 if ( !state.shifters.empty() ) {
413 double initialAllowed = 0;
414 do { // loop to compute allowed, does not actually move anything yet
415 initialAllowed = desiredSlideAmount;
416
417 for (auto &pair : shifters) {
418 auto newAmount = pair.second->AdjustOffsetSmaller( desiredSlideAmount );
419 if ( desiredSlideAmount != newAmount ) {
420 if ( newAmount * desiredSlideAmount < 0 ||
421 fabs(newAmount) > fabs(desiredSlideAmount) ) {
422 wxASSERT( false ); // AdjustOffsetSmaller didn't honor postcondition!
423 newAmount = 0; // Be sure the loop progresses to termination!
424 }
425 desiredSlideAmount = newAmount;
426 state.snapLeft = state.snapRight = -1; // see bug 1067
427 }
428 if (newAmount == 0)
429 break;
430 }
431 } while ( desiredSlideAmount != initialAllowed );
432 }
433
434 // Whether moving intervals or a whole track,
435 // finally, here is where clips are moved
436 if ( desiredSlideAmount != 0.0 )
437 state.DoHorizontalOffset( desiredSlideAmount );
438
439 //attempt to move a clip is counted to
440 wasMoved = true;
441
442 return (state.hSlideAmount = desiredSlideAmount);
443}

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.

Precondition
capturedTrack.IsLeader()
Parameters
hitTestResultmust not be `Miss`
pHitIf null, implies `Track`, overriding previous argument

Definition at line 282 of file TimeShiftHandle.cpp.

290{
291 assert(capturedTrack.IsLeader());
292 shifters.clear();
293
294 initialized = true;
295
296 auto &state = *this;
297 state.mCapturedTrack = capturedTrack.SharedPointer();
298
299 switch (hitTestResult) {
301 wxASSERT(false);
302 pHit.reset();
303 break;
305 pHit.reset();
306 break;
308 break;
310 state.movingSelection = true;
311 break;
312 default:
313 break;
314 }
315
316 if (!pHit)
317 return;
318
319 state.shifters[&capturedTrack] = std::move( pHit );
320
321 // Collect TrackShifters for the rest of the tracks
322 for (auto track : trackList) {
323 auto &pShifter = state.shifters[track];
324 if (!pShifter)
325 pShifter = MakeTrackShifter::Call(*track, project);
326 }
327
328 if ( state.movingSelection ) {
329 // All selected tracks may move some intervals
330 const ChannelGroupInterval interval{
331 viewInfo.selectedRegion.t0(),
332 viewInfo.selectedRegion.t1()
333 };
334 for ( const auto &pair : state.shifters ) {
335 auto &shifter = *pair.second;
336 auto &track = shifter.GetTrack();
337 if (&track == &capturedTrack)
338 // Don't change the choice of intervals made by HitTest
339 continue;
340 if ( track.IsSelected() )
341 shifter.SelectInterval( interval );
342 }
343 }
344
345 // Sync lock propagation of unfixing of intervals
346 if ( syncLocked ) {
347 bool change = true;
348 while( change ) {
349 change = false;
350
351 // Iterate over all unfixed intervals in all tracks
352 // that do propagation and are in sync lock groups ...
353 for ( auto &pair : state.shifters ) {
354 auto &shifter = *pair.second.get();
355 if (!shifter.SyncLocks())
356 continue;
357 auto &track = shifter.GetTrack();
358 auto group = SyncLock::Group(&track);
359 if (group.size() <= 1)
360 continue;
361
362 auto &intervals = shifter.MovingIntervals();
363 for (auto &interval : intervals) {
364
365 // ...and tell all other tracks in the sync lock group
366 // to select that interval...
367 for (auto pTrack2 : group) {
368 if (pTrack2 == &track)
369 continue;
370 // shifters maps from leader tracks only
371 auto &shifter2 = *shifters[pTrack2];
372 auto size = shifter2.MovingIntervals().size();
373 shifter2.SelectInterval(*interval);
374 change = change ||
375 (shifter2.SyncLocks() &&
376 size != shifter2.MovingIntervals().size());
377 }
378
379 }
380 }
381
382 // ... and repeat if any other interval became unfixed in a
383 // shifter that propagates
384 }
385 }
386}
const auto project
static Return Call(This &obj, Arguments ...arguments)
Invoke the method – but only after static initialization time.
A start and an end time, and whatever else subclasses associate with them.
Definition: Channel.h:30
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:160
bool IsLeader() const override
Definition: Track.cpp:291
@ 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:215

References AttachedVirtualFunction< Tag, Return, This, Arguments >::Call(), SyncLock::Group(), initialized, TrackShifter::Intervals, Track::IsLeader(), TrackShifter::Miss, project, 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 )
delete

Member Data Documentation

◆ hSlideAmount

double ClipMoveState::hSlideAmount {}

Definition at line 273 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 271 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 272 of file TimeShiftHandle.h.

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


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