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 WaveChannel;
27class WaveTrack;
28
29class WAVE_TRACK_SETTINGS_API SpectrogramSettings
30 : public PrefsListener
31 , public ClientData::Cloneable<>
32{
33 friend class SpectrumPrefs;
34public:
35
36 // Singleton for settings that are not per-track
37 class WAVE_TRACK_SETTINGS_API Globals
38 {
39 public:
40 static Globals &Get();
41 void SavePrefs();
42
43#ifdef SPECTRAL_SELECTION_GLOBAL_SWITCH
44 bool spectralSelection;
45#endif
46
47 private:
48 Globals();
49 void LoadPrefs();
50 };
51
52 enum {
53 LogMinWindowSize = 3,
54 LogMaxWindowSize = 15,
55
56 NumWindowSizes = LogMaxWindowSize - LogMinWindowSize + 1,
57 };
58
59 // Do not assume that this enumeration will remain the
60 // same as NumberScaleType in future. That enum may become
61 // more general purpose.
62 typedef int ScaleType;
63 enum ScaleTypeValues : int {
70
72 };
73
74 static const EnumValueSymbols &GetScaleNames();
75 static const EnumValueSymbols &GetColorSchemeNames();
76 static const TranslatableStrings &GetAlgorithmNames();
77
80 static SpectrogramSettings &Get(const WaveTrack &track);
81
85 static SpectrogramSettings &Get(const WaveChannel &channel);
86
87 // Force creation of channels's independent settings
88 static SpectrogramSettings &Own(WaveChannel &wc);
89
91 static void Reset(WaveChannel &channel);
92
93 static SpectrogramSettings &defaults();
98
99 PointerType Clone() const override;
100
101 bool IsDefault() const
102 {
103 return this == &defaults();
104 }
105
106 bool Validate(bool quiet);
107 void LoadPrefs();
108 void SavePrefs();
109
110 void UpdatePrefs() override;
111
112 void InvalidateCaches();
113 void DestroyWindows();
114 void CacheWindows();
115 void ConvertToEnumeratedWindowSizes();
116 void ConvertToActualWindowSizes();
117
118 // Need to be told what the bin unit is, as this structure does not know
119 // the rate
120 float findBin( float frequency, float binUnit ) const;
121
122 // If "bins" is false, units are Hz
123 NumberScale GetScale( float minFreq, float maxFreq ) const;
124
127
128 bool SpectralSelectionEnabled() const;
129
130public:
131 int range;
132 int gain;
134
136
137private:
139public:
140 size_t WindowSize() const { return windowSize; }
141
142private:
144public:
145 size_t ZeroPaddingFactor() const {
146 return algorithm == algPitchEAC ? 1 : zeroPaddingFactor;
147 }
148
149 size_t GetFFTLength() const; // window size (times zero padding, if STFT)
150 size_t NBins() const;
151
152 enum ColorScheme : int {
153 // Keep in correspondence with AColor::colorSchemes, AColor::gradient_pre
154 csColorNew = 0,
158
160 };
162
163 class ColorSchemeEnumSetting : public EnumSetting< ColorScheme > {
165 void Migrate(wxString &value) override;
166 };
168
170
171#ifndef SPECTRAL_SELECTION_GLOBAL_SWITCH
172 bool spectralSelection; // But should this vary per track? -- PRL
173#endif
174
175 typedef int Algorithm;
176 enum AlgorithmValues : int {
177 algSTFT = 0,
180
182 };
184
185#ifdef EXPERIMENTAL_FFT_Y_GRID
186 bool fftYGrid;
187#endif //EXPERIMENTAL_FFT_Y_GRID
188
189#ifdef EXPERIMENTAL_FIND_NOTES
190 bool fftFindNotes;
191 double findNotesMinA;
192 int numberOfMaxima;
193 bool findNotesQuantize;
194#endif //EXPERIMENTAL_FIND_NOTES
195
196 // Following fields are derived from preferences.
197
198 // Variables used for computing the spectrum
201
202 // Two other windows for computing reassigned spectrogram
203 Floats tWindow; // Window times time parameter
204 Floats dWindow; // Derivative of window
205};
206
207extern WAVE_TRACK_SETTINGS_API IntSetting SpectrumMaxFreq;
208
209class WAVE_TRACK_SETTINGS_API SpectrogramBounds
210 : public ClientData::Cloneable<>
211{
212public:
213
215 static SpectrogramBounds &Get(WaveTrack &track);
216
218 static const SpectrogramBounds &Get(const WaveTrack &track);
219
221 static SpectrogramBounds &Get(WaveChannel &channel);
222
224 static const SpectrogramBounds &Get(const WaveChannel &channel);
225
227 PointerType Clone() const override;
228
229 void GetBounds(const WaveChannel &wc, float &min, float &max) const;
230
231 void SetBounds(float min, float max)
232 { mSpectrumMin = min, mSpectrumMax = max; }
233
234private:
235 float mSpectrumMin = -1, mSpectrumMax = -1;
236};
237
238#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
WAVE_TRACK_SETTINGS_API IntSetting SpectrumMaxFreq
std::vector< TranslatableString > TranslatableStrings
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:514
Specialization of Setting for int.
Definition: Prefs.h:356
A listener notified of changes in preferences.
Definition: Prefs.h:652
virtual void UpdatePrefs()=0
Definition: Prefs.cpp:154
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:203
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:202
A convenient base class defining abstract virtual Clone() for a given kind of pointer.
Definition: ClientData.h:50
virtual PointerType Clone() const =0
Owner< Base > PointerType
Definition: ClientData.h:54
Cloneable & operator=(const Cloneable &)=default