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)
 
double FindDesiredSlideAmount (const ViewInfo &viewInfo, wxCoord xx, const wxMouseEvent &event, SnapManager *pSnapManager, bool slideUpDownOnly, bool snapPreferRightEdge, ClipMoveState &state, Track &track)
 
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 638 of file TimeShiftHandle.cpp.

◆ DetachedIntervals

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

Definition at line 708 of file TimeShiftHandle.cpp.

Function Documentation

◆ CheckFit()

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

Definition at line 711 of file TimeShiftHandle.cpp.

715 {
716 bool ok = true;
717 double firstTolerance = tolerance;
718
719 // The desiredSlideAmount may change and the tolerance may get used up.
720 for ( unsigned iPass = 0; iPass < 2 && ok; ++iPass ) {
721 for ( auto &pair : state.shifters ) {
722 auto *pSrcTrack = pair.first;
723 auto iter = correspondence.find( pSrcTrack );
724 if ( iter != correspondence.end() )
725 if( auto *pOtherTrack = iter->second )
726 if ( !(ok = pair.second->AdjustFit(
727 *pOtherTrack, intervals.at(pSrcTrack),
728 desiredSlideAmount /*in,out*/, tolerance)) )
729 break;
730 }
731
732 // If it fits ok, desiredSlideAmount could have been updated to get
733 // the clip to fit.
734 // Check again, in the new position, this time with zero tolerance.
735 if (firstTolerance == 0)
736 break;
737 else
738 tolerance = 0.0;
739 }
740
741 return ok;
742 }
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 475 of file TimeShiftHandle.cpp.

477{
478 // Compare with the other function FindCandidates in Snap
479 // Make the snap manager more selective than it would be if just constructed
480 // from the track list
481 SnapPointArray candidates;
482 for ( const auto &pair : shifters ) {
483 auto &shifter = pair.second;
484 auto &track = shifter->GetTrack();
485 for (const auto &interval : shifter->FixedIntervals() ) {
486 candidates.emplace_back( interval.Start(), &track );
487 if ( interval.Start() != interval.End() )
488 candidates.emplace_back( interval.End(), &track );
489 }
490 }
491 return candidates;
492}
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 640 of file TimeShiftHandle.cpp.

644 {
645 if (state.shifters.empty())
646 // Shift + Dragging hasn't yet supported vertical movement
647 return false;
648
649 // Accumulate new pairs for the correspondence, and merge them
650 // into the given correspondence only on success
651 Correspondence newPairs;
652
653 auto sameType = [&]( auto pTrack ){
654 return capturedTrack.SameKindAs( *pTrack );
655 };
656 if (!sameType(&track))
657 return false;
658
659 // All tracks of the same kind as the captured track
660 auto range = trackList.Any() + sameType;
661
662 // Find how far this track would shift down among those (signed)
663 const auto myPosition =
664 std::distance( range.first, trackList.Find( &capturedTrack ) );
665 const auto otherPosition =
666 std::distance( range.first, trackList.Find( &track ) );
667 auto diff = otherPosition - myPosition;
668
669 // Point to destination track
670 auto iter = range.first.advance( diff > 0 ? diff : 0 );
671
672 for (auto pTrack : range) {
673 auto &pShifter = state.shifters[pTrack];
674 if ( !pShifter->MovingIntervals().empty() ) {
675 // One of the interesting tracks
676
677 auto pOther = *iter;
678 if ( diff < 0 || !pOther )
679 // No corresponding track
680 return false;
681
682 if ( !pShifter->MayMigrateTo(*pOther) )
683 // Rejected for other reason
684 return false;
685
686 if ( correspondence.count(pTrack) )
687 // Don't overwrite the given correspondence
688 return false;
689
690 newPairs[ pTrack ] = pOther;
691 }
692
693 if ( diff < 0 )
694 ++diff; // Still consuming initial tracks
695 else
696 ++iter; // Safe to increment TrackIter even at end of range
697 }
698
699 // Success
700 if (correspondence.empty())
701 correspondence.swap(newPairs);
702 else
703 std::copy( newPairs.begin(), newPairs.end(),
704 std::inserter( correspondence, correspondence.end() ) );
705 return true;
706 }
bool SameKindAs(const Track &track) const
Definition: Track.h:535
auto Find(Track *pTrack) -> TrackIter< TrackType >
Turn a pointer into a TrackIter (constant time); get end iterator if this does not own the track.
Definition: Track.h:1402
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1440
std::unordered_map< Track *, Track * > Correspondence

References TrackList::Any(), 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:

◆ FindDesiredSlideAmount()

double anonymous_namespace{TimeShiftHandle.cpp}::FindDesiredSlideAmount ( const ViewInfo viewInfo,
wxCoord  xx,
const wxMouseEvent &  event,
SnapManager pSnapManager,
bool  slideUpDownOnly,
bool  snapPreferRightEdge,
ClipMoveState state,
Track track 
)

Definition at line 570 of file TimeShiftHandle.cpp.

576 {
577 auto &capturedTrack = *state.mCapturedTrack;
578 if (slideUpDownOnly)
579 return 0.0;
580 else {
581 double desiredSlideAmount =
582 viewInfo.PositionToTime(event.m_x) -
583 viewInfo.PositionToTime(state.mMouseClickX);
584 double clipLeft = 0, clipRight = 0;
585
586 if (!state.shifters.empty())
587 desiredSlideAmount =
588 state.shifters[ &track ]->QuantizeOffset( desiredSlideAmount );
589
590 // Adjust desiredSlideAmount using SnapManager
591 if (pSnapManager) {
592 auto pInterval = state.CapturedInterval();
593 if (pInterval) {
594 clipLeft = pInterval->Start() + desiredSlideAmount;
595 clipRight = pInterval->End() + desiredSlideAmount;
596 }
597 else {
598 clipLeft = capturedTrack.GetStartTime() + desiredSlideAmount;
599 clipRight = capturedTrack.GetEndTime() + desiredSlideAmount;
600 }
601
602 auto results =
603 pSnapManager->Snap(&capturedTrack, clipLeft, false);
604 auto newClipLeft = results.outTime;
605 results =
606 pSnapManager->Snap(&capturedTrack, clipRight, false);
607 auto newClipRight = results.outTime;
608
609 // Only one of them is allowed to snap
610 if (newClipLeft != clipLeft && newClipRight != clipRight) {
611 // Un-snap the un-preferred edge
612 if (snapPreferRightEdge)
613 newClipLeft = clipLeft;
614 else
615 newClipRight = clipRight;
616 }
617
618 // Take whichever one snapped (if any) and compute the NEW desiredSlideAmount
619 state.snapLeft = -1;
620 state.snapRight = -1;
621 if (newClipLeft != clipLeft) {
622 const double difference = (newClipLeft - clipLeft);
623 desiredSlideAmount += difference;
624 state.snapLeft =
625 viewInfo.TimeToPosition(newClipLeft, xx);
626 }
627 else if (newClipRight != clipRight) {
628 const double difference = (newClipRight - clipRight);
629 desiredSlideAmount += difference;
630 state.snapRight =
631 viewInfo.TimeToPosition(newClipRight, xx);
632 }
633 }
634 return desiredSlideAmount;
635 }
636 }
double Start() const
Definition: Track.h:193
SnapResults Snap(Track *currentTrack, double t, bool rightEdge)
Definition: Snap.cpp:275
double PositionToTime(int64 position, int64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:35
int64 TimeToPosition(double time, int64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ZoomInfo.cpp:45
const TrackInterval * 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, ClipMoveState::mMouseClickX, SnapResults::outTime, ZoomInfo::PositionToTime(), ClipMoveState::shifters, SnapManager::Snap(), ClipMoveState::snapLeft, ClipMoveState::snapRight, ConstTrackInterval::Start(), and ZoomInfo::TimeToPosition().

Referenced by TimeShiftHandle::Drag().

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

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