MCPcopy Create free account
hub / github.com/audacity/audacity / FindCorrespondence

Function FindCorrespondence

src/tracks/ui/TimeShiftHandle.cpp:585–653  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

583 using Correspondence = std::unordered_map< Track*, Track* >;
584
585 bool FindCorrespondence(
586 Correspondence &correspondence,
587 TrackList &trackList, Track &capturedTrack, Track &track,
588 ClipMoveState &state)
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

Callers 1

DoSlideVerticalMethod · 0.70

Calls 9

copyFunction · 0.85
emptyMethod · 0.45
AnyMethod · 0.45
FindMethod · 0.45
advanceMethod · 0.45
MayMigrateToMethod · 0.45
swapMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected