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

Function PositionToFrequency

src/tracks/ui/SelectHandle.cpp:84–106  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

82 /// Converts a position (mouse Y coordinate) to
83 /// frequency, in Hz.
84 double PositionToFrequency(const WaveChannel &wc,
85 bool maySnap,
86 wxInt64 mouseYCoordinate,
87 wxInt64 trackTopEdge,
88 int trackHeight)
89 {
90 const double rate = wc.GetRate();
91
92 // Handle snapping
93 if (maySnap &&
94 mouseYCoordinate - trackTopEdge < FREQ_SNAP_DISTANCE)
95 return rate;
96 if (maySnap &&
97 trackTopEdge + trackHeight - mouseYCoordinate < FREQ_SNAP_DISTANCE)
98 return -1;
99
100 const auto &settings = SpectrogramSettings::Get(wc);
101 float minFreq, maxFreq;
102 SpectrogramBounds::Get(wc).GetBounds(wc, minFreq, maxFreq);
103 const NumberScale numberScale(settings.GetScale(minFreq, maxFreq));
104 const double p = double(mouseYCoordinate - trackTopEdge) / trackHeight;
105 return numberScale.PositionToValue(1.0 - p);
106 }
107
108 template<typename T>
109 inline void SetIfNotNull(T * pValue, const T Value)

Callers 3

StartFreqSelectionMethod · 0.70
AdjustFreqSelectionMethod · 0.70

Calls 5

GetFunction · 0.85
GetScaleMethod · 0.80
PositionToValueMethod · 0.80
GetRateMethod · 0.45
GetBoundsMethod · 0.45

Tested by

no test coverage detected