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< TrackView > &pTrackView, bool useSnap, const TrackList &trackList, const TrackPanelMouseState &st, const ViewInfo &viewInfo)
 
SelectHandleoperator= (const SelectHandle &)=default
 
virtual ~SelectHandle ()
 
bool IsClicked () const
 
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)
 
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< TrackView > &pTrackView)
 
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, TrackView *pTrackView)
 
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, TrackView *pTrackView)
 
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< TrackViewmpView
 
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 144 of file SelectHandle.h.

144 {
146
150
154 } mFreqSelMode{ FREQ_SEL_INVALID };
enum SelectHandle::eFreqSelMode FREQ_SEL_INVALID
@ FREQ_SEL_SNAPPING_CENTER
Definition: SelectHandle.h:147
@ FREQ_SEL_PINNED_CENTER
Definition: SelectHandle.h:148

Constructor & Destructor Documentation

◆ SelectHandle() [1/2]

SelectHandle::SelectHandle ( const SelectHandle )
private

◆ SelectHandle() [2/2]

SelectHandle::SelectHandle ( const std::shared_ptr< TrackView > &  pTrackView,
bool  useSnap,
const TrackList trackList,
const TrackPanelMouseState st,
const ViewInfo viewInfo 
)
explicit

Definition at line 427 of file SelectHandle.cpp.

431 : mpView{ pTrackView }
432 // Selection dragging can snap to play region boundaries
433 , mSnapManager{ std::make_shared<SnapManager>(
434 *trackList.GetOwner(), trackList, viewInfo, SnapPointArray{
435 SnapPoint{ viewInfo.playRegion.GetLastActiveStart() },
436 SnapPoint{ viewInfo.playRegion.GetLastActiveEnd() },
437 } ) }
438{
439 const wxMouseState &state = st.state;
440 mRect = st.rect;
441
442 auto time = std::max(0.0, viewInfo.PositionToTime(state.m_x, mRect.x));
443 auto pTrack = pTrackView->FindTrack();
444 mSnapStart = mSnapManager->Snap(pTrack.get(), time, false);
447 else
448 mSnapStart.outCoord = -1;
449
450 mUseSnap = useSnap;
451}
std::vector< SnapPoint > SnapPointArray
Definition: Snap.h:43
std::weak_ptr< TrackView > mpView
Definition: SelectHandle.h:131
SnapResults mSnapStart
Definition: SelectHandle.h:136
std::shared_ptr< SnapManager > mSnapManager
Definition: SelectHandle.h:135
Definition: Snap.h:31
AudacityProject * GetOwner()
Definition: Track.h:1371
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:41
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 453 of file SelectHandle.cpp.

454{
455}

Member Function Documentation

◆ AdjustFreqSelection()

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

Definition at line 1242 of file SelectHandle.cpp.

1246{
1247 if (mFreqSelMode == FREQ_SEL_INVALID ||
1248 mFreqSelMode == FREQ_SEL_SNAPPING_CENTER)
1249 return;
1250
1251 // Extension happens only when dragging in the same track in which we
1252 // started, and that is of a spectrogram display type.
1253
1254 const double rate = wt->GetRate();
1255 const double frequency =
1256 PositionToFrequency(wt, true, mouseYCoordinate,
1257 trackTopEdge, trackHeight);
1258
1259 // Dragging center?
1260 if (mFreqSelMode == FREQ_SEL_DRAG_CENTER) {
1261 if (frequency == rate || frequency < 1.0)
1262 // snapped to top or bottom
1266 else {
1267 // mFreqSelPin holds the ratio of top to center
1268 const double maxRatio = findMaxRatio(frequency, rate);
1269 const double ratio = std::min(maxRatio, mFreqSelPin);
1271 frequency / ratio, frequency * ratio);
1272 }
1273 }
1274 else if (mFreqSelMode == FREQ_SEL_PINNED_CENTER) {
1275 if (mFreqSelPin >= 0) {
1276 // Change both upper and lower edges leaving centre where it is.
1277 if (frequency == rate || frequency < 1.0)
1278 // snapped to top or bottom
1282 else {
1283 // Given center and mouse position, find ratio of the larger to the
1284 // smaller, limit that to the frequency scale bounds, and adjust
1285 // top and bottom accordingly.
1286 const double maxRatio = findMaxRatio(mFreqSelPin, rate);
1287 double ratio = frequency / mFreqSelPin;
1288 if (ratio < 1.0)
1289 ratio = 1.0 / ratio;
1290 ratio = std::min(maxRatio, ratio);
1292 mFreqSelPin / ratio, mFreqSelPin * ratio);
1293 }
1294 }
1295 }
1296 else {
1297 // Dragging of upper or lower.
1298 const bool bottomDefined =
1299 !(mFreqSelMode == FREQ_SEL_TOP_FREE && mFreqSelPin < 0);
1300 const bool topDefined =
1301 !(mFreqSelMode == FREQ_SEL_BOTTOM_FREE && mFreqSelPin < 0);
1302 if (!bottomDefined || (topDefined && mFreqSelPin < frequency)) {
1303 // Adjust top
1304 if (frequency == rate)
1305 // snapped high; upper frequency is undefined
1307 else
1308 viewInfo.selectedRegion.setF1(std::max(1.0, frequency));
1309
1311 }
1312 else {
1313 // Adjust bottom
1314 if (frequency < 1.0)
1315 // snapped low; lower frequency is undefined
1317 else
1318 viewInfo.selectedRegion.setF0(std::min(rate / 2.0, frequency));
1319
1321 }
1322 }
1323}
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:162
static const int UndefinedFrequency
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
double GetRate() const override
Definition: WaveTrack.cpp:479
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 1164 of file SelectHandle.cpp.

1168{
1169 if (!mSelStartValid)
1170 // Must be dragging frequency bounds only.
1171 return;
1172
1173 double selend =
1174 std::max(0.0, viewInfo.PositionToTime(mouseXCoordinate, trackLeftEdge));
1175 double origSelend = selend;
1176
1177 auto pTrack = Track::SharedPointer( track );
1178 if (!pTrack)
1179 pTrack = TrackList::Get( *pProject ).Lock( FindTrack() );
1180
1181 if (pTrack && mSnapManager.get()) {
1182 bool rightEdge = (selend > mSelStart);
1183 mSnapEnd = mSnapManager->Snap(pTrack.get(), selend, rightEdge);
1184 if (mSnapEnd.Snapped()) {
1185 if (mUseSnap)
1186 selend = mSnapEnd.outTime;
1188 mSnapEnd.outCoord += trackLeftEdge;
1189 }
1191 mSnapEnd.outCoord = -1;
1192
1193 // Check if selection endpoints are too close together to snap (unless
1194 // using snap-to-time -- then we always accept the snap results)
1195 if (mSnapStart.outCoord >= 0 &&
1196 mSnapEnd.outCoord >= 0 &&
1197 std::abs(mSnapStart.outCoord - mSnapEnd.outCoord) < 3) {
1199 selend = origSelend;
1200 mSnapEnd.outCoord = -1;
1201 }
1202 }
1203 AssignSelection(viewInfo, selend, pTrack.get());
1204}
SnapResults mSnapEnd
Definition: SelectHandle.h:136
std::weak_ptr< Track > FindTrack()
void AssignSelection(ViewInfo &viewInfo, double selend, Track *pTrack)
bool mSelStartValid
Definition: SelectHandle.h:139
double mSelStart
Definition: SelectHandle.h:140
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:297
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1601
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
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 1206 of file SelectHandle.cpp.

1208{
1209 double sel0, sel1;
1210 if (mSelStart < selend) {
1211 sel0 = mSelStart;
1212 sel1 = selend;
1213 }
1214 else {
1215 sel1 = mSelStart;
1216 sel0 = selend;
1217 }
1218
1219 viewInfo.selectedRegion.setTimes(sel0, sel1);
1220}
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 1009 of file SelectHandle.cpp.

1010{
1011 mSelectionStateChanger.reset();
1013
1015}
std::shared_ptr< SelectionStateChanger > mSelectionStateChanger
Definition: SelectHandle.h:169
SelectedRegion mInitialSelection
Definition: SelectHandle.h:133
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 519 of file SelectHandle.cpp.

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

References AdjustFreqSelection(), AdjustSelection(), RefreshCode::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(), ProjectHistory::Get(), ViewInfo::Get(), TrackList::Get(), ProjectAudioIO::Get(), ProjectSettings::Get(), SelectionState::Get(), TrackPanel::Get(), WaveTrack::GetClipAtTime(), HandleCenterFrequencyClick(), ProjectAudioIO::IsAudioActive(), anonymous_namespace{SelectHandle.cpp}::isSpectralSelectionView(), TrackList::Lock(), 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(), settings(), StartFreqSelection(), StartSelection(), and SnapResults::timeSnappedTime.

Here is the call graph for this function:

◆ Connect()

void SelectHandle::Connect ( AudacityProject pProject)
private

Definition at line 1051 of file SelectHandle.cpp.

1052{
1053 mTimerHandler = std::make_shared<TimerHandler>( this, pProject );
1054}
std::shared_ptr< TimerHandler > mTimerHandler
Definition: SelectHandle.h:173

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

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

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

1020{
1021 if ( iPass == TrackArtist::PassSnapping ) {
1022 auto &dc = context.dc;
1023 // Draw snap guidelines if we have any
1024 if ( mSnapManager ) {
1025 auto coord1 = (mUseSnap || IsClicked()) ? mSnapStart.outCoord : -1;
1026 auto coord2 = (!mUseSnap || !IsClicked()) ? -1 : mSnapEnd.outCoord;
1027 mSnapManager->Draw( &dc, coord1, coord2 );
1028 }
1029 }
1030}
bool IsClicked() const

References TrackPanelDrawingContext::dc, IsClicked(), 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 1032 of file SelectHandle.cpp.

1035{
1036 if ( iPass == TrackArtist::PassSnapping )
1037 return MaximizeHeight( rect, panelRect );
1038 else
1039 return rect;
1040}
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 476 of file SelectHandle.cpp.

477{
478 SetUseSnap(true, project);
479}
void SetUseSnap(bool use, AudacityProject *pProject)

References SetUseSnap().

Here is the call graph for this function:

◆ Escape()

bool SelectHandle::Escape ( AudacityProject pProject)
overridevirtual

Reimplemented from UIHandle.

Definition at line 510 of file SelectHandle.cpp.

511{
512 if (SelectHandle::HasEscape(project)) {
513 SetUseSnap(false, project);
514 return true;
515 }
516 return false;
517}
bool HasEscape(AudacityProject *pProject) const override

References HasEscape(), and SetUseSnap().

Here is the call graph for this function:

◆ FindTrack()

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

Definition at line 1042 of file SelectHandle.cpp.

1043{
1044 auto pView = mpView.lock();
1045 if (!pView)
1046 return {};
1047 else
1048 return pView->FindTrack();
1049}

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

1327{
1328 if (shiftDown) {
1329 // Disable time selection
1330 mSelStartValid = false;
1331 mFreqSelTrack = pTrack->SharedPointer<const WaveTrack>();
1332 mFreqSelPin = value;
1333 mFreqSelMode = FREQ_SEL_DRAG_CENTER;
1334 }
1335 else {
1336#ifndef SPECTRAL_EDITING_ESC_KEY
1337 // Start center snapping
1338 // Turn center snapping on (the only way to do this)
1339 mFreqSelMode = FREQ_SEL_SNAPPING_CENTER;
1340 // Disable time selection
1341 mSelStartValid = false;
1342 mFrequencySnapper = std::make_shared<SpectrumAnalyst>();
1344#endif
1345 }
1346}
std::shared_ptr< SpectrumAnalyst > mFrequencySnapper
Definition: SelectHandle.h:163
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 505 of file SelectHandle.cpp.

506{
507 return HasSnap() && mUseSnap;
508}
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 499 of file SelectHandle.cpp.

500{
501 return
502 (IsClicked() ? mSnapEnd : mSnapStart).snappedPoint;
503}

References IsClicked(), 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< TrackView > &  pTrackView 
)
static

Definition at line 360 of file SelectHandle.cpp.

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

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

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

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

◆ IsClicked()

bool SelectHandle::IsClicked ( ) const

Definition at line 56 of file SelectHandle.cpp.

57{
58 return mSelectionStateChanger.get() != NULL;
59}

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,
TrackView pTrackView 
)
private

Definition at line 1391 of file SelectHandle.cpp.

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

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(), and Track::SharedPointer().

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

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

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

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

993{
994 using namespace RefreshCode;
995 ProjectHistory::Get( *pProject ).ModifyState(false);
996 mFrequencySnapper.reset();
997 mSnapManager.reset();
999 mSelectionStateChanger->Commit();
1000 mSelectionStateChanger.reset();
1001 }
1002
1003 if (mUseSnap && (mSnapStart.outCoord != -1 || mSnapEnd.outCoord != -1))
1004 return RefreshAll;
1005 else
1006 return RefreshNone;
1007}

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

Here is the call graph for this function:

◆ SetUseSnap()

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

Definition at line 481 of file SelectHandle.cpp.

482{
483 mUseSnap = use;
484
485 bool hasSnap = HasSnap();
486 if (hasSnap)
487 // Repaint to turn the snap lines on or off
489
490 if (IsClicked()) {
491 // Readjust the moving selection end
493 ViewInfo::Get( *project ),
495 nullptr);
496 }
497}
Result mChangeHighlight
Definition: UIHandle.h:139

References AssignSelection(), ViewInfo::Get(), HasSnap(), IsClicked(), UIHandle::mChangeHighlight, mSnapEnd, mUseSnap, SnapResults::outTime, 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 1441 of file SelectHandle.cpp.

1444{
1446 const auto windowSize = settings.GetFFTLength();
1447 const double rate = pTrack->GetRate();
1448 const double nyq = rate / 2.0;
1449 const double binFrequency = rate / windowSize;
1450
1451 double f1 = viewInfo.selectedRegion.f1();
1452 double centerFrequency = viewInfo.selectedRegion.fc();
1453 if (centerFrequency <= 0) {
1454 centerFrequency = up ? binFrequency : nyq;
1455 f1 = centerFrequency * sqrt(2.0);
1456 }
1457
1458 double ratio = f1 / centerFrequency;
1459 const int originalBin = floor(0.5 + centerFrequency / binFrequency);
1460 const int limitingBin = up ? floor(0.5 + nyq / binFrequency) : 1;
1461
1462 // This is crude and wasteful, doing the FFT each time the command is called.
1463 // It would be better to cache the data, but then invalidation of the cache would
1464 // need doing in all places that change the time selection.
1465 StartSnappingFreqSelection(analyst, viewInfo, pTrack);
1466 double snappedFrequency = centerFrequency;
1467 int bin = originalBin;
1468 if (up) {
1469 while (snappedFrequency <= centerFrequency &&
1470 bin < limitingBin)
1471 snappedFrequency = analyst.FindPeak(++bin * binFrequency, NULL);
1472 }
1473 else {
1474 while (snappedFrequency >= centerFrequency &&
1475 bin > limitingBin)
1476 snappedFrequency = analyst.FindPeak(--bin * binFrequency, NULL);
1477 }
1478
1479 // PRL: added these two lines with the big TrackPanel refactor
1480 const double maxRatio = findMaxRatio(snappedFrequency, rate);
1481 ratio = std::min(ratio, maxRatio);
1482
1484 (snappedFrequency / ratio, snappedFrequency * ratio);
1485}
double fc() const
Definition: ViewInfo.h:38
Spectrogram settings, either for one track or as defaults.
float FindPeak(float xPos, float *pY) const
const SpectrogramSettings & GetSpectrogramSettings() const
Definition: WaveTrack.cpp:799

References NotifyingSelectedRegion::f1(), NotifyingSelectedRegion::fc(), anonymous_namespace{SelectHandle.cpp}::findMaxRatio(), SpectrumAnalyst::FindPeak(), WaveTrack::GetRate(), WaveTrack::GetSpectrogramSettings(), min(), ViewInfo::selectedRegion, NotifyingSelectedRegion::setFrequencies(), settings(), and StartSnappingFreqSelection().

Here is the call graph for this function:

◆ StartFreqSelection()

void SelectHandle::StartFreqSelection ( ViewInfo viewInfo,
int  mouseYCoordinate,
int  trackTopEdge,
int  trackHeight,
TrackView pTrackView 
)
private

Definition at line 1222 of file SelectHandle.cpp.

1225{
1226 mFreqSelTrack.reset();
1227 mFreqSelMode = FREQ_SEL_INVALID;
1229
1230 if (isSpectralSelectionView(pTrackView)) {
1231 // Spectral selection track is always wave
1232 auto shTrack = pTrackView->FindTrack()->SharedPointer<const WaveTrack>();
1233 mFreqSelTrack = shTrack;
1234 mFreqSelMode = FREQ_SEL_FREE;
1235 mFreqSelPin =
1236 PositionToFrequency(shTrack.get(), false, mouseYCoordinate,
1237 trackTopEdge, trackHeight);
1239 }
1240}

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

1150{
1151 auto &viewInfo = ViewInfo::Get( *pProject );
1152 mSelStartValid = true;
1153
1154 viewInfo.selectedRegion.setTimes(mSelStart, mSelStart);
1155
1156 // PRL: commented out the Sonify stuff with the TrackPanel refactor.
1157 // It was no-op anyway.
1158 //SonifyBeginModifyState();
1159 ProjectHistory::Get( *pProject ).ModifyState(false);
1160 //SonifyEndModifyState();
1161}

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

1351{
1352 static const size_t minLength = 8;
1353
1354 const double rate = pTrack->GetRate();
1355
1356 // Grab samples, just for this track, at these times
1357 std::vector<float> frequencySnappingData;
1358 const auto start =
1359 pTrack->TimeToLongSamples(viewInfo.selectedRegion.t0());
1360 const auto end =
1361 pTrack->TimeToLongSamples(viewInfo.selectedRegion.t1());
1362 const auto length =
1363 std::min(frequencySnappingData.max_size(),
1364 limitSampleBufferSize(10485760, // as in FreqWindow.cpp
1365 end - start));
1366 const auto effectiveLength = std::max(minLength, length);
1367 frequencySnappingData.resize(effectiveLength, 0.0f);
1368 pTrack->GetFloats(
1369 &frequencySnappingData[0],
1370 start, length, fillZero,
1371 // Don't try to cope with exceptions, just read zeroes instead.
1372 false);
1373
1374 // Use same settings as are now used for spectrogram display,
1375 // except, shrink the window as needed so we get some answers
1376
1378 auto windowSize = settings.GetFFTLength();
1379
1380 while(windowSize > effectiveLength)
1381 windowSize >>= 1;
1382 const int windowType = settings.windowType;
1383
1384 analyst.Calculate(
1385 SpectrumAnalyst::Spectrum, windowType, windowSize, rate,
1386 &frequencySnappingData[0], length);
1387
1388 // We can now throw away the sample data but we keep the spectrum.
1389}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
@ fillZero
Definition: SampleFormat.h:54
double t1() const
Definition: ViewInfo.h:35
double t0() const
Definition: ViewInfo.h:34
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:67
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:42
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)
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References SpectrumAnalyst::Calculate(), PackedArray::end(), fillZero, SampleTrack::GetFloats(), WaveTrack::GetRate(), WaveTrack::GetSpectrogramSettings(), limitSampleBufferSize(), min(), ViewInfo::selectedRegion, settings(), SpectrumAnalyst::Spectrum, NotifyingSelectedRegion::t0(), NotifyingSelectedRegion::t1(), and SampleTrack::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 167 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 163 of file SelectHandle.h.

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

◆ mInitialSelection

SelectedRegion SelectHandle::mInitialSelection {}
private

Definition at line 133 of file SelectHandle.h.

Referenced by Cancel(), and Click().

◆ mMostRecentX

int SelectHandle::mMostRecentX { -1 }
private

Definition at line 165 of file SelectHandle.h.

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

◆ mMostRecentY

int SelectHandle::mMostRecentY { -1 }
private

Definition at line 165 of file SelectHandle.h.

Referenced by Click(), and Drag().

◆ mpView

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

Definition at line 131 of file SelectHandle.h.

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

◆ mRect

wxRect SelectHandle::mRect {}
private

◆ mSelectionBoundary

int SelectHandle::mSelectionBoundary { 0 }
private

Definition at line 142 of file SelectHandle.h.

Referenced by Click(), and Preview().

◆ mSelectionStateChanger

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

Definition at line 169 of file SelectHandle.h.

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

◆ mSelStart

double SelectHandle::mSelStart { 0.0 }
private

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

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

◆ mSnapManager

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

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

Referenced by Connect().

◆ mUseSnap

bool SelectHandle::mUseSnap { true }
private

◆ TimerHandler

Definition at line 172 of file SelectHandle.h.


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