diff --git a/src/TrackArtist.cpp b/src/TrackArtist.cpp index d75d9160b..b23940050 100644 --- a/src/TrackArtist.cpp +++ b/src/TrackArtist.cpp @@ -2344,7 +2344,7 @@ void TrackArtist::DrawClipSpectrum(WaveTrackCache &waveTrackCache, (zoomInfo.PositionToTime(0, -leftOffset) - tOffset) ); - const bool isSpectral = settings.spectralSelection; + const bool isSpectral = settings.SpectralSelectionEnabled(); const bool hidden = (ZoomInfo::HIDDEN == zoomInfo.GetFisheyeState()); const int begin = hidden ? 0 diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index f3269e81b..ea113b475 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -1813,7 +1813,7 @@ inline bool isSpectralSelectionTrack(const Track *pTrack, bool *pLogf = NULL) { settings.scaleType == SpectrogramSettings::stLogarithmic; *pLogf = logF; } - return (display == WaveTrack::Spectrum) && settings.spectralSelection; + return (display == WaveTrack::Spectrum) && settings.SpectralSelectionEnabled(); } else { if (pLogf) diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index 7852e6f16..04030efa7 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -605,7 +605,7 @@ bool NyquistEffect::Process() const WaveTrack::WaveTrackDisplay display = mCurTrack[0]->GetDisplay(); const bool bAllowSpectralEditing = (display == WaveTrack::Spectrum) && - mCurTrack[0]->GetSpectrogramSettings().spectralSelection; + mCurTrack[0]->GetSpectrogramSettings().SpectralSelectionEnabled(); if (bAllowSpectralEditing) { #if defined(EXPERIMENTAL_SPECTRAL_EDITING) diff --git a/src/prefs/SpectrogramSettings.cpp b/src/prefs/SpectrogramSettings.cpp index ce4e41081..173d2f58a 100644 --- a/src/prefs/SpectrogramSettings.cpp +++ b/src/prefs/SpectrogramSettings.cpp @@ -26,6 +26,33 @@ Paul Licameli #include #include +SpectrogramSettings::Globals::Globals() +{ + LoadPrefs(); +} + +void SpectrogramSettings::Globals::SavePrefs() +{ +#ifdef SPECTRAL_SELECTION_GLOBAL_SWITCH + gPrefs->Write(wxT("/Spectrum/EnableSpectralSelection"), spectralSelection); +#endif +} + +void SpectrogramSettings::Globals::LoadPrefs() +{ +#ifdef SPECTRAL_SELECTION_GLOBAL_SWITCH + spectralSelection + = (gPrefs->Read(wxT("/Spectrum/EnableSpectralSelection"), 0L) != 0); +#endif +} + +SpectrogramSettings::Globals +&SpectrogramSettings::Globals::Get() +{ + static Globals instance; + return instance; +} + SpectrogramSettings::SpectrogramSettings() : hFFT(0) , window(0) @@ -48,7 +75,9 @@ SpectrogramSettings::SpectrogramSettings(const SpectrogramSettings &other) #endif , isGrayscale(other.isGrayscale) , scaleType(other.scaleType) +#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH , spectralSelection(other.spectralSelection) +#endif #ifdef EXPERIMENTAL_FFT_Y_GRID , fftYGrid(other.fftYGrid) #endif @@ -82,7 +111,9 @@ SpectrogramSettings &SpectrogramSettings::operator= (const SpectrogramSettings & #endif isGrayscale = other.isGrayscale; scaleType = other.scaleType; +#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH spectralSelection = other.spectralSelection; +#endif #ifdef EXPERIMENTAL_FFT_Y_GRID fftYGrid = other.fftYGrid; #endif @@ -219,7 +250,10 @@ void SpectrogramSettings::LoadPrefs() isGrayscale = (gPrefs->Read(wxT("/Spectrum/Grayscale"), 0L) != 0); scaleType = ScaleType(gPrefs->Read(wxT("/Spectrum/ScaleType"), 0L)); + +#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH spectralSelection = (gPrefs->Read(wxT("/Spectrum/EnableSpectralSelection"), 0L) != 0); +#endif #ifdef EXPERIMENTAL_FFT_Y_GRID fftYGrid = (gPrefs->Read(wxT("/Spectrum/FFTYGrid"), 0L) != 0); @@ -276,7 +310,10 @@ void SpectrogramSettings::SavePrefs() gPrefs->Write(wxT("/Spectrum/Grayscale"), isGrayscale); gPrefs->Write(wxT("/Spectrum/ScaleType"), scaleType); + +#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH gPrefs->Write(wxT("/Spectrum/EnableSpectralSelection"), spectralSelection); +#endif #ifdef EXPERIMENTAL_FFT_Y_GRID gPrefs->Write(wxT("/Spectrum/FFTYGrid"), fftYGrid); @@ -486,3 +523,12 @@ int SpectrogramSettings::GetFFTLength(bool autocorrelation) const #endif ; } + +bool SpectrogramSettings::SpectralSelectionEnabled() const +{ +#ifdef SPECTRAL_SELECTION_GLOBAL_SWITCH + return Globals::Get().spectralSelection; +#else + return spectralSelection; +#endif +} diff --git a/src/prefs/SpectrogramSettings.h b/src/prefs/SpectrogramSettings.h index 393c9b27f..3f4a34dca 100644 --- a/src/prefs/SpectrogramSettings.h +++ b/src/prefs/SpectrogramSettings.h @@ -13,6 +13,8 @@ Paul Licameli #include "../Experimental.h" +#undef SPECTRAL_SELECTION_GLOBAL_SWITCH + struct FFTParam; class SpectrumPrefs; class wxArrayString; @@ -22,6 +24,22 @@ class SpectrogramSettings friend class SpectrumPrefs; public: + // Singleton for settings that are not per-track + class Globals + { + public: + static Globals &Get(); + void SavePrefs(); + +#ifdef SPECTRAL_SELECTION_GLOBAL_SWITCH + bool spectralSelection; +#endif + + private: + Globals(); + void LoadPrefs(); + }; + enum { LogMinWindowSize = 3, LogMaxWindowSize = 15, @@ -72,6 +90,7 @@ public: int GetMaxFreq(double rate) const; int GetLogMinFreq(double rate) const; int GetLogMaxFreq(double rate) const; + bool SpectralSelectionEnabled() const; void SetMinFreq(int freq); void SetMaxFreq(int freq); @@ -95,7 +114,9 @@ public: ScaleType scaleType; +#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH bool spectralSelection; // But should this vary per track? -- PRL +#endif #ifdef EXPERIMENTAL_FFT_Y_GRID bool fftYGrid; @@ -116,5 +137,4 @@ public: mutable float *window; #endif }; - #endif diff --git a/src/prefs/SpectrumPrefs.cpp b/src/prefs/SpectrumPrefs.cpp index 1d30f2c92..8c085ff22 100644 --- a/src/prefs/SpectrumPrefs.cpp +++ b/src/prefs/SpectrumPrefs.cpp @@ -218,8 +218,11 @@ void SpectrumPrefs::PopulateOrExchange(ShuttleGui & S) S.Id(ID_GRAYSCALE).TieCheckBox(_("S&how the spectrum using grayscale colors"), mTempSettings.isGrayscale); + +#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH S.Id(ID_SPECTRAL_SELECTION).TieCheckBox(_("Ena&ble spectral selection"), mTempSettings.spectralSelection); +#endif #ifdef EXPERIMENTAL_FFT_Y_GRID S.TieCheckBox(_("Show a grid along the &Y-axis"), @@ -257,6 +260,15 @@ void SpectrumPrefs::PopulateOrExchange(ShuttleGui & S) } // S.EndStatic(); +#ifdef SPECTRAL_SELECTION_GLOBAL_SWITCH + S.StartStatic(_("Global settings")); + { + S.TieCheckBox(_("Ena&ble spectral selection"), + SpectrogramSettings::Globals::Get().spectralSelection); + } + S.EndStatic(); +#endif + S.StartMultiColumn(2, wxALIGN_RIGHT); { S.Id(ID_APPLY).AddButton(_("Appl&y")); @@ -340,7 +352,10 @@ bool SpectrumPrefs::Apply() ShuttleGui S(this, eIsGettingFromDialog); PopulateOrExchange(S); + mTempSettings.ConvertToActualWindowSizes(); + SpectrogramSettings::Globals::Get().SavePrefs(); // always + if (mWt) { if (mDefaulted) { mWt->SetSpectrogramSettings(NULL);