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#include "GUIPrefs.h"
22#include "TracksPrefs.h"
23
24#include <algorithm>
25
26#include "Prefs.h"
27
28
30{
31 LoadPrefs();
32}
33
35{
36}
37
39{
40}
41
44{
45 static Globals instance;
46 return instance;
47}
48
50 [](SampleTrack&){
51 return std::make_unique<WaveformSettings>(WaveformSettings::defaults());
52 }
53};
54
56{
57 auto &mutTrack = const_cast<WaveTrack&>(track);
58 return static_cast<WaveformSettings&>(
59 mutTrack.WaveTrack::Attachments::Get(key1));
60}
61
63 WaveTrack &track, std::unique_ptr<WaveformSettings> pSettings)
64{
65 track.WaveTrack::Attachments::Assign(key1, move(pSettings));
66}
67
69{
70 LoadPrefs();
71}
72
74 : scaleType(other.scaleType)
75 , dBRange(other.dBRange)
76{
77}
78
80{
81 if (this != &other) {
82 scaleType = other.scaleType;
83 dBRange = other.dBRange;
84 }
85 return *this;
86}
87
89{
90 static WaveformSettings instance;
91 return instance;
92}
93
94bool WaveformSettings::Validate(bool /* quiet */)
95{
97 std::max(0, std::min((int)(stNumScaleTypes) - 1, (int)(scaleType)))
98 );
99
102
103 return true;
104}
105
107{
109
111
112 // Enforce legal values
113 Validate(true);
114
115 Update();
116}
117
119{
120}
121
123{
124}
125
126// This is a temporary hack until WaveformSettings gets fully integrated
128{
129 if (scaleType == defaults().scaleType) {
131 }
132
133 if (dBRange == defaults().dBRange){
135 }
136
137 // Enforce legal values
138 Validate(true);
139}
140
142{
143 // Assumes the codes are in ascending sequence.
144 wxArrayStringEx codes;
145 GUIPrefs::GetRangeChoices(nullptr, &codes);
146 int ii = 0;
147 for (int nn = codes.size(); ii < nn; ++ii) {
148 long value = 0;
149 codes[ii].ToLong(&value);
150 if (dBRange < value)
151 break;
152 }
153 dBRange = std::max(0, ii - 1);
154}
155
157{
158 wxArrayStringEx codes;
159 GUIPrefs::GetRangeChoices(nullptr, &codes);
160 long value = 0;
161 codes[std::max(0, std::min((int)(codes.size()) - 1, dBRange))]
162 .ToLong(&value);
163 dBRange = (int)(value);
164}
165
167{
169 ++dBRange;
171}
172
174{
176 --dBRange;
178}
179
180//static
182{
183 static const EnumValueSymbols result{
184 // Keep in correspondence with ScaleTypeValues:
185 { wxT("Linear"), XO("Linear (amp)") },
186 { wxT("dB"), XO("Logarithmic (dB)") },
187 { wxT("LinearDB"), XO("Linear (dB)") },
188 };
189 return result;
190}
191
193{
194}
195
197{
198 return std::make_unique<WaveformSettings>(*this);
199}
200
202 [](SampleTrack&){
203 return std::make_unique<WaveformScale>();
204 }
205};
206
208{
209 auto &mutTrack = const_cast<WaveTrack&>(track);
210 return static_cast<WaveformScale&>(
211 mutTrack.WaveTrack::Attachments::Get(key2));
212}
213
215
217{
218 return std::make_unique<WaveformScale>(*this);
219}
220
222{
223 return rect.GetTop() +
224 (int)((mDisplayMax / (mDisplayMax - mDisplayMin)) * rect.height);
225}
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")
static WaveTrack::Attachments::RegisteredFactory key2
static WaveTrack::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:266
static void GetRangeChoices(TranslatableStrings *pChoices, wxArrayStringEx *pCodes, int *pDefaultRangeIndex=nullptr)
Definition: GUIPrefs.cpp:65
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:200
static WaveformSettings::ScaleTypeValues WaveformScaleChoice()
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
int ZeroLevelYCoordinate(wxRect rect) const
static WaveformScale & Get(const WaveTrack &track)
Mutative access to attachment even if the track argument is const.
PointerType Clone() const override
~WaveformScale() override
Waveform settings, either for one track or as defaults.
static const EnumValueSymbols & GetScaleNames()
static void Set(WaveTrack &track, std::unique_ptr< WaveformSettings > pSettings)
Guarantee independence of settings, then assign.
bool Validate(bool quiet)
static WaveformSettings & defaults()
void UpdatePrefs() override
PointerType Clone() const override
~WaveformSettings() override
static WaveformSettings & Get(const WaveTrack &track)
WaveformSettings & operator=(const WaveformSettings &other)
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
ClientData::UniquePtr< Base > PointerType
Definition: ClientData.h:50