Audacity  2.2.2
TracksPrefs.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  TracksPrefs.cpp
6 
7  Brian Gunlogson
8  Joshua Haberman
9  Dominic Mazzoni
10  James Crook
11 
12 
13 *******************************************************************//*******************************************************************/
19 
20 #include "../Audacity.h"
21 #include "TracksPrefs.h"
22 
23 //#include <algorithm>
24 //#include <wx/defs.h>
25 
26 #include "../Prefs.h"
27 #include "../ShuttleGui.h"
28 #include "../WaveTrack.h"
29 
30 #include "../Experimental.h"
31 #include "../Internat.h"
32 
34 
35 namespace {
36  const wxChar *PinnedHeadPreferenceKey()
37  {
38  return wxT("/AudioIO/PinnedHead");
39  }
40 
41  bool PinnedHeadPreferenceDefault()
42  {
43  return false;
44  }
45 }
46 
47 
50  { XO("Waveform") },
51  { wxT("WaveformDB"), XO("Waveform (dB)") },
52  { XO("Spectrogram") }
53 };
54 static const int intChoicesView[] = {
55  (int)(WaveTrack::Waveform),
57  (int)(WaveTrack::Spectrum)
58 };
59 static const size_t nChoicesView = WXSIZEOF(choicesView);
60 static_assert( nChoicesView == WXSIZEOF(intChoicesView), "size mismatch" );
61 
62 static const size_t defaultChoiceView = 0;
63 
65 public:
67  const wxString &key,
68  const IdentInterfaceSymbol symbols[], size_t nSymbols,
69  size_t defaultSymbol,
70 
71  const int intValues[],
72  const wxString &oldKey
73  )
75  key, symbols, nSymbols, defaultSymbol, intValues, oldKey }
76  {}
77 
78  void Migrate( wxString &value ) override
79  {
80  // Special logic for this preference which was twice migrated!
81 
82  // First test for the older but not oldest key:
84  if (!value.empty())
85  return;
86 
87  // PRL: Bugs 1043, 1044
88  // 2.1.1 writes a NEW key for this preference, which got NEW values,
89  // to avoid confusing version 2.1.0 if it reads the preference file afterwards.
90  // Prefer the NEW preference key if it is present
91 
92  int oldMode;
93  gPrefs->Read(wxT("/GUI/DefaultViewMode"), // The very old key
94  &oldMode,
95  (int)(WaveTrack::Waveform));
96  auto viewMode = WaveTrack::ConvertLegacyDisplayValue(oldMode);
97 
98  // Now future-proof 2.1.1 against a recurrence of this sort of bug!
99  viewMode = WaveTrack::ValidateWaveTrackDisplay(viewMode);
100 
101  const_cast<TracksViewModeSetting*>(this)->WriteInt( viewMode );
102  gPrefs->Flush();
103 
104  value = mSymbols[ FindInt(viewMode) ].Internal();
105  }
106 };
107 
109  wxT("/GUI/DefaultViewModeChoice"),
111 
113  wxT("/GUI/DefaultViewModeNew")
114 };
115 
117 {
119 }
120 
123  { wxT("ConnectDots"), XO("Connect dots") },
124  { wxT("StemPlot"), XO("Stem plot") }
125 };
126 static const size_t nChoicesSampleDisplay = WXSIZEOF( choicesSampleDisplay );
127 static const int intChoicesSampleDisplay[] = {
129  (int) WaveTrack::StemPlot
130 };
131 static_assert(
132  nChoicesSampleDisplay == WXSIZEOF(intChoicesSampleDisplay), "size mismatch" );
133 
134 static const size_t defaultChoiceSampleDisplay = 1;
135 
137  wxT("/GUI/SampleViewChoice"),
139 
141  wxT("/GUI/SampleView")
142 };
143 
145 {
147 }
148 
151  { wxT("FitToWidth"), XO("Fit to Width") },
152  { wxT("ZoomToSelection"), XO("Zoom to Selection") },
153  { wxT("ZoomDefault"), XO("Zoom Default") },
154  { XO("Minutes") },
155  { XO("Seconds") },
156  { wxT("FifthsOfSeconds"), XO("5ths of Seconds") },
157  { wxT("TenthsOfSeconds"), XO("10ths of Seconds") },
158  { wxT("TwentiethsOfSeconds"), XO("20ths of Seconds") },
159  { wxT("FiftiethsOfSeconds"), XO("50ths of Seconds") },
160  { wxT("HundredthsOfSeconds"), XO("100ths of Seconds") },
161  { wxT("FiveHundredthsOfSeconds"), XO("500ths of Seconds") },
162  { XO("MilliSeconds") },
163  { XO("Samples") },
164  { wxT("FourPixelsPerSample"), XO("4 Pixels per Sample") },
165  { wxT("MaxZoom"), XO("Max Zoom") },
166 };
167 static const size_t nChoicesZoom = WXSIZEOF( choicesZoom );
168 static const int intChoicesZoom[] = {
184 };
185 static_assert( nChoicesZoom == WXSIZEOF(intChoicesZoom), "size mismatch" );
186 
187 static const size_t defaultChoiceZoom1 = 2; // kZoomDefault
188 
190  wxT("/GUI/ZoomPreset1Choice"),
192 
194  wxT("/GUI/ZoomPreset1")
195 };
196 
197 static const size_t defaultChoiceZoom2 = 13; // kZoom4To1
198 
200  wxT("/GUI/ZoomPreset2Choice"),
202 
204  wxT("/GUI/ZoomPreset2")
205 };
206 
208 {
210 }
211 
213 {
215 }
216 
218 TracksPrefs::TracksPrefs(wxWindow * parent, wxWindowID winid)
219 /* i18n-hint: "Tracks" include audio recordings but also other collections of
220  * data associated with a time line, such as sequences of labels, and musical
221  * notes */
222 : PrefsPanel(parent, winid, _("Tracks"))
223 {
224  Populate();
225 }
226 
228 {
229 }
230 
232 {
233  // Keep view choices and codes in proper correspondence --
234  // we don't display them by increasing integer values.
235 
236 
237  // How samples are displayed when zoomed in:
238 
239 
240  //------------------------- Main section --------------------
241  // Now construct the GUI itself.
242  // Use 'eIsCreatingFromPrefs' so that the GUI is
243  // initialised with values from gPrefs.
246  // ----------------------- End of main section --------------
247 }
248 
250 {
251  S.SetBorder(2);
252  S.StartScroller();
253 
254  S.StartStatic(_("Display"));
255  {
256  S.TieCheckBox(_("&Pinned Recording/Playback head"),
257  PinnedHeadPreferenceKey(),
258  PinnedHeadPreferenceDefault());
259  S.TieCheckBox(_("A&uto-scroll if head unpinned"),
260  wxT("/GUI/AutoScroll"),
261  true);
262  S.TieCheckBox(_("Auto-&fit track height"),
263  wxT("/GUI/TracksFitVerticallyZoomed"),
264  false);
265  S.TieCheckBox(_("Sho&w audio track name as overlay"),
266  wxT("/GUI/ShowTrackNameInWaveform"),
267  false);
268 #ifdef EXPERIMENTAL_HALF_WAVE
269  S.TieCheckBox(_("Use &half-wave display when collapsed"),
270  wxT("/GUI/CollapseToHalfWave"),
271  false);
272 #endif
273 
274  S.AddSpace(10);
275 
276  S.StartMultiColumn(2);
277  {
278  S.TieChoice(_("Default &view mode:"),
279  viewModeSetting );
280 
281  S.TieChoice(_("Display &samples:"),
283 
284  S.TieTextBox(_("Default audio track &name:"),
285  wxT("/GUI/TrackNames/DefaultTrackName"),
286  _("Audio Track"),
287  30);
288  }
289  S.EndMultiColumn();
290  }
291  S.EndStatic();
292 
293  S.StartStatic(_("Zoom Toggle"));
294  {
295  S.StartMultiColumn(4);
296  {
297  S.TieChoice(_("Preset 1:"),
298  zoom1Setting );
299 
300  S.TieChoice(_("Preset 2:"),
301  zoom2Setting );
302  }
303  }
304  S.EndStatic();
305  S.EndScroller();
306 }
307 
309 {
310  // JKC: Cache this setting as it is read many times during drawing, and otherwise causes screen flicker.
311  // Correct solution would be to re-write wxFileConfig to be efficient.
312  if( iPreferencePinned >= 0 )
313  return iPreferencePinned == 1;
314  bool bResult = gPrefs->ReadBool(PinnedHeadPreferenceKey(), PinnedHeadPreferenceDefault());
315  iPreferencePinned = bResult ? 1: 0;
316  return bResult;
317 }
318 
319 void TracksPrefs::SetPinnedHeadPreference(bool value, bool flush)
320 {
321  iPreferencePinned = value ? 1 :0;
322  gPrefs->Write(PinnedHeadPreferenceKey(), value);
323  if(flush)
324  gPrefs->Flush();
325 }
326 
328 {
329  const auto name =
330  gPrefs->Read(wxT("/GUI/TrackNames/DefaultTrackName"), wxT(""));
331 
332  if (name.empty() || ( name == "Audio Track" ))
333  // When nothing was specified,
334  // the default-default is whatever translation of...
335  /* i18n-hint: The default name for an audio track. */
336  return _("Audio Track");
337  else
338  return name;
339 }
340 
342 {
343  // Bug 1583: Clear the caching of the preference pinned state.
344  iPreferencePinned = -1;
345  ShuttleGui S(this, eIsSavingToPrefs);
347 
348  // Bug 1661: Don't store the name for new tracks if the name is the
349  // default in that language.
350  if (GetDefaultAudioTrackNamePreference() == _("Audio Track")) {
351  gPrefs->DeleteEntry(wxT("/GUI/TrackNames/DefaultTrackName"));
352  gPrefs->Flush();
353  }
354 
355  return true;
356 }
357 
359 {
360  return "Tracks_Preferences";
361 }
362 
363 PrefsPanel *TracksPrefsFactory::operator () (wxWindow *parent, wxWindowID winid)
364 {
365  wxASSERT(parent); // to justify safenew
366  return safenew TracksPrefs(parent, winid);
367 }
wxChoice * TieChoice(const wxString &Prompt, WrappedType &WrappedRef, const wxArrayString *pChoices)
PrefsPanel * operator()(wxWindow *parent, wxWindowID winid) override
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
TracksPrefs(wxWindow *parent, wxWindowID winid)
void Populate()
virtual int ReadInt() const
Definition: Prefs.cpp:419
static const IdentInterfaceSymbol choicesSampleDisplay[]
static void SetPinnedHeadPreference(bool value, bool flush=false)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
static const int intChoicesSampleDisplay[]
const IdentInterfaceSymbol * mSymbols
Definition: Prefs.h:96
static WaveTrackDisplay ConvertLegacyDisplayValue(int oldValue)
Definition: WaveTrack.cpp:259
A PrefsPanel for track display and behavior properties.
Definition: TracksPrefs.h:27
void Migrate(wxString &value) override
Definition: TracksPrefs.cpp:78
static wxString GetDefaultAudioTrackNamePreference()
void EndMultiColumn()
static const size_t nChoicesSampleDisplay
static TracksViewModeSetting viewModeSetting
int WaveTrackDisplay
Definition: WaveTrack.h:531
#define XO(s)
Definition: Internat.h:33
void EndScroller()
Definition: ShuttleGui.cpp:828
static EncodedEnumSetting zoom1Setting
bool Commit() override
static const size_t defaultChoiceZoom2
#define safenew
Definition: Audacity.h:230
static const size_t defaultChoiceView
Definition: TracksPrefs.cpp:62
static WaveTrack::ZoomPresets Zoom2Choice()
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:795
static EncodedEnumSetting zoom2Setting
static WaveTrack::SampleDisplay SampleViewChoice()
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
static WaveTrackDisplay ValidateWaveTrackDisplay(WaveTrackDisplay display)
Definition: WaveTrack.cpp:293
static const int intChoicesZoom[]
static const size_t defaultChoiceSampleDisplay
TracksViewModeSetting(const wxString &key, const IdentInterfaceSymbol symbols[], size_t nSymbols, size_t defaultSymbol, const int intValues[], const wxString &oldKey)
Definition: TracksPrefs.cpp:66
static WaveTrack::WaveTrackDisplay ViewModeChoice()
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
static const size_t nChoicesView
Definition: TracksPrefs.cpp:59
bool WriteInt(int code)
Definition: Prefs.cpp:457
static const size_t defaultChoiceZoom1
Used within the PrefsDialog, classes derived from this class include AudioIOPrefs, BatchPrefs, DirectoriesPrefs, FileFormatPrefs, GUIPrefs, KeyConfigPrefs, MousePrefs, QualityPrefs, SpectrumPrefs and ThemePrefs.
Definition: PrefsPanel.h:45
_("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 nChoicesZoom
wxCheckBox * TieCheckBox(const wxString &Prompt, WrappedType &WrappedRef)
const wxChar * name
Definition: Distortion.cpp:94
static bool GetPinnedHeadPreference()
const wxString & Internal() const
void PopulateOrExchange(ShuttleGui &S) override
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:763
static WaveTrack::ZoomPresets Zoom1Choice()
static const int intChoicesView[]
Definition: TracksPrefs.cpp:54
static const IdentInterfaceSymbol choicesView[]
Definition: TracksPrefs.cpp:49
wxSizerItem * AddSpace(int width, int height)
wxString HelpPageName() override
void SetBorder(int Border)
Definition: ShuttleGui.h:286
static const IdentInterfaceSymbol choicesZoom[]
size_t FindInt(int code) const
Definition: Prefs.cpp:429
static EncodedEnumSetting sampleDisplaySetting
static int iPreferencePinned
Definition: TracksPrefs.h:49
wxTextCtrl * TieTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
void Migrate(wxString &) override
Definition: Prefs.cpp:439