Audacity  2.2.2
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 #include "../Audacity.h"
19 #include "QualityPrefs.h"
20 
21 #include <wx/defs.h>
22 
23 #include "../AudioIO.h"
24 #include "../Dither.h"
25 #include "../Prefs.h"
26 #include "../Resample.h"
27 #include "../SampleFormat.h"
28 #include "../ShuttleGui.h"
29 #include "../Internat.h"
30 
31 #define ID_SAMPLE_RATE_CHOICE 7001
32 
33 BEGIN_EVENT_TABLE(QualityPrefs, PrefsPanel)
34  EVT_CHOICE(ID_SAMPLE_RATE_CHOICE, QualityPrefs::OnSampleRateChoice)
36 
37 QualityPrefs::QualityPrefs(wxWindow * parent, wxWindowID winid)
38 /* i18n-hint: meaning accuracy in reproduction of sounds */
39 : PrefsPanel(parent, winid, _("Quality"))
40 {
41  Populate();
42 }
43 
45 {
46 }
47 
49 {
50  // First any pre-processing for constructing the GUI.
52  gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
54  44100);
55 
56  //------------------------- Main section --------------------
57  // Now construct the GUI itself.
58  // Use 'eIsCreatingFromPrefs' so that the GUI is
59  // initialised with values from gPrefs.
62  // ----------------------- End of main section --------------
63 
64  wxCommandEvent e;
65  OnSampleRateChoice(e); // Enable/disable the control.
66 }
67 
73 {
74  //------------ Dither Names
75  mDitherNames.Add(_("None")); mDitherLabels.push_back(Dither::none);
76  mDitherNames.Add(_("Rectangle")); mDitherLabels.push_back(Dither::rectangle);
77  mDitherNames.Add(_("Triangle")); mDitherLabels.push_back(Dither::triangle);
78  mDitherNames.Add(_("Shaped")); mDitherLabels.push_back(Dither::shaped);
79 
80  //------------ Sample Rate Names
81  // JKC: I don't understand the following comment.
82  // Can someone please explain or correct it?
83  // XXX: This should use a previously changed, but not yet saved
84  // sound card setting from the "I/O" preferences tab.
85  // LLL: It means that until the user clicks "Ok" in preferences, the
86  // GetSupportedSampleRates() call should use the devices they
87  // may have changed on the Audio I/O page. As coded, the sample
88  // rates it will return could be completely invalid as they will
89  // be what's supported by the devices that were selected BEFORE
90  // coming into preferences.
91  //
92  // GetSupportedSampleRates() allows passing in device names, but
93  // how do you get at them as they are on the Audio I/O page????
94  for (int i = 0; i < AudioIO::NumStandardRates; i++) {
95  int iRate = AudioIO::StandardRates[i];
96  mSampleRateLabels.push_back(iRate);
97  mSampleRateNames.Add(wxString::Format(wxT("%i Hz"), iRate));
98  }
99 
100  mSampleRateNames.Add(_("Other..."));
101 
102  // The label for the 'Other...' case can be any value at all.
103  mSampleRateLabels.push_back(44100); // If chosen, this value will be overwritten
104 
105  //------------- Sample Format Names
106  mSampleFormatNames.Add(wxT("16-bit")); mSampleFormatLabels.push_back(int16Sample);
107  mSampleFormatNames.Add(wxT("24-bit")); mSampleFormatLabels.push_back(int24Sample);
108  mSampleFormatNames.Add(wxT("32-bit float")); mSampleFormatLabels.push_back(floatSample);
109 
110  //------------- Converter Names
111  int numConverters = Resample::GetNumMethods();
112  for (int i = 0; i < numConverters; i++) {
114  mConverterLabels.push_back(i);
115  }
116 }
117 
119 {
120  S.SetBorder(2);
121  S.StartScroller();
122 
123  S.StartStatic(_("Sampling"));
124  {
125  S.StartMultiColumn(2);
126  {
127  S.AddPrompt(_("Default Sample &Rate:"));
128 
129  S.StartMultiColumn(2);
130  {
131  // If the value in Prefs isn't in the list, then we want
132  // the last item, 'Other...' to be shown.
133  S.SetNoMatchSelector(mSampleRateNames.GetCount() - 1);
134  // First the choice...
135  // We make sure it uses the ID we want, so that we get changes
137  // We make sure we have a pointer to it, so that we can drive it.
138  mSampleRates = S.TieChoice( {},
139  wxT("/SamplingRate/DefaultProjectSampleRate"),
144 
145  // Now do the edit box...
148  15);
149  }
150  S.EndHorizontalLay();
151 
152  S.TieChoice(_("Default Sample &Format:"),
153  wxT("/SamplingRate/DefaultProjectSampleFormat"),
154  floatSample,
158  }
159  S.EndMultiColumn();
160  }
161  S.EndStatic();
162 
163  S.StartStatic(_("Real-time Conversion"));
164  {
165  S.StartMultiColumn(2, wxEXPAND);
166  {
167  S.TieChoice(_("Sample Rate Con&verter:"),
173 
174  /* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
175  S.TieChoice(_("&Dither:"),
176  wxT("/Quality/DitherAlgorithm"),
177  Dither::none,
178  mDitherNames,
179  mDitherLabels);
181  }
182  S.EndMultiColumn();
183  }
184  S.EndStatic();
185 
186  S.StartStatic(_("High-quality Conversion"));
187  {
188  S.StartMultiColumn(2);
189  {
190  S.TieChoice(_("Sample Rate Conver&ter:"),
196 
197  /* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
198  S.TieChoice(_("Dit&her:"),
199  wxT("/Quality/HQDitherAlgorithm"),
201  mDitherNames,
202  mDitherLabels);
204  }
205  S.EndMultiColumn();
206  }
207  S.EndStatic();
208  S.EndScroller();
209 
210 }
211 
214 void QualityPrefs::OnSampleRateChoice(wxCommandEvent & WXUNUSED(e))
215 {
216  int sel = mSampleRates->GetSelection();
217  mOtherSampleRate->Enable(sel == (int)mSampleRates->GetCount() - 1);
218 }
219 
221 {
222  ShuttleGui S(this, eIsSavingToPrefs);
224 
225  // The complex compound control may have value 'other' in which case the
226  // value in prefs comes from the second field.
227  if (mOtherSampleRate->IsEnabled()) {
228  gPrefs->Write(wxT("/SamplingRate/DefaultProjectSampleRate"), mOtherSampleRateValue);
229  gPrefs->Flush();
230  }
231 
232  // Tell CopySamples() to use these ditherers now
233  InitDitherers();
234 
235  return true;
236 }
237 
239 {
240  return "Quality_Preferences";
241 }
242 
243 PrefsPanel *QualityPrefsFactory::operator () (wxWindow *parent, wxWindowID winid)
244 {
245  wxASSERT(parent); // to justify safenew
246  return safenew QualityPrefs(parent, winid);
247 }
void PopulateOrExchange(ShuttleGui &S)
wxChoice * TieChoice(const wxString &Prompt, WrappedType &WrappedRef, const wxArrayString *pChoices)
#define ID_SAMPLE_RATE_CHOICE
wxArrayString mSampleRateNames
Definition: QualityPrefs.h:43
std::vector< int > mSampleRateLabels
Definition: QualityPrefs.h:44
void SetNoMatchSelector(int iSelector)
Definition: ShuttleGui.h:253
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
std::vector< int > mDitherLabels
Definition: QualityPrefs.h:42
static int GetNumMethods()
Definition: Resample.cpp:53
void GetNamesAndLabels()
static wxString GetMethodName(int index)
Definition: Resample.cpp:55
void EndMultiColumn()
std::vector< int > mSampleFormatLabels
Definition: QualityPrefs.h:46
virtual ~QualityPrefs()
static int GetOptimalSupportedSampleRate()
Get a supported sample rate which can be used a an optimal default.
Definition: AudioIO.cpp:3150
void EndScroller()
Definition: ShuttleGui.cpp:770
wxArrayString mDitherNames
Definition: QualityPrefs.h:41
wxString HelpPageName() override
wxChoice * mSampleRates
Definition: QualityPrefs.h:50
#define safenew
Definition: Audacity.h:223
void EndHorizontalLay()
Definition: ShuttleGui.cpp:975
static const wxString GetBestMethodKey()
Definition: Resample.cpp:86
void AddPrompt(const wxString &Prompt)
Right aligned text string.
Definition: ShuttleGui.cpp:215
void SetSizeHints(int minX=-1, int minY=-1)
void InitDitherers()
static const wxString GetFastMethodKey()
Definition: Resample.cpp:81
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
static int GetBestMethodDefault()
Definition: Resample.cpp:92
PrefsPanel * operator()(wxWindow *parent, wxWindowID winid) override
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:733
A PrefsPanel used for setting audio quality.
Definition: QualityPrefs.h:26
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:998
bool Commit() override
ShuttleGui & Id(int id)
int mOtherSampleRateValue
Definition: QualityPrefs.h:52
wxTextCtrl * mOtherSampleRate
Definition: QualityPrefs.h:51
wxTextCtrl * TieNumericTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
std::vector< int > mConverterLabels
Definition: QualityPrefs.h:48
static int GetFastMethodDefault()
Definition: Resample.cpp:91
Used within the PrefsDialog, classes derived from this class include AudioIOPrefs, BatchPrefs, DirectoriesPrefs, FileFormatPrefs, GUIPrefs, KeyConfigPrefs, MousePrefs, QualityPrefs, SpectrumPrefs and ThemePrefs.
Definition: PrefsPanel.h:43
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
void OnSampleRateChoice(wxCommandEvent &e)
wxArrayString mSampleFormatNames
Definition: QualityPrefs.h:45
static const int NumStandardRates
How many standard sample rates there are.
Definition: AudioIO.h:385
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:701
wxArrayString mConverterNames
Definition: QualityPrefs.h:47
static const int StandardRates[]
Array of common audio sample rates.
Definition: AudioIO.h:383
END_EVENT_TABLE()
void SetBorder(int Border)
Definition: ShuttleGui.h:251