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 #include "QualitySettings.h"
21 
22 #include <wx/choice.h>
23 #include <wx/defs.h>
24 #include <wx/textctrl.h>
25 
26 #include "../AudioIOBase.h"
27 #include "Dither.h"
28 #include "Prefs.h"
29 #include "Resample.h"
30 #include "../ShuttleGui.h"
31 
32 #define ID_SAMPLE_RATE_CHOICE 7001
33 
35 BEGIN_EVENT_TABLE(QualityPrefs, PrefsPanel)
38 
39 QualityPrefs::QualityPrefs(wxWindow * parent, wxWindowID winid)
40 /* i18n-hint: meaning accuracy in reproduction of sounds */
41 : PrefsPanel(parent, winid, XO("Quality"))
42 {
43  Populate();
44 }
45 
47 {
48 }
49 
51 {
53 }
54 
56 {
57  return XO("Preferences for Quality");
58 }
59 
61 {
62  return "Quality_Preferences";
63 }
64 
66 {
67  // First any pre-processing for constructing the GUI.
70 
71  //------------------------- Main section --------------------
72  // Now construct the GUI itself.
73  // Use 'eIsCreatingFromPrefs' so that the GUI is
74  // initialised with values from gPrefs.
77  // ----------------------- End of main section --------------
78 
79  wxCommandEvent e;
80  OnSampleRateChoice(e); // Enable/disable the control.
81 }
82 
88 {
89  //------------ Sample Rate Names
90  // JKC: I don't understand the following comment.
91  // Can someone please explain or correct it?
92  // XXX: This should use a previously changed, but not yet saved
93  // sound card setting from the "I/O" preferences tab.
94  // LLL: It means that until the user clicks "Ok" in preferences, the
95  // GetSupportedSampleRates() call should use the devices they
96  // may have changed on the Audio I/O page. As coded, the sample
97  // rates it will return could be completely invalid as they will
98  // be what's supported by the devices that were selected BEFORE
99  // coming into preferences.
100  //
101  // GetSupportedSampleRates() allows passing in device names, but
102  // how do you get at them as they are on the Audio I/O page????
103  for (int i = 0; i < AudioIOBase::NumStandardRates; i++) {
104  int iRate = AudioIOBase::StandardRates[i];
105  mSampleRateLabels.push_back(iRate);
106  mSampleRateNames.push_back( XO("%i Hz").Format( iRate ) );
107  }
108 
109  mSampleRateNames.push_back(XO("Other..."));
110 
111  // The label for the 'Other...' case can be any value at all.
112  mSampleRateLabels.push_back(44100); // If chosen, this value will be overwritten
113 }
114 
116 {
117  S.SetBorder(2);
118  S.StartScroller();
119 
120  S.StartStatic(XO("Sampling"));
121  {
122  S.StartMultiColumn(2);
123  {
124  S.AddPrompt(XXO("Default Sample &Rate:"));
125 
126  S.StartMultiColumn(2);
127  {
128  // First the choice...
129  // We make sure it uses the ID we want, so that we get changes
130  // We make sure we have a pointer to it, so that we can drive it.
131  mSampleRates =
132  S
134  .TieNumberAsChoice( {},
138  // If the value in Prefs isn't in the list, then we want
139  // the last item, 'Other...' to be shown.
140  mSampleRateNames.size() - 1 );
141 
142  // Now do the edit box...
145  15);
146  }
147  S.EndHorizontalLay();
148 
149  S
150  .TieChoice( XXO("Default Sample &Format:"),
152  }
153  S.EndMultiColumn();
154  }
155  S.EndStatic();
156 
157  S.StartStatic(XO("Real-time Conversion"));
158  {
159  S.StartMultiColumn(2, wxEXPAND);
160  {
161  S.TieChoice(XXO("Sample Rate Con&verter:"),
163 
164  /* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
165  S.TieChoice(XXO("&Dither:"),
167  }
168  S.EndMultiColumn();
169  }
170  S.EndStatic();
171 
172  S.StartStatic(XO("High-quality Conversion"));
173  {
174  S.StartMultiColumn(2);
175  {
176  S.TieChoice(XXO("Sample Rate Conver&ter:"),
178 
179  /* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
180  S.TieChoice(XXO("Dit&her:"),
182  }
183  S.EndMultiColumn();
184  }
185  S.EndStatic();
186  S.EndScroller();
187 
188 }
189 
192 void QualityPrefs::OnSampleRateChoice(wxCommandEvent & WXUNUSED(e))
193 {
194  int sel = mSampleRates->GetSelection();
195  mOtherSampleRate->Enable(sel == (int)mSampleRates->GetCount() - 1);
196 }
197 
199 {
200  ShuttleGui S(this, eIsSavingToPrefs);
202 
203  // The complex compound control may have value 'other' in which case the
204  // value in prefs comes from the second field.
205  if (mOtherSampleRate->IsEnabled()) {
207  gPrefs->Flush();
208  }
209 
210  // Tell CopySamples() to use these ditherers now
211  InitDitherers();
212 
213  return true;
214 }
215 
216 namespace{
218  [](wxWindow *parent, wxWindowID winid, AudacityProject *)
219  {
220  wxASSERT(parent); // to justify safenew
221  return safenew QualityPrefs(parent, winid);
222  }
223 };
224 }
225 
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
QualityPrefs::mSampleRateNames
TranslatableStrings mSampleRateNames
Definition: QualityPrefs.h:45
AudioIOBase::StandardRates
static const int StandardRates[]
Array of common audio sample rates.
Definition: AudioIOBase.h:202
QualityPrefs
A PrefsPanel used for setting audio quality.
Definition: QualityPrefs.h:29
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
Dither::BestSetting
static EnumSetting< DitherType > BestSetting
Definition: Dither.h:29
QualityPrefs::mOtherSampleRate
wxTextCtrl * mOtherSampleRate
Definition: QualityPrefs.h:49
Resample::FastMethodSetting
static EnumSetting< int > FastMethodSetting
Definition: Resample.h:42
Setting::Write
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:172
Format
Abstract base class used in importing a file.
QualitySettings::SampleFormatSetting
AUDACITY_DLL_API EnumSetting< sampleFormat > SampleFormatSetting
Definition: QualitySettings.cpp:20
PrefsPanel::Registration
Definition: PrefsPanel.h:84
XO
#define XO(s)
Definition: Internat.h:31
ShuttleGuiBase::TieNumberAsChoice
virtual wxChoice * TieNumberAsChoice(const TranslatableString &Prompt, const IntSetting &Setting, const TranslatableStrings &Choices, const std::vector< int > *pInternalChoices=nullptr, int iNoMatchSelector=0)
Definition: ShuttleGui.cpp:2011
ID_SAMPLE_RATE_CHOICE
#define ID_SAMPLE_RATE_CHOICE
Definition: QualityPrefs.cpp:32
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
QualityPrefs::mSampleRateLabels
std::vector< int > mSampleRateLabels
Definition: QualityPrefs.h:46
QualityPrefs::GetDescription
TranslatableString GetDescription() override
Definition: QualityPrefs.cpp:55
AudioIOBase::NumStandardRates
static const int NumStandardRates
How many standard sample rates there are.
Definition: AudioIOBase.h:204
QualityPrefs.h
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2274
Setting::Read
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:128
ShuttleGuiBase::EndScroller
void EndScroller()
Definition: ShuttleGui.cpp:971
QualityPrefs::mOtherSampleRateValue
int mOtherSampleRateValue
Definition: QualityPrefs.h:50
XXO
#define XXO(s)
Definition: Internat.h:44
ShuttleGuiBase::StartScroller
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:938
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1177
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
QualityPrefs::mSampleRates
wxChoice * mSampleRates
Definition: QualityPrefs.h:48
QualityPrefs::OnSampleRateChoice
void OnSampleRateChoice(wxCommandEvent &e)
Definition: QualityPrefs.cpp:192
QualitySettings::DefaultSampleRate
AUDACITY_DLL_API IntSetting DefaultSampleRate
Definition: QualitySettings.cpp:15
QualityPrefs::HelpPageName
ManualPageID HelpPageName() override
If not empty string, the Help button is added below the panel.
Definition: QualityPrefs.cpp:60
ShuttleGuiBase::TieNumericTextBox
wxTextCtrl * TieNumericTextBox(const TranslatableString &Prompt, int &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1673
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:893
eIsSavingToPrefs
@ eIsSavingToPrefs
Definition: ShuttleGui.h:48
QualityPrefs::Populate
void Populate()
Definition: QualityPrefs.cpp:65
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
QualitySettings.h
QualityPrefs::Commit
bool Commit() override
Definition: QualityPrefs.cpp:198
QualityPrefs::~QualityPrefs
virtual ~QualityPrefs()
Definition: QualityPrefs.cpp:46
TaggedIdentifier< ManualPageIDTag >
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:113
InitDitherers
void InitDitherers()
Definition: SampleFormat.cpp:53
anonymous_namespace{QualityPrefs.cpp}::sAttachment
PrefsPanel::Registration sAttachment
Definition: QualityPrefs.cpp:217
QualityPrefs::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: QualityPrefs.cpp:115
QualityPrefs::GetNamesAndLabels
void GetNamesAndLabels()
Definition: QualityPrefs.cpp:87
PrefsPanel
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
QUALITY_PREFS_PLUGIN_SYMBOL
#define QUALITY_PREFS_PLUGIN_SYMBOL
Definition: QualityPrefs.h:26
Prefs.h
ShuttleGuiBase::AddPrompt
void AddPrompt(const TranslatableString &Prompt, int wrapWidth=0)
Right aligned text string.
Definition: ShuttleGui.cpp:238
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
eIsCreatingFromPrefs
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:47
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:922
safenew
#define safenew
Definition: MemoryX.h:10
Resample::BestMethodSetting
static EnumSetting< int > BestMethodSetting
Definition: Resample.h:43
END_EVENT_TABLE
END_EVENT_TABLE()
ShuttleGuiBase::TieChoice
wxChoice * TieChoice(const TranslatableString &Prompt, TranslatableString &Selected, const TranslatableStrings &choices)
Definition: ShuttleGui.cpp:1727
QualityPrefs::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: QualityPrefs.cpp:50
Dither::FastSetting
static EnumSetting< DitherType > FastSetting
Definition: Dither.h:28
Resample.h
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
Dither.h