Audacity  2.3.1
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 
34 
36  { wxT("Format16Bit"), XO("16-bit") },
37  { wxT("Format24Bit"), XO("24-bit") },
38  { wxT("Format32BitFloat"), XO("32-bit float") }
39 };
40 static const size_t nChoicesFormat = WXSIZEOF( choicesFormat );
41 static const int intChoicesFormat[] = {
45 };
46 static_assert( nChoicesFormat == WXSIZEOF(intChoicesFormat), "size mismatch" );
47 
48 static const size_t defaultChoiceFormat = 2; // floatSample
49 
51  wxT("/SamplingRate/DefaultProjectSampleFormatChoice"),
53 
55  wxT("/SamplingRate/DefaultProjectSampleFormat"),
56 };
57 
60  { XO("None") },
61  { XO("Rectangle") },
62  { XO("Triangle") },
63  { XO("Shaped") },
64 };
65 static const size_t nChoicesDither = WXSIZEOF( choicesDither );
66 static const int intChoicesDither[] = {
67  (int) DitherType::none,
70  (int) DitherType::shaped,
71 };
72 static_assert(
73  nChoicesDither == WXSIZEOF( intChoicesDither ),
74  "size mismatch"
75 );
76 
77 static const size_t defaultFastDither = 0; // none
78 
80  wxT("Quality/DitherAlgorithmChoice"),
83  wxT("Quality/DitherAlgorithm")
84 };
85 
86 static const size_t defaultBestDither = 3; // shaped
87 
89  wxT("Quality/HQDitherAlgorithmChoice"),
91 
93  wxT("Quality/HQDitherAlgorithm")
94 };
95 
97 BEGIN_EVENT_TABLE(QualityPrefs, PrefsPanel)
98  EVT_CHOICE(ID_SAMPLE_RATE_CHOICE, QualityPrefs::OnSampleRateChoice)
100 
101 QualityPrefs::QualityPrefs(wxWindow * parent, wxWindowID winid)
102 /* i18n-hint: meaning accuracy in reproduction of sounds */
103 : PrefsPanel(parent, winid, _("Quality"))
104 {
105  Populate();
106 }
107 
109 {
110 }
111 
113 {
114  // First any pre-processing for constructing the GUI.
116  gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
118  44100);
119 
120  //------------------------- Main section --------------------
121  // Now construct the GUI itself.
122  // Use 'eIsCreatingFromPrefs' so that the GUI is
123  // initialised with values from gPrefs.
126  // ----------------------- End of main section --------------
127 
128  wxCommandEvent e;
129  OnSampleRateChoice(e); // Enable/disable the control.
130 }
131 
137 {
138  //------------ Sample Rate Names
139  // JKC: I don't understand the following comment.
140  // Can someone please explain or correct it?
141  // XXX: This should use a previously changed, but not yet saved
142  // sound card setting from the "I/O" preferences tab.
143  // LLL: It means that until the user clicks "Ok" in preferences, the
144  // GetSupportedSampleRates() call should use the devices they
145  // may have changed on the Audio I/O page. As coded, the sample
146  // rates it will return could be completely invalid as they will
147  // be what's supported by the devices that were selected BEFORE
148  // coming into preferences.
149  //
150  // GetSupportedSampleRates() allows passing in device names, but
151  // how do you get at them as they are on the Audio I/O page????
152  for (int i = 0; i < AudioIO::NumStandardRates; i++) {
153  int iRate = AudioIO::StandardRates[i];
154  mSampleRateLabels.push_back(iRate);
155  mSampleRateNames.Add(wxString::Format(wxT("%i Hz"), iRate));
156  }
157 
158  mSampleRateNames.Add(_("Other..."));
159 
160  // The label for the 'Other...' case can be any value at all.
161  mSampleRateLabels.push_back(44100); // If chosen, this value will be overwritten
162 }
163 
165 {
166  S.SetBorder(2);
167  S.StartScroller();
168 
169  S.StartStatic(_("Sampling"));
170  {
171  S.StartMultiColumn(2);
172  {
173  S.AddPrompt(_("Default Sample &Rate:"));
174 
175  S.StartMultiColumn(2);
176  {
177  // If the value in Prefs isn't in the list, then we want
178  // the last item, 'Other...' to be shown.
179  S.SetNoMatchSelector(mSampleRateNames.GetCount() - 1);
180  // First the choice...
181  // We make sure it uses the ID we want, so that we get changes
183  // We make sure we have a pointer to it, so that we can drive it.
185  wxT("/SamplingRate/DefaultProjectSampleRate"),
189 
190  // Now do the edit box...
193  15);
194  }
195  S.EndHorizontalLay();
196 
197  S.TieChoice(_("Default Sample &Format:"),
198  formatSetting);
199  }
200  S.EndMultiColumn();
201  }
202  S.EndStatic();
203 
204  S.StartStatic(_("Real-time Conversion"));
205  {
206  S.StartMultiColumn(2, wxEXPAND);
207  {
208  S.TieChoice(_("Sample Rate Con&verter:"),
210 
211  /* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
212  S.TieChoice(_("&Dither:"),
214  }
215  S.EndMultiColumn();
216  }
217  S.EndStatic();
218 
219  S.StartStatic(_("High-quality Conversion"));
220  {
221  S.StartMultiColumn(2);
222  {
223  S.TieChoice(_("Sample Rate Conver&ter:"),
225 
226  /* i18n-hint: technical term for randomization to reduce undesirable resampling artifacts */
227  S.TieChoice(_("Dit&her:"),
229  }
230  S.EndMultiColumn();
231  }
232  S.EndStatic();
233  S.EndScroller();
234 
235 }
236 
239 void QualityPrefs::OnSampleRateChoice(wxCommandEvent & WXUNUSED(e))
240 {
241  int sel = mSampleRates->GetSelection();
242  mOtherSampleRate->Enable(sel == (int)mSampleRates->GetCount() - 1);
243 }
244 
246 {
247  ShuttleGui S(this, eIsSavingToPrefs);
249 
250  // The complex compound control may have value 'other' in which case the
251  // value in prefs comes from the second field.
252  if (mOtherSampleRate->IsEnabled()) {
253  gPrefs->Write(wxT("/SamplingRate/DefaultProjectSampleRate"), mOtherSampleRateValue);
254  gPrefs->Flush();
255  }
256 
257  // Tell CopySamples() to use these ditherers now
258  InitDitherers();
259 
260  return true;
261 }
262 
264 {
265  return "Quality_Preferences";
266 }
267 
268 PrefsPanel *QualityPrefsFactory::operator () (wxWindow *parent, wxWindowID winid)
269 {
270  wxASSERT(parent); // to justify safenew
271  return safenew QualityPrefs(parent, winid);
272 }
273 
275 {
277 }
278 
280 {
282 }
283 
285 {
287 }
288 
wxChoice * TieChoice(const wxString &Prompt, WrappedType &WrappedRef, const wxArrayString *pChoices)
#define ID_SAMPLE_RATE_CHOICE
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
wxArrayString mSampleRateNames
Definition: QualityPrefs.h:48
virtual int ReadInt() const
Definition: Prefs.cpp:420
std::vector< int > mSampleRateLabels
Definition: QualityPrefs.h:49
void SetNoMatchSelector(int iSelector)
Definition: ShuttleGui.h:288
void PopulateOrExchange(ShuttleGui &S) override
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
Definition: Dither.h:18
static DitherType BestDitherChoice()
static const size_t nChoicesDither
void GetNamesAndLabels()
static DitherType FastDitherChoice()
void EndMultiColumn()
static const size_t defaultChoiceFormat
static const int intChoicesFormat[]
virtual ~QualityPrefs()
static EncodedEnumSetting FastMethodSetting
Definition: Resample.h:48
#define XO(s)
Definition: Internat.h:33
static int GetOptimalSupportedSampleRate()
Get a supported sample rate which can be used a an optimal default.
Definition: AudioIO.cpp:3085
void EndScroller()
Definition: ShuttleGui.cpp:836
static const ComponentInterfaceSymbol choicesDither[]
wxString HelpPageName() override
Definition: Dither.h:18
static EncodedEnumSetting bestDitherSetting
wxChoice * mSampleRates
Definition: QualityPrefs.h:51
#define safenew
Definition: Audacity.h:230
static EncodedEnumSetting BestMethodSetting
Definition: Resample.h:49
void EndHorizontalLay()
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
static const size_t defaultFastDither
void AddPrompt(const wxString &Prompt)
Right aligned text string.
Definition: ShuttleGui.cpp:239
static EncodedEnumSetting formatSetting
void InitDitherers()
PrefsPanel * operator()(wxWindow *parent, wxWindowID winid) override
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:803
A PrefsPanel used for setting audio quality.
Definition: QualityPrefs.h:28
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
static const int intChoicesDither[]
sampleFormat
Definition: Types.h:188
bool Commit() override
ShuttleGui & Id(int id)
int mOtherSampleRateValue
Definition: QualityPrefs.h:53
wxTextCtrl * mOtherSampleRate
Definition: QualityPrefs.h:52
wxTextCtrl * TieNumericTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs...
Definition: PrefsPanel.h:50
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
static const size_t nChoicesFormat
virtual wxChoice * TieNumberAsChoice(const wxString &Prompt, const wxString &SettingName, const int Default, const wxArrayString &Choices, const std::vector< int > &InternalChoices)
void OnSampleRateChoice(wxCommandEvent &e)
DitherType
These ditherers are currently available:
Definition: Dither.h:17
static const int NumStandardRates
How many standard sample rates there are.
Definition: AudioIO.h:1039
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:771
static const ComponentInterfaceSymbol choicesFormat[]
static const int StandardRates[]
Array of common audio sample rates.
Definition: AudioIO.h:1037
END_EVENT_TABLE()
static sampleFormat SampleFormatChoice()
static const size_t defaultBestDither
void SetBorder(int Border)
Definition: ShuttleGui.h:286
static EncodedEnumSetting fastDitherSetting