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

◆ DetachedIntervals

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

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

545 {
546 auto track = state.mCapturedTrack.get();
547 double clipLeft, clipRight;
548
549 // Adjust desiredSlideAmount using SnapManager
550 if (pSnapManager) {
551 auto pInterval = state.CapturedInterval();
552 if (pInterval) {
553 clipLeft = pInterval->Start() + desiredSlideAmount;
554 clipRight = pInterval->End() + desiredSlideAmount;
555 }
556 else {
557 clipLeft = track->GetStartTime() + desiredSlideAmount;
558 clipRight = track->GetEndTime() + desiredSlideAmount;
559 }
560
561 auto results =
562 pSnapManager->Snap(track, clipLeft, false);
563 auto newClipLeft = results.outTime;
564 results =
565 pSnapManager->Snap(track, clipRight, false);
566 auto newClipRight = results.outTime;
567
568 // Only one of them is allowed to snap
569 if (newClipLeft != clipLeft && newClipRight != clipRight) {
570 // Un-snap the un-preferred edge
571 if (snapPreferRightEdge)
572 newClipLeft = clipLeft;
573 else
574 newClipRight = clipRight;
575 }
576
577 // Take whichever one snapped (if any) and compute the NEW desiredSlideAmount
578 state.snapLeft = -1;
579 state.snapRight = -1;
580 if (newClipLeft != clipLeft) {
581 const double difference = (newClipLeft - clipLeft);
582 desiredSlideAmount += difference;
583 state.snapLeft =
584 viewInfo.TimeToPosition(newClipLeft, xx);
585 }
586 else if (newClipRight != clipRight) {
587 const double difference = (newClipRight - clipRight);
588 desiredSlideAmount += difference;
589 state.snapRight =
590 viewInfo.TimeToPosition(newClipRight, xx);
591 }
592 }
593 }
double Start() const
Definition: Channel.h:41
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 671 of file TimeShiftHandle.cpp.

675 {
676 bool ok = true;
677 double firstTolerance = tolerance;
678
679 // The desiredSlideAmount may change and the tolerance may get used up.
680 for ( unsigned iPass = 0; iPass < 2 && ok; ++iPass ) {
681 for ( auto &pair : state.shifters ) {
682 auto *pSrcTrack = pair.first;
683 auto iter = correspondence.find( pSrcTrack );
684 if ( iter != correspondence.end() )
685 if( auto *pOtherTrack = iter->second )
686 if ( !(ok = pair.second->AdjustFit(
687 *pOtherTrack, intervals.at(pSrcTrack),
688 desiredSlideAmount /*in,out*/, tolerance)) )
689 break;
690 }
691
692 // If it fits ok, desiredSlideAmount could have been updated to get
693 // the clip to fit.
694 // Check again, in the new position, this time with zero tolerance.
695 if (firstTolerance == 0)
696 break;
697 else
698 tolerance = 0.0;
699 }
700
701 return ok;
702 }
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 446 of file TimeShiftHandle.cpp.

448{
449 // Compare with the other function FindCandidates in Snap
450 // Make the snap manager more selective than it would be if just constructed
451 // from the track list
452 SnapPointArray candidates;
453 for (const auto &pair : shifters) {
454 auto &shifter = pair.second;
455 auto &track = shifter->GetTrack();
456 for (const auto &interval : shifter->FixedIntervals()) {
457 candidates.emplace_back(interval->Start(), &track);
458 if (interval->Start() != interval->End())
459 candidates.emplace_back(interval->End(), &track);
460 }
461 }
462 return candidates;
463}
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 597 of file TimeShiftHandle.cpp.

601 {
602 if (state.shifters.empty())
603 // Shift + Dragging hasn't yet supported vertical movement
604 return false;
605
606 // Accumulate new pairs for the correspondence, and merge them
607 // into the given correspondence only on success
608 Correspondence newPairs;
609
610 auto sameType = [&](auto pTrack){
611 return capturedTrack.SameKindAs(*pTrack);
612 };
613 if (!sameType(&track))
614 return false;
615
616 // All tracks of the same kind as the captured track
617 auto range = trackList.Any() + sameType;
618
619 // Find how far this track would shift down among those (signed)
620 const auto myPosition =
621 std::distance(range.first, trackList.Find(&capturedTrack));
622 const auto otherPosition =
623 std::distance(range.first, trackList.Find(&track));
624 auto diff = otherPosition - myPosition;
625
626 // Point to destination track for first of range, when diff >= 0
627 // Otherwise the loop below iterates -diff times checking that initial
628 // members of the range are not the shifting tracks
629 auto iter = range.first.advance(diff >= 0 ? diff : 0);
630
631 for (auto pTrack : range) {
632 auto &pShifter = state.shifters[pTrack];
633 if (!pShifter->MovingIntervals().empty()) {
634 // One of the interesting tracks
635
636 auto pOther = *iter;
637 if (diff < 0 || !pOther)
638 // No corresponding track
639 return false;
640
641 assert(pOther->IsLeader()); // by construction of range
642 if (!pShifter->MayMigrateTo(*pOther))
643 // Rejected for other reason
644 return false;
645
646 if (correspondence.count(pTrack))
647 // Don't overwrite the given correspondence
648 return false;
649
650 newPairs[pTrack] = pOther;
651 }
652
653 if (diff < 0)
654 ++diff; // Still consuming initial tracks
655 else
656 ++iter; // Safe to increment TrackIter even at end of range
657 }
658
659 // Success
660 if (correspondence.empty())
661 correspondence.swap(newPairs);
662 else
663 copy(newPairs.begin(), newPairs.end(),
664 inserter(correspondence, correspondence.end()));
665 return true;
666 }
bool SameKindAs(const Track &track) const
Definition: Track.h:410
TrackIter< Track > Find(Track *pTrack)
Definition: Track.cpp:519
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1079
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 704 of file TimeShiftHandle.cpp.

704 {
705 // Tracks may be in an inconsistent state; throw to the application
706 // handler which restores consistency from undo history
708 XO("Could not shift between tracks")};
709 }
@ 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: