forked from tenacityteam/tenacity-legacy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWaveformSettings.cpp
174 lines (136 loc) · 3.28 KB
/
WaveformSettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**********************************************************************
Audacity: A Digital Audio Editor
WaveformSettings.cpp
Paul Licameli
*******************************************************************//**
\class WaveformSettings
\brief Waveform settings, either for one track or as defaults.
*//*******************************************************************/
#include "WaveformSettings.h"
#include "GUISettings.h"
#include "GUIPrefs.h"
#include "TracksPrefs.h"
#include <algorithm>
#include <wx/intl.h>
#include "../Prefs.h"
WaveformSettings::Globals::Globals()
{
LoadPrefs();
}
void WaveformSettings::Globals::SavePrefs()
{
}
void WaveformSettings::Globals::LoadPrefs()
{
}
WaveformSettings::Globals
&WaveformSettings::Globals::Get()
{
static Globals instance;
return instance;
}
WaveformSettings::WaveformSettings()
{
LoadPrefs();
}
WaveformSettings::WaveformSettings(const WaveformSettings &other)
: scaleType(other.scaleType)
, dBRange(other.dBRange)
{
}
WaveformSettings &WaveformSettings::operator= (const WaveformSettings &other)
{
if (this != &other) {
scaleType = other.scaleType;
dBRange = other.dBRange;
}
return *this;
}
WaveformSettings& WaveformSettings::defaults()
{
static WaveformSettings instance;
return instance;
}
bool WaveformSettings::Validate(bool /* quiet */)
{
scaleType = ScaleType(
std::max(0, std::min((int)(stNumScaleTypes) - 1, (int)(scaleType)))
);
ConvertToEnumeratedDBRange();
ConvertToActualDBRange();
return true;
}
void WaveformSettings::LoadPrefs()
{
scaleType = TracksPrefs::WaveformScaleChoice();
dBRange = gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE);
// Enforce legal values
Validate(true);
Update();
}
void WaveformSettings::SavePrefs()
{
}
void WaveformSettings::Update()
{
}
// This is a temporary hack until WaveformSettings gets fully integrated
void WaveformSettings::UpdatePrefs()
{
if (scaleType == defaults().scaleType) {
scaleType = TracksPrefs::WaveformScaleChoice();
}
if (dBRange == defaults().dBRange){
dBRange = gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE);
}
// Enforce legal values
Validate(true);
}
void WaveformSettings::ConvertToEnumeratedDBRange()
{
// Assumes the codes are in ascending sequence.
wxArrayStringEx codes;
GUIPrefs::GetRangeChoices(nullptr, &codes);
int ii = 0;
for (int nn = codes.size(); ii < nn; ++ii) {
long value = 0;
codes[ii].ToLong(&value);
if (dBRange < value)
break;
}
dBRange = std::max(0, ii - 1);
}
void WaveformSettings::ConvertToActualDBRange()
{
wxArrayStringEx codes;
GUIPrefs::GetRangeChoices(nullptr, &codes);
long value = 0;
codes[std::max(0, std::min((int)(codes.size()) - 1, dBRange))]
.ToLong(&value);
dBRange = (int)(value);
}
void WaveformSettings::NextLowerDBRange()
{
ConvertToEnumeratedDBRange();
++dBRange;
ConvertToActualDBRange();
}
void WaveformSettings::NextHigherDBRange()
{
ConvertToEnumeratedDBRange();
--dBRange;
ConvertToActualDBRange();
}
//static
const EnumValueSymbols &WaveformSettings::GetScaleNames()
{
static const EnumValueSymbols result{
// Keep in correspondence with ScaleTypeValues:
XO("Linear"),
XO("dB"),
};
return result;
}
WaveformSettings::~WaveformSettings()
{
}