Audacity  3.0.3
QualityPrefs.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  QualityPrefs.cpp
6 
7  Joshua Haberman
8  James Crook
9 
10 
11 *******************************************************************//*******************************************************************/
17 
18 
19 #include "QualityPrefs.h"
20 
21 #include <wx/choice.h>
22 #include <wx/defs.h>
23 #include <wx/textctrl.h>
24 
25 #include "../AudioIOBase.h"
26 #include "../Dither.h"
27 #include "../Prefs.h"
28 #include "../Resample.h"
29 #include "../ShuttleGui.h"
30 
31 #define ID_SAMPLE_RATE_CHOICE 7001
32 
34 
36  wxT("/SamplingRate/DefaultProjectSampleFormatChoice"),
37  {
38  { wxT("Format16Bit"), XO("16-bit") },
39  { wxT("Format24Bit"), XO("24-bit") },
40  { wxT("Format32BitFloat"), XO("32-bit float") }
41  },
42  2, // floatSample
43 
44  // for migrating old preferences:
45  {
49  },
50  wxT("/SamplingRate/DefaultProjectSampleFormat"),
51 };
52 
54 BEGIN_EVENT_TABLE(QualityPrefs, PrefsPanel)
57 
58 QualityPrefs::QualityPrefs(wxWindow * parent, wxWindowID winid)
59 /* i18n-hint: meaning accuracy in reproduction of sounds */
60 : PrefsPanel(parent, winid, XO("Quality"))
61 {
62  Populate();
63 }
64 
66 {
67 }
68 
70 {
72 }
73 
75 {
76  return XO("Preferences for Quality");
77 }
78 
80 {
81  return "Quality_Preferences";
82 }
83 
85 {
86  // First any pre-processing for constructing the GUI.
88  gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
91 
92  //------------------------- Main section --------------------
93  // Now construct the GUI itself.
94  // Use 'eIsCreatingFromPrefs' so that the GUI is
95  // initialised with values from gPrefs.
98  // ----------------------- End of main section --------------
99 
100  wxCommandEvent e;
101  OnSampleRateChoice(e); // Enable/disable the control.
102 }
103 
109 {
110  //------------ Sample Rate Names
111  // JKC: I don't understand the following comment.
112  // Can someone please explain or correct it?
113  // XXX: This should use a previously changed, but not yet saved
114  // sound card setting from the "I/O" preferences tab.
115  // LLL: It means that until the user clicks "Ok" in preferences, the
116  // GetSupportedSampleRates() call should use the devices they
117  // may have changed on the Audio I/O page. As coded, the sample
118  // rates it will return could be completely invalid as they will
119  // be what's supported by the devices that were selected BEFORE
120  // coming into preferences.
121  //
122  // GetSupportedSampleRates() allows passing in device names, but
123  // how do you get at them as they are on the Audio I/O page????
124  for (int i = 0; i < AudioIOBase::NumStandardRates; i++) {
125  int iRate = AudioIOBase::StandardRates[i];
126  mSampleRateLabels.push_back(iRate);
127  mSampleRateNames.push_back( XO("%i Hz").Format( iRate ) );
128  }
129 
130  mSampleRateNames.push_back(XO("Other..."));
131 
132  // The label for the 'Other...' case can be any value at all.
133  mSampleRateLabels.push_back(44100); // If chosen, this value will be overwritten
134 }
135 
137 {
138  S.SetBorder(2);
139  S.StartScroller();
140 
141  S.StartStatic(XO("Sampling"));
142  {
143  S.StartMultiColumn(2);
144  {
145  S.AddPrompt(XXO("Default Sample &Rate:"));
146 
147  S.StartMultiColumn(2);
148  {
149  // First the choice...
150  // We make sure it uses the ID we want, so that we get changes
152  // We make sure we have a pointer to it, so that we can drive it.
154  {wxT("/SamplingRate/DefaultProjectSampleRate"),
158  // If the value in Prefs isn't in the list, then we want
159  // the last item, 'Other...' to be shown.
160  mSampleRateNames.size() - 1
161  );
162 
163  // Now do the edit box...
166  15);
167  }
168  S.EndHorizontalLay();
169 
170  S.TieChoice(XXO("Default Sample &Format:"),
171  formatSetting);
172  }
173  S.EndMultiColumn();
174  }
175  S.EndStatic();
176 
177  S.StartStatic(XO("Real-time Conversion"));
178  {
179  S.StartMultiColumn(2, wxEXPAND);
180  {
181  S.TieChoice(XXO("Sample Rate Con&verter:"),
183 
184  /* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
185  S.TieChoice(XXO("&Dither:"),
187  }
188  S.EndMultiColumn();
189  }
190  S.EndStatic();
191 
192  S.StartStatic(XO("High-quality Conversion"));
193  {
194  S.StartMultiColumn(2);
195  {
196  S.TieChoice(XXO("Sample Rate Conver&ter:"),
198 
199  /* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
200  S.TieChoice(XXO("Dit&her:"),
202  }
203  S.EndMultiColumn();
204  }
205  S.EndStatic();
206  S.EndScroller();
207 
208 }
209 
212 void QualityPrefs::OnSampleRateChoice(wxCommandEvent & WXUNUSED(e))
213 {
214  int sel = mSampleRates->GetSelection();
215  mOtherSampleRate->Enable(sel == (int)mSampleRates->GetCount() - 1);
216 }
217 
219 {
220  ShuttleGui S(this, eIsSavingToPrefs);
222 
223  // The complex compound control may have value 'other' in which case the
224  // value in prefs comes from the second field.
225  if (mOtherSampleRate->IsEnabled()) {
226  gPrefs->Write(wxT("/SamplingRate/DefaultProjectSampleRate"), mOtherSampleRateValue);
227  gPrefs->Flush();
228  }
229 
230  // Tell CopySamples() to use these ditherers now
231  InitDitherers();
232 
233  return true;
234 }
235 
236 namespace{
238  [](wxWindow *parent, wxWindowID winid, AudacityProject *)
239  {
240  wxASSERT(parent); // to justify safenew
241  return safenew QualityPrefs(parent, winid);
242  }
243 };
244 }
245 
247 {
248  return formatSetting.ReadEnum();
249 }
250 
TranslatableString
Definition: Types.h:290
QualityPrefs::mSampleRateNames
TranslatableStrings mSampleRateNames
Definition: QualityPrefs.h:47
AudioIOBase::StandardRates
static const int StandardRates[]
Array of common audio sample rates.
Definition: AudioIOBase.h:208
QualityPrefs
A PrefsPanel used for setting audio quality.
Definition: QualityPrefs.h:29
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:67
Dither::BestSetting
static EnumSetting< DitherType > BestSetting
Definition: Dither.h:28
QualityPrefs::mOtherSampleRate
wxTextCtrl * mOtherSampleRate
Definition: QualityPrefs.h:51
int24Sample
@ int24Sample
Definition: Types.h:713
Resample::FastMethodSetting
static EnumSetting< int > FastMethodSetting
Definition: Resample.h:44
Format
Abstract base class used in importing a file.
PrefsPanel::Registration
Definition: PrefsPanel.h:83
XO
#define XO(s)
Definition: Internat.h:32
ID_SAMPLE_RATE_CHOICE
#define ID_SAMPLE_RATE_CHOICE
Definition: QualityPrefs.cpp:31
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1212
QualityPrefs::mSampleRateLabels
std::vector< int > mSampleRateLabels
Definition: QualityPrefs.h:48
QualityPrefs::GetDescription
TranslatableString GetDescription() override
Definition: QualityPrefs.cpp:74
floatSample
@ floatSample
Definition: Types.h:714
AudioIOBase::NumStandardRates
static const int NumStandardRates
How many standard sample rates there are.
Definition: AudioIOBase.h:210
QualityPrefs.h
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2248
ShuttleGuiBase::EndScroller
void EndScroller()
Definition: ShuttleGui.cpp:964
QualityPrefs::mOtherSampleRateValue
int mOtherSampleRateValue
Definition: QualityPrefs.h:52
sampleFormat
sampleFormat
Definition: Types.h:709
XXO
#define XXO(s)
Definition: Internat.h:45
ShuttleGuiBase::StartScroller
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:931
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1170
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1203
QualityPrefs::mSampleRates
wxChoice * mSampleRates
Definition: QualityPrefs.h:50
AudioIOBase::GetOptimalSupportedSampleRate
static int GetOptimalSupportedSampleRate()
Get a supported sample rate which can be used a an optimal default.
Definition: AudioIOBase.cpp:693
QualityPrefs::OnSampleRateChoice
void OnSampleRateChoice(wxCommandEvent &e)
Definition: QualityPrefs.cpp:212
formatSetting
static EnumSetting< sampleFormat > formatSetting
Definition: QualityPrefs.cpp:35
ShuttleGuiBase::TieNumericTextBox
wxTextCtrl * TieNumericTextBox(const TranslatableString &Prompt, int &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1647
QualityPrefs::SampleFormatChoice
static sampleFormat SampleFormatChoice()
Definition: QualityPrefs.cpp:246
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:886
eIsSavingToPrefs
@ eIsSavingToPrefs
Definition: ShuttleGui.h:46
QualityPrefs::Populate
void Populate()
Definition: QualityPrefs.cpp:84
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:151
QualityPrefs::Commit
bool Commit() override
Definition: QualityPrefs.cpp:218
QualityPrefs::~QualityPrefs
virtual ~QualityPrefs()
Definition: QualityPrefs.cpp:65
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
InitDitherers
void InitDitherers()
Definition: SampleFormat.cpp:53
anonymous_namespace{QualityPrefs.cpp}::sAttachment
PrefsPanel::Registration sAttachment
Definition: QualityPrefs.cpp:237
int16Sample
@ int16Sample
Definition: Types.h:712
ShuttleGuiBase::TieNumberAsChoice
virtual wxChoice * TieNumberAsChoice(const TranslatableString &Prompt, const SettingSpec< int > &Setting, const TranslatableStrings &Choices, const std::vector< int > *pInternalChoices=nullptr, int iNoMatchSelector=0)
Definition: ShuttleGui.cpp:1985
QualityPrefs::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: QualityPrefs.cpp:136
QualityPrefs::GetNamesAndLabels
void GetNamesAndLabels()
Definition: QualityPrefs.cpp:108
EnumSetting
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:174
PrefsPanel
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:50
QUALITY_PREFS_PLUGIN_SYMBOL
#define QUALITY_PREFS_PLUGIN_SYMBOL
Definition: QualityPrefs.h:26
ShuttleGuiBase::AddPrompt
void AddPrompt(const TranslatableString &Prompt, int wrapWidth=0)
Right aligned text string.
Definition: ShuttleGui.cpp:231
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:497
eIsCreatingFromPrefs
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:45
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:915
safenew
#define safenew
Definition: MemoryX.h:8
Resample::BestMethodSetting
static EnumSetting< int > BestMethodSetting
Definition: Resample.h:45
END_EVENT_TABLE
END_EVENT_TABLE()
ShuttleGuiBase::TieChoice
wxChoice * TieChoice(const TranslatableString &Prompt, TranslatableString &Selected, const TranslatableStrings &choices)
Definition: ShuttleGui.cpp:1701
QualityPrefs::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: QualityPrefs.cpp:69
Dither::FastSetting
static EnumSetting< DitherType > FastSetting
Definition: Dither.h:28
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:638
QualityPrefs::HelpPageName
wxString HelpPageName() override
Definition: QualityPrefs.cpp:79