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 236 of file TimeShiftHandle.h.

Member Typedef Documentation

◆ ShifterMap

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

Definition at line 245 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 379 of file TimeShiftHandle.cpp.

380{
381 auto pTrack = mCapturedTrack.get();
382 if (pTrack) {
383 auto iter = shifters.find(pTrack);
384 if (iter != shifters.end()) {
385 auto &pShifter = iter->second;
386 if (pShifter) {
387 auto &intervals = pShifter->MovingIntervals();
388 if (!intervals.empty())
389 return intervals[0].get();
390 }
391 }
392 }
393 return nullptr;
394}
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 280 of file TimeShiftHandle.h.

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

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

124{
125 if (!shifters.empty()) {
126 for (auto &pair : shifters)
127 pair.second->DoHorizontalOffset(offset);
128 }
129 else if (mCapturedTrack)
130 mCapturedTrack->ShiftBy(offset);
131}

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

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

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

282{
283 shifters.clear();
284
285 initialized = true;
286
287 auto &state = *this;
288 state.mCapturedTrack = capturedTrack.SharedPointer();
289
290 switch (hitTestResult) {
292 wxASSERT(false);
293 pHit.reset();
294 break;
296 pHit.reset();
297 break;
299 break;
301 state.movingSelection = true;
302 break;
303 default:
304 break;
305 }
306
307 if (!pHit)
308 return;
309
310 state.shifters[&capturedTrack] = std::move( pHit );
311
312 // Collect TrackShifters for the rest of the tracks
313 for (auto track : trackList) {
314 auto &pShifter = state.shifters[track];
315 if (!pShifter)
316 pShifter = MakeTrackShifter::Call(*track, project);
317 }
318
319 if ( state.movingSelection ) {
320 // All selected tracks may move some intervals
321 const TrackShifter::TimeInterval interval{
322 viewInfo.selectedRegion.t0(),
323 viewInfo.selectedRegion.t1()
324 };
325 for ( const auto &pair : state.shifters ) {
326 auto &shifter = *pair.second;
327 auto &track = shifter.GetTrack();
328 if (&track == &capturedTrack)
329 // Don't change the choice of intervals made by HitTest
330 continue;
331 if ( track.IsSelected() )
332 shifter.SelectInterval( interval );
333 }
334 }
335
336 // Sync lock propagation of unfixing of intervals
337 if ( syncLocked ) {
338 bool change = true;
339 while( change ) {
340 change = false;
341
342 // Iterate over all unfixed intervals in all tracks
343 // that do propagation and are in sync lock groups ...
344 for ( auto &pair : state.shifters ) {
345 auto &shifter = *pair.second.get();
346 if (!shifter.SyncLocks())
347 continue;
348 auto &track = shifter.GetTrack();
349 auto group = SyncLock::Group(track);
350 if (group.size() <= 1)
351 continue;
352
353 auto &intervals = shifter.MovingIntervals();
354 for (auto &interval : intervals) {
355
356 // ...and tell all other tracks in the sync lock group
357 // to select that interval...
358 for (auto pTrack2 : group) {
359 if (pTrack2 == &track)
360 continue;
361 auto &shifter2 = *shifters[pTrack2];
362 auto size = shifter2.MovingIntervals().size();
363 shifter2.SelectInterval({
364 interval->Start(), interval->End() });
365 change = change ||
366 (shifter2.SyncLocks() &&
367 size != shifter2.MovingIntervals().size());
368 }
369
370 }
371 }
372
373 // ... and repeat if any other interval became unfixed in a
374 // shifter that propagates
375 }
376 }
377}
const auto project
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 &track)
Definition: SyncLock.cpp:150
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:146
@ 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
A simple time interval.

References AttachedVirtualFunction< Tag, Return, This, Arguments >::Call(), SyncLock::Group(), initialized, TrackShifter::Intervals, 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 274 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 272 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 273 of file TimeShiftHandle.h.

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


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