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

Function AdjustToSnap

src/tracks/ui/TimeShiftHandle.cpp:527–581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

525
526namespace {
527 void AdjustToSnap(
528 const ViewInfo &viewInfo, wxCoord xx,
529 SnapManager *pSnapManager,
530 bool snapPreferRightEdge,
531 ClipMoveState &state,
532 double& desiredSlideAmount)
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 }
582
583 using Correspondence = std::unordered_map< Track*, Track* >;
584

Callers 1

DragMethod · 0.85

Calls 8

CapturedIntervalMethod · 0.80
TimeToPositionMethod · 0.80
getMethod · 0.45
StartMethod · 0.45
EndMethod · 0.45
GetStartTimeMethod · 0.45
GetEndTimeMethod · 0.45
SnapMethod · 0.45

Tested by

no test coverage detected