forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQualityPrefs.cpp
More file actions
250 lines (206 loc) · 7.29 KB
/
Copy pathQualityPrefs.cpp
File metadata and controls
250 lines (206 loc) · 7.29 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/**********************************************************************
Audacity: A Digital Audio Editor
QualityPrefs.cpp
Joshua Haberman
James Crook
*******************************************************************//**
\class QualityPrefs
\brief A PrefsPanel used for setting audio quality.
*//*******************************************************************/
#include "../Audacity.h"
#include "QualityPrefs.h"
#include <wx/choice.h>
#include <wx/defs.h>
#include <wx/textctrl.h>
#include "../AudioIOBase.h"
#include "../Dither.h"
#include "../Prefs.h"
#include "../Resample.h"
#include "../ShuttleGui.h"
#define ID_SAMPLE_RATE_CHOICE 7001
//////////
static EnumSetting< sampleFormat > formatSetting{
wxT("/SamplingRate/DefaultProjectSampleFormatChoice"),
{
{ wxT("Format16Bit"), XO("16-bit") },
{ wxT("Format24Bit"), XO("24-bit") },
{ wxT("Format32BitFloat"), XO("32-bit float") }
},
2, // floatSample
// for migrating old preferences:
{
int16Sample,
int24Sample,
floatSample
},
wxT("/SamplingRate/DefaultProjectSampleFormat"),
};
//////////
BEGIN_EVENT_TABLE(QualityPrefs, PrefsPanel)
EVT_CHOICE(ID_SAMPLE_RATE_CHOICE, QualityPrefs::OnSampleRateChoice)
END_EVENT_TABLE()
QualityPrefs::QualityPrefs(wxWindow * parent, wxWindowID winid)
/* i18n-hint: meaning accuracy in reproduction of sounds */
: PrefsPanel(parent, winid, XO("Quality"))
{
Populate();
}
QualityPrefs::~QualityPrefs()
{
}
ComponentInterfaceSymbol QualityPrefs::GetSymbol()
{
return QUALITY_PREFS_PLUGIN_SYMBOL;
}
TranslatableString QualityPrefs::GetDescription()
{
return XO("Preferences for Quality");
}
wxString QualityPrefs::HelpPageName()
{
return "Quality_Preferences";
}
void QualityPrefs::Populate()
{
// First any pre-processing for constructing the GUI.
GetNamesAndLabels();
gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
&mOtherSampleRateValue,
AudioIOBase::GetOptimalSupportedSampleRate());
//------------------------- Main section --------------------
// Now construct the GUI itself.
// Use 'eIsCreatingFromPrefs' so that the GUI is
// initialised with values from gPrefs.
ShuttleGui S(this, eIsCreatingFromPrefs);
PopulateOrExchange(S);
// ----------------------- End of main section --------------
wxCommandEvent e;
OnSampleRateChoice(e); // Enable/disable the control.
}
/// Gets the lists of names and lists of labels which are
/// used in the choice controls.
/// The names are what the user sees in the wxChoice.
/// The corresponding labels are what gets stored.
void QualityPrefs::GetNamesAndLabels()
{
//------------ Sample Rate Names
// JKC: I don't understand the following comment.
// Can someone please explain or correct it?
// XXX: This should use a previously changed, but not yet saved
// sound card setting from the "I/O" preferences tab.
// LLL: It means that until the user clicks "Ok" in preferences, the
// GetSupportedSampleRates() call should use the devices they
// may have changed on the Audio I/O page. As coded, the sample
// rates it will return could be completely invalid as they will
// be what's supported by the devices that were selected BEFORE
// coming into preferences.
//
// GetSupportedSampleRates() allows passing in device names, but
// how do you get at them as they are on the Audio I/O page????
for (int i = 0; i < AudioIOBase::NumStandardRates; i++) {
int iRate = AudioIOBase::StandardRates[i];
mSampleRateLabels.push_back(iRate);
mSampleRateNames.push_back( XO("%i Hz").Format( iRate ) );
}
mSampleRateNames.push_back(XO("Other..."));
// The label for the 'Other...' case can be any value at all.
mSampleRateLabels.push_back(44100); // If chosen, this value will be overwritten
}
void QualityPrefs::PopulateOrExchange(ShuttleGui & S)
{
S.SetBorder(2);
S.StartScroller();
S.StartStatic(XO("Sampling"));
{
S.StartMultiColumn(2);
{
S.AddPrompt(XXO("Default Sample &Rate:"));
S.StartMultiColumn(2);
{
// First the choice...
// We make sure it uses the ID we want, so that we get changes
S.Id(ID_SAMPLE_RATE_CHOICE);
// We make sure we have a pointer to it, so that we can drive it.
mSampleRates = S.TieNumberAsChoice( {},
{wxT("/SamplingRate/DefaultProjectSampleRate"),
AudioIOBase::GetOptimalSupportedSampleRate()},
mSampleRateNames,
&mSampleRateLabels,
// If the value in Prefs isn't in the list, then we want
// the last item, 'Other...' to be shown.
mSampleRateNames.size() - 1
);
// Now do the edit box...
mOtherSampleRate = S.TieNumericTextBox( {},
mOtherSampleRateValue,
15);
}
S.EndHorizontalLay();
S.TieChoice(XXO("Default Sample &Format:"),
formatSetting);
}
S.EndMultiColumn();
}
S.EndStatic();
S.StartStatic(XO("Real-time Conversion"));
{
S.StartMultiColumn(2, wxEXPAND);
{
S.TieChoice(XXO("Sample Rate Con&verter:"),
Resample::FastMethodSetting);
/* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
S.TieChoice(XXO("&Dither:"),
Dither::FastSetting);
}
S.EndMultiColumn();
}
S.EndStatic();
S.StartStatic(XO("High-quality Conversion"));
{
S.StartMultiColumn(2);
{
S.TieChoice(XXO("Sample Rate Conver&ter:"),
Resample::BestMethodSetting);
/* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
S.TieChoice(XXO("Dit&her:"),
Dither::BestSetting);
}
S.EndMultiColumn();
}
S.EndStatic();
S.EndScroller();
}
/// Enables or disables the Edit box depending on
/// whether we selected 'Other...' or not.
void QualityPrefs::OnSampleRateChoice(wxCommandEvent & WXUNUSED(e))
{
int sel = mSampleRates->GetSelection();
mOtherSampleRate->Enable(sel == (int)mSampleRates->GetCount() - 1);
}
bool QualityPrefs::Commit()
{
ShuttleGui S(this, eIsSavingToPrefs);
PopulateOrExchange(S);
// The complex compound control may have value 'other' in which case the
// value in prefs comes from the second field.
if (mOtherSampleRate->IsEnabled()) {
gPrefs->Write(wxT("/SamplingRate/DefaultProjectSampleRate"), mOtherSampleRateValue);
gPrefs->Flush();
}
// Tell CopySamples() to use these ditherers now
InitDitherers();
return true;
}
namespace{
PrefsPanel::Registration sAttachment{ "Quality",
[](wxWindow *parent, wxWindowID winid, AudacityProject *)
{
wxASSERT(parent); // to justify safenew
return safenew QualityPrefs(parent, winid);
}
};
}
sampleFormat QualityPrefs::SampleFormatChoice()
{
return formatSetting.ReadEnum();
}