Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
SelectHandle Class Reference

#include <SelectHandle.h>

Inheritance diagram for SelectHandle:
[legend]
Collaboration diagram for SelectHandle:
[legend]

Classes

class  TimerHandler
 

Public Member Functions

 SelectHandle (const std::shared_ptr< ChannelView > &pChannelView, bool useSnap, const TrackList &trackList, const TrackPanelMouseState &st, const ViewInfo &viewInfo)
 
SelectHandleoperator= (const SelectHandle &)=default
 
virtual ~SelectHandle ()
 
std::shared_ptr< const ChannelFindChannel () const override
 
bool IsDragging () const override
 
void SetUseSnap (bool use, AudacityProject *pProject)
 
void Enter (bool forward, AudacityProject *pProject) override
 
bool HasSnap () const
 
bool HasEscape (AudacityProject *pProject) const override
 
bool Escape (AudacityProject *pProject) override
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *) override
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual void Enter (bool forward, AudacityProject *pProject)
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape (AudacityProject *pProject) const
 
virtual bool Escape (AudacityProject *pProject)
 
virtual bool HandlesRightClick ()
 Whether the handle has any special right-button handling. More...
 
virtual Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject)=0
 
virtual Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)=0
 
virtual Result Cancel (AudacityProject *pProject)=0
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
virtual std::shared_ptr< const ChannelFindChannel () const =0
 
virtual bool IsDragging () const
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 
virtual void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
 
virtual wxRect DrawingArea (TrackPanelDrawingContext &context, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
 

Static Public Member Functions

static UIHandlePtr HitTest (std::weak_ptr< SelectHandle > &holder, const TrackPanelMouseState &state, const AudacityProject *pProject, const std::shared_ptr< ChannelView > &pChannelView)
 
static UIHandle::Result NeedChangeHighlight (const SelectHandle &oldState, const SelectHandle &newState)
 
static void SnapCenterOnce (SpectrumAnalyst &analyst, ViewInfo &viewInfo, const WaveTrack *pTrack, bool up)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 
- Static Public Member Functions inherited from TrackPanelDrawable
static wxRect MaximizeWidth (const wxRect &rect, const wxRect &panelRect)
 
static wxRect MaximizeHeight (const wxRect &rect, const wxRect &panelRect)
 

Private Types

enum  eFreqSelMode {
  FREQ_SEL_INVALID , FREQ_SEL_SNAPPING_CENTER , FREQ_SEL_PINNED_CENTER , FREQ_SEL_DRAG_CENTER ,
  FREQ_SEL_FREE , FREQ_SEL_TOP_FREE , FREQ_SEL_BOTTOM_FREE
}
 

Private Member Functions

 SelectHandle (const SelectHandle &)
 
std::weak_ptr< TrackFindTrack ()
 
void Connect (AudacityProject *pProject)
 
void StartSelection (AudacityProject *pProject)
 Reset our selection markers. More...
 
void AdjustSelection (AudacityProject *pProject, ViewInfo &viewInfo, int mouseXCoordinate, int trackLeftEdge, Track *pTrack)
 Extend or contract the existing selection. More...
 
void AssignSelection (ViewInfo &viewInfo, double selend, Track *pTrack)
 
void StartFreqSelection (ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge, int trackHeight, ChannelView *pChannelView)
 
void AdjustFreqSelection (const WaveTrack *wt, ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge, int trackHeight)
 
void HandleCenterFrequencyClick (const ViewInfo &viewInfo, bool shiftDown, const WaveTrack *pTrack, double value)
 
void MoveSnappingFreqSelection (AudacityProject *pProject, ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge, int trackHeight, ChannelView *pChannelView)
 
void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
 
wxRect DrawingArea (TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
 

Static Private Member Functions

static void StartSnappingFreqSelection (SpectrumAnalyst &analyst, const ViewInfo &viewInfo, const WaveTrack *pTrack)
 

Private Attributes

std::weak_ptr< ChannelViewmpView
 
wxRect mRect {}
 
SelectedRegion mInitialSelection {}
 
std::shared_ptr< SnapManagermSnapManager
 
SnapResults mSnapStart
 
SnapResults mSnapEnd
 
bool mUseSnap { true }
 
bool mSelStartValid {}
 
double mSelStart { 0.0 }
 
int mSelectionBoundary { 0 }
 
enum SelectHandle::eFreqSelMode FREQ_SEL_INVALID
 
std::weak_ptr< const WaveTrackmFreqSelTrack
 
double mFreqSelPin { -1.0 }
 
std::shared_ptr< SpectrumAnalystmFrequencySnapper
 
int mMostRecentX { -1 }
 
int mMostRecentY { -1 }
 
bool mAutoScrolling {}
 
std::shared_ptr< SelectionStateChangermSelectionStateChanger
 
friend TimerHandler
 
std::shared_ptr< TimerHandlermTimerHandler
 

Additional Inherited Members

- Public Types inherited from UIHandle
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 30 of file SelectHandle.h.

Member Enumeration Documentation

◆ eFreqSelMode

Enumerator
FREQ_SEL_INVALID 
FREQ_SEL_SNAPPING_CENTER 
FREQ_SEL_PINNED_CENTER 
FREQ_SEL_DRAG_CENTER 
FREQ_SEL_FREE 
FREQ_SEL_TOP_FREE 
FREQ_SEL_BOTTOM_FREE 

Definition at line 146 of file SelectHandle.h.

146 {
148
152
156 } mFreqSelMode{ FREQ_SEL_INVALID };
enum SelectHandle::eFreqSelMode FREQ_SEL_INVALID
@ FREQ_SEL_SNAPPING_CENTER
Definition: SelectHandle.h:149
@ FREQ_SEL_PINNED_CENTER
Definition: SelectHandle.h:150

Constructor & Destructor Documentation

◆ SelectHandle() [1/2]

SelectHandle::SelectHandle ( const SelectHandle )
private

◆ SelectHandle() [2/2]

SelectHandle::SelectHandle ( const std::shared_ptr< ChannelView > &  pChannelView,
bool  useSnap,
const TrackList trackList,
const TrackPanelMouseState st,
const ViewInfo viewInfo 
)

Definition at line 433 of file SelectHandle.cpp.

437 : mpView{ pChannelView }
438 // Selection dragging can snap to play region boundaries
439 , mSnapManager{ std::make_shared<SnapManager>(
440 *trackList.GetOwner(), trackList, viewInfo, SnapPointArray{
441 SnapPoint{ viewInfo.playRegion.GetLastActiveStart() },
442 SnapPoint{ viewInfo.playRegion.GetLastActiveEnd() },
443 } ) }
444{
445 const wxMouseState &state = st.state;
446 mRect = st.rect;
447
448 auto time = std::max(0.0, viewInfo.PositionToTime(state.m_x, mRect.x));
449 auto pTrack = pChannelView->FindTrack();
450 mSnapStart = mSnapManager->Snap(pTrack.get(), time, false);
453 else
454 mSnapStart.outCoord = -1;
455
456 mUseSnap = useSnap;
457}
std::vector< SnapPoint > SnapPointArray
Definition: Snap.h:43
SnapResults mSnapStart
Definition: SelectHandle.h:138
std::weak_ptr< ChannelView > mpView
Definition: SelectHandle.h:133
std::shared_ptr< SnapManager > mSnapManager
Definition: SelectHandle.h:137
Definition: Snap.h:31
AudacityProject * GetOwner()
Definition: Track.h:1032
double PositionToTime(int64 position, int64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:34
wxInt64 outCoord
Definition: Snap.h:48
bool snappedPoint
Definition: Snap.h:49

References mRect, mSnapManager, mSnapStart, mUseSnap, SnapResults::outCoord, ZoomInfo::PositionToTime(), TrackPanelMouseState::rect, SnapResults::snappedPoint, and TrackPanelMouseState::state.

Here is the call graph for this function:

◆ ~SelectHandle()

SelectHandle::~SelectHandle ( )
virtual

Definition at line 459 of file SelectHandle.cpp.

460{
461}

Member Function Documentation

◆ AdjustFreqSelection()

void SelectHandle::AdjustFreqSelection ( const WaveTrack wt,
ViewInfo viewInfo,
int  mouseYCoordinate,
int  trackTopEdge,
int  trackHeight 
)
private

Definition at line 1251 of file SelectHandle.cpp.

1255{
1256 if (mFreqSelMode == FREQ_SEL_INVALID ||
1257 mFreqSelMode == FREQ_SEL_SNAPPING_CENTER)
1258 return;
1259
1260 // Extension happens only when dragging in the same track in which we
1261 // started, and that is of a spectrogram display type.
1262
1263 const double rate = wt->GetRate();
1264 const double frequency =
1265 PositionToFrequency(wt, true, mouseYCoordinate,
1266 trackTopEdge, trackHeight);
1267
1268 // Dragging center?
1269 if (mFreqSelMode == FREQ_SEL_DRAG_CENTER) {
1270 if (frequency == rate || frequency < 1.0)
1271 // snapped to top or bottom
1275 else {
1276 // mFreqSelPin holds the ratio of top to center
1277 const double maxRatio = findMaxRatio(frequency, rate);
1278 const double ratio = std::min(maxRatio, mFreqSelPin);
1280 frequency / ratio, frequency * ratio);
1281 }
1282 }
1283 else if (mFreqSelMode == FREQ_SEL_PINNED_CENTER) {
1284 if (mFreqSelPin >= 0) {
1285 // Change both upper and lower edges leaving centre where it is.
1286 if (frequency == rate || frequency < 1.0)
1287 // snapped to top or bottom
1291 else {
1292 // Given center and mouse position, find ratio of the larger to the
1293 // smaller, limit that to the frequency scale bounds, and adjust
1294 // top and bottom accordingly.
1295 const double maxRatio = findMaxRatio(mFreqSelPin, rate);
1296 double ratio = frequency / mFreqSelPin;
1297 if (ratio < 1.0)
1298 ratio = 1.0 / ratio;
1299 ratio = std::min(maxRatio, ratio);
1301 mFreqSelPin / ratio, mFreqSelPin * ratio);
1302 }
1303 }
1304 }
1305 else {
1306 // Dragging of upper or lower.
1307 const bool bottomDefined =
1308 !(mFreqSelMode == FREQ_SEL_TOP_FREE && mFreqSelPin < 0);
1309 const bool topDefined =
1310 !(mFreqSelMode == FREQ_SEL_BOTTOM_FREE && mFreqSelPin < 0);
1311 if (!bottomDefined || (topDefined && mFreqSelPin < frequency)) {
1312 // Adjust top
1313 if (frequency == rate)
1314 // snapped high; upper frequency is undefined
1316 else
1317 viewInfo.selectedRegion.setF1(std::max(1.0, frequency));
1318
1320 }
1321 else {
1322 // Adjust bottom
1323 if (frequency < 1.0)
1324 // snapped low; lower frequency is undefined
1326 else
1327 viewInfo.selectedRegion.setF0(std::min(rate / 2.0, frequency));
1328
1330 }
1331 }
1332}
int min(int a, int b)
bool setF0(double f, bool maySwap=true)
Definition: ViewInfo.cpp:115
bool setFrequencies(double f0, double f1)
Definition: ViewInfo.cpp:105
bool setF1(double f, bool maySwap=true)
Definition: ViewInfo.cpp:125
double mFreqSelPin
Definition: SelectHandle.h:164
static const int UndefinedFrequency
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
double GetRate() const override
Definition: WaveTrack.cpp:1141
double findMaxRatio(double center, double rate)
double PositionToFrequency(const WaveTrack *wt, bool maySnap, wxInt64 mouseYCoordinate, wxInt64 trackTopEdge, int trackHeight)

References anonymous_namespace{SelectHandle.cpp}::findMaxRatio(), FREQ_SEL_BOTTOM_FREE, FREQ_SEL_DRAG_CENTER, FREQ_SEL_INVALID, FREQ_SEL_PINNED_CENTER, FREQ_SEL_SNAPPING_CENTER, FREQ_SEL_TOP_FREE, WaveTrack::GetRate(), mFreqSelPin, min(), anonymous_namespace{SelectHandle.cpp}::PositionToFrequency(), ViewInfo::selectedRegion, NotifyingSelectedRegion::setF0(), NotifyingSelectedRegion::setF1(), NotifyingSelectedRegion::setFrequencies(), and SelectedRegion::UndefinedFrequency.

Referenced by Click(), and Drag().

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

◆ AdjustSelection()

void SelectHandle::AdjustSelection ( AudacityProject pProject,
ViewInfo viewInfo,
int  mouseXCoordinate,
int  trackLeftEdge,
Track pTrack 
)
private

Extend or contract the existing selection.

Definition at line 1173 of file SelectHandle.cpp.

1177{
1178 if (!mSelStartValid)
1179 // Must be dragging frequency bounds only.
1180 return;
1181
1182 double selend =
1183 std::max(0.0, viewInfo.PositionToTime(mouseXCoordinate, trackLeftEdge));
1184 double origSelend = selend;
1185
1186 auto pTrack = Track::SharedPointer( track );
1187 if (!pTrack)
1188 pTrack = TrackList::Get( *pProject ).Lock( FindTrack() );
1189
1190 if (pTrack && mSnapManager.get()) {
1191 bool rightEdge = (selend > mSelStart);
1192 mSnapEnd = mSnapManager->Snap(pTrack.get(), selend, rightEdge);
1193 if (mSnapEnd.Snapped()) {
1194 if (mUseSnap)
1195 selend = mSnapEnd.outTime;
1197 mSnapEnd.outCoord += trackLeftEdge;
1198 }
1200 mSnapEnd.outCoord = -1;
1201
1202 // Check if selection endpoints are too close together to snap (unless
1203 // using snap-to-time -- then we always accept the snap results)
1204 if (mSnapStart.outCoord >= 0 &&
1205 mSnapEnd.outCoord >= 0 &&
1206 std::abs(mSnapStart.outCoord - mSnapEnd.outCoord) < 3) {
1208 selend = origSelend;
1209 mSnapEnd.outCoord = -1;
1210 }
1211 }
1212 AssignSelection(viewInfo, selend, pTrack.get());
1213}
SnapResults mSnapEnd
Definition: SelectHandle.h:138
std::weak_ptr< Track > FindTrack()
void AssignSelection(ViewInfo &viewInfo, double selend, Track *pTrack)
bool mSelStartValid
Definition: SelectHandle.h:141
double mSelStart
Definition: SelectHandle.h:142
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:160
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1246
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347
bool snappedTime
Definition: Snap.h:50
double outTime
Definition: Snap.h:47
bool Snapped() const
Definition: Snap.h:52

References AssignSelection(), FindTrack(), TrackList::Get(), TrackList::Lock(), mSelStart, mSelStartValid, mSnapEnd, mSnapManager, mSnapStart, mUseSnap, SnapResults::outCoord, SnapResults::outTime, ZoomInfo::PositionToTime(), Track::SharedPointer(), SnapResults::Snapped(), SnapResults::snappedPoint, and SnapResults::snappedTime.

Referenced by Click(), and Drag().

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

◆ AssignSelection()

void SelectHandle::AssignSelection ( ViewInfo viewInfo,
double  selend,
Track pTrack 
)
private

Definition at line 1215 of file SelectHandle.cpp.

1217{
1218 double sel0, sel1;
1219 if (mSelStart < selend) {
1220 sel0 = mSelStart;
1221 sel1 = selend;
1222 }
1223 else {
1224 sel1 = mSelStart;
1225 sel0 = selend;
1226 }
1227
1228 viewInfo.selectedRegion.setTimes(sel0, sel1);
1229}
bool setTimes(double t0, double t1)
Definition: ViewInfo.cpp:51

References mSelStart, ViewInfo::selectedRegion, and NotifyingSelectedRegion::setTimes().

Referenced by AdjustSelection(), and SetUseSnap().

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

◆ Cancel()

UIHandle::Result SelectHandle::Cancel ( AudacityProject pProject)
overridevirtual

Implements UIHandle.

Definition at line 1018 of file SelectHandle.cpp.

1019{
1020 mSelectionStateChanger.reset();
1022
1024}
std::shared_ptr< SelectionStateChanger > mSelectionStateChanger
Definition: SelectHandle.h:171
SelectedRegion mInitialSelection
Definition: SelectHandle.h:135
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235

References ViewInfo::Get(), mInitialSelection, mSelectionStateChanger, RefreshCode::RefreshAll, and ViewInfo::selectedRegion.

Here is the call graph for this function:

◆ Click()

UIHandle::Result SelectHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

This method gets called when we're handling selection and the mouse was just clicked.

Implements UIHandle.

Definition at line 532 of file SelectHandle.cpp.

534{
537
538 using namespace RefreshCode;
539
540 const auto pView = mpView.lock();
541 if ( !pView )
542 return Cancelled;
543
544 wxMouseEvent &event = evt.event;
545 auto &trackList = TrackList::Get(*pProject);
546 const auto sTrack = trackList.Lock(FindTrack());
547 const auto pTrack = sTrack.get();
548 const auto pLeader = *trackList.Find(pTrack);
549 auto &trackPanel = TrackPanel::Get(*pProject);
550 auto &viewInfo = ViewInfo::Get(*pProject);
551
552 mMostRecentX = event.m_x;
553 mMostRecentY = event.m_y;
554
555 bool selectChange = (
556 event.LeftDown() &&
557 event.ControlDown() &&
558 pTrack->TypeSwitch<bool>( [&](LabelTrack &){
559 // We should reach this, only in default of other hits on glyphs or
560 // text boxes.
561 bool bShift = event.ShiftDown();
562 bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
564 *pProject, *pTrack, bShift, true, !unsafe);
565 return true;
566 } )
567 );
568 if ( selectChange )
569 // Do not start a drag
570 return RefreshAll | Cancelled;
571
572 auto &selectionState = SelectionState::Get( *pProject );
573 if (event.LeftDClick() && !event.ShiftDown()) {
574 // Deselect all other tracks and select this one.
575 selectionState.SelectNone(trackList);
576
577 if (pLeader)
578 selectionState.SelectTrack(*pLeader, true, true);
579
580 // Default behavior: select whole track
582 viewInfo, *pLeader, SyncLockState::Get(*pProject).IsSyncLocked());
583
584 // Special case: if we're over a clip in a WaveTrack,
585 // select just that clip
586 pTrack->TypeSwitch( [&] ( WaveTrack &wt ) {
587 auto time = viewInfo.PositionToTime(event.m_x, mRect.x);
588 WaveClip *const selectedClip = wt.GetClipAtTime(time);
589 if (selectedClip) {
590 viewInfo.selectedRegion.setTimes(
591 selectedClip->GetPlayStartTime(), selectedClip->GetPlayEndTime());
592 }
593 } );
594
595 ProjectHistory::Get( *pProject ).ModifyState(false);
596
597 // Do not start a drag
598 return RefreshAll | Cancelled;
599 }
600 else if (!event.LeftDown())
601 return Cancelled;
602
603 mInitialSelection = viewInfo.selectedRegion;
604
606 std::make_shared<SelectionStateChanger>(selectionState, trackList);
607
609
610 bool bShiftDown = event.ShiftDown();
611 bool bCtrlDown = event.ControlDown();
612
614 auto xx = viewInfo.TimeToPosition(mSelStart, mRect.x);
615
616 // I. Shift-click adjusts an existing selection
617 if (bShiftDown || bCtrlDown) {
618 if (bShiftDown)
619 selectionState.ChangeSelectionOnShiftClick(trackList, *pTrack);
620 if( bCtrlDown ){
621 //Commented out bIsSelected toggles, as in Track Control Panel.
622 //bool bIsSelected = pTrack->GetSelected();
623 //Actual bIsSelected will always add.
624 bool bIsSelected = false;
625 // Don't toggle away the last selected track.
626 if (!bIsSelected || trackPanel.GetSelectedTrackCount() > 1)
627 if (pLeader)
628 selectionState.SelectTrack(*pLeader, !bIsSelected, true);
629 }
630
631 double value;
632 // Shift-click, choose closest boundary
633 SelectionBoundary boundary =
634 ChooseBoundary(viewInfo, xx, event.m_y,
635 pView.get(), mRect, false, false, &value);
636 mSelectionBoundary = boundary;
637 switch (boundary) {
638 case SBLeft:
639 case SBRight:
640 {
641#ifdef EXPERIMENTAL_SPECTRAL_EDITING
642 // If drag starts, change time selection only
643 // (also exit frequency snapping)
644 mFreqSelMode = FREQ_SEL_INVALID;
645#endif
646 mSelStartValid = true;
647 mSelStart = value;
649 AdjustSelection(pProject, viewInfo, event.m_x, mRect.x, pTrack);
650 break;
651 }
652#ifdef EXPERIMENTAL_SPECTRAL_EDITING
653 case SBBottom:
654 case SBTop:
655 {
656 mFreqSelTrack = pTrack->SharedPointer<const WaveTrack>();
657 mFreqSelPin = value;
658 mFreqSelMode =
659 (boundary == SBBottom)
661
662 // Drag frequency only, not time:
663 mSelStartValid = false;
665 static_cast<WaveTrack*>(pTrack),
666 viewInfo, event.m_y, mRect.y, mRect.height);
667 break;
668 }
669 case SBCenter:
670 {
671 const auto wt = static_cast<const WaveTrack*>(pTrack);
672 HandleCenterFrequencyClick(viewInfo, true, wt, value);
673 break;
674 }
675#endif
676 default:
677 wxASSERT(false);
678 };
679
680 // For persistence of the selection change:
681 ProjectHistory::Get( *pProject ).ModifyState(false);
682
683 // Get timer events so we can auto-scroll
684 Connect(pProject);
685
686 // Full refresh since the label area may need to indicate
687 // newly selected tracks.
688 return RefreshAll;
689 }
690
691 // II. Unmodified click starts a NEW selection
692
693 //Make sure you are within the selected track
694 bool startNewSelection = true;
695 if (pTrack && pTrack->GetSelected()) {
696#ifdef EXPERIMENTAL_SPECTRAL_EDITING
697 if (mFreqSelMode == FREQ_SEL_SNAPPING_CENTER &&
698 isSpectralSelectionView(pView.get())) {
699 // This code is no longer reachable, but it had a place in the
700 // spectral selection prototype. It used to be that you could be
701 // in a center-frequency-snapping mode that was not a mouse drag
702 // but responded to mouse movements. Click exited that and dragged
703 // width instead. PRL.
704
705 // Ignore whether we are inside the time selection.
706 // Exit center-snapping, start dragging the width.
707 mFreqSelMode = FREQ_SEL_PINNED_CENTER;
708 mFreqSelTrack = pTrack->SharedPointer<const WaveTrack>();
709 mFreqSelPin = viewInfo.selectedRegion.fc();
710 // Do not adjust time boundaries
711 mSelStartValid = false;
713 static_cast<WaveTrack*>(pTrack),
714 viewInfo, event.m_y, mRect.y, mRect.height);
715 // For persistence of the selection change:
716 ProjectHistory::Get( *pProject ).ModifyState(false);
717 mSelectionBoundary = SBWidth;
718 return RefreshNone;
719 }
720 else
721#endif
722 {
723 // Not shift-down, choose boundary only within snapping
724 double value;
725 SelectionBoundary boundary =
726 ChooseBoundary(viewInfo, xx, event.m_y,
727 pView.get(), mRect, true, true, &value);
728 mSelectionBoundary = boundary;
729 switch (boundary) {
730 case SBNone:
731 // startNewSelection remains true
732 break;
733 case SBLeft:
734 case SBRight:
735 startNewSelection = false;
736#ifdef EXPERIMENTAL_SPECTRAL_EDITING
737 // Disable frequency selection
738 mFreqSelMode = FREQ_SEL_INVALID;
739#endif
740 mSelStartValid = true;
741 mSelStart = value;
743 break;
744#ifdef EXPERIMENTAL_SPECTRAL_EDITING
745 case SBBottom:
746 case SBTop:
747 case SBWidth:
748 startNewSelection = false;
749 // Disable time selection
750 mSelStartValid = false;
751 mFreqSelTrack = pTrack->SharedPointer<const WaveTrack>();
752 mFreqSelPin = value;
753 mFreqSelMode =
754 (boundary == SBWidth) ? FREQ_SEL_PINNED_CENTER :
755 (boundary == SBBottom) ? FREQ_SEL_BOTTOM_FREE :
757 break;
758 case SBCenter:
759 {
760 const auto wt = static_cast<const WaveTrack*>(pTrack);
761 HandleCenterFrequencyClick(viewInfo, false, wt, value);
762 startNewSelection = false;
763 break;
764 }
765#endif
766 default:
767 wxASSERT(false);
768 }
769 }
770 }
771
772 // III. Common case for starting a NEW selection
773
774 if (startNewSelection) {
775 // If we didn't move a selection boundary, start a NEW selection
776 selectionState.SelectNone(trackList);
777#ifdef EXPERIMENTAL_SPECTRAL_EDITING
778 StartFreqSelection (viewInfo, event.m_y, mRect.y, mRect.height,
779 pView.get());
780#endif
781 StartSelection(pProject);
782 if (pLeader)
783 selectionState.SelectTrack(*pLeader, true, true);
784 TrackFocus::Get(*pProject).Set(pTrack);
785
786 Connect(pProject);
787 return RefreshAll;
788 }
789 else {
790 Connect(pProject);
791 return RefreshAll;
792 }
793}
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
void HandleCenterFrequencyClick(const ViewInfo &viewInfo, bool shiftDown, const WaveTrack *pTrack, double value)
std::weak_ptr< const WaveTrack > mFreqSelTrack
Definition: SelectHandle.h:157
void StartFreqSelection(ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge, int trackHeight, ChannelView *pChannelView)
void AdjustSelection(AudacityProject *pProject, ViewInfo &viewInfo, int mouseXCoordinate, int trackLeftEdge, Track *pTrack)
Extend or contract the existing selection.
int mSelectionBoundary
Definition: SelectHandle.h:144
void AdjustFreqSelection(const WaveTrack *wt, ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge, int trackHeight)
void Connect(AudacityProject *pProject)
void StartSelection(AudacityProject *pProject)
Reset our selection markers.
static void SelectTrackLength(ViewInfo &viewInfo, Track &track, bool syncLocked)
static SelectionState & Get(AudacityProject &project)
bool IsSyncLocked() const
Definition: SyncLock.cpp:43
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:26
Track * Get()
Definition: TrackFocus.cpp:156
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:233
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:138
A Track that contains audio waveform data.
Definition: WaveTrack.h:227
const WaveClip * GetClipAtTime(double time) const
Definition: WaveTrack.cpp:3772
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
void DoListSelection(AudacityProject &project, Track &t, bool shift, bool ctrl, bool modifyState)
bool isSpectralSelectionView(const ChannelView *pChannelView)
SelectionBoundary ChooseBoundary(const ViewInfo &viewInfo, wxCoord xx, wxCoord yy, const ChannelView *pChannelView, const wxRect &rect, bool mayDragWidth, bool onlyWithinSnapDistance, double *pPinValue=NULL)
double timeSnappedTime
Definition: Snap.h:46

References AdjustFreqSelection(), AdjustSelection(), Cancelled, anonymous_namespace{SelectHandle.cpp}::ChooseBoundary(), Connect(), SelectUtilities::DoListSelection(), TrackPanelMouseEvent::event, FindTrack(), FREQ_SEL_BOTTOM_FREE, FREQ_SEL_INVALID, FREQ_SEL_PINNED_CENTER, FREQ_SEL_SNAPPING_CENTER, FREQ_SEL_TOP_FREE, TrackFocus::Get(), ProjectAudioIO::Get(), ProjectHistory::Get(), ViewInfo::Get(), SelectionState::Get(), SyncLockState::Get(), TrackList::Get(), TrackPanel::Get(), WaveTrack::GetClipAtTime(), HandleCenterFrequencyClick(), ProjectAudioIO::IsAudioActive(), anonymous_namespace{SelectHandle.cpp}::isSpectralSelectionView(), SyncLockState::IsSyncLocked(), mFreqSelPin, mFreqSelTrack, mInitialSelection, mMostRecentX, mMostRecentY, ProjectHistory::ModifyState(), mpView, mRect, mSelectionBoundary, mSelectionStateChanger, mSelStart, mSelStartValid, mSnapStart, mUseSnap, SnapResults::outTime, RefreshCode::RefreshAll, RefreshCode::RefreshNone, anonymous_namespace{SelectHandle.cpp}::SBLeft, anonymous_namespace{SelectHandle.cpp}::SBNone, anonymous_namespace{SelectHandle.cpp}::SBRight, SelectionState::SelectTrackLength(), StartFreqSelection(), StartSelection(), and SnapResults::timeSnappedTime.

Here is the call graph for this function:

◆ Connect()

void SelectHandle::Connect ( AudacityProject pProject)
private

Definition at line 1060 of file SelectHandle.cpp.

1061{
1062 mTimerHandler = std::make_shared<TimerHandler>( this, pProject );
1063}
std::shared_ptr< TimerHandler > mTimerHandler
Definition: SelectHandle.h:175

References mTimerHandler.

Referenced by Click().

Here is the caller graph for this function:

◆ Drag()

UIHandle::Result SelectHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

AS: If we're dragging to adjust a selection (or actually, if the screen is scrolling while you're selecting), we handle it here.

Implements UIHandle.

Definition at line 795 of file SelectHandle.cpp.

797{
798 using namespace RefreshCode;
799
800 const auto pView = mpView.lock();
801 if ( !pView )
802 return Cancelled;
803
804 auto &viewInfo = ViewInfo::Get( *pProject );
805 const wxMouseEvent &event = evt.event;
806
807 int x = mAutoScrolling ? mMostRecentX : event.m_x;
808 int y = mAutoScrolling ? mMostRecentY : event.m_y;
809 mMostRecentX = x;
810 mMostRecentY = y;
811
815
816 // Fuhggeddaboudit if we're not dragging and not autoscrolling.
817 if (!event.Dragging() && !mAutoScrolling)
818 return RefreshNone;
819
820 if (event.CmdDown()) {
821 // Ctrl-drag has no meaning, fuhggeddaboudit
822 // JKC YES it has meaning.
823 //return RefreshNone;
824 }
825
826 // Also fuhggeddaboudit if not in a track.
827 auto pTrack = TrackList::Get( *pProject ).Lock( FindTrack() );
828 if (!pTrack)
829 return RefreshNone;
830
831 // JKC: Logic to prevent a selection smaller than 5 pixels to
832 // prevent accidental dragging when selecting.
833 // (if user really wants a tiny selection, they should zoom in).
834 // Can someone make this value of '5' configurable in
835 // preferences?
836 enum { minimumSizedSelection = 5 }; //measured in pixels
837
838 // Might be dragging frequency bounds only, test
839 if (mSelStartValid) {
840 wxInt64 SelStart = viewInfo.TimeToPosition(mSelStart, mRect.x); //cvt time to pixels.
841 // Abandon this drag if selecting < 5 pixels.
842 if (wxLongLong(SelStart - x).Abs() < minimumSizedSelection)
843 return RefreshNone;
844 }
845
846 if (evt.pCell) {
847 if ( auto clickedTrack =
848 static_cast<CommonTrackPanelCell*>(evt.pCell.get())->FindTrack() ) {
849 // Handle which tracks are selected
850 Track *sTrack = pTrack.get();
851 Track *eTrack = clickedTrack.get();
852 auto &trackList = TrackList::Get( *pProject );
853 if ( sTrack && eTrack && !event.ControlDown() ) {
854 auto &selectionState = SelectionState::Get( *pProject );
855 selectionState.SelectRangeOfTracks( trackList, *sTrack, *eTrack );
856 }
857
858 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
859 #ifndef SPECTRAL_EDITING_ESC_KEY
860 if (mFreqSelMode == FREQ_SEL_SNAPPING_CENTER &&
861 !viewInfo.selectedRegion.isPoint())
863 (pProject, viewInfo, y, mRect.y, mRect.height, pView.get());
864 else
865 #endif
866 if ( TrackList::Get( *pProject ).Lock(mFreqSelTrack) == pTrack )
868 static_cast<WaveTrack*>(pTrack.get()),
869 viewInfo, y, mRect.y, mRect.height);
870 #endif
871
872 AdjustSelection(pProject, viewInfo, x, mRect.x, clickedTrack.get());
873 }
874 }
875
876 return RefreshNone
877
878 // If scrubbing does not use the helper poller thread, then
879 // don't refresh at every mouse event, because it slows down seek-scrub.
880 // Instead, let OnTimer do it, which is often enough.
881 // And even if scrubbing does use the thread, then skipping refresh does not
882 // bring that advantage, but it is probably still a good idea anyway.
883
884 // | UpdateSelection
885
886 ;
887}
std::shared_ptr< Track > FindTrack()
bool mAutoScrolling
Definition: SelectHandle.h:169
void MoveSnappingFreqSelection(AudacityProject *pProject, ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge, int trackHeight, ChannelView *pChannelView)
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122

References AdjustFreqSelection(), AdjustSelection(), Cancelled, TrackPanelMouseEvent::event, CommonTrackPanelCell::FindTrack(), FindTrack(), FREQ_SEL_SNAPPING_CENTER, ViewInfo::Get(), SelectionState::Get(), TrackList::Get(), TrackList::Lock(), mAutoScrolling, mFreqSelTrack, mMostRecentX, mMostRecentY, MoveSnappingFreqSelection(), mpView, mRect, mSelStart, mSelStartValid, TrackPanelMouseEvent::pCell, and RefreshCode::RefreshNone.

Referenced by SelectHandle::TimerHandler::OnTimer().

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

◆ Draw()

void SelectHandle::Draw ( TrackPanelDrawingContext context,
const wxRect &  rect,
unsigned  iPass 
)
overrideprivatevirtual

Reimplemented from TrackPanelDrawable.

Definition at line 1026 of file SelectHandle.cpp.

1029{
1030 if ( iPass == TrackArtist::PassSnapping ) {
1031 auto &dc = context.dc;
1032 // Draw snap guidelines if we have any
1033 if ( mSnapManager ) {
1034 auto coord1 = (mUseSnap || IsDragging()) ? mSnapStart.outCoord : -1;
1035 auto coord2 = (!mUseSnap || !IsDragging()) ? -1 : mSnapEnd.outCoord;
1036 TrackArt::DrawSnapLines(&dc, coord1, coord2);
1037 }
1038 }
1039}
bool IsDragging() const override
AUDACITY_DLL_API void DrawSnapLines(wxDC *dc, wxInt64 snap0, wxInt64 snap1)
Definition: TrackArt.cpp:768

References TrackPanelDrawingContext::dc, TrackArt::DrawSnapLines(), IsDragging(), mSnapEnd, mSnapManager, mSnapStart, mUseSnap, SnapResults::outCoord, and TrackArtist::PassSnapping.

Here is the call graph for this function:

◆ DrawingArea()

wxRect SelectHandle::DrawingArea ( TrackPanelDrawingContext ,
const wxRect &  rect,
const wxRect &  panelRect,
unsigned  iPass 
)
overrideprivatevirtual

Reimplemented from TrackPanelDrawable.

Definition at line 1041 of file SelectHandle.cpp.

1044{
1045 if ( iPass == TrackArtist::PassSnapping )
1046 return MaximizeHeight( rect, panelRect );
1047 else
1048 return rect;
1049}
static wxRect MaximizeHeight(const wxRect &rect, const wxRect &panelRect)

References TrackPanelDrawable::MaximizeHeight(), and TrackArtist::PassSnapping.

Here is the call graph for this function:

◆ Enter()

void SelectHandle::Enter ( bool  forward,
AudacityProject pProject 
)
overridevirtual

Reimplemented from UIHandle.

Definition at line 489 of file SelectHandle.cpp.

490{
491 SetUseSnap(true, project);
492}
const auto project
void SetUseSnap(bool use, AudacityProject *pProject)

References project, and SetUseSnap().

Here is the call graph for this function:

◆ Escape()

bool SelectHandle::Escape ( AudacityProject pProject)
overridevirtual

Reimplemented from UIHandle.

Definition at line 523 of file SelectHandle.cpp.

524{
526 SetUseSnap(false, project);
527 return true;
528 }
529 return false;
530}
bool HasEscape(AudacityProject *pProject) const override

References HasEscape(), project, and SetUseSnap().

Here is the call graph for this function:

◆ FindChannel()

std::shared_ptr< const Channel > SelectHandle::FindChannel ( ) const
overridevirtual
Returns
pointer to associated channel, if any

Implements UIHandle.

Definition at line 463 of file SelectHandle.cpp.

464{
465 if (auto pView = mpView.lock())
466 return pView->FindChannel();
467 return nullptr;
468}

References mpView.

◆ FindTrack()

std::weak_ptr< Track > SelectHandle::FindTrack ( )
private

Definition at line 1051 of file SelectHandle.cpp.

1052{
1053 auto pView = mpView.lock();
1054 if (!pView)
1055 return {};
1056 else
1057 return pView->FindTrack();
1058}

References mpView.

Referenced by AdjustSelection(), Click(), Drag(), SelectHandle::TimerHandler::OnTimer(), and Preview().

Here is the caller graph for this function:

◆ HandleCenterFrequencyClick()

void SelectHandle::HandleCenterFrequencyClick ( const ViewInfo viewInfo,
bool  shiftDown,
const WaveTrack pTrack,
double  value 
)
private

Definition at line 1334 of file SelectHandle.cpp.

1336{
1337 if (shiftDown) {
1338 // Disable time selection
1339 mSelStartValid = false;
1340 mFreqSelTrack = pTrack->SharedPointer<const WaveTrack>();
1341 mFreqSelPin = value;
1342 mFreqSelMode = FREQ_SEL_DRAG_CENTER;
1343 }
1344 else {
1345#ifndef SPECTRAL_EDITING_ESC_KEY
1346 // Start center snapping
1347 // Turn center snapping on (the only way to do this)
1348 mFreqSelMode = FREQ_SEL_SNAPPING_CENTER;
1349 // Disable time selection
1350 mSelStartValid = false;
1351 mFrequencySnapper = std::make_shared<SpectrumAnalyst>();
1353#endif
1354 }
1355}
std::shared_ptr< SpectrumAnalyst > mFrequencySnapper
Definition: SelectHandle.h:165
static void StartSnappingFreqSelection(SpectrumAnalyst &analyst, const ViewInfo &viewInfo, const WaveTrack *pTrack)

References FREQ_SEL_DRAG_CENTER, FREQ_SEL_SNAPPING_CENTER, mFreqSelPin, mFreqSelTrack, mFrequencySnapper, mSelStartValid, Track::SharedPointer(), and StartSnappingFreqSelection().

Referenced by Click().

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

◆ HasEscape()

bool SelectHandle::HasEscape ( AudacityProject pProject) const
overridevirtual

Reimplemented from UIHandle.

Definition at line 518 of file SelectHandle.cpp.

519{
520 return HasSnap() && mUseSnap;
521}
bool HasSnap() const

References HasSnap(), and mUseSnap.

Referenced by Escape(), and Preview().

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

◆ HasSnap()

bool SelectHandle::HasSnap ( ) const

Definition at line 512 of file SelectHandle.cpp.

513{
514 return
515 (IsDragging() ? mSnapEnd : mSnapStart).snappedPoint;
516}

References IsDragging(), mSnapEnd, and mSnapStart.

Referenced by HasEscape(), Preview(), and SetUseSnap().

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

◆ HitTest()

UIHandlePtr SelectHandle::HitTest ( std::weak_ptr< SelectHandle > &  holder,
const TrackPanelMouseState state,
const AudacityProject pProject,
const std::shared_ptr< ChannelView > &  pChannelView 
)
static

Definition at line 368 of file SelectHandle.cpp.

372{
373 // This handle is a little special because there may be some state to
374 // preserve during movement before the click.
375 auto old = holder.lock();
376 bool oldUseSnap = true;
377 if (old) {
378 // It should not have started listening to timer events
379 if( old->mTimerHandler ) {
380 wxASSERT(false);
381 // Handle this eventuality anyway, don't leave a dangling back-pointer
382 // in the attached event handler.
383 old->mTimerHandler.reset();
384 }
385 oldUseSnap = old->mUseSnap;
386 }
387
388 const auto &viewInfo = ViewInfo::Get( *pProject );
389 auto result = std::make_shared<SelectHandle>(
390 pChannelView, oldUseSnap, TrackList::Get(*pProject), st, viewInfo);
391
392 result = AssignUIHandlePtr(holder, result);
393
394 //Make sure we are within the selected track
395 auto pTrack = pChannelView->FindTrack();
396 if (!pTrack->GetSelected())
397 {
398 return result;
399 }
400
401 {
402 const wxRect &rect = st.rect;
403 wxInt64 leftSel = viewInfo.TimeToPosition(viewInfo.selectedRegion.t0(), rect.x);
404 wxInt64 rightSel = viewInfo.TimeToPosition(viewInfo.selectedRegion.t1(), rect.x);
405 // Something is wrong if right edge comes before left edge
406 wxASSERT(!(rightSel < leftSel));
407 static_cast<void>(leftSel); // Suppress unused variable warnings if not in debug-mode
408 static_cast<void>(rightSel);
409 }
410
411 return result;
412}
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:159

References AssignUIHandlePtr(), ViewInfo::Get(), TrackList::Get(), and TrackPanelMouseState::rect.

Referenced by CommonChannelView::HitTest(), NoteTrackAffordanceControls::HitTest(), and WaveTrackAffordanceControls::HitTest().

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

◆ IsDragging()

bool SelectHandle::IsDragging ( ) const
overridevirtual

Whether the handle is dragging, affecting other panel painting; default returns false

Reimplemented from UIHandle.

Definition at line 60 of file SelectHandle.cpp.

61{
62 return mSelectionStateChanger.get() != NULL;
63}

References mSelectionStateChanger.

Referenced by Draw(), HasSnap(), Preview(), and SetUseSnap().

Here is the caller graph for this function:

◆ MoveSnappingFreqSelection()

void SelectHandle::MoveSnappingFreqSelection ( AudacityProject pProject,
ViewInfo viewInfo,
int  mouseYCoordinate,
int  trackTopEdge,
int  trackHeight,
ChannelView pChannelView 
)
private

Definition at line 1400 of file SelectHandle.cpp.

1404{
1405 auto pTrack = pChannelView->FindTrack().get();
1406 if (pTrack &&
1407 pTrack->GetSelected() &&
1408 isSpectralSelectionView(pChannelView)) {
1409 // Spectral selection track is always wave
1410 WaveTrack *const wt = static_cast<WaveTrack*>(pTrack);
1411 // PRL:
1412 // What would happen if center snapping selection began in one spectrogram track,
1413 // then continues inside another? We do not then recalculate
1414 // the spectrum (as was done in StartSnappingFreqSelection)
1415 // but snap according to the peaks in the old track.
1416
1417 // But if we always supply the original clicked track here that doesn't matter.
1418 const double rate = wt->GetRate();
1419 const double frequency =
1420 PositionToFrequency(wt, false, mouseYCoordinate,
1421 trackTopEdge, trackHeight);
1422 const double snappedFrequency =
1423 mFrequencySnapper->FindPeak(frequency, NULL);
1424 const double maxRatio = findMaxRatio(snappedFrequency, rate);
1425 double ratio = 2.0; // An arbitrary octave on each side, at most
1426 {
1427 const double f0 = viewInfo.selectedRegion.f0();
1428 const double f1 = viewInfo.selectedRegion.f1();
1429 if (f1 >= f0 && f0 >= 0)
1430 // Preserve already chosen ratio instead
1431 ratio = sqrt(f1 / f0);
1432 }
1433 ratio = std::min(ratio, maxRatio);
1434
1435 mFreqSelPin = snappedFrequency;
1437 snappedFrequency / ratio, snappedFrequency * ratio);
1438
1439 // A change here would affect what AdjustFreqSelection() does
1440 // in the prototype version where you switch from moving center to
1441 // dragging width with a click. No effect now.
1442 mFreqSelTrack = wt->SharedPointer<const WaveTrack>();
1443
1444 // SelectNone();
1445 // SelectTrack(pTrack, true);
1446 TrackFocus::Get( *pProject ).Set(pTrack);
1447 }
1448}
double f1() const
Definition: ViewInfo.h:38
double f0() const
Definition: ViewInfo.h:37
__finl float_x4 __vecc sqrt(const float_x4 &a)

References NotifyingSelectedRegion::f0(), NotifyingSelectedRegion::f1(), anonymous_namespace{SelectHandle.cpp}::findMaxRatio(), CommonTrackPanelCell::FindTrack(), TrackFocus::Get(), WaveTrack::GetRate(), anonymous_namespace{SelectHandle.cpp}::isSpectralSelectionView(), mFreqSelPin, mFreqSelTrack, mFrequencySnapper, min(), anonymous_namespace{SelectHandle.cpp}::PositionToFrequency(), ViewInfo::selectedRegion, NotifyingSelectedRegion::setFrequencies(), Track::SharedPointer(), and staffpad::audio::simd::sqrt().

Referenced by Drag().

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

◆ NeedChangeHighlight()

UIHandle::Result SelectHandle::NeedChangeHighlight ( const SelectHandle oldState,
const SelectHandle newState 
)
static

Definition at line 414 of file SelectHandle.cpp.

416{
417 auto useSnap = oldState.mUseSnap;
418 // This is guaranteed when constructing the NEW handle:
419 wxASSERT( useSnap == newState.mUseSnap );
420 if (!useSnap)
421 return 0;
422
423 auto &oldSnapState = oldState.mSnapStart;
424 auto &newSnapState = newState.mSnapStart;
425 if ( oldSnapState.Snapped() == newSnapState.Snapped() &&
426 (!oldSnapState.Snapped() ||
427 oldSnapState.outCoord == newSnapState.outCoord) )
428 return 0;
429
431}

References mSnapStart, mUseSnap, and RefreshCode::RefreshAll.

◆ operator=()

SelectHandle & SelectHandle::operator= ( const SelectHandle )
default

◆ Preview()

HitTestPreview SelectHandle::Preview ( const TrackPanelMouseState state,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 889 of file SelectHandle.cpp.

891{
892 if (!HasSnap() && !mUseSnap)
893 // Moved out of snapping; revert to un-escaped state
894 mUseSnap = true;
895
896 const auto pView = mpView.lock();
897 if ( !pView )
898 return {};
899
900 auto pTrack = FindTrack().lock();
901 if (!pTrack)
902 return {};
903
905 wxCursor *pCursor = SelectCursor();
906 if (IsDragging())
907 // Use same cursor as at the click
910 (mFreqSelMode == FREQ_SEL_SNAPPING_CENTER),
911 tip, pCursor);
912 else {
913 // Choose one of many cursors for mouse-over
914
915 auto &viewInfo = ViewInfo::Get( *pProject );
916
917 auto &state = st.state;
919 auto xx = viewInfo.TimeToPosition(time, mRect.x);
920
921 const bool bMultiToolMode =
923
924 //In Multi-tool mode, give multitool prompt if no-special-hit.
925 if (bMultiToolMode) {
926 // Look up the current key binding for Preferences.
927 // (Don't assume it's the default!)
928 auto keyStr =
929 CommandManager::Get( *pProject ).GetKeyFromName(wxT("Preferences"))
930 .Display( true );
931 if (keyStr.empty())
932 // No keyboard preference defined for opening Preferences dialog
933 /* i18n-hint: These are the names of a menu and a command in that menu */
934 keyStr = _("Edit, Preferences...");
935
936 /* i18n-hint: %s is usually replaced by "Ctrl+P" for Windows/Linux, "Command+," for Mac */
937 tip = XO("Multi-Tool Mode: %s for Mouse and Keyboard Preferences.")
938 .Format( keyStr );
939 // Later in this function we may point to some other string instead.
940 if (!pTrack->GetSelected())
941 ;
942 else {
943 const wxRect &rect = st.rect;
944 const bool bShiftDown = state.ShiftDown();
945 const bool bCtrlDown = state.ControlDown();
946 const bool bModifierDown = bShiftDown || bCtrlDown;
947
948 // If not shift-down and not snapping center, then
949 // choose boundaries only in snapping tolerance,
950 // and may choose center.
951 SelectionBoundary boundary =
952 ChooseBoundary(viewInfo, xx, state.m_y,
953 pView.get(), rect, !bModifierDown, !bModifierDown);
954
955 SetTipAndCursorForBoundary(boundary, !bShiftDown, tip, pCursor);
956 }
957 }
958
959#if 0
960 // This is a vestige of an idea in the prototype version.
961 // Center would snap without mouse button down, click would pin the center
962 // and drag width.
963#ifdef EXPERIMENTAL_SPECTRAL_EDITING
964 if ((mFreqSelMode == FREQ_SEL_SNAPPING_CENTER) &&
966 // Not shift-down, but center frequency snapping toggle is on
967 tip = XO("Click and drag to set frequency bandwidth.");
968 pCursor = &*envelopeCursor;
969 return {};
970 }
971#endif
972#endif
973
974 if (!pTrack->GetSelected())
975 ;
976 else {
977 const wxRect &rect = st.rect;
978 const bool bShiftDown = state.ShiftDown();
979 const bool bCtrlDown = state.ControlDown();
980 const bool bModifierDown = bShiftDown || bCtrlDown;
982 viewInfo, xx, state.m_y,
983 pView.get(), rect, !bModifierDown, !bModifierDown);
984 SetTipAndCursorForBoundary(boundary, !bShiftDown, tip, pCursor);
985 }
986 }
987 if (tip.empty()) {
988 tip = XO("Click and drag to select audio");
989 }
990 if (HasEscape(pProject) && mUseSnap) {
991 tip.Join(
992/* i18n-hint: "Snapping" means automatic alignment of selection edges to any nearby label or clip boundaries */
993 XO("(snapping)"), wxT(" ")
994 );
995 }
996 return { tip, pCursor };
997}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
#define _(s)
Definition: Internat.h:73
static CommandManager & Get(AudacityProject &project)
NormalizedKeyString GetKeyFromName(const CommandID &name) const
static ProjectSettings & Get(AudacityProject &project)
int GetTool() const
Holds a msgid for the translation catalog; may also bind format arguments.
TranslatableString & Join(TranslatableString arg, const wxString &separator={}) &
Append another translatable string.
void SetTipAndCursorForBoundary(SelectionBoundary boundary, bool frequencySnapping, TranslatableString &tip, wxCursor *&pCursor)
wxString Display(bool usesSpecialChars=false) const
Definition: Keyboard.cpp:56

References _, anonymous_namespace{SelectHandle.cpp}::ChooseBoundary(), NormalizedKeyString::Display(), TranslatableString::empty(), FindTrack(), FREQ_SEL_SNAPPING_CENTER, CommandManager::Get(), ViewInfo::Get(), ProjectSettings::Get(), CommandManager::GetKeyFromName(), ProjectSettings::GetTool(), HasEscape(), HasSnap(), IsDragging(), anonymous_namespace{SelectHandle.cpp}::isSpectralSelectionView(), TranslatableString::Join(), mpView, mRect, mSelectionBoundary, mSnapStart, ToolCodes::multiTool, mUseSnap, SnapResults::outTime, TrackPanelMouseState::rect, anonymous_namespace{SelectHandle.cpp}::SelectCursor(), anonymous_namespace{SelectHandle.cpp}::SetTipAndCursorForBoundary(), TrackPanelMouseState::state, SnapResults::timeSnappedTime, wxT(), and XO().

Here is the call graph for this function:

◆ Release()

UIHandle::Result SelectHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

Implements UIHandle.

Definition at line 999 of file SelectHandle.cpp.

1001{
1002 PitchAndSpeedDialog::Get(*pProject).TryRetarget(event);
1003 using namespace RefreshCode;
1004 ProjectHistory::Get( *pProject ).ModifyState(false);
1005 mFrequencySnapper.reset();
1006 mSnapManager.reset();
1008 mSelectionStateChanger->Commit();
1009 mSelectionStateChanger.reset();
1010 }
1011
1012 if (mUseSnap && (mSnapStart.outCoord != -1 || mSnapEnd.outCoord != -1))
1013 return RefreshAll;
1014 else
1015 return RefreshNone;
1016}
static PitchAndSpeedDialog & Get(AudacityProject &project)
void TryRetarget(const TrackPanelMouseEvent &event)

References ProjectHistory::Get(), PitchAndSpeedDialog::Get(), mFrequencySnapper, ProjectHistory::ModifyState(), mSelectionStateChanger, mSnapEnd, mSnapManager, mSnapStart, mUseSnap, SnapResults::outCoord, RefreshCode::RefreshAll, RefreshCode::RefreshNone, and PitchAndSpeedDialog::TryRetarget().

Here is the call graph for this function:

◆ SetUseSnap()

void SelectHandle::SetUseSnap ( bool  use,
AudacityProject pProject 
)

Definition at line 494 of file SelectHandle.cpp.

495{
496 mUseSnap = use;
497
498 bool hasSnap = HasSnap();
499 if (hasSnap)
500 // Repaint to turn the snap lines on or off
502
503 if (IsDragging()) {
504 // Readjust the moving selection end
508 nullptr);
509 }
510}
Result mChangeHighlight
Definition: UIHandle.h:147

References AssignSelection(), ViewInfo::Get(), HasSnap(), IsDragging(), UIHandle::mChangeHighlight, mSnapEnd, mUseSnap, SnapResults::outTime, project, RefreshCode::RefreshAll, and SnapResults::timeSnappedTime.

Referenced by Enter(), and Escape().

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

◆ SnapCenterOnce()

void SelectHandle::SnapCenterOnce ( SpectrumAnalyst analyst,
ViewInfo viewInfo,
const WaveTrack pTrack,
bool  up 
)
static

Definition at line 1450 of file SelectHandle.cpp.

1453{
1454 const auto &settings = SpectrogramSettings::Get(*pTrack);
1455 const auto windowSize = settings.GetFFTLength();
1456 const double rate = pTrack->GetRate();
1457 const double nyq = rate / 2.0;
1458 const double binFrequency = rate / windowSize;
1459
1460 double f1 = viewInfo.selectedRegion.f1();
1461 double centerFrequency = viewInfo.selectedRegion.fc();
1462 if (centerFrequency <= 0) {
1463 centerFrequency = up ? binFrequency : nyq;
1464 f1 = centerFrequency * sqrt(2.0);
1465 }
1466
1467 double ratio = f1 / centerFrequency;
1468 const int originalBin = floor(0.5 + centerFrequency / binFrequency);
1469 const int limitingBin = up ? floor(0.5 + nyq / binFrequency) : 1;
1470
1471 // This is crude and wasteful, doing the FFT each time the command is called.
1472 // It would be better to cache the data, but then invalidation of the cache would
1473 // need doing in all places that change the time selection.
1474 StartSnappingFreqSelection(analyst, viewInfo, pTrack);
1475 double snappedFrequency = centerFrequency;
1476 int bin = originalBin;
1477 if (up) {
1478 while (snappedFrequency <= centerFrequency &&
1479 bin < limitingBin)
1480 snappedFrequency = analyst.FindPeak(++bin * binFrequency, NULL);
1481 }
1482 else {
1483 while (snappedFrequency >= centerFrequency &&
1484 bin > limitingBin)
1485 snappedFrequency = analyst.FindPeak(--bin * binFrequency, NULL);
1486 }
1487
1488 // PRL: added these two lines with the big TrackPanel refactor
1489 const double maxRatio = findMaxRatio(snappedFrequency, rate);
1490 ratio = std::min(ratio, maxRatio);
1491
1493 (snappedFrequency / ratio, snappedFrequency * ratio);
1494}
static Settings & settings()
Definition: TrackInfo.cpp:69
double fc() const
Definition: ViewInfo.h:39
static SpectrogramSettings & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
float FindPeak(float xPos, float *pY) const

References NotifyingSelectedRegion::f1(), NotifyingSelectedRegion::fc(), anonymous_namespace{SelectHandle.cpp}::findMaxRatio(), SpectrumAnalyst::FindPeak(), SpectrogramSettings::Get(), WaveTrack::GetRate(), min(), ViewInfo::selectedRegion, NotifyingSelectedRegion::setFrequencies(), settings(), staffpad::audio::simd::sqrt(), and StartSnappingFreqSelection().

Here is the call graph for this function:

◆ StartFreqSelection()

void SelectHandle::StartFreqSelection ( ViewInfo viewInfo,
int  mouseYCoordinate,
int  trackTopEdge,
int  trackHeight,
ChannelView pChannelView 
)
private

Definition at line 1231 of file SelectHandle.cpp.

1234{
1235 mFreqSelTrack.reset();
1236 mFreqSelMode = FREQ_SEL_INVALID;
1238
1239 if (isSpectralSelectionView(pChannelView)) {
1240 // Spectral selection track is always wave
1241 auto shTrack = pChannelView->FindTrack()->SharedPointer<const WaveTrack>();
1242 mFreqSelTrack = shTrack;
1243 mFreqSelMode = FREQ_SEL_FREE;
1244 mFreqSelPin =
1245 PositionToFrequency(shTrack.get(), false, mouseYCoordinate,
1246 trackTopEdge, trackHeight);
1248 }
1249}

References CommonTrackPanelCell::FindTrack(), FREQ_SEL_FREE, FREQ_SEL_INVALID, anonymous_namespace{SelectHandle.cpp}::isSpectralSelectionView(), mFreqSelPin, mFreqSelTrack, anonymous_namespace{SelectHandle.cpp}::PositionToFrequency(), ViewInfo::selectedRegion, NotifyingSelectedRegion::setFrequencies(), and SelectedRegion::UndefinedFrequency.

Referenced by Click().

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

◆ StartSelection()

void SelectHandle::StartSelection ( AudacityProject pProject)
private

Reset our selection markers.

Definition at line 1158 of file SelectHandle.cpp.

1159{
1160 auto &viewInfo = ViewInfo::Get( *pProject );
1161 mSelStartValid = true;
1162
1163 viewInfo.selectedRegion.setTimes(mSelStart, mSelStart);
1164
1165 // PRL: commented out the Sonify stuff with the TrackPanel refactor.
1166 // It was no-op anyway.
1167 //SonifyBeginModifyState();
1168 ProjectHistory::Get( *pProject ).ModifyState(false);
1169 //SonifyEndModifyState();
1170}

References ProjectHistory::Get(), ViewInfo::Get(), ProjectHistory::ModifyState(), mSelStart, and mSelStartValid.

Referenced by Click().

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

◆ StartSnappingFreqSelection()

void SelectHandle::StartSnappingFreqSelection ( SpectrumAnalyst analyst,
const ViewInfo viewInfo,
const WaveTrack pTrack 
)
staticprivate

Definition at line 1357 of file SelectHandle.cpp.

1360{
1361 static const size_t minLength = 8;
1362
1363 const double rate = pTrack->GetRate();
1364
1365 // Grab samples, just for this track, at these times
1366 std::vector<float> frequencySnappingData;
1367 const auto start =
1368 pTrack->TimeToLongSamples(viewInfo.selectedRegion.t0());
1369 const auto end =
1370 pTrack->TimeToLongSamples(viewInfo.selectedRegion.t1());
1371 const auto length =
1372 std::min(frequencySnappingData.max_size(),
1373 limitSampleBufferSize(10485760, // as in FreqWindow.cpp
1374 end - start));
1375 const auto effectiveLength = std::max(minLength, length);
1376 frequencySnappingData.resize(effectiveLength, 0.0f);
1377 pTrack->GetFloats(
1378 &frequencySnappingData[0],
1379 start, length, FillFormat::fillZero,
1380 // Don't try to cope with exceptions, just read zeroes instead.
1381 false);
1382
1383 // Use same settings as are now used for spectrogram display,
1384 // except, shrink the window as needed so we get some answers
1385
1386 const auto &settings = SpectrogramSettings::Get(*pTrack);
1387 auto windowSize = settings.GetFFTLength();
1388
1389 while(windowSize > effectiveLength)
1390 windowSize >>= 1;
1391 const int windowType = settings.windowType;
1392
1393 analyst.Calculate(
1394 SpectrumAnalyst::Spectrum, windowType, windowSize, rate,
1395 &frequencySnappingData[0], length);
1396
1397 // We can now throw away the sample data but we keep the spectrum.
1398}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
double t1() const
Definition: ViewInfo.h:36
double t0() const
Definition: ViewInfo.h:35
bool Calculate(Algorithm alg, int windowFunc, size_t windowSize, double rate, const float *data, size_t dataLen, float *pYMin=NULL, float *pYMax=NULL, FreqGauge *progress=NULL)
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches first channel only
Definition: SampleTrack.h:46
sampleCount TimeToLongSamples(double t0) const
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References SpectrumAnalyst::Calculate(), PackedArray::end(), fillZero, SpectrogramSettings::Get(), WaveTrack::GetFloats(), WaveTrack::GetRate(), limitSampleBufferSize(), min(), ViewInfo::selectedRegion, settings(), SpectrumAnalyst::Spectrum, NotifyingSelectedRegion::t0(), NotifyingSelectedRegion::t1(), and WideSampleSequence::TimeToLongSamples().

Referenced by HandleCenterFrequencyClick(), and SnapCenterOnce().

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

Member Data Documentation

◆ FREQ_SEL_INVALID

enum SelectHandle::eFreqSelMode SelectHandle::FREQ_SEL_INVALID
private

◆ mAutoScrolling

bool SelectHandle::mAutoScrolling {}
private

Definition at line 169 of file SelectHandle.h.

Referenced by Drag(), and SelectHandle::TimerHandler::OnTimer().

◆ mFreqSelPin

double SelectHandle::mFreqSelPin { -1.0 }
private

◆ mFreqSelTrack

std::weak_ptr<const WaveTrack> SelectHandle::mFreqSelTrack
private

◆ mFrequencySnapper

std::shared_ptr<SpectrumAnalyst> SelectHandle::mFrequencySnapper
private

Definition at line 165 of file SelectHandle.h.

Referenced by HandleCenterFrequencyClick(), MoveSnappingFreqSelection(), and Release().

◆ mInitialSelection

SelectedRegion SelectHandle::mInitialSelection {}
private

Definition at line 135 of file SelectHandle.h.

Referenced by Cancel(), and Click().

◆ mMostRecentX

int SelectHandle::mMostRecentX { -1 }
private

Definition at line 167 of file SelectHandle.h.

Referenced by Click(), Drag(), and SelectHandle::TimerHandler::OnTimer().

◆ mMostRecentY

int SelectHandle::mMostRecentY { -1 }
private

Definition at line 167 of file SelectHandle.h.

Referenced by Click(), and Drag().

◆ mpView

std::weak_ptr<ChannelView> SelectHandle::mpView
private

Definition at line 133 of file SelectHandle.h.

Referenced by Click(), Drag(), FindChannel(), FindTrack(), and Preview().

◆ mRect

wxRect SelectHandle::mRect {}
private

◆ mSelectionBoundary

int SelectHandle::mSelectionBoundary { 0 }
private

Definition at line 144 of file SelectHandle.h.

Referenced by Click(), and Preview().

◆ mSelectionStateChanger

std::shared_ptr<SelectionStateChanger> SelectHandle::mSelectionStateChanger
private

Definition at line 171 of file SelectHandle.h.

Referenced by Cancel(), Click(), IsDragging(), and Release().

◆ mSelStart

double SelectHandle::mSelStart { 0.0 }
private

Definition at line 142 of file SelectHandle.h.

Referenced by AdjustSelection(), AssignSelection(), Click(), Drag(), and StartSelection().

◆ mSelStartValid

bool SelectHandle::mSelStartValid {}
private

◆ mSnapEnd

SnapResults SelectHandle::mSnapEnd
private

Definition at line 138 of file SelectHandle.h.

Referenced by AdjustSelection(), Draw(), HasSnap(), Release(), and SetUseSnap().

◆ mSnapManager

std::shared_ptr<SnapManager> SelectHandle::mSnapManager
private

Definition at line 137 of file SelectHandle.h.

Referenced by AdjustSelection(), Draw(), Release(), and SelectHandle().

◆ mSnapStart

SnapResults SelectHandle::mSnapStart
private

◆ mTimerHandler

std::shared_ptr<TimerHandler> SelectHandle::mTimerHandler
private

Definition at line 175 of file SelectHandle.h.

Referenced by Connect().

◆ mUseSnap

bool SelectHandle::mUseSnap { true }
private

◆ TimerHandler

Definition at line 174 of file SelectHandle.h.


The documentation for this class was generated from the following files: