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.Attachments::Get<WaveformSettings>(key1);
57}
58
60{
61 return Get(channel.GetTrack());
62}
63
65 WaveChannel &channel, std::unique_ptr<WaveformSettings> pSettings)
66{
67 channel.GetTrack().Attachments::Assign(key1, move(pSettings));
68}
69
71{
72 LoadPrefs();
73}
74
76 : scaleType(other.scaleType)
77 , dBRange(other.dBRange)
78{
79}
80
82{
83 if (this != &other) {
84 scaleType = other.scaleType;
85 dBRange = other.dBRange;
86 }
87 return *this;
88}
89
91{
92 static WaveformSettings instance;
93 return instance;
94}
95
96bool WaveformSettings::Validate(bool /* quiet */)
97{
99 std::max(0, std::min((int)(stNumScaleTypes) - 1, (int)(scaleType)))
100 );
101
104
105 return true;
106}
107
109{
111
113
114 // Enforce legal values
115 Validate(true);
116
117 Update();
118}
119
121{
122}
123
125{
126}
127
128// This is a temporary hack until WaveformSettings gets fully integrated
130{
131 if (scaleType == defaults().scaleType) {
133 }
134
135 if (dBRange == defaults().dBRange){
137 }
138
139 // Enforce legal values
140 Validate(true);
141}
142
144{
145 // Assumes the codes are in ascending sequence.
146 wxArrayStringEx codes;
147 GUIPrefs::GetRangeChoices(nullptr, &codes);
148 int ii = 0;
149 for (int nn = codes.size(); ii < nn; ++ii) {
150 long value = 0;
151 codes[ii].ToLong(&value);
152 if (dBRange < value)
153 break;
154 }
155 dBRange = std::max(0, ii - 1);
156}
157
159{
160 wxArrayStringEx codes;
161 GUIPrefs::GetRangeChoices(nullptr, &codes);
162 long value = 0;
163 codes[std::max(0, std::min((int)(codes.size()) - 1, dBRange))]
164 .ToLong(&value);
165 dBRange = (int)(value);
166}
167
169{
171 ++dBRange;
173}
174
176{
178 --dBRange;
180}
181
182//static
184{
185 static const EnumValueSymbols result{
186 // Keep in correspondence with ScaleTypeValues:
187 { wxT("Linear"), XO("Linear (amp)") },
188 { wxT("dB"), XO("Logarithmic (dB)") },
189 { wxT("LinearDB"), XO("Linear (dB)") },
190 };
191 return result;
192}
193
195{
196}
197
199{
200 return std::make_unique<WaveformSettings>(*this);
201}
202
204key2{ [](auto &) { return std::make_unique<WaveformScale>(); } };
205
207{
208 auto &mutTrack = const_cast<WaveTrack&>(track);
209 return mutTrack.Attachments::Get<WaveformScale>(key2);
210}
211
213{
214 return Get(channel.GetTrack());
215}
216
218
220{
221 return std::make_unique<WaveformScale>(*this);
222}
223
225{
226 return rect.GetTop() +
227 (int)((mDisplayMax / (mDisplayMax - mDisplayMin)) * rect.height);
228}
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:275
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:207
static WaveformSettings::ScaleTypeValues WaveformScaleChoice()
WaveTrack & GetTrack()
Definition: WaveTrack.h:840
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
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 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)
WaveformSettings & operator=(const WaveformSettings &other)
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Owner< Base > PointerType
Definition: ClientData.h:54