Audacity 3.2.0
Enumerations | Functions
anonymous_namespace{SelectHandle.cpp} Namespace Reference

Enumerations

enum  SelectionBoundary { SBNone , SBLeft , SBRight }
 

Functions

wxInt64 FrequencyToPosition (const WaveTrack *wt, double frequency, wxInt64 trackTopEdge, int trackHeight)
 Converts a frequency to screen y position. More...
 
double PositionToFrequency (const WaveTrack *wt, bool maySnap, wxInt64 mouseYCoordinate, wxInt64 trackTopEdge, int trackHeight)
 
template<typename T >
void SetIfNotNull (T *pValue, const T Value)
 
bool isSpectralSelectionView (const ChannelView *pChannelView)
 
SelectionBoundary ChooseTimeBoundary (const double t0, const double t1, const ViewInfo &viewInfo, double selend, bool onlyWithinSnapDistance, wxInt64 *pPixelDist, double *pPinValue)
 
SelectionBoundary ChooseBoundary (const ViewInfo &viewInfo, wxCoord xx, wxCoord yy, const ChannelView *pChannelView, const wxRect &rect, bool mayDragWidth, bool onlyWithinSnapDistance, double *pPinValue=NULL)
 
wxCursor * SelectCursor ()
 
wxCursor * EnvelopeCursor ()
 
void SetTipAndCursorForBoundary (SelectionBoundary boundary, bool frequencySnapping, TranslatableString &tip, wxCursor *&pCursor)
 
template<class A , class B , class DIST >
bool within (A a, B b, DIST d)
 
double findMaxRatio (double center, double rate)
 

Enumeration Type Documentation

◆ SelectionBoundary

enum anonymous_namespace{SelectHandle.cpp}::SelectionBoundary
Enumerator
SBNone 
SBLeft 
SBRight 

Definition at line 128 of file SelectHandle.cpp.

128 {
129 SBNone,
131#ifdef EXPERIMENTAL_SPECTRAL_EDITING
132 SBBottom, SBTop, SBCenter, SBWidth,
133#endif
134 };

Function Documentation

◆ ChooseBoundary()

SelectionBoundary anonymous_namespace{SelectHandle.cpp}::ChooseBoundary ( const ViewInfo viewInfo,
wxCoord  xx,
wxCoord  yy,
const ChannelView pChannelView,
const wxRect &  rect,
bool  mayDragWidth,
bool  onlyWithinSnapDistance,
double *  pPinValue = NULL 
)

Definition at line 176 of file SelectHandle.cpp.

182 {
183 // Choose one of four boundaries to adjust, or the center frequency.
184 // May choose frequencies only if in a spectrogram view and
185 // within the time boundaries.
186 // May choose no boundary if onlyWithinSnapDistance is true.
187 // Otherwise choose the eligible boundary nearest the mouse click.
188 const double selend = viewInfo.PositionToTime(xx, rect.x);
189 wxInt64 pixelDist = 0;
190 const double t0 = viewInfo.selectedRegion.t0();
191 const double t1 = viewInfo.selectedRegion.t1();
192
193 SelectionBoundary boundary =
194 ChooseTimeBoundary(t0,t1,viewInfo, selend, onlyWithinSnapDistance,
195 &pixelDist, pPinValue);
196
197#ifdef EXPERIMENTAL_SPECTRAL_EDITING
198 //const double t0 = viewInfo.selectedRegion.t0();
199 //const double t1 = viewInfo.selectedRegion.t1();
200 const double f0 = viewInfo.selectedRegion.f0();
201 const double f1 = viewInfo.selectedRegion.f1();
202 const double fc = viewInfo.selectedRegion.fc();
203 double ratio = 0;
204
205 bool chooseTime = true;
206 bool chooseBottom = true;
207 bool chooseCenter = false;
208 // Consider adjustment of frequencies only if mouse is
209 // within the time boundaries
210 if (!viewInfo.selectedRegion.isPoint() &&
211 t0 <= selend && selend < t1 &&
212 isSpectralSelectionView(pChannelView)) {
213 // Spectral selection track is always wave
214 auto pTrack = pChannelView->FindTrack();
215 const WaveTrack *const wt =
216 static_cast<const WaveTrack*>(pTrack.get());
217 const wxInt64 bottomSel = (f0 >= 0)
218 ? FrequencyToPosition(wt, f0, rect.y, rect.height)
219 : rect.y + rect.height;
220 const wxInt64 topSel = (f1 >= 0)
221 ? FrequencyToPosition(wt, f1, rect.y, rect.height)
222 : rect.y;
223 wxInt64 signedBottomDist = (int)(yy - bottomSel);
224 wxInt64 verticalDist = std::abs(signedBottomDist);
225 if (bottomSel == topSel)
226 // Top and bottom are too close to resolve on screen
227 chooseBottom = (signedBottomDist >= 0);
228 else {
229 const wxInt64 topDist = std::abs((int)(yy - topSel));
230 if (topDist < verticalDist)
231 chooseBottom = false, verticalDist = topDist;
232 }
233 if (fc > 0
234#ifdef SPECTRAL_EDITING_ESC_KEY
235 && mayDragWidth
236#endif
237 ) {
238 const wxInt64 centerSel =
239 FrequencyToPosition(wt, fc, rect.y, rect.height);
240 const wxInt64 centerDist = abs((int)(yy - centerSel));
241 if (centerDist < verticalDist)
242 chooseCenter = true, verticalDist = centerDist,
243 ratio = f1 / fc;
244 }
245 if (verticalDist >= 0 &&
246 verticalDist < pixelDist) {
247 pixelDist = verticalDist;
248 chooseTime = false;
249 }
250 }
251
252 if (!chooseTime) {
253 // PRL: Seems I need a larger tolerance to make snapping work
254 // at top of track, not sure why
255 if (onlyWithinSnapDistance &&
256 pixelDist >= FREQ_SNAP_DISTANCE) {
257 SetIfNotNull(pPinValue, -1.0);
258 return SBNone;
259 }
260 else if (chooseCenter) {
261 SetIfNotNull(pPinValue, ratio);
262 return SBCenter;
263 }
264 else if (mayDragWidth && fc > 0) {
265 SetIfNotNull(pPinValue, fc);
266 return SBWidth;
267 }
268 else if (chooseBottom) {
269 SetIfNotNull(pPinValue, f1);
270 return SBBottom;
271 }
272 else {
273 SetIfNotNull(pPinValue, f0);
274 return SBTop;
275 }
276 }
277 else
278#endif
279 {
280 return boundary;
281 }
282 }
@ FREQ_SNAP_DISTANCE
std::shared_ptr< Track > FindTrack()
double t1() const
Definition: ViewInfo.h:36
double f1() const
Definition: ViewInfo.h:38
double fc() const
Definition: ViewInfo.h:39
bool isPoint() const
Definition: ViewInfo.h:40
double f0() const
Definition: ViewInfo.h:37
double t0() const
Definition: ViewInfo.h:35
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
A Track that contains audio waveform data.
Definition: WaveTrack.h:222
double PositionToTime(int64 position, int64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:34
wxInt64 FrequencyToPosition(const WaveTrack *wt, double frequency, wxInt64 trackTopEdge, int trackHeight)
Converts a frequency to screen y position.
void SetIfNotNull(T *pValue, const T Value)
SelectionBoundary ChooseTimeBoundary(const double t0, const double t1, const ViewInfo &viewInfo, double selend, bool onlyWithinSnapDistance, wxInt64 *pPixelDist, double *pPinValue)
bool isSpectralSelectionView(const ChannelView *pChannelView)

References ChooseTimeBoundary(), NotifyingSelectedRegion::f0(), NotifyingSelectedRegion::f1(), NotifyingSelectedRegion::fc(), CommonTrackPanelCell::FindTrack(), FREQ_SNAP_DISTANCE, FrequencyToPosition(), NotifyingSelectedRegion::isPoint(), isSpectralSelectionView(), ZoomInfo::PositionToTime(), SBNone, ViewInfo::selectedRegion, SetIfNotNull(), NotifyingSelectedRegion::t0(), and NotifyingSelectedRegion::t1().

Referenced by SelectHandle::Click(), and SelectHandle::Preview().

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

◆ ChooseTimeBoundary()

SelectionBoundary anonymous_namespace{SelectHandle.cpp}::ChooseTimeBoundary ( const double  t0,
const double  t1,
const ViewInfo viewInfo,
double  selend,
bool  onlyWithinSnapDistance,
wxInt64 *  pPixelDist,
double *  pPinValue 
)

Definition at line 136 of file SelectHandle.cpp.

142 {
143 const wxInt64 posS = viewInfo.TimeToPosition(selend);
144 const wxInt64 pos0 = viewInfo.TimeToPosition(t0);
145 wxInt64 pixelDist = std::abs(posS - pos0);
146 bool chooseLeft = true;
147
148 if (t1<=t0)
149 // Special case when selection is a point, and thus left
150 // and right distances are the same
151 chooseLeft = (selend < t0);
152 else {
153 const wxInt64 pos1 = viewInfo.TimeToPosition(t1);
154 const wxInt64 rightDist = std::abs(posS - pos1);
155 if (rightDist < pixelDist)
156 chooseLeft = false, pixelDist = rightDist;
157 }
158
159 SetIfNotNull(pPixelDist, pixelDist);
160
161 if (onlyWithinSnapDistance &&
162 pixelDist >= SELECTION_RESIZE_REGION) {
163 SetIfNotNull(pPinValue, -1.0);
164 return SBNone;
165 }
166 else if (chooseLeft) {
167 SetIfNotNull(pPinValue, t1);
168 return SBLeft;
169 }
170 else {
171 SetIfNotNull(pPinValue, t0);
172 return SBRight;
173 }
174 }
@ SELECTION_RESIZE_REGION
int64 TimeToPosition(double time, int64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ZoomInfo.cpp:44

References SBLeft, SBNone, SBRight, SELECTION_RESIZE_REGION, SetIfNotNull(), and ZoomInfo::TimeToPosition().

Referenced by ChooseBoundary().

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

◆ EnvelopeCursor()

wxCursor * anonymous_namespace{SelectHandle.cpp}::EnvelopeCursor ( )

Definition at line 291 of file SelectHandle.cpp.

292 {
293 // This one doubles as the center frequency cursor for spectral selection:
294 static auto envelopeCursor =
295 ::MakeCursor(wxCURSOR_ARROW, EnvCursorXpm, 16, 16);
296 return &*envelopeCursor;
297 }
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:188

References MakeCursor().

Referenced by SetTipAndCursorForBoundary().

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

◆ findMaxRatio()

double anonymous_namespace{SelectHandle.cpp}::findMaxRatio ( double  center,
double  rate 
)
inline

Definition at line 476 of file SelectHandle.cpp.

477 {
478 const double minFrequency = 1.0;
479 const double maxFrequency = (rate / 2.0);
480 const double frequency =
481 std::min(maxFrequency,
482 std::max(minFrequency, center));
483 return
484 std::min(frequency / minFrequency, maxFrequency / frequency);
485 }
int min(int a, int b)

References min().

Referenced by SelectHandle::AdjustFreqSelection(), SelectHandle::MoveSnappingFreqSelection(), and SelectHandle::SnapCenterOnce().

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

◆ FrequencyToPosition()

wxInt64 anonymous_namespace{SelectHandle.cpp}::FrequencyToPosition ( const WaveTrack wt,
double  frequency,
wxInt64  trackTopEdge,
int  trackHeight 
)

Converts a frequency to screen y position.

Definition at line 67 of file SelectHandle.cpp.

71 {
72 const auto &settings = SpectrogramSettings::Get(*wt);
73 float minFreq, maxFreq;
74 SpectrogramBounds::Get(*wt).GetBounds(*wt, minFreq, maxFreq);
75 const NumberScale numberScale(settings.GetScale(minFreq, maxFreq));
76 const float p = numberScale.ValueToPosition(frequency);
77 return trackTopEdge + wxInt64((1.0 - p) * trackHeight);
78 }
static Settings & settings()
Definition: TrackInfo.cpp:69
void GetBounds(const WaveTrack &wt, float &min, float &max) const
static SpectrogramBounds & Get(WaveTrack &track)
Get either the global default settings, or the track's own if previously created.
static SpectrogramSettings & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.

References SpectrogramSettings::Get(), SpectrogramBounds::Get(), SpectrogramBounds::GetBounds(), settings(), and NumberScale::ValueToPosition().

Referenced by ChooseBoundary().

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

◆ isSpectralSelectionView()

bool anonymous_namespace{SelectHandle.cpp}::isSpectralSelectionView ( const ChannelView pChannelView)
inline

Definition at line 116 of file SelectHandle.cpp.

116 {
117 return
118 pChannelView &&
119 pChannelView->IsSpectral() &&
120 pChannelView->FindTrack() &&
121 pChannelView->FindTrack()->TypeSwitch<bool>(
122 [&](const WaveTrack &wt) {
123 const auto &settings = SpectrogramSettings::Get(wt);
124 return settings.SpectralSelectionEnabled();
125 });
126 }
virtual bool IsSpectral() const

References CommonTrackPanelCell::FindTrack(), SpectrogramSettings::Get(), ChannelView::IsSpectral(), and settings().

Referenced by ChooseBoundary(), SelectHandle::Click(), SelectHandle::MoveSnappingFreqSelection(), SelectHandle::Preview(), and SelectHandle::StartFreqSelection().

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

◆ PositionToFrequency()

double anonymous_namespace{SelectHandle.cpp}::PositionToFrequency ( const WaveTrack wt,
bool  maySnap,
wxInt64  mouseYCoordinate,
wxInt64  trackTopEdge,
int  trackHeight 
)

Converts a position (mouse Y coordinate) to frequency, in Hz.

Definition at line 82 of file SelectHandle.cpp.

87 {
88 const double rate = wt->GetRate();
89
90 // Handle snapping
91 if (maySnap &&
92 mouseYCoordinate - trackTopEdge < FREQ_SNAP_DISTANCE)
93 return rate;
94 if (maySnap &&
95 trackTopEdge + trackHeight - mouseYCoordinate < FREQ_SNAP_DISTANCE)
96 return -1;
97
98 const auto &settings = SpectrogramSettings::Get(*wt);
99 float minFreq, maxFreq;
101 .GetBounds(*wt, minFreq, maxFreq);
102 const NumberScale numberScale(settings.GetScale(minFreq, maxFreq));
103 const double p = double(mouseYCoordinate - trackTopEdge) / trackHeight;
104 return numberScale.PositionToValue(1.0 - p);
105 }
double GetRate() const override
Definition: WaveTrack.cpp:1085

References FREQ_SNAP_DISTANCE, SpectrogramSettings::Get(), SpectrogramBounds::Get(), SpectrogramBounds::GetBounds(), WaveTrack::GetRate(), NumberScale::PositionToValue(), and settings().

Referenced by SelectHandle::AdjustFreqSelection(), SelectHandle::MoveSnappingFreqSelection(), and SelectHandle::StartFreqSelection().

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

◆ SelectCursor()

wxCursor * anonymous_namespace{SelectHandle.cpp}::SelectCursor ( )

Definition at line 284 of file SelectHandle.cpp.

285 {
286 static auto selectCursor =
287 ::MakeCursor(wxCURSOR_IBEAM, IBeamCursorXpm, 17, 16);
288 return &*selectCursor;
289 }

References MakeCursor().

Referenced by SelectHandle::Preview(), and SetTipAndCursorForBoundary().

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

◆ SetIfNotNull()

template<typename T >
void anonymous_namespace{SelectHandle.cpp}::SetIfNotNull ( T *  pValue,
const T  Value 
)
inline

Definition at line 108 of file SelectHandle.cpp.

109 {
110 if (pValue == NULL)
111 return;
112 *pValue = Value;
113 }

Referenced by ChooseBoundary(), and ChooseTimeBoundary().

Here is the caller graph for this function:

◆ SetTipAndCursorForBoundary()

void anonymous_namespace{SelectHandle.cpp}::SetTipAndCursorForBoundary ( SelectionBoundary  boundary,
bool  frequencySnapping,
TranslatableString tip,
wxCursor *&  pCursor 
)

Definition at line 299 of file SelectHandle.cpp.

302 {
303 static wxCursor adjustLeftSelectionCursor{ wxCURSOR_POINT_LEFT };
304 static wxCursor adjustRightSelectionCursor{ wxCURSOR_POINT_RIGHT };
305
306 static auto bottomFrequencyCursor =
307 ::MakeCursor(wxCURSOR_ARROW, BottomFrequencyCursorXpm, 16, 16);
308 static auto topFrequencyCursor =
309 ::MakeCursor(wxCURSOR_ARROW, TopFrequencyCursorXpm, 16, 16);
310 static auto bandWidthCursor =
311 ::MakeCursor(wxCURSOR_ARROW, BandWidthCursorXpm, 16, 16);
312
313 switch (boundary) {
314 case SBNone:
315 pCursor = SelectCursor();
316 break;
317 case SBLeft:
318 tip = XO("Click and drag to move left selection boundary.");
319 pCursor = &adjustLeftSelectionCursor;
320 break;
321 case SBRight:
322 tip = XO("Click and drag to move right selection boundary.");
323 pCursor = &adjustRightSelectionCursor;
324 break;
325#ifdef EXPERIMENTAL_SPECTRAL_EDITING
326 case SBBottom:
327 tip = XO("Click and drag to move bottom selection frequency.");
328 pCursor = &*bottomFrequencyCursor;
329 break;
330 case SBTop:
331 tip = XO("Click and drag to move top selection frequency.");
332 pCursor = &*topFrequencyCursor;
333 break;
334 case SBCenter:
335 {
336#ifndef SPECTRAL_EDITING_ESC_KEY
337 tip =
338 frequencySnapping ?
339 XO("Click and drag to move center selection frequency to a spectral peak.") :
340 XO("Click and drag to move center selection frequency.");
341
342#else
343 shiftDown;
344
345 tip =
346 XO("Click and drag to move center selection frequency.");
347
348#endif
349
350 pCursor = EnvelopeCursor();
351 }
352 break;
353 case SBWidth:
354 tip = XO("Click and drag to adjust frequency bandwidth.");
355 pCursor = &*bandWidthCursor;
356 break;
357#endif
358 default:
359 wxASSERT(false);
360 } // switch
361 // Falls through the switch if there was no boundary found.
362 }
XO("Cut/Copy/Paste")

References EnvelopeCursor(), MakeCursor(), SBLeft, SBNone, SBRight, SelectCursor(), and XO().

Referenced by SelectHandle::Preview().

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

◆ within()

template<class A , class B , class DIST >
bool anonymous_namespace{SelectHandle.cpp}::within ( A  a,
b,
DIST  d 
)

Definition at line 471 of file SelectHandle.cpp.

472 {
473 return (a > b - d) && (a < b + d);
474 }