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

Method ModifySpectralSelection

src/toolbars/SpectralSelectionBar.cpp:268–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268void SpectralSelectionBar::ModifySpectralSelection(bool done)
269{
270 auto &manager = ProjectSelectionManager::Get(mProject);
271 auto &tracks = TrackList::Get(mProject);
272 const auto nyq = WaveTrack::ProjectNyquistFrequency(mProject);
273
274 double bottom, top;
275 if (mbCenterAndWidth) {
276 mCenter = mCenterCtrl->GetValue();
277 mWidth = mWidthCtrl->GetValue();
278 if ((mCenter < 0 || mWidth < 0) &&
279 (mLow >= 0 || mHigh >= 0))
280 // Transition from defined spectral selection to undefined
281 bottom = top = SelectedRegion::UndefinedFrequency;
282 else if (mCenter < 0 && mWidth < 0)
283 bottom = top = SelectedRegion::UndefinedFrequency;
284 else {
285 if (mCenter < 0) {
286 mWidth = log(std::min(nyq, exp(mWidth)));
287 // Choose arbitrary center for the width
288 mCenter = sqrt(nyq);
289 }
290 else if (mWidth < 0) {
291 mCenter = std::max(1.0, std::min(nyq, mCenter));
292 // Choose arbitrary width for the center
293 const double ratio = std::min(mCenter, nyq / mCenter);
294 mWidth = log(ratio * ratio);
295 }
296 else {
297 mCenter = std::max(1.0, std::min(nyq, mCenter));
298 double ratio = std::min(mCenter, nyq / mCenter);
299 mWidth = std::min(2 * log(ratio), mWidth);
300 }
301
302 const double ratio = exp(mWidth / 2);
303 bottom = mCenter / ratio, top = mCenter * ratio;
304 }
305 }
306 else {
307 bottom = mLowCtrl->GetValue();
308 top = mHighCtrl->GetValue();
309
310 if (bottom >= 0)
311 bottom = std::min(nyq, bottom);
312 else
313 bottom = SelectedRegion::UndefinedFrequency;
314
315 if (top >= 0)
316 top = std::min(nyq, top);
317 else
318 top = SelectedRegion::UndefinedFrequency;
319 // These have to be in the right order.
320 if( bottom > top ){
321 // Oops. We must fix the order.
322 if( mLowCtrl->HasFocus() )
323 top = bottom;
324 else
325 bottom = top;

Callers 1

ApplyMethod · 0.45

Calls 5

GetFunction · 0.85
maxFunction · 0.85
minFunction · 0.50
sqrtFunction · 0.50
GetValueMethod · 0.45

Tested by

no test coverage detected