Audacity 3.2.0
Classes | Typedefs | Functions
anonymous_namespace{TimeShiftHandle.cpp} Namespace Reference

Classes

struct  TemporaryClipRemover
 

Typedefs

using Correspondence = std::unordered_map< Track *, Track * >
 
using DetachedIntervals = std::unordered_map< Track *, TrackShifter::Intervals >
 

Functions

SnapPointArray FindCandidates (const TrackList &tracks, const ClipMoveState::ShifterMap &shifters)
 
void AdjustToSnap (const ViewInfo &viewInfo, wxCoord xx, SnapManager *pSnapManager, bool snapPreferRightEdge, ClipMoveState &state, double &desiredSlideAmount)
 
bool FindCorrespondence (Correspondence &correspondence, TrackList &trackList, Track &capturedTrack, Track &track, ClipMoveState &state)
 
bool CheckFit (ClipMoveState &state, const Correspondence &correspondence, const DetachedIntervals &intervals, double tolerance, double &desiredSlideAmount)
 
void MigrationFailure ()
 

Typedef Documentation

◆ Correspondence

using anonymous_namespace{TimeShiftHandle.cpp}::Correspondence = typedef std::unordered_map< Track*, Track* >

Definition at line 583 of file TimeShiftHandle.cpp.

◆ DetachedIntervals

using anonymous_namespace{TimeShiftHandle.cpp}::DetachedIntervals = typedef std::unordered_map<Track*, TrackShifter::Intervals>

Definition at line 655 of file TimeShiftHandle.cpp.

Function Documentation

◆ AdjustToSnap()

void anonymous_namespace{TimeShiftHandle.cpp}::AdjustToSnap ( const ViewInfo viewInfo,
wxCoord  xx,
SnapManager pSnapManager,
bool  snapPreferRightEdge,
ClipMoveState state,
double &  desiredSlideAmount 
)

Definition at line 527 of file TimeShiftHandle.cpp.

533 {
534 auto track = state.mCapturedTrack.get();
535 double clipLeft, clipRight;
536
537 // Adjust desiredSlideAmount using SnapManager
538 if (pSnapManager) {
539 auto pInterval = state.CapturedInterval();
540 if (pInterval) {
541 clipLeft = pInterval->Start() + desiredSlideAmount;
542 clipRight = pInterval->End() + desiredSlideAmount;
543 }
544 else {
545 clipLeft = track->GetStartTime() + desiredSlideAmount;
546 clipRight = track->GetEndTime() + desiredSlideAmount;
547 }
548
549 auto results =
550 pSnapManager->Snap(track, clipLeft, false);
551 auto newClipLeft = results.outTime;
552 results =
553 pSnapManager->Snap(track, clipRight, false);
554 auto newClipRight = results.outTime;
555
556 // Only one of them is allowed to snap
557 if (newClipLeft != clipLeft && newClipRight != clipRight) {
558 // Un-snap the un-preferred edge
559 if (snapPreferRightEdge)
560 newClipLeft = clipLeft;
561 else
562 newClipRight = clipRight;
563 }
564
565 // Take whichever one snapped (if any) and compute the NEW desiredSlideAmount
566 state.snapLeft = -1;
567 state.snapRight = -1;
568 if (newClipLeft != clipLeft) {
569 const double difference = (newClipLeft - clipLeft);
570 desiredSlideAmount += difference;
571 state.snapLeft =
572 viewInfo.TimeToPosition(newClipLeft, xx);
573 }
574 else if (newClipRight != clipRight) {
575 const double difference = (newClipRight - clipRight);
576 desiredSlideAmount += difference;
577 state.snapRight =
578 viewInfo.TimeToPosition(newClipRight, xx);
579 }
580 }
581 }
virtual double Start() const =0
SnapResults Snap(Track *currentTrack, double t, bool rightEdge)
Definition: Snap.cpp:262
int64 TimeToPosition(double time, int64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ZoomInfo.cpp:44
const ChannelGroupInterval * CapturedInterval() const
Return pointer to the first fixed interval of the captured track, if there is one.
std::shared_ptr< Track > mCapturedTrack
double outTime
Definition: Snap.h:47

References ClipMoveState::CapturedInterval(), ClipMoveState::mCapturedTrack, SnapResults::outTime, SnapManager::Snap(), ClipMoveState::snapLeft, ClipMoveState::snapRight, ChannelGroupInterval::Start(), and ZoomInfo::TimeToPosition().

Referenced by TimeShiftHandle::Drag().

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

◆ CheckFit()

bool anonymous_namespace{TimeShiftHandle.cpp}::CheckFit ( ClipMoveState state,
const Correspondence correspondence,
const DetachedIntervals intervals,
double  tolerance,
double &  desiredSlideAmount 
)

Definition at line 658 of file TimeShiftHandle.cpp.

662 {
663 bool ok = true;
664 double firstTolerance = tolerance;
665
666 // The desiredSlideAmount may change and the tolerance may get used up.
667 for ( unsigned iPass = 0; iPass < 2 && ok; ++iPass ) {
668 for ( auto &pair : state.shifters ) {
669 auto *pSrcTrack = pair.first;
670 auto iter = correspondence.find( pSrcTrack );
671 if ( iter != correspondence.end() )
672 if( auto *pOtherTrack = iter->second )
673 if ( !(ok = pair.second->AdjustFit(
674 *pOtherTrack, intervals.at(pSrcTrack),
675 desiredSlideAmount /*in,out*/, tolerance)) )
676 break;
677 }
678
679 // If it fits ok, desiredSlideAmount could have been updated to get
680 // the clip to fit.
681 // Check again, in the new position, this time with zero tolerance.
682 if (firstTolerance == 0)
683 break;
684 else
685 tolerance = 0.0;
686 }
687
688 return ok;
689 }
ShifterMap shifters

References ClipMoveState::shifters.

Referenced by TimeShiftHandle::DoSlideVertical().

Here is the caller graph for this function:

◆ FindCandidates()

SnapPointArray anonymous_namespace{TimeShiftHandle.cpp}::FindCandidates ( const TrackList tracks,
const ClipMoveState::ShifterMap shifters 
)

Definition at line 437 of file TimeShiftHandle.cpp.

439{
440 // Compare with the other function FindCandidates in Snap
441 // Make the snap manager more selective than it would be if just constructed
442 // from the track list
443 SnapPointArray candidates;
444 for (const auto &pair : shifters) {
445 auto &shifter = pair.second;
446 auto &track = shifter->GetTrack();
447 for (const auto &interval : shifter->FixedIntervals()) {
448 candidates.emplace_back(interval->Start(), &track);
449 if (interval->Start() != interval->End())
450 candidates.emplace_back(interval->End(), &track);
451 }
452 }
453 return candidates;
454}
std::vector< SnapPoint > SnapPointArray
Definition: Snap.h:43

Referenced by TimeShiftHandle::Click().

Here is the caller graph for this function:

◆ FindCorrespondence()

bool anonymous_namespace{TimeShiftHandle.cpp}::FindCorrespondence ( Correspondence correspondence,
TrackList trackList,
Track capturedTrack,
Track track,
ClipMoveState state 
)

Definition at line 585 of file TimeShiftHandle.cpp.

589 {
590 if (state.shifters.empty())
591 // Shift + Dragging hasn't yet supported vertical movement
592 return false;
593
594 // Accumulate new pairs for the correspondence, and merge them
595 // into the given correspondence only on success
596 Correspondence newPairs;
597
598 auto sameType = [&](auto pTrack){
599 return capturedTrack.SameKindAs(*pTrack);
600 };
601 if (!sameType(&track))
602 return false;
603
604 // All tracks of the same kind as the captured track
605 auto range = trackList.Any() + sameType;
606
607 // Find how far this track would shift down among those (signed)
608 const auto myPosition =
609 std::distance(range.first, trackList.Find(&capturedTrack));
610 const auto otherPosition =
611 std::distance(range.first, trackList.Find(&track));
612 auto diff = otherPosition - myPosition;
613
614 // Point to destination track for first of range, when diff >= 0
615 // Otherwise the loop below iterates -diff times checking that initial
616 // members of the range are not the shifting tracks
617 auto iter = range.first.advance(diff >= 0 ? diff : 0);
618
619 for (auto pTrack : range) {
620 auto &pShifter = state.shifters[pTrack];
621 if (!pShifter->MovingIntervals().empty()) {
622 // One of the interesting tracks
623
624 auto pOther = *iter;
625 if (diff < 0 || !pOther)
626 // No corresponding track
627 return false;
628
629 if (!pShifter->MayMigrateTo(*pOther))
630 // Rejected for other reason
631 return false;
632
633 if (correspondence.count(pTrack))
634 // Don't overwrite the given correspondence
635 return false;
636
637 newPairs[pTrack] = pOther;
638 }
639
640 if (diff < 0)
641 ++diff; // Still consuming initial tracks
642 else
643 ++iter; // Safe to increment TrackIter even at end of range
644 }
645
646 // Success
647 if (correspondence.empty())
648 correspondence.swap(newPairs);
649 else
650 copy(newPairs.begin(), newPairs.end(),
651 inserter(correspondence, correspondence.end()));
652 return true;
653 }
bool SameKindAs(const Track &track) const
Definition: Track.h:373
TrackIter< Track > Find(Track *pTrack)
Definition: Track.cpp:470
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:950
std::unordered_map< Track *, Track * > Correspondence
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References TrackList::Any(), staffpad::vo::copy(), TrackList::Find(), Track::SameKindAs(), and ClipMoveState::shifters.

Referenced by TimeShiftHandle::DoSlideVertical().

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

◆ MigrationFailure()

void anonymous_namespace{TimeShiftHandle.cpp}::MigrationFailure ( )

Definition at line 691 of file TimeShiftHandle.cpp.

691 {
692 // Tracks may be in an inconsistent state; throw to the application
693 // handler which restores consistency from undo history
695 XO("Could not shift between tracks")};
696 }
@ Internal
Indicates internal failure from Audacity.
XO("Cut/Copy/Paste")
A MessageBoxException that shows a given, unvarying string.

References Internal, and XO().

Referenced by anonymous_namespace{TimeShiftHandle.cpp}::TemporaryClipRemover::Reinsert(), and TimeShiftHandle::Release().

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