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

Function ChooseBoundary

src/tracks/ui/SelectHandle.cpp:171–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169 }
170
171 SelectionBoundary ChooseBoundary(
172 const ViewInfo &viewInfo,
173 wxCoord xx, wxCoord yy, const ChannelView &channelView,
174 const wxRect &rect,
175 bool mayDragWidth, bool onlyWithinSnapDistance,
176 double *pPinValue = NULL)
177 {
178 // Choose one of four boundaries to adjust, or the center frequency.
179 // May choose frequencies only if in a spectrogram view and
180 // within the time boundaries.
181 // May choose no boundary if onlyWithinSnapDistance is true.
182 // Otherwise choose the eligible boundary nearest the mouse click.
183 const double selend = viewInfo.PositionToTime(xx, rect.x);
184 wxInt64 pixelDist = 0;
185 const double t0 = viewInfo.selectedRegion.t0();
186 const double t1 = viewInfo.selectedRegion.t1();
187
188 SelectionBoundary boundary =
189 ChooseTimeBoundary(t0,t1,viewInfo, selend, onlyWithinSnapDistance,
190 &pixelDist, pPinValue);
191
192 //const double t0 = viewInfo.selectedRegion.t0();
193 //const double t1 = viewInfo.selectedRegion.t1();
194 const double f0 = viewInfo.selectedRegion.f0();
195 const double f1 = viewInfo.selectedRegion.f1();
196 const double fc = viewInfo.selectedRegion.fc();
197 double ratio = 0;
198
199 bool chooseTime = true;
200 bool chooseBottom = true;
201 bool chooseCenter = false;
202 // Consider adjustment of frequencies only if mouse is
203 // within the time boundaries
204 if (!viewInfo.selectedRegion.isPoint() &&
205 t0 <= selend && selend < t1 &&
206 isSpectralSelectionView(channelView)) {
207 auto pWc = channelView.FindChannel<const WaveChannel>();
208 // Spectral selection track is always wave
209 assert(pWc);
210 auto &wc = *pWc;
211 const wxInt64 bottomSel = (f0 >= 0)
212 ? FrequencyToPosition(wc, f0, rect.y, rect.height)
213 : rect.y + rect.height;
214 const wxInt64 topSel = (f1 >= 0)
215 ? FrequencyToPosition(wc, f1, rect.y, rect.height)
216 : rect.y;
217 wxInt64 signedBottomDist = (int)(yy - bottomSel);
218 wxInt64 verticalDist = std::abs(signedBottomDist);
219 if (bottomSel == topSel)
220 // Top and bottom are too close to resolve on screen
221 chooseBottom = (signedBottomDist >= 0);
222 else {
223 const wxInt64 topDist = std::abs((int)(yy - topSel));
224 if (topDist < verticalDist)
225 chooseBottom = false, verticalDist = topDist;
226 }
227 if (fc > 0
228#ifdef SPECTRAL_EDITING_ESC_KEY

Callers 2

ClickMethod · 0.85
PreviewMethod · 0.85

Calls 5

ChooseTimeBoundaryFunction · 0.85
PositionToTimeMethod · 0.80
isSpectralSelectionViewFunction · 0.70
FrequencyToPositionFunction · 0.70
SetIfNotNullFunction · 0.70

Tested by

no test coverage detected