Audacity 3.2.0
WaveformSettings.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5WaveformSettings.cpp
6
7Paul Licameli
8
9*******************************************************************//*******************************************************************/
15
16
17#include "WaveformSettings.h"
18#include "WaveTrack.h"
19
20#include "Decibels.h"
21
22#include "Prefs.h"
23#include <algorithm>
24
26 wxT("/GUI/DefaultWaveformScaleChoice");
27const wxString WaveformSettings::dbLogValueString = wxT("dB");
28const wxString WaveformSettings::dbLinValueString = wxT("dBLin");
29
32 waveformScaleKey,
33 {
34 { wxT("Linear"), XO("Linear (amp)") },
35 { dbLogValueString, XO("Logarithmic (dB)") },
36 { dbLinValueString, XO("Linear (dB)") },
37 },
38
39 0, // linear
40
41 {
45 }
46 };
47
49{
50 LoadPrefs();
51}
52
54{
55}
56
58{
59}
60
63{
64 static Globals instance;
65 return instance;
66}
67
69key1{ [](auto &) {
70 return std::make_unique<WaveformSettings>(WaveformSettings::defaults()); } };
71
73{
74 auto &mutTrack = const_cast<WaveTrack&>(track);
75 return mutTrack.Attachments::Get<WaveformSettings>(key1);
76}
77
79{
80 return Get(channel.GetTrack());
81}
82
84 WaveChannel &channel, std::unique_ptr<WaveformSettings> pSettings)
85{
86 channel.GetTrack().Attachments::Assign(key1, move(pSettings));
87}
88
90{
91 LoadPrefs();
92}
93
95 : scaleType(other.scaleType)
96 , dBRange(other.dBRange)
97{
98}
99
101{
102 if (this != &other) {
103 scaleType = other.scaleType;
104 dBRange = other.dBRange;
105 }
106 return *this;
107}
108
110{
111 static WaveformSettings instance;
112 return instance;
113}
114
115bool WaveformSettings::Validate(bool /* quiet */)
116{
118 std::max(0, std::min((int)(stNumScaleTypes) - 1, (int)(scaleType)))
119 );
120
123
124 return true;
125}
126
128{
130
132
133 // Enforce legal values
134 Validate(true);
135
136 Update();
137}
138
140{
141}
142
144{
145}
146
147// This is a temporary hack until WaveformSettings gets fully integrated
149{
150 if (scaleType == defaults().scaleType) {
152 }
153
154 if (dBRange == defaults().dBRange){
156 }
157
158 // Enforce legal values
159 Validate(true);
160}
161
163{
164 // Assumes the codes are in ascending sequence.
165 wxArrayStringEx codes;
166 WaveformSettings::GetRangeChoices(nullptr, &codes);
167 int ii = 0;
168 for (int nn = codes.size(); ii < nn; ++ii) {
169 long value = 0;
170 codes[ii].ToLong(&value);
171 if (dBRange < value)
172 break;
173 }
174 dBRange = std::max(0, ii - 1);
175}
176
178{
179 wxArrayStringEx codes;
180 WaveformSettings::GetRangeChoices(nullptr, &codes);
181 long value = 0;
182 codes[std::max(0, std::min((int)(codes.size()) - 1, dBRange))]
183 .ToLong(&value);
184 dBRange = (int)(value);
185}
186
188{
190 ++dBRange;
192}
193
195{
197 --dBRange;
199}
200
201//static
203{
204 static const EnumValueSymbols result{
205 // Keep in correspondence with ScaleTypeValues:
206 { wxT("Linear"), XO("Linear (amp)") },
207 { wxT("dB"), XO("Logarithmic (dB)") },
208 { wxT("LinearDB"), XO("Linear (dB)") },
209 };
210 return result;
211}
212
214 TranslatableStrings* pChoices, wxArrayStringEx* pCodes,
215 int* pDefaultRangeIndex)
216{
217 static const wxArrayStringEx sCodes = {
218 wxT("36"), wxT("48"), wxT("60"), wxT("72"),
219 wxT("84"), wxT("96"), wxT("120"), wxT("145"),
220 };
221 if (pCodes)
222 *pCodes = sCodes;
223
224 static const std::initializer_list<TranslatableString> sChoices = {
225 XO("-36 dB (shallow range for high-amplitude editing)"),
226 XO("-48 dB (PCM range of 8 bit samples)"),
227 XO("-60 dB (PCM range of 10 bit samples)"),
228 XO("-72 dB (PCM range of 12 bit samples)"),
229 XO("-84 dB (PCM range of 14 bit samples)"),
230 XO("-96 dB (PCM range of 16 bit samples)"),
231 XO("-120 dB (approximate limit of human hearing)"),
232 XO("-145 dB (PCM range of 24 bit samples)"),
233 };
234
235 if (pChoices)
236 *pChoices = sChoices;
237
238 if (pDefaultRangeIndex)
239 *pDefaultRangeIndex = 2; // 60 == ENV_DB_RANGE
240}
241
243{
244}
245
247{
248 return std::make_unique<WaveformSettings>(*this);
249}
wxT("CloseDown"))
int min(int a, int b)
IntSetting DecibelScaleCutoff
Negation of this value is the lowest dB level that should be shown in dB scales.
Definition: Decibels.cpp:12
XO("Cut/Copy/Paste")
std::vector< TranslatableString > TranslatableStrings
static const ChannelGroup::Attachments::RegisteredFactory key1
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:275
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:514
Enum ReadEnum() const
Definition: Prefs.h:534
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:207
WaveTrack & GetTrack()
Definition: WaveTrack.h:841
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
Waveform settings, either for one track or as defaults.
static void GetRangeChoices(TranslatableStrings *pChoices, wxArrayStringEx *pCodes, int *pDefaultRangeIndex=nullptr)
static void Set(WaveChannel &channel, std::unique_ptr< WaveformSettings > pSettings)
Guarantee independence of settings, then assign.
static const EnumValueSymbols & GetScaleNames()
bool Validate(bool quiet)
static WaveformSettings & defaults()
void UpdatePrefs() override
PointerType Clone() const override
~WaveformSettings() override
static WaveformSettings & Get(const WaveTrack &track)
static const wxString dbLogValueString
WaveformSettings & operator=(const WaveformSettings &other)
static EnumSetting< ScaleTypeValues > waveformScaleSetting
static const wxString waveformScaleKey
static const wxString dbLinValueString
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Owner< Base > PointerType
Definition: ClientData.h:54