| 1454 | } |
| 1455 | |
| 1456 | void SelectHandle::SnapCenterOnce(SpectrumAnalyst &analyst, |
| 1457 | ViewInfo &viewInfo, const WaveChannel &wc, bool up) |
| 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 | |
| 1497 | viewInfo.selectedRegion.setFrequencies |
| 1498 | (snappedFrequency / ratio, snappedFrequency * ratio); |
| 1499 | } |
| 1500 | |
| 1501 | #if 0 |
| 1502 | // unused |
nothing calls this directly
no test coverage detected