Repository navigation
Expand file tree
/
Copy pathpreferences.cpp
More file actions
262 lines (200 loc) · 12.6 KB
/
Copy pathpreferences.cpp
File metadata and controls
262 lines (200 loc) · 12.6 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
#include <helpers/foobar2000+atl.h>
#include "resource.h"
#include "config.h"
static const GUID guid_pref_main = { 0x4a91f182, 0x82a1, 0x4c20, { 0xb1, 0x12, 0x82, 0x41, 0x90, 0xce, 0xda, 0x11 } };
static pfc::string8 get_dlg_item_text(HWND wnd, int id) {
pfc::string8 temp;
uGetDlgItemText(wnd, id, temp);
return temp;
}
static void init_combo(HWND wnd, int id, const char* const items[], size_t count, int selected) {
HWND combo = GetDlgItem(wnd, id);
SendMessage(combo, CB_RESETCONTENT, 0, 0);
for (size_t i = 0; i < count; ++i) {
pfc::stringcvt::string_wide_from_utf8 wstr(items[i]);
SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)wstr.get_ptr());
}
SendMessage(combo, CB_SETCURSEL, selected >= 0 && selected < (int)count ? selected : 0, 0);
}
static void set_combo_readonly(HWND wnd, int id, bool readonly) {
HWND combo = GetDlgItem(wnd, id);
SendMessage(combo, CB_SETDROPPEDWIDTH, readonly ? 0 : 1, 0);
EnableWindow(combo, !readonly);
}
class CPreferencesMain : public CDialogImpl<CPreferencesMain>, public preferences_page_instance {
public:
enum { IDD = IDD_PREFERENCES };
CPreferencesMain(preferences_page_callback::ptr callback) : m_callback(callback) {}
HWND get_wnd() override { return m_hWnd; }
t_uint32 get_state() override {
t_uint32 state = preferences_state::resettable;
if (HasChanged()) state |= preferences_state::changed;
return state;
}
void apply() override {
cfg_tag_bpm = get_dlg_item_text(m_hWnd, IDC_EDIT_TAG_BPM);
cfg_tag_key = get_dlg_item_text(m_hWnd, IDC_EDIT_TAG_KEY);
cfg_auto_save = uButton_GetCheck(m_hWnd, IDC_CHECK_AUTO_SAVE);
cfg_bpm_min = GetDlgItemInt(IDC_EDIT_BPM_MIN, NULL, FALSE);
cfg_bpm_max = GetDlgItemInt(IDC_EDIT_BPM_MAX, NULL, FALSE);
cfg_bpm_round = (int)SendDlgItemMessage(IDC_COMBO_BPM_ROUND, CB_GETCURSEL, 0, 0);
cfg_bpm_range_enabled = uButton_GetCheck(m_hWnd, IDC_CHECK_BPM_RANGE);
cfg_bpm_start_pct = GetDlgItemInt(IDC_EDIT_BPM_START_PCT, NULL, FALSE);
cfg_bpm_end_pct = GetDlgItemInt(IDC_EDIT_BPM_END_PCT, NULL, FALSE);
cfg_bpm_max_time_enabled = uButton_GetCheck(m_hWnd, IDC_CHECK_BPM_MAX_TIME);
cfg_bpm_max_time_val = GetDlgItemInt(IDC_EDIT_BPM_MAX_TIME, NULL, FALSE);
cfg_bpm_sample_time = GetDlgItemInt(IDC_EDIT_BPM_SAMPLE_TIME, NULL, FALSE);
cfg_bpm_sample_count = GetDlgItemInt(IDC_EDIT_BPM_SAMPLE_COUNT, NULL, FALSE);
cfg_bpm_candidate_mode = (int)SendDlgItemMessage(IDC_COMBO_BPM_CANDIDATE, CB_GETCURSEL, 0, 0);
cfg_bpm_interpolate = uButton_GetCheck(m_hWnd, IDC_CHECK_BPM_INTERPOLATE);
cfg_bpm_lpf_enabled = uButton_GetCheck(m_hWnd, IDC_CHECK_BPM_LPF);
cfg_bpm_lpf_cutoff = GetDlgItemInt(IDC_EDIT_BPM_LPF_CUTOFF, NULL, FALSE);
// === ЗАКОММЕНТИРОВАНО: FFT Size / Hop Size / Window Type (сейчас не используются) ===
// cfg_bpm_fft_size = (int)SendDlgItemMessage(IDC_COMBO_BPM_FFT, CB_GETCURSEL, 0, 0);
// cfg_bpm_hop_size = (int)SendDlgItemMessage(IDC_COMBO_BPM_HOP, CB_GETCURSEL, 0, 0);
// cfg_bpm_window_type = (int)SendDlgItemMessage(IDC_COMBO_BPM_WINDOW, CB_GETCURSEL, 0, 0);
cfg_bpm_auto_correct = uButton_GetCheck(m_hWnd, IDC_CHECK_BPM_AUTO_CORRECT);
cfg_key_fft = (int)SendDlgItemMessage(IDC_COMBO_KEY_FFT, CB_GETCURSEL, 0, 0);
cfg_key_profile = (int)SendDlgItemMessage(IDC_COMBO_KEY_PROFILE, CB_GETCURSEL, 0, 0);
cfg_key_fast = uButton_GetCheck(m_hWnd, IDC_CHECK_KEY_FAST);
OnChanged();
}
void reset() override {
uSetDlgItemText(*this, IDC_EDIT_TAG_BPM, DEFAULT_TAG_BPM);
uSetDlgItemText(*this, IDC_EDIT_TAG_KEY, DEFAULT_TAG_KEY);
uButton_SetCheck(m_hWnd, IDC_CHECK_AUTO_SAVE, DEFAULT_AUTO_SAVE);
SetDlgItemInt(IDC_EDIT_BPM_MIN, DEFAULT_BPM_MIN, FALSE);
SetDlgItemInt(IDC_EDIT_BPM_MAX, DEFAULT_BPM_MAX, FALSE);
SendDlgItemMessage(IDC_COMBO_BPM_ROUND, CB_SETCURSEL, DEFAULT_BPM_ROUND, 0);
uButton_SetCheck(m_hWnd, IDC_CHECK_BPM_RANGE, DEFAULT_BPM_RANGE_ENABLED);
SetDlgItemInt(IDC_EDIT_BPM_START_PCT, DEFAULT_BPM_START_PCT, FALSE);
SetDlgItemInt(IDC_EDIT_BPM_END_PCT, DEFAULT_BPM_END_PCT, FALSE);
uButton_SetCheck(m_hWnd, IDC_CHECK_BPM_MAX_TIME, DEFAULT_BPM_MAX_TIME_ENABLED);
SetDlgItemInt(IDC_EDIT_BPM_MAX_TIME, DEFAULT_BPM_MAX_TIME_VAL, FALSE);
SetDlgItemInt(IDC_EDIT_BPM_SAMPLE_TIME, DEFAULT_BPM_SAMPLE_TIME, FALSE);
SetDlgItemInt(IDC_EDIT_BPM_SAMPLE_COUNT, DEFAULT_BPM_SAMPLE_COUNT, FALSE);
SendDlgItemMessage(IDC_COMBO_BPM_CANDIDATE, CB_SETCURSEL, DEFAULT_BPM_CANDIDATE_MODE, 0);
uButton_SetCheck(m_hWnd, IDC_CHECK_BPM_INTERPOLATE, DEFAULT_BPM_INTERPOLATE);
uButton_SetCheck(m_hWnd, IDC_CHECK_BPM_LPF, DEFAULT_BPM_LPF_ENABLED);
SetDlgItemInt(IDC_EDIT_BPM_LPF_CUTOFF, DEFAULT_BPM_LPF_CUTOFF, FALSE);
// === ЗАКОММЕНТИРОВАНО: FFT Size / Hop Size / Window Type ===
// SendDlgItemMessage(IDC_COMBO_BPM_FFT, CB_SETCURSEL, DEFAULT_BPM_FFT_SIZE, 0);
// SendDlgItemMessage(IDC_COMBO_BPM_HOP, CB_SETCURSEL, DEFAULT_BPM_HOP_SIZE, 0);
// SendDlgItemMessage(IDC_COMBO_BPM_WINDOW, CB_SETCURSEL, DEFAULT_BPM_WINDOW, 0);
uButton_SetCheck(m_hWnd, IDC_CHECK_BPM_AUTO_CORRECT, DEFAULT_BPM_AUTO_CORRECT);
SendDlgItemMessage(IDC_COMBO_KEY_FFT, CB_SETCURSEL, DEFAULT_KEY_FFT, 0);
SendDlgItemMessage(IDC_COMBO_KEY_PROFILE, CB_SETCURSEL, DEFAULT_KEY_PROFILE, 0);
uButton_SetCheck(m_hWnd, IDC_CHECK_KEY_FAST, DEFAULT_KEY_FAST);
OnChanged();
}
BEGIN_MSG_MAP_EX(CPreferencesMain)
MSG_WM_INITDIALOG(OnInitDialog)
COMMAND_CODE_HANDLER_EX(EN_CHANGE, OnEditChange)
COMMAND_CODE_HANDLER_EX(BN_CLICKED, OnButtonClick)
COMMAND_CODE_HANDLER_EX(CBN_SELCHANGE, OnComboChange)
END_MSG_MAP()
private:
BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam) {
uSetDlgItemText(*this, IDC_EDIT_TAG_BPM, cfg_tag_bpm);
uSetDlgItemText(*this, IDC_EDIT_TAG_KEY, cfg_tag_key);
uButton_SetCheck(m_hWnd, IDC_CHECK_AUTO_SAVE, cfg_auto_save);
SetDlgItemInt(IDC_EDIT_BPM_MIN, cfg_bpm_min, FALSE);
SetDlgItemInt(IDC_EDIT_BPM_MAX, cfg_bpm_max, FALSE);
static const char* const bpm_round_opts[] = { "Integer (120)", "1 Decimal (120.5)", "2 Decimals (120.54)" };
init_combo(m_hWnd, IDC_COMBO_BPM_ROUND, bpm_round_opts, 3, cfg_bpm_round);
uButton_SetCheck(m_hWnd, IDC_CHECK_BPM_RANGE, cfg_bpm_range_enabled);
SetDlgItemInt(IDC_EDIT_BPM_START_PCT, cfg_bpm_start_pct, FALSE);
SetDlgItemInt(IDC_EDIT_BPM_END_PCT, cfg_bpm_end_pct, FALSE);
uButton_SetCheck(m_hWnd, IDC_CHECK_BPM_MAX_TIME, cfg_bpm_max_time_enabled);
SetDlgItemInt(IDC_EDIT_BPM_MAX_TIME, cfg_bpm_max_time_val, FALSE);
SetDlgItemInt(IDC_EDIT_BPM_SAMPLE_TIME, cfg_bpm_sample_time, FALSE);
SetDlgItemInt(IDC_EDIT_BPM_SAMPLE_COUNT, cfg_bpm_sample_count, FALSE);
static const char* const candidate_opts[] = { "Mode (Most Frequent)", "Median", "Average" };
init_combo(m_hWnd, IDC_COMBO_BPM_CANDIDATE, candidate_opts, 3, cfg_bpm_candidate_mode);
uButton_SetCheck(m_hWnd, IDC_CHECK_BPM_INTERPOLATE, cfg_bpm_interpolate);
uButton_SetCheck(m_hWnd, IDC_CHECK_BPM_LPF, cfg_bpm_lpf_enabled);
SetDlgItemInt(IDC_EDIT_BPM_LPF_CUTOFF, cfg_bpm_lpf_cutoff, FALSE);
// === ЗАКОММЕНТИРОВАНО: FFT Size / Hop Size / Window Type ===
// static const char* const bpm_fft_opts[] = { "1024", "2048", "4096", "8192" };
// init_combo(m_hWnd, IDC_COMBO_BPM_FFT, bpm_fft_opts, 4, cfg_bpm_fft_size);
//
// static const char* const bpm_hop_opts[] = { "256", "512", "1024" };
// init_combo(m_hWnd, IDC_COMBO_BPM_HOP, bpm_hop_opts, 3, cfg_bpm_hop_size);
//
// static const char* const bpm_win_opts[] = { "Hann", "Hamming", "Blackman", "Rectangular" };
// init_combo(m_hWnd, IDC_COMBO_BPM_WINDOW, bpm_win_opts, 4, cfg_bpm_window_type);
// Auto-correct
uButton_SetCheck(m_hWnd, IDC_CHECK_BPM_AUTO_CORRECT, cfg_bpm_auto_correct);
// KeyFinder настройки
static const char* const key_fft_opts[] = { "16384 (fixed)", "16384 (fixed)", "16384 (fixed)" };
init_combo(m_hWnd, IDC_COMBO_KEY_FFT, key_fft_opts, 3, 0);
set_combo_readonly(m_hWnd, IDC_COMBO_KEY_FFT, true);
static const char* const key_profile_opts[] = { "EDMA (fixed)", "EDMA (fixed)", "EDMA (fixed)" };
init_combo(m_hWnd, IDC_COMBO_KEY_PROFILE, key_profile_opts, 3, 0);
set_combo_readonly(m_hWnd, IDC_COMBO_KEY_PROFILE, true);
uButton_SetCheck(m_hWnd, IDC_CHECK_KEY_FAST, cfg_key_fast);
return TRUE;
}
void OnEditChange(UINT uNotifyCode, int nID, CWindow wndCtl) {
// === ЗАКОММЕНТИРОВАНО: FFT/Hop/Window больше не в UI ===
// if (nID == IDC_COMBO_KEY_FFT || nID == IDC_COMBO_KEY_PROFILE) {
// return;
// }
if (nID == IDC_COMBO_KEY_FFT || nID == IDC_COMBO_KEY_PROFILE) {
return;
}
OnChanged();
}
void OnButtonClick(UINT uNotifyCode, int nID, CWindow wndCtl) {
OnChanged();
}
void OnComboChange(UINT uNotifyCode, int nID, CWindow wndCtl) {
if (nID == IDC_COMBO_KEY_FFT || nID == IDC_COMBO_KEY_PROFILE) {
SendDlgItemMessage(IDC_COMBO_KEY_FFT, CB_SETCURSEL, 0, 0);
SendDlgItemMessage(IDC_COMBO_KEY_PROFILE, CB_SETCURSEL, 0, 0);
return;
}
OnChanged();
}
void OnChanged() { m_callback->on_state_changed(); }
bool HasChanged() {
if (cfg_tag_bpm != get_dlg_item_text(m_hWnd, IDC_EDIT_TAG_BPM)) return true;
if (cfg_tag_key != get_dlg_item_text(m_hWnd, IDC_EDIT_TAG_KEY)) return true;
if (cfg_auto_save != uButton_GetCheck(m_hWnd, IDC_CHECK_AUTO_SAVE)) return true;
if (cfg_bpm_min != (int)GetDlgItemInt(IDC_EDIT_BPM_MIN, NULL, FALSE)) return true;
if (cfg_bpm_max != (int)GetDlgItemInt(IDC_EDIT_BPM_MAX, NULL, FALSE)) return true;
if (cfg_bpm_round != (int)SendDlgItemMessage(IDC_COMBO_BPM_ROUND, CB_GETCURSEL, 0, 0)) return true;
if (cfg_bpm_range_enabled != uButton_GetCheck(m_hWnd, IDC_CHECK_BPM_RANGE)) return true;
if (cfg_bpm_start_pct != (int)GetDlgItemInt(IDC_EDIT_BPM_START_PCT, NULL, FALSE)) return true;
if (cfg_bpm_end_pct != (int)GetDlgItemInt(IDC_EDIT_BPM_END_PCT, NULL, FALSE)) return true;
if (cfg_bpm_max_time_enabled != uButton_GetCheck(m_hWnd, IDC_CHECK_BPM_MAX_TIME)) return true;
if (cfg_bpm_max_time_val != (int)GetDlgItemInt(IDC_EDIT_BPM_MAX_TIME, NULL, FALSE)) return true;
if (cfg_bpm_sample_time != (int)GetDlgItemInt(IDC_EDIT_BPM_SAMPLE_TIME, NULL, FALSE)) return true;
if (cfg_bpm_sample_count != (int)GetDlgItemInt(IDC_EDIT_BPM_SAMPLE_COUNT, NULL, FALSE)) return true;
if (cfg_bpm_candidate_mode != (int)SendDlgItemMessage(IDC_COMBO_BPM_CANDIDATE, CB_GETCURSEL, 0, 0)) return true;
if (cfg_bpm_interpolate != uButton_GetCheck(m_hWnd, IDC_CHECK_BPM_INTERPOLATE)) return true;
if (cfg_bpm_lpf_enabled != uButton_GetCheck(m_hWnd, IDC_CHECK_BPM_LPF)) return true;
if (cfg_bpm_lpf_cutoff != (int)GetDlgItemInt(IDC_EDIT_BPM_LPF_CUTOFF, NULL, FALSE)) return true;
// === ЗАКОММЕНТИРОВАНО: FFT/Hop/Window больше не в UI ===
// if (cfg_bpm_fft_size != (int)SendDlgItemMessage(IDC_COMBO_BPM_FFT, CB_GETCURSEL, 0, 0)) return true;
// if (cfg_bpm_hop_size != (int)SendDlgItemMessage(IDC_COMBO_BPM_HOP, CB_GETCURSEL, 0, 0)) return true;
// if (cfg_bpm_window_type != (int)SendDlgItemMessage(IDC_COMBO_BPM_WINDOW, CB_GETCURSEL, 0, 0)) return true;
if (cfg_bpm_auto_correct != uButton_GetCheck(m_hWnd, IDC_CHECK_BPM_AUTO_CORRECT)) return true;
if (cfg_key_fast != uButton_GetCheck(m_hWnd, IDC_CHECK_KEY_FAST)) return true;
return false;
}
preferences_page_callback::ptr m_callback;
};
class preferences_page_main_impl : public preferences_page_v3 {
public:
const char* get_name() override { return "BPM & Key Detector"; }
GUID get_guid() override { return guid_pref_main; }
GUID get_parent_guid() override { return preferences_page::guid_tools; }
bool get_help_url(pfc::string_base& p_out) override { return false; }
preferences_page_instance::ptr instantiate(HWND parent, preferences_page_callback::ptr callback) override {
auto p = fb2k::service_new<CPreferencesMain>(callback);
p->Create(parent);
return p;
}
};
static service_factory_single_t<preferences_page_main_impl> g_pref_main_factory;