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 TrackFindTrack () 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 TrackFindTrack () 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 WaveChannel &wc, bool up)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 
static std::shared_ptr< const TrackTrackFromChannel (const std::shared_ptr< const Channel > &pChannel)
 A frequent convenience in the definition of UIHandles. More...
 
- 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::shared_ptr< ChannelFindChannel ()
 
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)
 
void StartFreqSelection (ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge, int trackHeight, ChannelView &channelView)
 
void AdjustFreqSelection (const WaveChannel &wc, ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge, int trackHeight)
 
void HandleCenterFrequencyClick (const ViewInfo &viewInfo, bool shiftDown, const std::shared_ptr< const WaveChannel > &pWc, double value)
 
void MoveSnappingFreqSelection (AudacityProject *pProject, ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge, int trackHeight, ChannelView &channelView, Track *pTrack)
 
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 TrackFindTrack (Channel *)
 
static void StartSnappingFreqSelection (SpectrumAnalyst &analyst, const ViewInfo &viewInfo, const WaveChannel &wc)
 

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 WaveChannelmFreqSelTrack
 
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 32 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 147 of file SelectHandle.h.

147 {
149
153
157 } mFreqSelMode{ FREQ_SEL_INVALID };
enum SelectHandle::eFreqSelMode FREQ_SEL_INVALID
@ FREQ_SEL_SNAPPING_CENTER
Definition: SelectHandle.h:150
@ FREQ_SEL_PINNED_CENTER
Definition: SelectHandle.h:151

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 423 of file SelectHandle.cpp.

427 : mpView{ pChannelView }
428 // Selection dragging can snap to play region boundaries
429 , mSnapManager{ std::make_shared<SnapManager>(
430 *trackList.GetOwner(), trackList, viewInfo, SnapPointArray{
431 SnapPoint{ viewInfo.playRegion.GetLastActiveStart() },
432 SnapPoint{ viewInfo.playRegion.GetLastActiveEnd() },
433 } ) }
434{
435 const wxMouseState &state = st.state;
436 mRect = st.rect;
437
438 auto time = std::max(0.0, viewInfo.PositionToTime(state.m_x, mRect.x));
439 auto pTrack = FindTrack(pChannelView->FindChannel().get());
440 mSnapStart = mSnapManager->Snap(pTrack, time, false);
443 else
444 mSnapStart.outCoord = -1;
445
446 mUseSnap = useSnap;
447}
std::vector< SnapPoint > SnapPointArray
Definition: Snap.h:43
SnapResults mSnapStart
Definition: SelectHandle.h:139
std::weak_ptr< ChannelView > mpView
Definition: SelectHandle.h:134
std::shared_ptr< SnapManager > mSnapManager
Definition: SelectHandle.h:138
std::shared_ptr< const Track > FindTrack() const override
Definition: Snap.h:31
AudacityProject * GetOwner()
Definition: Track.h:887
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 FindTrack(), 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 449 of file SelectHandle.cpp.

450{
451}

Member Function Documentation

◆ AdjustFreqSelection()

void SelectHandle::AdjustFreqSelection ( const WaveChannel wc,
ViewInfo viewInfo,
int  mouseYCoordinate,
int  trackTopEdge,
int  trackHeight 
)
private

Definition at line 1257 of file SelectHandle.cpp.

1261{
1262 if (mFreqSelMode == FREQ_SEL_INVALID ||
1263 mFreqSelMode == FREQ_SEL_SNAPPING_CENTER)
1264 return;
1265
1266 // Extension happens only when dragging in the same track in which we
1267 // started, and that is of a spectrogram display type.
1268
1269 const double rate = wc.GetRate();
1270 const double frequency =
1271 PositionToFrequency(wc, true, mouseYCoordinate,
1272 trackTopEdge, trackHeight);
1273
1274 // Dragging center?
1275 if (mFreqSelMode == FREQ_SEL_DRAG_CENTER) {
1276 if (frequency == rate || frequency < 1.0)
1277 // snapped to top or bottom
1281 else {
1282 // mFreqSelPin holds the ratio of top to center
1283 const double maxRatio = findMaxRatio(frequency, rate);
1284 const double ratio = std::min(maxRatio, mFreqSelPin);
1286 frequency / ratio, frequency * ratio);
1287 }
1288 }
1289 else if (mFreqSelMode == FREQ_SEL_PINNED_CENTER) {
1290 if (mFreqSelPin >= 0) {
1291 // Change both upper and lower edges leaving centre where it is.
1292 if (frequency == rate || frequency < 1.0)
1293 // snapped to top or bottom
1297 else {
1298 // Given center and mouse position, find ratio of the larger to the
1299 // smaller, limit that to the frequency scale bounds, and adjust
1300 // top and bottom accordingly.
1301 const double maxRatio = findMaxRatio(mFreqSelPin, rate);
1302 double ratio = frequency / mFreqSelPin;
1303 if (ratio < 1.0)
1304 ratio = 1.0 / ratio;
1305 ratio = std::min(maxRatio, ratio);
1307 mFreqSelPin / ratio, mFreqSelPin * ratio);
1308 }
1309 }
1310 }
1311 else {
1312 // Dragging of upper or lower.
1313 const bool bottomDefined =
1314 !(mFreqSelMode == FREQ_SEL_TOP_FREE && mFreqSelPin < 0);
1315 const bool topDefined =
1316 !(mFreqSelMode == FREQ_SEL_BOTTOM_FREE && mFreqSelPin < 0);
1317 if (!bottomDefined || (topDefined && mFreqSelPin < frequency)) {
1318 // Adjust top
1319 if (frequency == rate)
1320 // snapped high; upper frequency is undefined
1322 else
1323 viewInfo.selectedRegion.setF1(std::max(1.0, frequency));
1324
1326 }
1327 else {
1328 // Adjust bottom
1329 if (frequency < 1.0)
1330 // snapped low; lower frequency is undefined
1332 else
1333 viewInfo.selectedRegion.setF0(std::min(rate / 2.0, frequency));
1334
1336 }
1337 }
1338}
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:165
static const int UndefinedFrequency
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
double GetRate() const override
Definition: WaveTrack.cpp:816
double findMaxRatio(double center, double rate)
double PositionToFrequency(const WaveChannel &wc, 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, WaveChannel::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 1178 of file SelectHandle.cpp.

1181{
1182 if (!mSelStartValid)
1183 // Must be dragging frequency bounds only.
1184 return;
1185
1186 double selend =
1187 std::max(0.0, viewInfo.PositionToTime(mouseXCoordinate, trackLeftEdge));
1188 double origSelend = selend;
1189
1190 if (!track) {
1191 const auto sChannel = FindChannel();
1192 track = sChannel
1193 ? dynamic_cast<Track*>(&sChannel->GetChannelGroup())
1194 : nullptr;
1195 }
1196
1197 if (track && mSnapManager.get()) {
1198 bool rightEdge = (selend > mSelStart);
1199 mSnapEnd = mSnapManager->Snap(track, selend, rightEdge);
1200 if (mSnapEnd.Snapped()) {
1201 if (mUseSnap)
1202 selend = mSnapEnd.outTime;
1204 mSnapEnd.outCoord += trackLeftEdge;
1205 }
1207 mSnapEnd.outCoord = -1;
1208
1209 // Check if selection endpoints are too close together to snap (unless
1210 // using snap-to-time -- then we always accept the snap results)
1211 if (mSnapStart.outCoord >= 0 &&
1212 mSnapEnd.outCoord >= 0 &&
1213 std::abs(mSnapStart.outCoord - mSnapEnd.outCoord) < 3) {
1215 selend = origSelend;
1216 mSnapEnd.outCoord = -1;
1217 }
1218 }
1219 AssignSelection(viewInfo, selend);
1220}
void AssignSelection(ViewInfo &viewInfo, double selend)
std::shared_ptr< Channel > FindChannel()
SnapResults mSnapEnd
Definition: SelectHandle.h:139
bool mSelStartValid
Definition: SelectHandle.h:142
double mSelStart
Definition: SelectHandle.h:143
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
bool snappedTime
Definition: Snap.h:50
double outTime
Definition: Snap.h:47
bool Snapped() const
Definition: Snap.h:52

References AssignSelection(), FindChannel(), mSelStart, mSelStartValid, mSnapEnd, mSnapManager, mSnapStart, mUseSnap, SnapResults::outCoord, SnapResults::outTime, ZoomInfo::PositionToTime(), 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 
)
private

Definition at line 1222 of file SelectHandle.cpp.

1223{
1224 double sel0, sel1;
1225 if (mSelStart < selend) {
1226 sel0 = mSelStart;
1227 sel1 = selend;
1228 }
1229 else {
1230 sel1 = mSelStart;
1231 sel0 = selend;
1232 }
1233
1234 viewInfo.selectedRegion.setTimes(sel0, sel1);
1235}
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 1032 of file SelectHandle.cpp.

1033{
1034 mSelectionStateChanger.reset();
1036
1038}
std::shared_ptr< SelectionStateChanger > mSelectionStateChanger
Definition: SelectHandle.h:172
SelectedRegion mInitialSelection
Definition: SelectHandle.h:136
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 540 of file SelectHandle.cpp.

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

1066{
1067 mTimerHandler = std::make_shared<TimerHandler>( this, pProject );
1068}
std::shared_ptr< TimerHandler > mTimerHandler
Definition: SelectHandle.h:176

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 809 of file SelectHandle.cpp.

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

References AdjustFreqSelection(), AdjustSelection(), Cancelled, TrackPanelMouseEvent::event, CommonTrackPanelCell::FindTrack(), FindTrack(), FREQ_SEL_SNAPPING_CENTER, ViewInfo::Get(), SelectionState::Get(), TrackList::Get(), 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 1040 of file SelectHandle.cpp.

1043{
1044 if ( iPass == TrackArtist::PassSnapping ) {
1045 auto &dc = context.dc;
1046 // Draw snap guidelines if we have any
1047 if ( mSnapManager ) {
1048 auto coord1 = (mUseSnap || IsDragging()) ? mSnapStart.outCoord : -1;
1049 auto coord2 = (!mUseSnap || !IsDragging()) ? -1 : mSnapEnd.outCoord;
1050 TrackArt::DrawSnapLines(&dc, coord1, coord2);
1051 }
1052 }
1053}
bool IsDragging() const override
AUDACITY_DLL_API void DrawSnapLines(wxDC *dc, wxInt64 snap0, wxInt64 snap1)
Definition: TrackArt.cpp:775

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 1055 of file SelectHandle.cpp.

1058{
1059 if ( iPass == TrackArtist::PassSnapping )
1060 return MaximizeHeight( rect, panelRect );
1061 else
1062 return rect;
1063}
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 498 of file SelectHandle.cpp.

499{
500 SetUseSnap(true, project);
501}
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 531 of file SelectHandle.cpp.

532{
534 SetUseSnap(false, project);
535 return true;
536 }
537 return false;
538}
bool HasEscape(AudacityProject *pProject) const override

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

Here is the call graph for this function:

◆ FindChannel()

std::shared_ptr< Channel > SelectHandle::FindChannel ( )
private

Definition at line 453 of file SelectHandle.cpp.

454{
455 if (const auto pView = mpView.lock())
456 return pView->FindChannel();
457 else
458 return {};
459}

References mpView.

Referenced by AdjustSelection(), FindTrack(), and SelectHandle::TimerHandler::OnTimer().

Here is the caller graph for this function:

◆ FindTrack() [1/3]

Track * SelectHandle::FindTrack ( )
private

Definition at line 473 of file SelectHandle.cpp.

474{
475 const auto pChannel = FindChannel();
476 return FindTrack(pChannel.get());
477}

References FindChannel(), and FindTrack().

Here is the call graph for this function:

◆ FindTrack() [2/3]

std::shared_ptr< const Track > SelectHandle::FindTrack ( ) const
overridevirtual
Returns
pointer to associated track, if any

Implements UIHandle.

Definition at line 461 of file SelectHandle.cpp.

462{
463 return TrackFromChannel(const_cast<SelectHandle &>(*this).FindChannel());
464}
static std::shared_ptr< const Track > TrackFromChannel(const std::shared_ptr< const Channel > &pChannel)
A frequent convenience in the definition of UIHandles.
Definition: UIHandle.cpp:63

References FindChannel(), and UIHandle::TrackFromChannel().

Referenced by Click(), Drag(), FindTrack(), HitTest(), Preview(), and SelectHandle().

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

◆ FindTrack() [3/3]

Track * SelectHandle::FindTrack ( Channel pChannel)
staticprivate

Definition at line 466 of file SelectHandle.cpp.

467{
468 return pChannel
469 ? dynamic_cast<Track*>(&pChannel->GetChannelGroup())
470 : nullptr;
471}
ChannelGroup & GetChannelGroup()
Channel object's lifetime is assumed to be nested in its Track's.
Definition: Channel.cpp:43

References Channel::GetChannelGroup().

Here is the call graph for this function:

◆ HandleCenterFrequencyClick()

void SelectHandle::HandleCenterFrequencyClick ( const ViewInfo viewInfo,
bool  shiftDown,
const std::shared_ptr< const WaveChannel > &  pWc,
double  value 
)
private

Definition at line 1340 of file SelectHandle.cpp.

1342{
1343 if (shiftDown) {
1344 // Disable time selection
1345 mSelStartValid = false;
1346 mFreqSelTrack = pWc;
1347 mFreqSelPin = value;
1348 mFreqSelMode = FREQ_SEL_DRAG_CENTER;
1349 }
1350 else {
1351#ifndef SPECTRAL_EDITING_ESC_KEY
1352 // Start center snapping
1353 // Turn center snapping on (the only way to do this)
1354 mFreqSelMode = FREQ_SEL_SNAPPING_CENTER;
1355 // Disable time selection
1356 mSelStartValid = false;
1357 mFrequencySnapper = std::make_shared<SpectrumAnalyst>();
1359#endif
1360 }
1361}
static void StartSnappingFreqSelection(SpectrumAnalyst &analyst, const ViewInfo &viewInfo, const WaveChannel &wc)
std::shared_ptr< SpectrumAnalyst > mFrequencySnapper
Definition: SelectHandle.h:166

References FREQ_SEL_DRAG_CENTER, FREQ_SEL_SNAPPING_CENTER, mFreqSelPin, mFreqSelTrack, mFrequencySnapper, mSelStartValid, 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 526 of file SelectHandle.cpp.

527{
528 return HasSnap() && mUseSnap;
529}
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 520 of file SelectHandle.cpp.

521{
522 return
523 (IsDragging() ? mSnapEnd : mSnapStart).snappedPoint;
524}

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 358 of file SelectHandle.cpp.

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

References AssignUIHandlePtr(), FindTrack(), 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 61 of file SelectHandle.cpp.

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

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 channelView,
Track pTrack 
)
private

Definition at line 1405 of file SelectHandle.cpp.

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

References NotifyingSelectedRegion::f0(), NotifyingSelectedRegion::f1(), CommonChannelCell::FindChannel(), anonymous_namespace{SelectHandle.cpp}::findMaxRatio(), TrackFocus::Get(), Track::GetSelected(), anonymous_namespace{SelectHandle.cpp}::isSpectralSelectionView(), mFreqSelPin, mFreqSelTrack, mFrequencySnapper, min(), anonymous_namespace{SelectHandle.cpp}::PositionToFrequency(), ViewInfo::selectedRegion, NotifyingSelectedRegion::setFrequencies(), 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 404 of file SelectHandle.cpp.

406{
407 auto useSnap = oldState.mUseSnap;
408 // This is guaranteed when constructing the NEW handle:
409 wxASSERT( useSnap == newState.mUseSnap );
410 if (!useSnap)
411 return 0;
412
413 auto &oldSnapState = oldState.mSnapStart;
414 auto &newSnapState = newState.mSnapStart;
415 if ( oldSnapState.Snapped() == newSnapState.Snapped() &&
416 (!oldSnapState.Snapped() ||
417 oldSnapState.outCoord == newSnapState.outCoord) )
418 return 0;
419
421}

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 903 of file SelectHandle.cpp.

905{
906 if (!HasSnap() && !mUseSnap)
907 // Moved out of snapping; revert to un-escaped state
908 mUseSnap = true;
909
910 const auto pView = mpView.lock();
911 if ( !pView )
912 return {};
913 auto &view = *pView;
914
915 const auto pChannel = view.FindChannel();
916 if (!pChannel)
917 return {};
918
920 wxCursor *pCursor = SelectCursor();
921 if (IsDragging())
922 // Use same cursor as at the click
925 (mFreqSelMode == FREQ_SEL_SNAPPING_CENTER),
926 tip, pCursor);
927 else {
928 // Choose one of many cursors for mouse-over
929
930 auto &viewInfo = ViewInfo::Get( *pProject );
931
932 auto &state = st.state;
934 auto xx = viewInfo.TimeToPosition(time, mRect.x);
935
936 const bool bMultiToolMode =
938
939 //In Multi-tool mode, give multitool prompt if no-special-hit.
940 const auto pTrack = FindTrack();
941 if (bMultiToolMode) {
942 // Look up the current key binding for Preferences.
943 // (Don't assume it's the default!)
944 auto keyStr =
945 CommandManager::Get( *pProject ).GetKeyFromName(wxT("Preferences"))
946 .Display( true );
947 if (keyStr.empty())
948 // No keyboard preference defined for opening Preferences dialog
949 /* i18n-hint: These are the names of a menu and a command in that menu */
950 keyStr = _("Edit, Preferences...");
951
952 /* i18n-hint: %s is usually replaced by "Ctrl+P" for Windows/Linux, "Command+," for Mac */
953 tip = XO("Multi-Tool Mode: %s for Mouse and Keyboard Preferences.")
954 .Format( keyStr );
955 // Later in this function we may point to some other string instead.
956 if (!pTrack->GetSelected())
957 ;
958 else {
959 const wxRect &rect = st.rect;
960 const bool bShiftDown = state.ShiftDown();
961 const bool bCtrlDown = state.ControlDown();
962 const bool bModifierDown = bShiftDown || bCtrlDown;
963
964 // If not shift-down and not snapping center, then
965 // choose boundaries only in snapping tolerance,
966 // and may choose center.
967 SelectionBoundary boundary =
968 ChooseBoundary(viewInfo, xx, state.m_y,
969 view, rect, !bModifierDown, !bModifierDown);
970
971 SetTipAndCursorForBoundary(boundary, !bShiftDown, tip, pCursor);
972 }
973 }
974
975#if 0
976 // This is a vestige of an idea in the prototype version.
977 // Center would snap without mouse button down, click would pin the center
978 // and drag width.
979 if ((mFreqSelMode == FREQ_SEL_SNAPPING_CENTER) &&
981 // Not shift-down, but center frequency snapping toggle is on
982 tip = XO("Click and drag to set frequency bandwidth.");
983 pCursor = &*envelopeCursor;
984 return {};
985 }
986#endif
987
988 if (!pTrack->GetSelected())
989 ;
990 else {
991 const wxRect &rect = st.rect;
992 const bool bShiftDown = state.ShiftDown();
993 const bool bCtrlDown = state.ControlDown();
994 const bool bModifierDown = bShiftDown || bCtrlDown;
996 viewInfo, xx, state.m_y,
997 view, rect, !bModifierDown, !bModifierDown);
998 SetTipAndCursorForBoundary(boundary, !bShiftDown, tip, pCursor);
999 }
1000 }
1001 if (tip.empty()) {
1002 tip = XO("Click and drag to select audio");
1003 }
1004 if (HasEscape(pProject) && mUseSnap) {
1005 tip.Join(
1006/* i18n-hint: "Snapping" means automatic alignment of selection edges to any nearby label or clip boundaries */
1007 XO("(snapping)"), wxT(" ")
1008 );
1009 }
1010 return { tip, pCursor };
1011}
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 1013 of file SelectHandle.cpp.

1015{
1016 PitchAndSpeedDialog::Get(*pProject).TryRetarget(event);
1017 using namespace RefreshCode;
1018 ProjectHistory::Get( *pProject ).ModifyState(false);
1019 mFrequencySnapper.reset();
1020 mSnapManager.reset();
1022 mSelectionStateChanger->Commit();
1023 mSelectionStateChanger.reset();
1024 }
1025
1026 if (mUseSnap && (mSnapStart.outCoord != -1 || mSnapEnd.outCoord != -1))
1027 return RefreshAll;
1028 else
1029 return RefreshNone;
1030}
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 503 of file SelectHandle.cpp.

504{
505 mUseSnap = use;
506
507 bool hasSnap = HasSnap();
508 if (hasSnap)
509 // Repaint to turn the snap lines on or off
511
512 if (IsDragging()) {
513 // Readjust the moving selection end
517 }
518}
Result mChangeHighlight
Definition: UIHandle.h:152

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 WaveChannel wc,
bool  up 
)
static

Definition at line 1456 of file SelectHandle.cpp.

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

References NotifyingSelectedRegion::f1(), NotifyingSelectedRegion::fc(), anonymous_namespace{SelectHandle.cpp}::findMaxRatio(), SpectrumAnalyst::FindPeak(), SpectrogramSettings::Get(), WaveChannel::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 channelView 
)
private

Definition at line 1237 of file SelectHandle.cpp.

1240{
1241 mFreqSelTrack.reset();
1242 mFreqSelMode = FREQ_SEL_INVALID;
1244
1245 if (isSpectralSelectionView(channelView)) {
1246 // Spectral selection track is always wave
1247 auto shTrack = channelView.FindChannel<WaveChannel>();
1248 mFreqSelTrack = shTrack;
1249 mFreqSelMode = FREQ_SEL_FREE;
1250 mFreqSelPin =
1251 PositionToFrequency(*shTrack, false, mouseYCoordinate,
1252 trackTopEdge, trackHeight);
1254 }
1255}

References CommonChannelCell::FindChannel(), 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 1163 of file SelectHandle.cpp.

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

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 WaveChannel wc 
)
staticprivate

Definition at line 1363 of file SelectHandle.cpp.

1365{
1366 static const size_t minLength = 8;
1367
1368 const double rate = wc.GetRate();
1369
1370 // Grab samples, just for this track, at these times
1371 std::vector<float> frequencySnappingData;
1372 const auto start =
1373 wc.TimeToLongSamples(viewInfo.selectedRegion.t0());
1374 const auto end =
1375 wc.TimeToLongSamples(viewInfo.selectedRegion.t1());
1376 const auto length =
1377 std::min(frequencySnappingData.max_size(),
1378 limitSampleBufferSize(10485760, // as in FreqWindow.cpp
1379 end - start));
1380 const auto effectiveLength = std::max(minLength, length);
1381 frequencySnappingData.resize(effectiveLength, 0.0f);
1382 wc.GetFloats(
1383 &frequencySnappingData[0],
1384 start, length, FillFormat::fillZero,
1385 // Don't try to cope with exceptions, just read zeroes instead.
1386 false);
1387
1388 // Use same settings as are now used for spectrogram display,
1389 // except, shrink the window as needed so we get some answers
1390
1391 const auto &settings = SpectrogramSettings::Get(wc);
1392 auto windowSize = settings.GetFFTLength();
1393
1394 while(windowSize > effectiveLength)
1395 windowSize >>= 1;
1396 const int windowType = settings.windowType;
1397
1398 analyst.Calculate(
1399 SpectrumAnalyst::Spectrum, windowType, windowSize, rate,
1400 &frequencySnappingData[0], length);
1401
1402 // We can now throw away the sample data but we keep the spectrum.
1403}
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, ProgressFn 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 from the unique channel
Definition: WaveTrack.h:129
sampleCount TimeToLongSamples(double t0) const
const char * end(const char *str) noexcept
Definition: StringUtils.h:106

References SpectrumAnalyst::Calculate(), details::end(), fillZero, SpectrogramSettings::Get(), WaveChannel::GetFloats(), WaveChannel::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 170 of file SelectHandle.h.

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

◆ mFreqSelPin

double SelectHandle::mFreqSelPin { -1.0 }
private

◆ mFreqSelTrack

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

◆ mFrequencySnapper

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

Definition at line 166 of file SelectHandle.h.

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

◆ mInitialSelection

SelectedRegion SelectHandle::mInitialSelection {}
private

Definition at line 136 of file SelectHandle.h.

Referenced by Cancel(), and Click().

◆ mMostRecentX

int SelectHandle::mMostRecentX { -1 }
private

Definition at line 168 of file SelectHandle.h.

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

◆ mMostRecentY

int SelectHandle::mMostRecentY { -1 }
private

Definition at line 168 of file SelectHandle.h.

Referenced by Click(), and Drag().

◆ mpView

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

Definition at line 134 of file SelectHandle.h.

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

◆ mRect

wxRect SelectHandle::mRect {}
private

◆ mSelectionBoundary

int SelectHandle::mSelectionBoundary { 0 }
private

Definition at line 145 of file SelectHandle.h.

Referenced by Click(), and Preview().

◆ mSelectionStateChanger

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

Definition at line 172 of file SelectHandle.h.

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

◆ mSelStart

double SelectHandle::mSelStart { 0.0 }
private

Definition at line 143 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 139 of file SelectHandle.h.

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

◆ mSnapManager

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

Definition at line 138 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 176 of file SelectHandle.h.

Referenced by Connect().

◆ mUseSnap

bool SelectHandle::mUseSnap { true }
private

◆ TimerHandler

Definition at line 175 of file SelectHandle.h.


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