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 dbValueString = wxT("dB");
59}
60
63 {
64 { XO("Linear") },
65 { dbValueString, XO("Logarithmic (dB)") },
66 },
67
68 0, // linear
69
70 {
73 }
74};
75
77// There is a complicated migration history here!
78namespace {
79 const auto key0 = wxT("/GUI/DefaultViewMode");
80 const auto key1 = wxT("/GUI/DefaultViewModeNew");
81 const auto key2 = wxT("/GUI/DefaultViewModeChoice");
82 const auto key3 = wxT("/GUI/DefaultViewModeChoiceNew");
83
84 const wxString obsoleteValue{ wxT("WaveformDB") };
85};
86
88 : public EnumSetting< WaveTrackViewConstants::Display > {
89public:
91
92 void Migrate( wxString &value ) override
93 {
94 // Special logic for this preference which was three times migrated!
95
96 // PRL: Bugs 1043, 1044
97 // 2.1.1 writes a NEW key for this preference, which got NEW values,
98 // to avoid confusing version 2.1.0 if it reads the preference file afterwards.
99 // Prefer the NEW preference key if it is present
100
101 static const EnumValueSymbol waveformSymbol{ XO("Waveform") };
102 static const EnumValueSymbol spectrumSymbol{ XO("Spectrogram") };
103
105 int oldMode;
106 wxString newValue;
107 auto stringValue =
109 switch ( display ) {
111 return spectrumSymbol.Internal();
113 return obsoleteValue;
114 default:
115 return waveformSymbol.Internal();
116 }
117 };
118
119 if ( gPrefs->Read(key0, // The very old key
120 &oldMode,
123 newValue = stringValue( viewMode );
124 }
125 else if ( gPrefs->Read(key1,
126 &oldMode,
128 viewMode = static_cast<WaveTrackViewConstants::Display>( oldMode );
129 newValue = stringValue( viewMode );
130 }
131 else
132 gPrefs->Read( key2, &newValue );
133
134 if ( !gPrefs->Read( key3, &value ) ) {
135 if (newValue == obsoleteValue) {
136 newValue = waveformSymbol.Internal();
138 }
139
140 Write( value = newValue );
141 gPrefs->Flush();
142 return;
143 }
144 }
145};
146
148{
149 // Do a delayed computation, so that registration of sub-view types completes
150 // first
151 const auto &types = WaveTrackSubViewType::All();
152 auto symbols = transform_container< EnumValueSymbols >(
153 types, std::mem_fn( &WaveTrackSubViewType::name ) );
154 auto ids = transform_container< std::vector< WaveTrackSubViewType::Display > >(
155 types, std::mem_fn( &WaveTrackSubViewType::id ) );
156
157 // Special entry for multi
158 symbols.push_back( WaveTrackViewConstants::MultiViewSymbol );
159 ids.push_back( WaveTrackViewConstants::MultiView );
160
161 return {
162 key3,
163 symbols,
164 0, // Waveform
165 ids
166 };
167}
168
170{
171 return ViewModeSetting().ReadEnum();
172}
173
175{
176 return waveformScaleSetting.ReadEnum();
177}
178
182 wxT("/GUI/SampleViewChoice"),
183 {
184 { wxT("ConnectDots"), XO("Connect dots") },
185 { wxT("StemPlot"), XO("Stem plot") }
186 },
187 1, // StemPlot
188
189 // for migrating old preferences:
190 {
193 },
194 wxT("/GUI/SampleView")
195};
196
198{
199 return sampleDisplaySetting.ReadEnum();
200}
201
203static const std::initializer_list<EnumValueSymbol> choicesZoom{
204 { wxT("FitToWidth"), XO("Fit to Width") },
205 { wxT("ZoomToSelection"), XO("Zoom to Selection") },
206 { wxT("ZoomDefault"), XO("Zoom Default") },
207 { XO("Minutes") },
208 { XO("Seconds") },
209 { wxT("FifthsOfSeconds"), XO("5ths of Seconds") },
210 { wxT("TenthsOfSeconds"), XO("10ths of Seconds") },
211 { wxT("TwentiethsOfSeconds"), XO("20ths of Seconds") },
212 { wxT("FiftiethsOfSeconds"), XO("50ths of Seconds") },
213 { wxT("HundredthsOfSeconds"), XO("100ths of Seconds") },
214 { wxT("FiveHundredthsOfSeconds"), XO("500ths of Seconds") },
215 { XO("MilliSeconds") },
216 { XO("Samples") },
217 { wxT("FourPixelsPerSample"), XO("4 Pixels per Sample") },
218 { wxT("MaxZoom"), XO("Max Zoom") },
219};
220static auto enumChoicesZoom = {
236};
237
239 wxT("/GUI/ZoomPreset1Choice"),
241 2, // kZoomDefault
242
243 // for migrating old preferences:
245 wxT("/GUI/ZoomPreset1")
246};
247
249 wxT("/GUI/ZoomPreset2Choice"),
251 13, // kZoom4To1
252
253 // for migrating old preferences:
255 wxT("/GUI/ZoomPreset2")
256};
257
259{
260 return zoom1Setting.ReadEnum();
261}
262
264{
265 return zoom2Setting.ReadEnum();
266}
267
269TracksPrefs::TracksPrefs(wxWindow * parent, wxWindowID winid)
270/* i18n-hint: "Tracks" include audio recordings but also other collections of
271 * data associated with a time line, such as sequences of labels, and musical
272 * notes */
273: PrefsPanel(parent, winid, XO("Tracks"))
274{
275 Populate();
276}
277
279{
280}
281
283{
285}
286
288{
289 return XO("Preferences for Tracks");
290}
291
293{
294 return "Tracks_Preferences";
295}
296
298{
299 // Keep view choices and codes in proper correspondence --
300 // we don't display them by increasing integer values.
301
302
303 // How samples are displayed when zoomed in:
304
305
306 //------------------------- Main section --------------------
307 // Now construct the GUI itself.
308 // Use 'eIsCreatingFromPrefs' so that the GUI is
309 // initialised with values from gPrefs.
312 // ----------------------- End of main section --------------
313}
314
316{
317 auto viewModeSetting = ViewModeSetting();
318
319 S.SetBorder(2);
320 S.StartScroller();
321
322 S.StartStatic(XO("Display"));
323 {
324 S.TieCheckBox(XXO("Auto-&fit track height"),
325 {wxT("/GUI/TracksFitVerticallyZoomed"),
326 false});
327 S.TieCheckBox(XXO("Sho&w track name as overlay"),
328 {wxT("/GUI/ShowTrackNameInWaveform"),
329 false});
330#ifdef EXPERIMENTAL_HALF_WAVE
331 S.TieCheckBox(XXO("Use &half-wave display when collapsed"),
332 {wxT("/GUI/CollapseToHalfWave"),
333 false});
334#endif
335#ifdef SHOW_PINNED_UNPINNED_IN_PREFS
336 S.TieCheckBox(XXO("&Pinned Recording/Playback head"),
339#endif
340 S.TieCheckBox(XXO("A&uto-scroll if head unpinned"),
341 {wxT("/GUI/AutoScroll"),
342 true});
343
344 S.AddSpace(10);
345
346 S.StartMultiColumn(2);
347 {
348#ifdef SHOW_PINNED_POSITION_IN_PREFS
349 S.TieNumericTextBox(
350 XXO("Pinned &head position"),
353 30
354 );
355#endif
356
357 S.TieChoice(XXO("Default &view mode:"),
358 viewModeSetting );
359
360 S.TieChoice(XXO("Default Waveform scale:"),
362
363 S.TieChoice(XXO("Display &samples:"),
365
366 S.TieTextBox(XXO("Default audio track &name:"),
368 30);
369 }
370 S.EndMultiColumn();
371 }
372 S.EndStatic();
373
374 S.StartStatic(XO("Zoom Toggle"));
375 {
376 S.StartMultiColumn(4);
377 {
378 S.TieChoice(XXO("Preset 1:"),
379 zoom1Setting );
380
381 S.TieChoice(XXO("Preset 2:"),
382 zoom2Setting );
383 }
384 }
385 S.EndStatic();
386 S.EndScroller();
387}
388
390{
391 // JKC: Cache this setting as it is read many times during drawing, and otherwise causes screen flicker.
392 // Correct solution would be to re-write wxFileConfig to be efficient.
393 if( iPreferencePinned >= 0 )
394 return iPreferencePinned == 1;
395 bool bResult = gPrefs->ReadBool(PinnedHeadPreferenceKey(), PinnedHeadPreferenceDefault());
396 iPreferencePinned = bResult ? 1: 0;
397 return bResult;
398}
399
400void TracksPrefs::SetPinnedHeadPreference(bool value, bool flush)
401{
402 iPreferencePinned = value ? 1 :0;
403 gPrefs->Write(PinnedHeadPreferenceKey(), value);
404 if(flush)
405 gPrefs->Flush();
406}
407
409{
410 auto value = gPrefs->ReadDouble(
413 return std::max(0.0, std::min(1.0, value));
414}
415
417{
418 value = std::max(0.0, std::min(1.0, value));
420 if(flush)
421 gPrefs->Flush();
422}
423
425{
426 // Bug 1583: Clear the caching of the preference pinned state.
430
431 // Bug 1661: Don't store the name for new tracks if the name is the
432 // default in that language.
436 gPrefs->Flush();
437 }
438
440 return true;
441}
442
443namespace{
445 [](wxWindow *parent, wxWindowID winid, AudacityProject *)
446 {
447 wxASSERT(parent); // to justify safenew
448 return safenew TracksPrefs(parent, winid);
449 }
450};
451}
wxT("CloseDown"))
int min(int a, int b)
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define safenew
Definition: MemoryX.h:10
FileConfig * gPrefs
Definition: Prefs.cpp:71
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:48
@ eIsSavingToPrefs
Definition: ShuttleGui.h:49
#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:61
static auto enumChoicesZoom
#define TRACKS_PREFS_PLUGIN_SYMBOL
Definition: TracksPrefs.h:25
static const AudacityProject::AttachedObjects::RegisteredFactory key2
Definition: WaveTrack.cpp:2806
StringSetting AudioTrackNameSetting
Definition: WaveTrack.cpp:2850
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
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:524
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:628
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:92
Holds a msgid for the translation catalog; may also bind format arguments.
static wxString GetDefaultAudioTrackNamePreference()
Definition: WaveTrack.cpp:100
@ 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.