From 778e7726dff16d584c4ba5fea8a5037bc5ed1c88 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 15 Jun 2015 10:36:17 -0400 Subject: [PATCH] Safe copy constructor and assignment for SpectrogramSettings --- src/prefs/SpectrogramSettings.cpp | 64 +++++++++++++++++++++++++++++++ src/prefs/SpectrogramSettings.h | 2 + 2 files changed, 66 insertions(+) diff --git a/src/prefs/SpectrogramSettings.cpp b/src/prefs/SpectrogramSettings.cpp index 6c8ca2328..bc5d0c6bf 100644 --- a/src/prefs/SpectrogramSettings.cpp +++ b/src/prefs/SpectrogramSettings.cpp @@ -26,6 +26,69 @@ SpectrogramSettings::SpectrogramSettings() UpdatePrefs(); } +SpectrogramSettings::SpectrogramSettings(const SpectrogramSettings &other) + : minFreq(other.minFreq) + , maxFreq(other.maxFreq) + , logMinFreq(other.logMinFreq) + , logMaxFreq(other.logMaxFreq) + , range(other.range) + , gain(other.gain) + , frequencyGain(other.frequencyGain) + , windowType(other.windowType) + , windowSize(other.windowSize) +#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS + , zeroPaddingFactor(other.zeroPaddingFactor) +#endif + , isGrayscale(other.isGrayscale) +#ifdef EXPERIMENTAL_FFT_Y_GRID + , fftYGrid(other.fftYGrid) +#endif +#ifdef EXPERIMENTAL_FIND_NOTES + , fftFindNotes(other.fftFindNotes) + , findNotesMinA(other.findNotesMinA) + , numberOfMaxima(other.numberOfMaxima) + , findNotesQuantize(other.findNotesQuantize) +#endif + + // Do not copy these! + , hFFT(0) + , window(0) +{ +} + +SpectrogramSettings &SpectrogramSettings::operator= (const SpectrogramSettings &other) +{ + if (this != &other) { + minFreq = other.minFreq; + maxFreq = other.maxFreq; + logMinFreq = other.logMinFreq; + logMaxFreq = other.logMaxFreq; + range = other.range; + gain = other.gain; + frequencyGain = other.frequencyGain; + windowType = other.windowType; + windowSize = other.windowSize; +#ifdef EXPERIMENTAL_ZERO_PADDED_SPECTROGRAMS + zeroPaddingFactor = other.zeroPaddingFactor; +#endif + isGrayscale = other.isGrayscale; +#ifdef EXPERIMENTAL_FFT_Y_GRID + fftYGrid = other.fftYGrid; +#endif +#ifdef EXPERIMENTAL_FIND_NOTES + fftFindNotes = other.fftFindNotes; + findNotesMinA = other.findNotesMinA; + numberOfMaxima = other.numberOfMaxima; + findNotesQuantize = other.findNotesQuantize; +#endif + + // Do not copy these! + hFFT = 0; + window = 0; + } + return *this; +} + SpectrogramSettings& SpectrogramSettings::defaults() { static SpectrogramSettings instance; @@ -112,6 +175,7 @@ void SpectrogramSettings::DestroyWindows() #endif } + namespace { enum { WINDOW, TWINDOW, DWINDOW }; diff --git a/src/prefs/SpectrogramSettings.h b/src/prefs/SpectrogramSettings.h index 71a505ed8..9cb9e9ac5 100644 --- a/src/prefs/SpectrogramSettings.h +++ b/src/prefs/SpectrogramSettings.h @@ -20,6 +20,8 @@ class SpectrogramSettings public: static SpectrogramSettings &defaults(); SpectrogramSettings(); + SpectrogramSettings(const SpectrogramSettings &other); + SpectrogramSettings& operator= (const SpectrogramSettings &other); ~SpectrogramSettings(); void UpdatePrefs();