Audacity 3.2.0
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
21#include "TracksPrefs.h"
22#include "MemoryX.h"
23
24//#include <algorithm>
25//#include <wx/defs.h>
26
27#include "Prefs.h"
28#include "ShuttleGui.h"
29#include "WaveTrack.h"
30
32
33namespace {
35 {
36 return wxT("/AudioIO/PinnedHead");
37 }
38
40 {
41 return false;
42 }
43
45 {
46 return wxT("/AudioIO/PinnedHeadPosition");
47 }
48
50 {
51 return 0.5;
52 }
53}
54
55
56namespace {
57 const auto waveformScaleKey = wxT("/GUI/DefaultWaveformScaleChoice");
58 const auto dbLogValueString = wxT("dB");
59 const auto dbLinValueString = wxT("dBLin");
60}
61
64 {
65 { wxT("Linear"), XO("Linear (amp)") },
66 { dbLogValueString, XO("Logarithmic (dB)") },
67 { dbLinValueString, XO("Linear (dB)") },
68 },
69
70 0, // linear
71
72 {
76 }
77};
78
80// There is a complicated migration history here!
81namespace {
82 const auto key0 = wxT("/GUI/DefaultViewMode");
83 const auto key1 = wxT("/GUI/DefaultViewModeNew");
84 const auto key2 = wxT("/GUI/DefaultViewModeChoice");
85 const auto key3 = wxT("/GUI/DefaultViewModeChoiceNew");
86
87 const wxString obsoleteValue{ wxT("WaveformDB") };
88};
89
91 : public EnumSetting< WaveTrackViewConstants::Display > {
92public:
94
95 void Migrate( wxString &value ) override
96 {
97 // Special logic for this preference which was three times migrated!
98
99 // PRL: Bugs 1043, 1044
100 // 2.1.1 writes a NEW key for this preference, which got NEW values,
101 // to avoid confusing version 2.1.0 if it reads the preference file afterwards.
102 // Prefer the NEW preference key if it is present
103
104 static const EnumValueSymbol waveformSymbol{ XO("Waveform") };
105 static const EnumValueSymbol spectrumSymbol{ XO("Spectrogram") };
106
108 int oldMode;
109 wxString newValue;
110 auto stringValue =
112 switch ( display ) {
114 return spectrumSymbol.Internal();
116 return obsoleteValue;
117 default:
118 return waveformSymbol.Internal();
119 }
120 };
121
122 if ( gPrefs->Read(key0, // The very old key
123 &oldMode,
126 newValue = stringValue( viewMode );
127 }
128 else if ( gPrefs->Read(key1,
129 &oldMode,
131 viewMode = static_cast<WaveTrackViewConstants::Display>( oldMode );
132 newValue = stringValue( viewMode );
133 }
134 else
135 gPrefs->Read( key2, &newValue );
136
137 if ( !gPrefs->Read( key3, &value ) ) {
138 if (newValue == obsoleteValue) {
139 newValue = waveformSymbol.Internal();
141 }
142
143 Write( value = newValue );
144 gPrefs->Flush();
145 return;
146 }
147 }
148};
149
151{
152 // Do a delayed computation, so that registration of sub-view types completes
153 // first
154 const auto &types = WaveTrackSubViewType::All();
155 auto symbols = transform_container< EnumValueSymbols >(
156 types, std::mem_fn( &WaveTrackSubViewType::name ) );
157 auto ids = transform_container< std::vector< WaveTrackSubViewType::Display > >(
158 types, std::mem_fn( &WaveTrackSubViewType::id ) );
159
160 // Special entry for multi
161 symbols.push_back( WaveTrackViewConstants::MultiViewSymbol );
162 ids.push_back( WaveTrackViewConstants::MultiView );
163
164 return {
165 key3,
166 symbols,
167 0, // Waveform
168 ids
169 };
170}
171
173{
174 return ViewModeSetting().ReadEnum();
175}
176
178{
179 return waveformScaleSetting.ReadEnum();
180}
181
185 wxT("/GUI/SampleViewChoice"),
186 {
187 { wxT("ConnectDots"), XO("Connect dots") },
188 { wxT("StemPlot"), XO("Stem plot") }
189 },
190 1, // StemPlot
191
192 // for migrating old preferences:
193 {
196 },
197 wxT("/GUI/SampleView")
198};
199
201{
202 return sampleDisplaySetting.ReadEnum();
203}
204
206static const std::initializer_list<EnumValueSymbol> choicesZoom{
207 { wxT("FitToWidth"), XO("Fit to Width") },
208 { wxT("ZoomToSelection"), XO("Zoom to Selection") },
209 { wxT("ZoomDefault"), XO("Zoom Default") },
210 { XO("Minutes") },
211 { XO("Seconds") },
212 { wxT("FifthsOfSeconds"), XO("5ths of Seconds") },
213 { wxT("TenthsOfSeconds"), XO("10ths of Seconds") },
214 { wxT("TwentiethsOfSeconds"), XO("20ths of Seconds") },
215 { wxT("FiftiethsOfSeconds"), XO("50ths of Seconds") },
216 { wxT("HundredthsOfSeconds"), XO("100ths of Seconds") },
217 { wxT("FiveHundredthsOfSeconds"), XO("500ths of Seconds") },
218 { XO("MilliSeconds") },
219 { XO("Samples") },
220 { wxT("FourPixelsPerSample"), XO("4 Pixels per Sample") },
221 { wxT("MaxZoom"), XO("Max Zoom") },
222};
223static auto enumChoicesZoom = {
239};
240
242 wxT("/GUI/ZoomPreset1Choice"),
244 2, // kZoomDefault
245
246 // for migrating old preferences:
248 wxT("/GUI/ZoomPreset1")
249};
250
252 wxT("/GUI/ZoomPreset2Choice"),
254 13, // kZoom4To1
255
256 // for migrating old preferences:
258 wxT("/GUI/ZoomPreset2")
259};
260
262{
263 return zoom1Setting.ReadEnum();
264}
265
267{
268 return zoom2Setting.ReadEnum();
269}
270
272TracksPrefs::TracksPrefs(wxWindow * parent, wxWindowID winid)
273/* i18n-hint: "Tracks" include audio recordings but also other collections of
274 * data associated with a time line, such as sequences of labels, and musical
275 * notes */
276: PrefsPanel(parent, winid, XO("Tracks"))
277{
278 Populate();
279}
280
282{
283}
284
286{
288}
289
291{
292 return XO("Preferences for Tracks");
293}
294
296{
297 return "Tracks_Preferences";
298}
299
301{
302 // Keep view choices and codes in proper correspondence --
303 // we don't display them by increasing integer values.
304
305
306 // How samples are displayed when zoomed in:
307
308
309 //------------------------- Main section --------------------
310 // Now construct the GUI itself.
311 // Use 'eIsCreatingFromPrefs' so that the GUI is
312 // initialised with values from gPrefs.
315 // ----------------------- End of main section --------------
316}
317
319{
320 auto viewModeSetting = ViewModeSetting();
321
322 S.SetBorder(2);
323 S.StartScroller();
324
325 S.StartStatic(XO("Display"));
326 {
327 S.TieCheckBox(XXO("Auto-&fit track height"),
328 {wxT("/GUI/TracksFitVerticallyZoomed"),
329 false});
330 S.TieCheckBox(XXO("Sho&w track name as overlay"),
331 {wxT("/GUI/ShowTrackNameInWaveform"),
332 false});
333#ifdef EXPERIMENTAL_HALF_WAVE
334 S.TieCheckBox(XXO("Use &half-wave display when collapsed"),
335 {wxT("/GUI/CollapseToHalfWave"),
336 false});
337#endif
338#ifdef SHOW_PINNED_UNPINNED_IN_PREFS
339 S.TieCheckBox(XXO("&Pinned Recording/Playback head"),
342#endif
343 S.TieCheckBox(XXO("A&uto-scroll if head unpinned"),
344 {wxT("/GUI/AutoScroll"),
345 true});
346
347 S.AddSpace(10);
348
349 S.StartMultiColumn(2);
350 {
351#ifdef SHOW_PINNED_POSITION_IN_PREFS
352 S.TieNumericTextBox(
353 XXO("Pinned &head position"),
356 30
357 );
358#endif
359
360 S.TieChoice(XXO("Default &view mode:"),
361 viewModeSetting );
362
363 S.TieChoice(XXO("Default Waveform scale:"),
365
366 S.TieChoice(XXO("Display &samples:"),
368
369 S.TieTextBox(XXO("Default audio track &name:"),
371 30);
372 }
373 S.EndMultiColumn();
374 }
375 S.EndStatic();
376
377 S.StartStatic(XO("Zoom Toggle"));
378 {
379 S.StartMultiColumn(4);
380 {
381 S.TieChoice(XXO("Preset 1:"),
382 zoom1Setting );
383
384 S.TieChoice(XXO("Preset 2:"),
385 zoom2Setting );
386 }
387 }
388 S.EndStatic();
389 S.EndScroller();
390}
391
393{
394 // JKC: Cache this setting as it is read many times during drawing, and otherwise causes screen flicker.
395 // Correct solution would be to re-write wxFileConfig to be efficient.
396 if( iPreferencePinned >= 0 )
397 return iPreferencePinned == 1;
398 bool bResult = gPrefs->ReadBool(PinnedHeadPreferenceKey(), PinnedHeadPreferenceDefault());
399 iPreferencePinned = bResult ? 1: 0;
400 return bResult;
401}
402
403void TracksPrefs::SetPinnedHeadPreference(bool value, bool flush)
404{
405 iPreferencePinned = value ? 1 :0;
406 gPrefs->Write(PinnedHeadPreferenceKey(), value);
407 if(flush)
408 gPrefs->Flush();
409}
410
412{
413 auto value = gPrefs->ReadDouble(
416 return std::max(0.0, std::min(1.0, value));
417}
418
420{
421 value = std::max(0.0, std::min(1.0, value));
423 if(flush)
424 gPrefs->Flush();
425}
426
428{
429 // Bug 1583: Clear the caching of the preference pinned state.
433
434 // Bug 1661: Don't store the name for new tracks if the name is the
435 // default in that language.
439 gPrefs->Flush();
440 }
441
443 return true;
444}
445
446namespace{
448 [](wxWindow *parent, wxWindowID winid, AudacityProject *)
449 {
450 wxASSERT(parent); // to justify safenew
451 return safenew TracksPrefs(parent, winid);
452 }
453};
454}
wxT("CloseDown"))
int min(int a, int b)
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
FileConfig * gPrefs
Definition: Prefs.cpp:70
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:46
@ eIsSavingToPrefs
Definition: ShuttleGui.h:47
#define S(N)
Definition: ToChars.cpp:64
static EnumSetting< WaveTrackViewConstants::ZoomPresets > zoom2Setting
static const std::initializer_list< EnumValueSymbol > choicesZoom
static EnumSetting< WaveTrackViewConstants::ZoomPresets > zoom1Setting
static TracksViewModeEnumSetting ViewModeSetting()
static EnumSetting< WaveTrackViewConstants::SampleDisplay > sampleDisplaySetting
static EnumSetting< WaveformSettings::ScaleTypeValues > waveformScaleSetting
Definition: TracksPrefs.cpp:62
static auto enumChoicesZoom
#define TRACKS_PREFS_PLUGIN_SYMBOL
Definition: TracksPrefs.h:25
StringSetting AudioTrackNameSetting
Definition: WaveTrack.cpp:2646
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
bool Write(const wxString &value)
Definition: Prefs.cpp:390
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:507
Enum ReadEnum() const
Definition: Prefs.h:527
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
bool Delete()
Delete the key if present, and return true iff it was.
Definition: Prefs.cpp:508
void Invalidate() override
Definition: Prefs.h:282
const T & GetDefault() const
Definition: Prefs.h:192
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
A PrefsPanel for track display and behavior properties.
Definition: TracksPrefs.h:28
static WaveformSettings::ScaleTypeValues WaveformScaleChoice()
TracksPrefs(wxWindow *parent, wxWindowID winid)
static void SetPinnedHeadPreference(bool value, bool flush=false)
static bool GetPinnedHeadPreference()
TranslatableString GetDescription() const override
ManualPageID HelpPageName() override
If not empty string, the Help button is added below the panel.
static double GetPinnedHeadPositionPreference()
static WaveTrackViewConstants::ZoomPresets Zoom1Choice()
void PopulateOrExchange(ShuttleGui &S) override
static void SetPinnedHeadPositionPreference(double value, bool flush=false)
void Populate()
static int iPreferencePinned
Definition: TracksPrefs.h:54
static WaveTrackViewConstants::ZoomPresets Zoom2Choice()
bool Commit() override
static WaveTrackViewConstants::SampleDisplay SampleViewChoice()
ComponentInterfaceSymbol GetSymbol() const override
static WaveTrackViewConstants::Display ViewModeChoice()
void Migrate(wxString &value) override
Definition: TracksPrefs.cpp:95
Holds a msgid for the translation catalog; may also bind format arguments.
static wxString GetDefaultAudioTrackNamePreference()
Definition: WaveTrack.cpp:164
@ MultiView
"Multi" is special, not really a view type on par with the others.
AUDACITY_DLL_API const EnumValueSymbol MultiViewSymbol
String identifier for a preference for one of each type of view.
Display ConvertLegacyDisplayValue(int oldValue)
const wxChar * PinnedHeadPositionPreferenceKey()
Definition: TracksPrefs.cpp:44
PrefsPanel::Registration sAttachment
static const std::vector< WaveTrackSubViewType > & All()
Discover all registered types.