forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTracksPrefs.cpp
More file actions
461 lines (386 loc) · 12.5 KB
/
Copy pathTracksPrefs.cpp
File metadata and controls
461 lines (386 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/**********************************************************************
Audacity: A Digital Audio Editor
TracksPrefs.cpp
Brian Gunlogson
Joshua Haberman
Dominic Mazzoni
James Crook
*******************************************************************//**
\class TracksPrefs
\brief A PrefsPanel for track display and behavior properties.
*//*******************************************************************/
#include "../Audacity.h"
#include "TracksPrefs.h"
//#include <algorithm>
//#include <wx/defs.h>
#include "../Prefs.h"
#include "../ShuttleGui.h"
#include "../tracks/playabletrack/wavetrack/ui/WaveTrackViewConstants.h"
int TracksPrefs::iPreferencePinned = -1;
namespace {
const wxChar *PinnedHeadPreferenceKey()
{
return wxT("/AudioIO/PinnedHead");
}
bool PinnedHeadPreferenceDefault()
{
return false;
}
const wxChar *PinnedHeadPositionPreferenceKey()
{
return wxT("/AudioIO/PinnedHeadPosition");
}
double PinnedHeadPositionPreferenceDefault()
{
return 0.5;
}
}
namespace {
const auto waveformScaleKey = wxT("/GUI/DefaultWaveformScaleChoice");
const auto dbValueString = wxT("dB");
}
static EnumSetting< WaveformSettings::ScaleTypeValues > waveformScaleSetting{
waveformScaleKey,
{
{ XO("Linear") },
{ dbValueString, XO("Logarithmic (dB)") },
},
0, // linear
{
WaveformSettings::stLinear,
WaveformSettings::stLogarithmic,
}
};
//////////
// There is a complicated migration history here!
namespace {
const auto key0 = wxT("/GUI/DefaultViewMode");
const auto key1 = wxT("/GUI/DefaultViewModeNew");
const auto key2 = wxT("/GUI/DefaultViewModeChoice");
const auto key3 = wxT("/GUI/DefaultViewModeChoiceNew");
const wxString obsoleteValue{ wxT("WaveformDB") };
};
class TracksViewModeEnumSetting
: public EnumSetting< WaveTrackViewConstants::Display > {
public:
using EnumSetting< WaveTrackViewConstants::Display >::EnumSetting;
void Migrate( wxString &value ) override
{
// Special logic for this preference which was three times migrated!
// PRL: Bugs 1043, 1044
// 2.1.1 writes a NEW key for this preference, which got NEW values,
// to avoid confusing version 2.1.0 if it reads the preference file afterwards.
// Prefer the NEW preference key if it is present
static const EnumValueSymbol waveformSymbol{ XO("Waveform") };
static const EnumValueSymbol spectrumSymbol{ XO("Spectrogram") };
WaveTrackViewConstants::Display viewMode;
int oldMode;
wxString newValue;
auto stringValue =
[]( WaveTrackViewConstants::Display display ){
switch ( display ) {
case WaveTrackViewConstants::Spectrum:
return spectrumSymbol.Internal();
case WaveTrackViewConstants::obsoleteWaveformDBDisplay:
return obsoleteValue;
default:
return waveformSymbol.Internal();
}
};
if ( gPrefs->Read(key0, // The very old key
&oldMode,
(int)(WaveTrackViewConstants::Waveform) ) ) {
viewMode = WaveTrackViewConstants::ConvertLegacyDisplayValue(oldMode);
newValue = stringValue( viewMode );
}
else if ( gPrefs->Read(key1,
&oldMode,
(int)(WaveTrackViewConstants::Waveform) ) ) {
viewMode = static_cast<WaveTrackViewConstants::Display>( oldMode );
newValue = stringValue( viewMode );
}
else
gPrefs->Read( key2, &newValue );
if ( !gPrefs->Read( key3, &value ) ) {
if (newValue == obsoleteValue) {
newValue = waveformSymbol.Internal();
gPrefs->Write(waveformScaleKey, dbValueString);
}
Write( value = newValue );
gPrefs->Flush();
return;
}
}
};
static TracksViewModeEnumSetting viewModeSetting()
{
// Do a delayed computation, so that registration of sub-view types completes
// first
const auto &types = WaveTrackSubViewType::All();
auto symbols = transform_container< EnumValueSymbols >(
types, std::mem_fn( &WaveTrackSubViewType::name ) );
auto ids = transform_container< std::vector< WaveTrackSubViewType::Display > >(
types, std::mem_fn( &WaveTrackSubViewType::id ) );
// Special entry for multi
symbols.push_back( WaveTrackViewConstants::MultiViewSymbol );
ids.push_back( WaveTrackViewConstants::MultiView );
return {
key3,
symbols,
0, // Waveform
ids
};
}
WaveTrackViewConstants::Display TracksPrefs::ViewModeChoice()
{
return viewModeSetting().ReadEnum();
}
WaveformSettings::ScaleTypeValues TracksPrefs::WaveformScaleChoice()
{
return waveformScaleSetting.ReadEnum();
}
//////////
static EnumSetting< WaveTrackViewConstants::SampleDisplay >
sampleDisplaySetting{
wxT("/GUI/SampleViewChoice"),
{
{ wxT("ConnectDots"), XO("Connect dots") },
{ wxT("StemPlot"), XO("Stem plot") }
},
1, // StemPlot
// for migrating old preferences:
{
WaveTrackViewConstants::LinearInterpolate,
WaveTrackViewConstants::StemPlot
},
wxT("/GUI/SampleView")
};
WaveTrackViewConstants::SampleDisplay TracksPrefs::SampleViewChoice()
{
return sampleDisplaySetting.ReadEnum();
}
//////////
static const std::initializer_list<EnumValueSymbol> choicesZoom{
{ wxT("FitToWidth"), XO("Fit to Width") },
{ wxT("ZoomToSelection"), XO("Zoom to Selection") },
{ wxT("ZoomDefault"), XO("Zoom Default") },
{ XO("Minutes") },
{ XO("Seconds") },
{ wxT("FifthsOfSeconds"), XO("5ths of Seconds") },
{ wxT("TenthsOfSeconds"), XO("10ths of Seconds") },
{ wxT("TwentiethsOfSeconds"), XO("20ths of Seconds") },
{ wxT("FiftiethsOfSeconds"), XO("50ths of Seconds") },
{ wxT("HundredthsOfSeconds"), XO("100ths of Seconds") },
{ wxT("FiveHundredthsOfSeconds"), XO("500ths of Seconds") },
{ XO("MilliSeconds") },
{ XO("Samples") },
{ wxT("FourPixelsPerSample"), XO("4 Pixels per Sample") },
{ wxT("MaxZoom"), XO("Max Zoom") },
};
static auto enumChoicesZoom = {
WaveTrackViewConstants::kZoomToFit,
WaveTrackViewConstants::kZoomToSelection,
WaveTrackViewConstants::kZoomDefault,
WaveTrackViewConstants::kZoomMinutes,
WaveTrackViewConstants::kZoomSeconds,
WaveTrackViewConstants::kZoom5ths,
WaveTrackViewConstants::kZoom10ths,
WaveTrackViewConstants::kZoom20ths,
WaveTrackViewConstants::kZoom50ths,
WaveTrackViewConstants::kZoom100ths,
WaveTrackViewConstants::kZoom500ths,
WaveTrackViewConstants::kZoomMilliSeconds,
WaveTrackViewConstants::kZoomSamples,
WaveTrackViewConstants::kZoom4To1,
WaveTrackViewConstants::kMaxZoom,
};
static EnumSetting< WaveTrackViewConstants::ZoomPresets > zoom1Setting{
wxT("/GUI/ZoomPreset1Choice"),
choicesZoom,
2, // kZoomDefault
// for migrating old preferences:
enumChoicesZoom,
wxT("/GUI/ZoomPreset1")
};
static EnumSetting< WaveTrackViewConstants::ZoomPresets > zoom2Setting{
wxT("/GUI/ZoomPreset2Choice"),
choicesZoom,
13, // kZoom4To1
// for migrating old preferences:
enumChoicesZoom,
wxT("/GUI/ZoomPreset2")
};
WaveTrackViewConstants::ZoomPresets TracksPrefs::Zoom1Choice()
{
return zoom1Setting.ReadEnum();
}
WaveTrackViewConstants::ZoomPresets TracksPrefs::Zoom2Choice()
{
return zoom2Setting.ReadEnum();
}
//////////
TracksPrefs::TracksPrefs(wxWindow * parent, wxWindowID winid)
/* i18n-hint: "Tracks" include audio recordings but also other collections of
* data associated with a time line, such as sequences of labels, and musical
* notes */
: PrefsPanel(parent, winid, XO("Tracks"))
{
Populate();
}
TracksPrefs::~TracksPrefs()
{
}
ComponentInterfaceSymbol TracksPrefs::GetSymbol()
{
return TRACKS_PREFS_PLUGIN_SYMBOL;
}
TranslatableString TracksPrefs::GetDescription()
{
return XO("Preferences for Tracks");
}
wxString TracksPrefs::HelpPageName()
{
return "Tracks_Preferences";
}
void TracksPrefs::Populate()
{
// Keep view choices and codes in proper correspondence --
// we don't display them by increasing integer values.
// How samples are displayed when zoomed in:
//------------------------- Main section --------------------
// Now construct the GUI itself.
// Use 'eIsCreatingFromPrefs' so that the GUI is
// initialised with values from gPrefs.
ShuttleGui S(this, eIsCreatingFromPrefs);
PopulateOrExchange(S);
// ----------------------- End of main section --------------
}
void TracksPrefs::PopulateOrExchange(ShuttleGui & S)
{
S.SetBorder(2);
S.StartScroller();
S.StartStatic(XO("Display"));
{
S.TieCheckBox(XXO("Auto-&fit track height"),
{wxT("/GUI/TracksFitVerticallyZoomed"),
false});
S.TieCheckBox(XXO("Sho&w track name as overlay"),
{wxT("/GUI/ShowTrackNameInWaveform"),
false});
#ifdef EXPERIMENTAL_HALF_WAVE
S.TieCheckBox(XXO("Use &half-wave display when collapsed"),
{wxT("/GUI/CollapseToHalfWave"),
false});
#endif
#ifdef SHOW_PINNED_UNPINNED_IN_PREFS
S.TieCheckBox(XXO("&Pinned Recording/Playback head"),
{PinnedHeadPreferenceKey(),
PinnedHeadPreferenceDefault()});
#endif
S.TieCheckBox(XXO("A&uto-scroll if head unpinned"),
{wxT("/GUI/AutoScroll"),
true});
S.AddSpace(10);
S.StartMultiColumn(2);
{
#ifdef SHOW_PINNED_POSITION_IN_PREFS
S.TieNumericTextBox(
XXO("Pinned &head position"),
{PinnedHeadPositionPreferenceKey(),
PinnedHeadPositionPreferenceDefault()},
30
);
#endif
S.TieChoice(XXO("Default &view mode:"),
viewModeSetting() );
S.TieChoice(XXO("Default Waveform scale:"),
waveformScaleSetting );
S.TieChoice(XXO("Display &samples:"),
sampleDisplaySetting );
S.TieTextBox(XXO("Default audio track &name:"),
{wxT("/GUI/TrackNames/DefaultTrackName"),
_("Audio Track")},
30);
}
S.EndMultiColumn();
}
S.EndStatic();
S.StartStatic(XO("Zoom Toggle"));
{
S.StartMultiColumn(4);
{
S.TieChoice(XXO("Preset 1:"),
zoom1Setting );
S.TieChoice(XXO("Preset 2:"),
zoom2Setting );
}
}
S.EndStatic();
S.EndScroller();
}
bool TracksPrefs::GetPinnedHeadPreference()
{
// JKC: Cache this setting as it is read many times during drawing, and otherwise causes screen flicker.
// Correct solution would be to re-write wxFileConfig to be efficient.
if( iPreferencePinned >= 0 )
return iPreferencePinned == 1;
bool bResult = gPrefs->ReadBool(PinnedHeadPreferenceKey(), PinnedHeadPreferenceDefault());
iPreferencePinned = bResult ? 1: 0;
return bResult;
}
void TracksPrefs::SetPinnedHeadPreference(bool value, bool flush)
{
iPreferencePinned = value ? 1 :0;
gPrefs->Write(PinnedHeadPreferenceKey(), value);
if(flush)
gPrefs->Flush();
}
double TracksPrefs::GetPinnedHeadPositionPreference()
{
auto value = gPrefs->ReadDouble(
PinnedHeadPositionPreferenceKey(),
PinnedHeadPositionPreferenceDefault());
return std::max(0.0, std::min(1.0, value));
}
void TracksPrefs::SetPinnedHeadPositionPreference(double value, bool flush)
{
value = std::max(0.0, std::min(1.0, value));
gPrefs->Write(PinnedHeadPositionPreferenceKey(), value);
if(flush)
gPrefs->Flush();
}
wxString TracksPrefs::GetDefaultAudioTrackNamePreference()
{
const auto name =
gPrefs->Read(wxT("/GUI/TrackNames/DefaultTrackName"), wxT(""));
if (name.empty() || ( name == "Audio Track" ))
// When nothing was specified,
// the default-default is whatever translation of...
/* i18n-hint: The default name for an audio track. */
return _("Audio Track");
else
return name;
}
bool TracksPrefs::Commit()
{
// Bug 1583: Clear the caching of the preference pinned state.
iPreferencePinned = -1;
ShuttleGui S(this, eIsSavingToPrefs);
PopulateOrExchange(S);
// Bug 1661: Don't store the name for new tracks if the name is the
// default in that language.
if (GetDefaultAudioTrackNamePreference() == _("Audio Track")) {
gPrefs->DeleteEntry(wxT("/GUI/TrackNames/DefaultTrackName"));
gPrefs->Flush();
}
return true;
}
namespace{
PrefsPanel::Registration sAttachment{ "Tracks",
[](wxWindow *parent, wxWindowID winid, AudacityProject *)
{
wxASSERT(parent); // to justify safenew
return safenew TracksPrefs(parent, winid);
}
};
}