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
50key1{ [](auto &) {
51 return std::make_unique<WaveformSettings>(WaveformSettings::defaults()); } };
52
54{
55 auto &mutTrack = const_cast<WaveTrack&>(track);
56 return mutTrack.GetGroupData().Attachments
57 ::Get<WaveformSettings>(key1);
58}
59
61 WaveTrack &track, std::unique_ptr<WaveformSettings> pSettings)
62{
63 track.GetGroupData().Attachments
64 ::Assign(key1, move(pSettings));
65}
66
68{
69 LoadPrefs();
70}
71
73 : scaleType(other.scaleType)
74 , dBRange(other.dBRange)
75{
76}
77
79{
80 if (this != &other) {
81 scaleType = other.scaleType;
82 dBRange = other.dBRange;
83 }
84 return *this;
85}
86
88{
89 static WaveformSettings instance;
90 return instance;
91}
92
93bool WaveformSettings::Validate(bool /* quiet */)
94{
96 std::max(0, std::min((int)(stNumScaleTypes) - 1, (int)(scaleType)))
97 );
98
101
102 return true;
103}
104
106{
108
110
111 // Enforce legal values
112 Validate(true);
113
114 Update();
115}
116
118{
119}
120
122{
123}
124
125// This is a temporary hack until WaveformSettings gets fully integrated
127{
128 if (scaleType == defaults().scaleType) {
130 }
131
132 if (dBRange == defaults().dBRange){
134 }
135
136 // Enforce legal values
137 Validate(true);
138}
139
141{
142 // Assumes the codes are in ascending sequence.
143 wxArrayStringEx codes;
144 GUIPrefs::GetRangeChoices(nullptr, &codes);
145 int ii = 0;
146 for (int nn = codes.size(); ii < nn; ++ii) {
147 long value = 0;
148 codes[ii].ToLong(&value);
149 if (dBRange < value)
150 break;
151 }
152 dBRange = std::max(0, ii - 1);
153}
154
156{
157 wxArrayStringEx codes;
158 GUIPrefs::GetRangeChoices(nullptr, &codes);
159 long value = 0;
160 codes[std::max(0, std::min((int)(codes.size()) - 1, dBRange))]
161 .ToLong(&value);
162 dBRange = (int)(value);
163}
164
166{
168 ++dBRange;
170}
171
173{
175 --dBRange;
177}
178
179//static
181{
182 static const EnumValueSymbols result{
183 // Keep in correspondence with ScaleTypeValues:
184 { wxT("Linear"), XO("Linear (amp)") },
185 { wxT("dB"), XO("Logarithmic (dB)") },
186 { wxT("LinearDB"), XO("Linear (dB)") },
187 };
188 return result;
189}
190
192{
193}
194
196{
197 return std::make_unique<WaveformSettings>(*this);
198}
199
201key2{ [](auto &) { return std::make_unique<WaveformScale>(); } };
202
204{
205 auto &mutTrack = const_cast<WaveTrack&>(track);
206 return mutTrack.GetGroupData().Attachments
207 ::Get<WaveformScale>(key2);
208}
209
211
213{
214 return std::make_unique<WaveformScale>(*this);
215}
216
218{
219 return rect.GetTop() +
220 (int)((mDisplayMax / (mDisplayMax - mDisplayMin)) * rect.height);
221}
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 const ChannelGroup::Attachments::RegisteredFactory key2
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:274
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:205
ChannelGroupData & GetGroupData()
Definition: Track.cpp:159
static WaveformSettings::ScaleTypeValues WaveformScaleChoice()
A Track that contains audio waveform data.
Definition: WaveTrack.h:222
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.
Owner< Base > PointerType
Definition: ClientData.h:53