Audacity 3.2.0
SpectrogramSettings.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5SpectrogramSettings.h
6
7Paul Licameli
8
9**********************************************************************/
10
11#ifndef __AUDACITY_SPECTROGRAM_SETTINGS__
12#define __AUDACITY_SPECTROGRAM_SETTINGS__
13
14#include "ClientData.h" // to inherit
15#include "Prefs.h"
16#include "SampleFormat.h"
17#include "RealFFTf.h"
18
19#undef SPECTRAL_SELECTION_GLOBAL_SWITCH
20
22struct FFTParam;
23class NumberScale;
24class SpectrumPrefs;
25class wxArrayStringEx;
26class WaveTrack;
27
28class AUDACITY_DLL_API SpectrogramSettings
29 : public PrefsListener
30 , public ClientData::Cloneable<>
31{
32 friend class SpectrumPrefs;
33public:
34
35 // Singleton for settings that are not per-track
36 class AUDACITY_DLL_API Globals
37 {
38 public:
39 static Globals &Get();
40 void SavePrefs();
41
42#ifdef SPECTRAL_SELECTION_GLOBAL_SWITCH
43 bool spectralSelection;
44#endif
45
46 private:
47 Globals();
48 void LoadPrefs();
49 };
50
51 enum {
52 LogMinWindowSize = 3,
53 LogMaxWindowSize = 15,
54
55 NumWindowSizes = LogMaxWindowSize - LogMinWindowSize + 1,
56 };
57
58 // Do not assume that this enumeration will remain the
59 // same as NumberScaleType in future. That enum may become
60 // more general purpose.
61 typedef int ScaleType;
62 enum ScaleTypeValues : int {
69
71 };
72
73 static const EnumValueSymbols &GetScaleNames();
74 static const EnumValueSymbols &GetColorSchemeNames();
75 static const TranslatableStrings &GetAlgorithmNames();
76
77 // Return either the track's independent settings or global defaults
79 static SpectrogramSettings &Get(const WaveTrack &track);
80
81 // Force creation of track's independent settings
82 static SpectrogramSettings &Own(WaveTrack &track);
83
85 static void Reset(WaveTrack &track);
86
87 static SpectrogramSettings &defaults();
92
93 PointerType Clone() const override;
94
95 bool IsDefault() const
96 {
97 return this == &defaults();
98 }
99
100 bool Validate(bool quiet);
101 void LoadPrefs();
102 void SavePrefs();
103
104 void UpdatePrefs() override;
105
106 void InvalidateCaches();
107 void DestroyWindows();
108 void CacheWindows();
109 void ConvertToEnumeratedWindowSizes();
110 void ConvertToActualWindowSizes();
111
112 // Need to be told what the bin unit is, as this structure does not know
113 // the rate
114 float findBin( float frequency, float binUnit ) const;
115
116 // If "bins" is false, units are Hz
117 NumberScale GetScale( float minFreq, float maxFreq ) const;
118
121
122 bool SpectralSelectionEnabled() const;
123
124public:
125 int range;
126 int gain;
128
130
131private:
133public:
134 size_t WindowSize() const { return windowSize; }
135
136private:
138public:
139 size_t ZeroPaddingFactor() const {
140 return algorithm == algPitchEAC ? 1 : zeroPaddingFactor;
141 }
142
143 size_t GetFFTLength() const; // window size (times zero padding, if STFT)
144 size_t NBins() const;
145
146 enum ColorScheme : int {
147 // Keep in correspondence with AColor::colorSchemes, AColor::gradient_pre
148 csColorNew = 0,
152
154 };
156
157 class ColorSchemeEnumSetting : public EnumSetting< ColorScheme > {
159 void Migrate(wxString &value) override;
160 };
162
164
165#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
166 bool spectralSelection; // But should this vary per track? -- PRL
167#endif
168
169 typedef int Algorithm;
170 enum AlgorithmValues : int {
171 algSTFT = 0,
174
176 };
178
179#ifdef EXPERIMENTAL_FFT_Y_GRID
180 bool fftYGrid;
181#endif //EXPERIMENTAL_FFT_Y_GRID
182
183#ifdef EXPERIMENTAL_FIND_NOTES
184 bool fftFindNotes;
185 double findNotesMinA;
186 int numberOfMaxima;
187 bool findNotesQuantize;
188#endif //EXPERIMENTAL_FIND_NOTES
189
190 // Following fields are derived from preferences.
191
192 // Variables used for computing the spectrum
195
196 // Two other windows for computing reassigned spectrogram
197 Floats tWindow; // Window times time parameter
198 Floats dWindow; // Derivative of window
199};
200
201extern AUDACITY_DLL_API IntSetting SpectrumMaxFreq;
202
203class AUDACITY_DLL_API SpectrogramBounds
204 : public ClientData::Cloneable<>
205{
206public:
207
209 static SpectrogramBounds &Get( WaveTrack &track );
210
212 static const SpectrogramBounds &Get( const WaveTrack &track );
213
215 PointerType Clone() const override;
216
217 void GetBounds(const WaveTrack &wt, float &min, float &max) const;
218
219 void SetBounds(float min, float max)
220 { mSpectrumMin = min, mSpectrumMax = max; }
221
222private:
223 float mSpectrumMin = -1, mSpectrumMax = -1;
224};
225
226#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
int min(int a, int b)
std::unique_ptr< FFTParam, FFTDeleter > HFFT
Definition: RealFFTf.h:22
AUDACITY_DLL_API IntSetting SpectrumMaxFreq
std::vector< TranslatableString > TranslatableStrings
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:512
Specialization of Setting for int.
Definition: Prefs.h:354
A listener notified of changes in preferences.
Definition: Prefs.h:561
virtual void UpdatePrefs()=0
Definition: Prefs.cpp:125
void SetBounds(float min, float max)
~SpectrogramBounds() override
Spectrogram settings, either for one track or as defaults.
static ColorSchemeEnumSetting colorSchemeSetting
size_t ZeroPaddingFactor() const
A PrefsPanel for spectrum settings.
Definition: SpectrumPrefs.h:42
A Track that contains audio waveform data.
Definition: WaveTrack.h:222
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
A convenient base class defining abstract virtual Clone() for a given kind of pointer.
Definition: ClientData.h:49
virtual PointerType Clone() const =0
Owner< Base > PointerType
Definition: ClientData.h:53
Cloneable & operator=(const Cloneable &)=default