mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-02 08:59:28 +02:00
Simplify SelectHandle ctor; make frequency snapping functions static
This commit is contained in:
parent
2b146bf543
commit
f3e31eca8b
@ -5896,7 +5896,8 @@ void AudacityProject::DoNextPeakFrequency(bool up)
|
||||
}
|
||||
|
||||
if (pTrack) {
|
||||
SelectHandle::Instance().SnapCenterOnce(mViewInfo, pTrack, up);
|
||||
SpectrumAnalyst analyst;
|
||||
SelectHandle::SnapCenterOnce(analyst, mViewInfo, pTrack, up);
|
||||
mTrackPanel->Refresh(false);
|
||||
ModifyState(false);
|
||||
}
|
||||
|
@ -50,28 +50,6 @@ enum {
|
||||
// #define SPECTRAL_EDITING_ESC_KEY
|
||||
|
||||
SelectHandle::SelectHandle()
|
||||
: mRect()
|
||||
, mInitialSelection()
|
||||
|
||||
, mSnapManager()
|
||||
, mSnapLeft(-1)
|
||||
, mSnapRight(-1)
|
||||
|
||||
, mSelStartValid(false)
|
||||
, mSelStart(0.0)
|
||||
|
||||
, mSelectionBoundary(0)
|
||||
|
||||
, mFreqSelMode(FREQ_SEL_INVALID)
|
||||
, mFreqSelPin(-1.0)
|
||||
, mFrequencySnapper(new SpectrumAnalyst)
|
||||
|
||||
, mMostRecentX(-1)
|
||||
, mMostRecentY(-1)
|
||||
|
||||
, mAutoScrolling(false)
|
||||
|
||||
, mConnectedProject(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1230,13 +1208,15 @@ void SelectHandle::HandleCenterFrequencyClick
|
||||
mFreqSelMode = FREQ_SEL_SNAPPING_CENTER;
|
||||
// Disable time selection
|
||||
mSelStartValid = false;
|
||||
StartSnappingFreqSelection(viewInfo, pTrack);
|
||||
mFrequencySnapper = std::make_unique<SpectrumAnalyst>();
|
||||
StartSnappingFreqSelection(*mFrequencySnapper, viewInfo, pTrack);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void SelectHandle::StartSnappingFreqSelection
|
||||
(const ViewInfo &viewInfo, const WaveTrack *pTrack)
|
||||
(SpectrumAnalyst &analyst,
|
||||
const ViewInfo &viewInfo, const WaveTrack *pTrack)
|
||||
{
|
||||
static const size_t minLength = 8;
|
||||
|
||||
@ -1270,7 +1250,7 @@ void SelectHandle::StartSnappingFreqSelection
|
||||
windowSize >>= 1;
|
||||
const int windowType = settings.windowType;
|
||||
|
||||
mFrequencySnapper->Calculate(
|
||||
analyst.Calculate(
|
||||
SpectrumAnalyst::Spectrum, windowType, windowSize, rate,
|
||||
&frequencySnappingData[0], length);
|
||||
|
||||
@ -1327,7 +1307,8 @@ void SelectHandle::MoveSnappingFreqSelection
|
||||
}
|
||||
|
||||
void SelectHandle::SnapCenterOnce
|
||||
(ViewInfo &viewInfo, const WaveTrack *pTrack, bool up)
|
||||
(SpectrumAnalyst &analyst,
|
||||
ViewInfo &viewInfo, const WaveTrack *pTrack, bool up)
|
||||
{
|
||||
const SpectrogramSettings &settings = pTrack->GetSpectrogramSettings();
|
||||
const auto windowSize = settings.GetFFTLength();
|
||||
@ -1349,18 +1330,18 @@ void SelectHandle::SnapCenterOnce
|
||||
// This is crude and wasteful, doing the FFT each time the command is called.
|
||||
// It would be better to cache the data, but then invalidation of the cache would
|
||||
// need doing in all places that change the time selection.
|
||||
StartSnappingFreqSelection(viewInfo, pTrack);
|
||||
StartSnappingFreqSelection(analyst, viewInfo, pTrack);
|
||||
double snappedFrequency = centerFrequency;
|
||||
int bin = originalBin;
|
||||
if (up) {
|
||||
while (snappedFrequency <= centerFrequency &&
|
||||
bin < limitingBin)
|
||||
snappedFrequency = mFrequencySnapper->FindPeak(++bin * binFrequency, NULL);
|
||||
snappedFrequency = analyst.FindPeak(++bin * binFrequency, NULL);
|
||||
}
|
||||
else {
|
||||
while (snappedFrequency >= centerFrequency &&
|
||||
bin > limitingBin)
|
||||
snappedFrequency = mFrequencySnapper->FindPeak(--bin * binFrequency, NULL);
|
||||
snappedFrequency = analyst.FindPeak(--bin * binFrequency, NULL);
|
||||
}
|
||||
|
||||
// PRL: added these two lines with the big TrackPanel refactor
|
||||
|
@ -89,37 +89,39 @@ private:
|
||||
void HandleCenterFrequencyClick
|
||||
(const ViewInfo &viewInfo, bool shiftDown,
|
||||
const WaveTrack *pTrack, double value);
|
||||
void StartSnappingFreqSelection
|
||||
(const ViewInfo &viewInfo, const WaveTrack *pTrack);
|
||||
static void StartSnappingFreqSelection
|
||||
(SpectrumAnalyst &analyst,
|
||||
const ViewInfo &viewInfo, const WaveTrack *pTrack);
|
||||
void MoveSnappingFreqSelection
|
||||
(AudacityProject *pProject, ViewInfo &viewInfo, int mouseYCoordinate,
|
||||
int trackTopEdge,
|
||||
int trackHeight, Track *pTrack);
|
||||
public:
|
||||
// This is needed to implement a command assignable to keystrokes
|
||||
void SnapCenterOnce
|
||||
(ViewInfo &viewInfo, const WaveTrack *pTrack, bool up);
|
||||
static void SnapCenterOnce
|
||||
(SpectrumAnalyst &analyst,
|
||||
ViewInfo &viewInfo, const WaveTrack *pTrack, bool up);
|
||||
private:
|
||||
//void ResetFreqSelectionPin
|
||||
// (const ViewInfo &viewInfo, double hintFrequency, bool logF);
|
||||
|
||||
|
||||
std::weak_ptr<Track> mpTrack;
|
||||
wxRect mRect;
|
||||
SelectedRegion mInitialSelection;
|
||||
wxRect mRect{};
|
||||
SelectedRegion mInitialSelection{};
|
||||
|
||||
// Handles snapping the selection boundaries or track boundaries to
|
||||
// line up with existing tracks or labels. mSnapLeft and mSnapRight
|
||||
// are the horizontal index of pixels to display user feedback
|
||||
// guidelines so the user knows when such snapping is taking place.
|
||||
std::unique_ptr<SnapManager> mSnapManager;
|
||||
wxInt64 mSnapLeft;
|
||||
wxInt64 mSnapRight;
|
||||
wxInt64 mSnapLeft{ -1 };
|
||||
wxInt64 mSnapRight{ -1 };
|
||||
|
||||
bool mSelStartValid;
|
||||
double mSelStart;
|
||||
bool mSelStartValid{};
|
||||
double mSelStart{ 0.0 };
|
||||
|
||||
int mSelectionBoundary;
|
||||
int mSelectionBoundary{ 0 };
|
||||
|
||||
enum eFreqSelMode {
|
||||
FREQ_SEL_INVALID,
|
||||
@ -131,7 +133,7 @@ private:
|
||||
FREQ_SEL_FREE,
|
||||
FREQ_SEL_TOP_FREE,
|
||||
FREQ_SEL_BOTTOM_FREE,
|
||||
} mFreqSelMode;
|
||||
} mFreqSelMode{ FREQ_SEL_INVALID };
|
||||
std::weak_ptr<const WaveTrack> mFreqSelTrack;
|
||||
// Following holds:
|
||||
// the center for FREQ_SEL_PINNED_CENTER,
|
||||
@ -139,16 +141,15 @@ private:
|
||||
// a frequency boundary for FREQ_SEL_FREE, FREQ_SEL_TOP_FREE, or
|
||||
// FREQ_SEL_BOTTOM_FREE,
|
||||
// and is ignored otherwise.
|
||||
double mFreqSelPin;
|
||||
double mFreqSelPin{ -1.0 };
|
||||
std::unique_ptr<SpectrumAnalyst> mFrequencySnapper;
|
||||
|
||||
int mMostRecentX, mMostRecentY;
|
||||
int mMostRecentX{ -1 }, mMostRecentY{ -1 };
|
||||
|
||||
bool mAutoScrolling;
|
||||
bool mAutoScrolling{};
|
||||
|
||||
AudacityProject *mConnectedProject;
|
||||
AudacityProject *mConnectedProject{};
|
||||
|
||||
std::unique_ptr<SelectionStateChanger> mSelectionStateChanger;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user