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

Method AdjustFreqSelection

src/tracks/ui/SelectHandle.cpp:1257–1338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1255}
1256
1257void SelectHandle::AdjustFreqSelection(
1258 const WaveChannel &wc, ViewInfo &viewInfo,
1259 int mouseYCoordinate, int trackTopEdge,
1260 int trackHeight)
1261{
1262 if (mFreqSelMode == FREQ_SEL_INVALID ||
1263 mFreqSelMode == FREQ_SEL_SNAPPING_CENTER)
1264 return;
1265
1266 // Extension happens only when dragging in the same track in which we
1267 // started, and that is of a spectrogram display type.
1268
1269 const double rate = wc.GetRate();
1270 const double frequency =
1271 PositionToFrequency(wc, true, mouseYCoordinate,
1272 trackTopEdge, trackHeight);
1273
1274 // Dragging center?
1275 if (mFreqSelMode == FREQ_SEL_DRAG_CENTER) {
1276 if (frequency == rate || frequency < 1.0)
1277 // snapped to top or bottom
1278 viewInfo.selectedRegion.setFrequencies(
1279 SelectedRegion::UndefinedFrequency,
1280 SelectedRegion::UndefinedFrequency);
1281 else {
1282 // mFreqSelPin holds the ratio of top to center
1283 const double maxRatio = findMaxRatio(frequency, rate);
1284 const double ratio = std::min(maxRatio, mFreqSelPin);
1285 viewInfo.selectedRegion.setFrequencies(
1286 frequency / ratio, frequency * ratio);
1287 }
1288 }
1289 else if (mFreqSelMode == FREQ_SEL_PINNED_CENTER) {
1290 if (mFreqSelPin >= 0) {
1291 // Change both upper and lower edges leaving centre where it is.
1292 if (frequency == rate || frequency < 1.0)
1293 // snapped to top or bottom
1294 viewInfo.selectedRegion.setFrequencies(
1295 SelectedRegion::UndefinedFrequency,
1296 SelectedRegion::UndefinedFrequency);
1297 else {
1298 // Given center and mouse position, find ratio of the larger to the
1299 // smaller, limit that to the frequency scale bounds, and adjust
1300 // top and bottom accordingly.
1301 const double maxRatio = findMaxRatio(mFreqSelPin, rate);
1302 double ratio = frequency / mFreqSelPin;
1303 if (ratio < 1.0)
1304 ratio = 1.0 / ratio;
1305 ratio = std::min(maxRatio, ratio);
1306 viewInfo.selectedRegion.setFrequencies(
1307 mFreqSelPin / ratio, mFreqSelPin * ratio);
1308 }
1309 }
1310 }
1311 else {
1312 // Dragging of upper or lower.
1313 const bool bottomDefined =
1314 !(mFreqSelMode == FREQ_SEL_TOP_FREE && mFreqSelPin < 0);

Callers

nothing calls this directly

Calls 8

maxFunction · 0.85
setFrequenciesMethod · 0.80
setF1Method · 0.80
setF0Method · 0.80
PositionToFrequencyFunction · 0.70
findMaxRatioFunction · 0.70
minFunction · 0.50
GetRateMethod · 0.45

Tested by

no test coverage detected