-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreferences.cpp
More file actions
428 lines (334 loc) · 10.9 KB
/
Preferences.cpp
File metadata and controls
428 lines (334 loc) · 10.9 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
/** $VER: Preferences.cpp (2026.01.07) P. Stuer **/
#include "pch.h"
#include <helpers\foobar2000+atl.h>
#include <helpers\atl-misc.h>
#include <helpers\advconfig_impl.h>
#include <helpers\DarkMode.h>
#include <pfc\string-conv-lite.h>
#include "Preferences.h"
#include "Configuration.h"
#include "Resources.h"
#pragma hdrstop
const WCHAR * PlaybackModes[] =
{
L"Loop never",
L"Loop",
L"Loop with fade out",
L"Loop forever"
};
/*
const uint32_t OutputFrequencies[] =
{
FREQUENCY_55_5K,
FREQUENCY_55_4K,
FREQUENCY_48_0K,
FREQUENCY_44_1K,
FREQUENCY_22_0K,
FREQUENCY_11_0K,
};
*/
#pragma warning(disable: 4820) // x bytes padding added after last data member
/// <summary>
/// Implements the preferences page for the component.
/// </summary>
class Preferences : public CDialogImpl<Preferences>, public preferences_page_instance
{
public:
Preferences(preferences_page_callback::ptr callback) : m_bMsgHandled(FALSE), _Callback(callback) { }
Preferences(const Preferences &) = delete;
Preferences(const Preferences &&) = delete;
Preferences& operator=(const Preferences &) = delete;
Preferences& operator=(Preferences &&) = delete;
virtual ~Preferences() { };
enum
{
IDD = IDD_PREFERENCES
};
#pragma region preferences_page_instance
/// <summary>
/// Returns a combination of preferences_state constants.
/// </summary>
virtual t_uint32 get_state() final
{
t_uint32 State = preferences_state::resettable | preferences_state::dark_mode_supported;
if (HasChanged())
State |= preferences_state::changed;
return State;
}
/// <summary>
/// Applies the changes to the preferences.
/// </summary>
virtual void apply() final
{
CfgSamplesPath = _SamplesPath;
CfgPlaybackMode = _PlaybackMode;
CfgLoopCount = _LoopCount;
CfgFadeOutDuration = _FadeOutDuration;
CfgSynthesisRate = _SynthesisRate;
CfgUsePPS = _UsePPS;
CfgUseSSG = _UseSSG;
OnChanged();
}
/// <summary>
/// Resets this page's content to the default values. Does not apply any changes - lets user preview the changes before hitting "apply".
/// </summary>
virtual void reset() final
{
_SamplesPath = DefaultSamplesPath;
_PlaybackMode = DefaultPlaybackMode;
_LoopCount = DefaultLoopCount;
_FadeOutDuration = DefaultFadeOutDuration;
_SynthesisRate = DefaultSynthesisRate;
_UsePPS = DefaultUsePPS;
_UseSSG = DefaultUseSSG;
UpdateDialog();
OnChanged();
}
#pragma endregion
//WTL message map
BEGIN_MSG_MAP_EX(Preferences)
MSG_WM_INITDIALOG(OnInitDialog)
COMMAND_HANDLER_EX(IDC_SAMPLES_PATH, EN_KILLFOCUS, OnEditUpdate)
COMMAND_HANDLER_EX(IDC_SAMPLES_PATH_SELECT, BN_CLICKED, OnButtonClicked)
COMMAND_HANDLER_EX(IDC_PLAYBACK_MODE, CBN_SELCHANGE, OnSelectionChanged)
COMMAND_HANDLER_EX(IDC_LOOP_COUNT, EN_UPDATE, OnEditUpdate)
COMMAND_HANDLER_EX(IDC_FADE_OUT_DURATION, EN_UPDATE, OnEditUpdate)
// COMMAND_HANDLER_EX(IDC_SYNTHESIS_RATE, CBN_SELCHANGE, OnSelectionChanged)
COMMAND_HANDLER_EX(IDC_USE_PPS, BN_CLICKED, OnButtonClicked)
COMMAND_HANDLER_EX(IDC_USE_SSG, BN_CLICKED, OnButtonClicked)
END_MSG_MAP()
private:
/// <summary>
/// Initializes the dialog.
/// </summary>
BOOL OnInitDialog(CWindow, LPARAM) noexcept
{
_DarkModeHooks.AddDialogWithControls(*this);
_SamplesPath = CfgSamplesPath;
_PlaybackMode = (uint32_t) CfgPlaybackMode;
_LoopCount = (uint32_t) CfgLoopCount;
_FadeOutDuration = (uint32_t) CfgFadeOutDuration;
_SynthesisRate = (uint32_t) CfgSynthesisRate;
_UsePPS = CfgUsePPS;
_UseSSG = CfgUseSSG;
{
auto cb = (CComboBox) GetDlgItem(IDC_PLAYBACK_MODE);
for (size_t i = 0; i < _countof(PlaybackModes); ++i)
cb.AddString(PlaybackModes[i]);
}
UpdateDialog();
return FALSE;
}
/*
/// <summary>
/// Handles the notification when a control loses focus.
/// </summary>
void OnLostFocus(UINT code, int id, CWindow) noexcept
{
if (!((code == EN_KILLFOCUS) && (id == IDC_SAMPLES_PATH)))
return;
WCHAR Text[MAX_PATH];
GetDlgItemText(id, Text, _countof(Text));
_SamplesPath = pfc::utf8FromWide(Text);
OnChanged();
}
*/
/// <summary>
/// Handles a click on a button.
/// </summary>
void OnButtonClicked(UINT, int id, CWindow) noexcept
{
switch (id)
{
case IDC_SAMPLES_PATH_SELECT:
{
pfc::string DirectoryPath = _SamplesPath;
if (::uBrowseForFolder(m_hWnd, "Locate PDX samples...", DirectoryPath))
{
_SamplesPath = DirectoryPath;
pfc::wstringLite w = pfc::wideFromUTF8(DirectoryPath);
SetDlgItemText(IDC_SAMPLES_PATH, w);
OnChanged();
}
break;
}
case IDC_USE_PPS:
{
_UsePPS = (bool) IsDlgButtonChecked(IDC_USE_PPS);
OnChanged();
break;
}
case IDC_USE_SSG:
{
_UseSSG = (bool) IsDlgButtonChecked(IDC_USE_SSG);
OnChanged();
break;
}
}
}
/// <summary>
/// Handles a combobox change.
/// </summary>
void OnSelectionChanged(UINT, int id, CWindow) noexcept
{
switch (id)
{
case IDC_PLAYBACK_MODE:
{
auto cb = (CComboBox) GetDlgItem(IDC_PLAYBACK_MODE);
_PlaybackMode = (uint32_t) cb.GetCurSel();
break;
}
/*
case IDC_SYNTHESIS_RATE:
{
auto cb = (CComboBox) GetDlgItem(IDC_SYNTHESIS_RATE);
_SynthesisRate = SynthesisRates[cb.GetCurSel()];
break;
}
*/
}
UpdateDialog();
OnChanged();
}
/// <summary>
/// Handles a textbox update.
/// </summary>
void OnEditUpdate(UINT, int id, CWindow) noexcept
{
switch (id)
{
case IDC_SAMPLES_PATH:
{
_SamplesPath = ::uGetDlgItemText(m_hWnd, IDC_SAMPLES_PATH);
OnChanged();
break;
}
case IDC_LOOP_COUNT:
{
pfc::string Text = ::uGetDlgItemText(m_hWnd, IDC_LOOP_COUNT);
char * p; long Value = ::strtol(Text, &p, 10);
if ((*p == '\0') && (Value > 0) && (Value <= ~0U))
{
_LoopCount = (uint32_t) Value;
OnChanged();
}
break;
}
case IDC_FADE_OUT_DURATION:
{
pfc::string Text = ::uGetDlgItemText(m_hWnd, IDC_FADE_OUT_DURATION);
char * p; long Value = ::strtol(Text, &p, 10);
if ((*p == '\0') && (Value > 0) && (Value <= ~0U))
{
_FadeOutDuration = (uint32_t) Value;
OnChanged();
}
break;
}
}
}
/// <summary>
/// Returns whether our dialog content is different from the current configuration (whether the Apply button should be enabled or not)
/// </summary>
bool HasChanged() const noexcept
{
if (_SamplesPath != CfgSamplesPath)
return true;
if (_PlaybackMode != CfgPlaybackMode)
return true;
if (_LoopCount != CfgLoopCount)
return true;
if (_FadeOutDuration != CfgFadeOutDuration)
return true;
if (_UsePPS != CfgUsePPS)
return true;
if (_UseSSG != CfgUseSSG)
return true;
// if (_SynthesisRate != CfgSynthesisRate)
// return true;
return false;
}
/// <summary>
/// Tells the host that our state has changed to enable/disable the apply button appropriately.
/// </summary>
void OnChanged() const noexcept
{
_Callback->on_state_changed();
}
/// <summary>
/// Updates the appearance of the dialog according to the values of the settings.
/// </summary>
void UpdateDialog() noexcept
{
::uSetDlgItemText(m_hWnd, IDC_SAMPLES_PATH, _SamplesPath);
{
auto cb = (CComboBox) GetDlgItem(IDC_PLAYBACK_MODE);
cb.SetCurSel((int32_t) _PlaybackMode);
}
{
bool Flag = (_PlaybackMode == PlaybackModes::Loop) || (_PlaybackMode == PlaybackModes::LoopWithFadeOut);
GetDlgItem(IDC_LOOP_COUNT).EnableWindow(Flag);
}
::uSetDlgItemText(m_hWnd, IDC_LOOP_COUNT, pfc::format_int(_LoopCount));
{
bool Flag = (_PlaybackMode == PlaybackModes::LoopWithFadeOut);
GetDlgItem(IDC_FADE_OUT_DURATION).EnableWindow(Flag);
}
::uSetDlgItemText(m_hWnd, IDC_FADE_OUT_DURATION, pfc::format_int(_FadeOutDuration));
/*
{
auto cb = (CComboBox) GetDlgItem(IDC_SYNTHESIS_RATE);
int Index = 0;
for (int i = 0; i < _countof(SynthesisRates); ++i)
{
cb.AddString(pfc::wideFromUTF8(pfc::format_int(SynthesisRates[i])));
if (_SynthesisRate == SynthesisRates[i])
Index = i;
}
cb.SetCurSel(Index);
}
*/
CheckDlgButton(IDC_USE_PPS, _UsePPS);
CheckDlgButton(IDC_USE_SSG, _UseSSG);
}
private:
const preferences_page_callback::ptr _Callback;
fb2k::CDarkModeHooks _DarkModeHooks;
pfc::string _SamplesPath;
uint32_t _PlaybackMode;
uint32_t _LoopCount;
uint32_t _FadeOutDuration;
uint32_t _SynthesisRate;
bool _UsePPS;
bool _UseSSG;
};
#pragma warning(default: 4820) // x bytes padding added after last data member
#pragma region PreferencesPage
/// <summary>
/// preferences_page_impl<> helper deals with instantiation of our dialog; inherits from preferences_page_v3.
/// </summary>
class PreferencesPage : public preferences_page_impl<Preferences>
{
public:
PreferencesPage() noexcept { };
PreferencesPage(const PreferencesPage &) = delete;
PreferencesPage(const PreferencesPage &&) = delete;
PreferencesPage & operator=(const PreferencesPage &) = delete;
PreferencesPage & operator=(PreferencesPage &&) = delete;
virtual ~PreferencesPage() noexcept { };
const char * get_name() noexcept
{
return STR_COMPONENT_NAME;
}
GUID get_guid() noexcept
{
return GUID_PREFERENCES;
}
GUID get_parent_guid() noexcept
{
return guid_input;
}
};
static preferences_page_factory_t<PreferencesPage> _PreferencesPageFactory;
#pragma endregion