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 
48 TracksPrefs::TracksPrefs(wxWindow * parent)
49 /* i18n-hint: "Tracks" include audio recordings but also other collections of
50  * data associated with a time line, such as sequences of labels, and musical
51  * notes */
52 : PrefsPanel(parent, _("Tracks"))
53 {
54  // Bugs 1043, 1044
55  // First rewrite legacy preferences
56  gPrefs->Write(wxT("/GUI/DefaultViewModeNew"),
58 
59  Populate();
60 }
61 
63 {
64 }
65 
67 {
68  // Keep view choices and codes in proper correspondence --
69  // we don't display them by increasing integer values.
70 
71  mViewChoices.Add(_("Waveform"));
72  mViewCodes.Add((int)(WaveTrack::Waveform));
73 
74  mViewChoices.Add(_("Waveform (dB)"));
76 
77  mViewChoices.Add(_("Spectrogram"));
79 
80 
81  // How samples are displayed when zoomed in:
82 
83  mSampleDisplayChoices.Add(_("Connect dots"));
85 
86  mSampleDisplayChoices.Add(_("Stem plot"));
88 
89  mZoomChoices.Add( _("Fit to Width") );
91  mZoomChoices.Add( _("Zoom to Selection") );
93  mZoomChoices.Add( _("Zoom Default") );
95  mZoomChoices.Add( _("Minutes") );
97  mZoomChoices.Add( _("Seconds") );
99  mZoomChoices.Add( _("MilliSeconds") );
101  mZoomChoices.Add( _("Samples") );
103  mZoomChoices.Add( _("4 Pixels per Sample") );
105  mZoomChoices.Add( _("Max Zoom") );
107 
108 
109 
110  //------------------------- Main section --------------------
111  // Now construct the GUI itself.
112  // Use 'eIsCreatingFromPrefs' so that the GUI is
113  // initialised with values from gPrefs.
116  // ----------------------- End of main section --------------
117 }
118 
120 {
121  S.SetBorder(2);
122  S.StartScroller();
123 
124  S.StartStatic(_("Display"));
125  {
126  S.TieCheckBox(_("&Pinned Recording/Playback head"),
127  PinnedHeadPreferenceKey(),
128  PinnedHeadPreferenceDefault());
129  S.TieCheckBox(_("A&uto-scroll if head unpinned"),
130  wxT("/GUI/AutoScroll"),
131  true);
132  S.TieCheckBox(_("Auto-&fit track height"),
133  wxT("/GUI/TracksFitVerticallyZoomed"),
134  false);
135 
136  S.AddSpace(10);
137 
138  S.StartMultiColumn(2);
139  {
140  S.TieChoice(_("Default &view mode:"),
141  wxT("/GUI/DefaultViewModeNew"),
142  0,
143  mViewChoices,
144  mViewCodes);
146 
147  S.TieChoice(_("Display &samples:"),
148  wxT("/GUI/SampleView"),
149  1,
153 
154  S.TieTextBox(_("Default audio track &name:"),
155  wxT("/GUI/TrackNames/DefaultTrackName"),
156  _("Audio Track"),
157  30);
158  }
159  S.EndMultiColumn();
160 
161  S.TieCheckBox(_("Sho&w audio track name as overlay"),
162  wxT("/GUI/ShowTrackNameInWaveform"),
163  false);
164  }
165  S.EndStatic();
166 
167  S.StartStatic(_("Zoom Toggle"));
168  {
169  S.StartMultiColumn(4);
170  {
171  S.TieChoice(_("Preset 1:"),
172  wxT("/GUI/ZoomPreset1"),
174  mZoomChoices,
175  mZoomCodes);
177 
178  S.TieChoice(_("Preset 2:"),
179  wxT("/GUI/ZoomPreset2"),
181  mZoomChoices,
182  mZoomCodes);
184  }
185  }
186  S.EndStatic();
187  S.EndScroller();
188 }
189 
191 {
192  // JKC: Cache this setting as it is read many times during drawing, and otherwise causes screen flicker.
193  // Correct solution would be to re-write wxFileConfig to be efficient.
194  if( iPreferencePinned >= 0 )
195  return iPreferencePinned == 1;
196  bool bResult = gPrefs->ReadBool(PinnedHeadPreferenceKey(), PinnedHeadPreferenceDefault());
197  iPreferencePinned = bResult ? 1: 0;
198  return bResult;
199 }
200 
201 void TracksPrefs::SetPinnedHeadPreference(bool value, bool flush)
202 {
203  iPreferencePinned = value ? 1 :0;
204  gPrefs->Write(PinnedHeadPreferenceKey(), value);
205  if(flush)
206  gPrefs->Flush();
207 }
208 
210 {
211  const auto name =
212  gPrefs->Read(wxT("/GUI/TrackNames/DefaultTrackName"), wxT(""));
213  if (name.empty())
214  // When nothing was specified,
215  // the default-default is whatever translation of...
216  return _("Audio Track");
217  else
218  return name;
219 }
220 
222 {
223  // Bug 1583: Clear the caching of the preference pinned state.
224  iPreferencePinned = -1;
225  ShuttleGui S(this, eIsSavingToPrefs);
227 
228  if (gPrefs->Read(wxT("/GUI/TrackNames/DefaultTrackName"),
229  _("Audio Track")) == _("Audio Track")) {
230  gPrefs->DeleteEntry(wxT("/GUI/TrackNames/DefaultTrackName"));
231  gPrefs->Flush();
232  }
233 
234  return true;
235 }
236 
238 {
239  return "Tracks_Preferences";
240 }
241 
243 {
244  wxASSERT(parent); // to justify safenew
245  return safenew TracksPrefs(parent);
246 }
wxChoice * TieChoice(const wxString &Prompt, WrappedType &WrappedRef, const wxArrayString *pChoices)
void Populate()
Definition: TracksPrefs.cpp:66
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:366
A PrefsPanel for track display and behavior properties.
Definition: TracksPrefs.h:25
static WaveTrackDisplay FindDefaultViewMode()
Definition: WaveTrack.cpp:231
wxArrayString mSampleDisplayChoices
Definition: TracksPrefs.h:47
static wxString GetDefaultAudioTrackNamePreference()
void EndMultiColumn()
wxArrayInt mViewCodes
Definition: TracksPrefs.h:44
void EndScroller()
Definition: ShuttleGui.cpp:770
bool Commit() override
#define safenew
Definition: Audacity.h:223
void SetSizeHints(int minX=-1, int minY=-1)
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:733
wxArrayString mViewChoices
Definition: TracksPrefs.h:45
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:998
void PopulateOrExchange(ShuttleGui &S)
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 &)
wxArrayString mZoomChoices
Definition: TracksPrefs.h:49
wxCheckBox * TieCheckBox(const wxString &Prompt, WrappedType &WrappedRef)
const wxChar * name
Definition: Distortion.cpp:94
TracksPrefs(wxWindow *parent)
Definition: TracksPrefs.cpp:48
static bool GetPinnedHeadPreference()
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:701
wxArrayInt mSampleDisplayCodes
Definition: TracksPrefs.h:46
wxSizerItem * AddSpace(int width, int height)
wxString HelpPageName() override
void SetBorder(int Border)
Definition: ShuttleGui.h:251
static int iPreferencePinned
Definition: TracksPrefs.h:42
wxTextCtrl * TieTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
wxArrayInt mZoomCodes
Definition: TracksPrefs.h:48
PrefsPanel * Create(wxWindow *parent) override