-
Notifications
You must be signed in to change notification settings - Fork 3
/
dlg_cfg.cpp
1431 lines (1283 loc) · 37.9 KB
/
dlg_cfg.cpp
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*3456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
0000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999*/
#define _USE_MATH_DEFINES
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <stdtype.h>
#include <emu/SoundDevs.h>
#include <emu/EmuCores.h>
#include <emu/SoundEmu.h> // for SndEmu_GetDevName()
#include "resource.h"
#include "playcfg.hpp"
#include "FileInfoStorage.hpp"
#include "in_vgm.h"
extern PluginConfig pluginCfg;
#ifndef M_LN2
#define M_LN2 0.693147180559945309417
#endif
#define HIDE_VGM7Z
#define TAB_ICON_WIDTH 16
#define TAB_ICON_TRANSP 0xFF00FF
// Dialogue box tabsheet handler
#define NUM_CFG_TABS 5
#define CfgPlayback hWndCfgTab[0]
#define CfgTags hWndCfgTab[1]
#define Cfg7z hWndCfgTab[2]
#define CfgMuting hWndCfgTab[3]
#define CfgOptPan hWndCfgTab[4]
#define SLIDER_GETPOS(hWnd, dlgID) (UINT16) \
SendDlgItemMessage(hWnd, dlgID, TBM_GETPOS, 0, 0)
#define SLIDER_SETPOS(hWnd, dlgID, Pos) SendDlgItemMessage(hWnd, dlgID, TBM_SETPOS, TRUE, Pos)
#define CTRL_DISABLE(hWnd, dlgID) EnableWindow(GetDlgItem(hWnd, dlgID), FALSE)
#define CTRL_ENABLE(hWnd, dlgID) EnableWindow(GetDlgItem(hWnd, dlgID), TRUE)
#define CTRL_HIDE(hWnd, dlgID) ShowWindow(GetDlgItem(hWnd, dlgID), SW_HIDE)
#define CTRL_SHOW(hWnd, dlgID) ShowWindow(GetDlgItem(hWnd, dlgID), SW_SHOW)
#define CTRL_SET_ENABLE(hWnd, dlgID, Enable) EnableWindow(GetDlgItem(hWnd, dlgID), Enable)
#define CTRL_IS_ENABLED(hWnd, dlgID, Enable) IsWindowEnabled(GetDlgItem(hWnd, dlgID))
#define SETCHECKBOX(hWnd, dlgID, Check) SendDlgItemMessage(hWnd, dlgID, BM_SETCHECK, Check, 0)
#define CREATE_CHILD(dlgID, DlgProc) \
CreateDialog(hPluginInst, (LPCTSTR)dlgID, hWndMain, DlgProc)
#define COMBO_ADDSTR(hWnd, dlgID, String) \
SendDlgItemMessageA(hWnd, dlgID, CB_ADDSTRING, 0, (LPARAM)String)
#define COMBO_GETPOS(hWnd, dlgID) SendDlgItemMessage(hWnd, dlgID, CB_GETCURSEL, 0, 0)
#define COMBO_SETPOS(hWnd, dlgID, Pos) SendDlgItemMessage(hWnd, dlgID, CB_SETCURSEL, Pos, 0)
#define CHECK2BOOL(hWnd, dlgID) (IsDlgButtonChecked(hWnd, dlgID) == BST_CHECKED)
typedef HRESULT (__stdcall *ETDT_FUNC)(HWND hwnd, DWORD dwFlags); // EnableThemeDialogTexture
typedef BOOL (__stdcall *ITDTE_FUNC)(HWND hwnd); // IsThemeDialogTextureEnabled
// Function Prototypes from in_vgm.c
const char* GetIniFilePath(void);
FileInfoStorage* GetMainPlayerFIS(void);
FileInfoStorage* GetMainPlayerFISScan(void);
void RefreshPlaybackOptions(void);
void RefreshMuting(void);
void RefreshPanning(void);
void UpdatePlayback(void);
// Function Prototypes from dlg_fileinfo.c
void QueueInfoReload(void);
// Function Prototypes
int ConfigDlg_Show(HINSTANCE hDllInst, HWND hWndParent);
static void InitConfigDialog(HWND hWndMain);
static inline void AddTab(HWND tabCtrlWnd, int ImgIndex, char* TabTitle);
static void EnableWinXPVisualStyles(HWND hWndMain);
static void Slider_Setup(HWND hWndDlg, int dlgID, int minVal, int maxVal, int largeStep, int tickFreq);
static BOOL SetDlgItemFloat(HWND hDlg, int nIDDlgItem, double value, int precision);
static int LoadConfigDialogInfo(HWND hWndDlg);
static BOOL CALLBACK ConfigDialogProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK CfgDlgPlaybackProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK CfgDlgTagsProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK CfgDlgMutingProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK CfgDlgOptPanProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK CfgDlgChildProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam);
static inline bool IsSongPlaying(void);
static bool IsChipAvailable(const ChipOptions& cOpts);
static UINT32 GetChipCore(const ChipOptions& cOpts);
static void ShowMutingCheckBoxes(UINT8 ChipID, UINT8 ChipSet);
static void SetMutingData(UINT32 CheckBox, bool MuteOn);
static inline UINT16 PanPos2Slider(INT16 panPos);
static inline INT16 PanSlider2Pos(UINT16 sliderValue);
static void ShowOptPanBoxes(UINT8 ChipID, UINT8 ChipSet);
static void SetPanningData(UINT32 sliderID, UINT16 value, bool noRefresh);
void Dialogue_TrackChange(void);
static HINSTANCE hPluginInst;
static HWND hWndCfgTab[NUM_CFG_TABS];
static bool LoopTimeMode;
static UINT8 muteChipID = 0x00;
static UINT8 muteChipSet = 0;
static ChipOptions* muteCOpts;
int ConfigDlg_Show(HINSTANCE hDllInst, HWND hWndParent)
{
hPluginInst = hDllInst;
return DialogBox(hDllInst, (LPTSTR)DlgConfigMain, hWndParent, ConfigDialogProc);
}
static void InitConfigDialog(HWND hWndMain)
{
HWND TabCtrlWnd;
RECT TabDispRect;
RECT TabRect;
HIMAGELIST hImgList;
unsigned int CurTab;
TabCtrlWnd = GetDlgItem(hWndMain, TabCollection);
InitCommonControls();
// Load images for tabs
hImgList = ImageList_LoadImage(hPluginInst, (LPCSTR)TabIcons, TAB_ICON_WIDTH, 0,
TAB_ICON_TRANSP, IMAGE_BITMAP, LR_CREATEDIBSECTION);
TabCtrl_SetImageList(TabCtrlWnd, hImgList);
// Add tabs
AddTab(TabCtrlWnd, 0, "Playback");
AddTab(TabCtrlWnd, 1, "Tags");
#ifndef HIDE_VGM7Z
AddTab(TabCtrlWnd, 2, "VGM7z");
#endif
AddTab(TabCtrlWnd, 3, "Muting");
AddTab(TabCtrlWnd, 5, "Other Opts");
// Get display rect
GetWindowRect(TabCtrlWnd, &TabDispRect);
GetWindowRect(hWndMain, &TabRect);
OffsetRect(&TabDispRect,
-TabRect.left - GetSystemMetrics(SM_CXDLGFRAME),
-TabRect.top - GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYCAPTION));
TabCtrl_AdjustRect(TabCtrlWnd, FALSE, &TabDispRect);
// Create child windows
CfgPlayback = CREATE_CHILD(DlgCfgPlayback, CfgDlgPlaybackProc);
CfgTags = CREATE_CHILD(DlgCfgTags, CfgDlgTagsProc);
Cfg7z = CREATE_CHILD(DlgCfgVgm7z, CfgDlgChildProc);
CfgMuting = CREATE_CHILD(DlgCfgMuting, CfgDlgMutingProc);
CfgOptPan = CREATE_CHILD(DlgCfgOptPan, CfgDlgOptPanProc);
EnableWinXPVisualStyles(hWndMain);
// position tabs
TabDispRect.right -= TabDispRect.left; // .right gets Tab Width
TabDispRect.bottom -= TabDispRect.top; // .bottom gets Tab Height
for (CurTab = 0; CurTab < NUM_CFG_TABS; CurTab ++)
{
SetWindowPos(hWndCfgTab[CurTab], HWND_TOP, TabDispRect.left, TabDispRect.top,
TabDispRect.right, TabDispRect.bottom, SWP_NOZORDER);
}
// show first tab, hide the others
ShowWindow(hWndCfgTab[0], SW_SHOW);
for (CurTab = 1; CurTab < NUM_CFG_TABS; CurTab ++)
ShowWindow(hWndCfgTab[CurTab], SW_HIDE);
return;
}
static inline void AddTab(HWND tabCtrlWnd, int ImgIndex, char* TabTitle)
{
TC_ITEM newTab;
int tabIndex;
tabIndex = TabCtrl_GetItemCount(tabCtrlWnd);
newTab.mask = TCIF_TEXT;
newTab.mask |= (ImgIndex >= 0) ? TCIF_IMAGE : 0;
newTab.pszText = TabTitle;
newTab.iImage = ImgIndex;
TabCtrl_InsertItem(tabCtrlWnd, tabIndex, &newTab);
return;
}
static void EnableWinXPVisualStyles(HWND hWndMain)
{
HMODULE uxtDLL = LoadLibrary("uxtheme.dll");
if (uxtDLL == NULL)
return;
ETDT_FUNC EnThemeDlgTex = (ETDT_FUNC)GetProcAddress(uxtDLL, "EnableThemeDialogTexture");
ITDTE_FUNC ThemeDlgTexIsEn = (ITDTE_FUNC)GetProcAddress(uxtDLL, "IsThemeDialogTextureEnabled");
if (ThemeDlgTexIsEn == NULL || EnThemeDlgTex == NULL)
{
FreeLibrary(uxtDLL);
return;
}
if (ThemeDlgTexIsEn(hWndMain))
{
unsigned int curTab;
#ifndef ETDT_ENABLETAB
#define ETDT_ENABLETAB 6
#endif
// draw pages with theme texture
for (curTab = 0; curTab < NUM_CFG_TABS; curTab ++)
EnThemeDlgTex(hWndCfgTab[curTab], ETDT_ENABLETAB);
}
FreeLibrary(uxtDLL);
return;
}
static void Slider_Setup(HWND hWndDlg, int dlgID, int minVal, int maxVal, int largeStep, int tickFreq)
{
LONG retL;
retL = SendDlgItemMessage(hWndDlg, dlgID, TBM_SETRANGE, 0, MAKELONG(minVal, maxVal));
// Note to TBM_SETTICFREQ:
// Needs Automatic Ticks enabled, draw a tick mark every x ticks.
retL = SendDlgItemMessage(hWndDlg, dlgID, TBM_SETTICFREQ, tickFreq, 0);
retL = SendDlgItemMessage(hWndDlg, dlgID, TBM_SETLINESIZE, 0, 1);
retL = SendDlgItemMessage(hWndDlg, dlgID, TBM_SETPAGESIZE, 0, largeStep);
return;
}
static BOOL SetDlgItemFloat(HWND hDlg, int nIDDlgItem, double value, int precision)
{
char TempStr[0x10];
sprintf(TempStr, "%.*f", precision, value);
return SetDlgItemTextA(hDlg, nIDDlgItem, TempStr);
}
static int LoadConfigDialogInfo(HWND hWndDlg)
{
const GeneralOptions& gOpts = pluginCfg.genOpts;
char tempStr[0x18];
// --- Main Dialog ---
CheckDlgButton(hWndDlg, ImmediateUpdCheck,
gOpts.immediateUpdate ? BST_CHECKED : BST_UNCHECKED);
// --- Playback Tab ---
COMBO_ADDSTR(CfgPlayback, ResmpModeList, "linear interpolation");
COMBO_ADDSTR(CfgPlayback, ResmpModeList, "nearest-neighbour");
COMBO_ADDSTR(CfgPlayback, ResmpModeList, "lin. up, NN down");
COMBO_ADDSTR(CfgPlayback, ChipSmpModeList, "native");
COMBO_ADDSTR(CfgPlayback, ChipSmpModeList, "highest (nat./cust.)");
COMBO_ADDSTR(CfgPlayback, ChipSmpModeList, "custom");
COMBO_ADDSTR(CfgPlayback, ChipSmpModeList, "highest, FM native");
LoopTimeMode = false;
SetDlgItemInt(CfgPlayback, LoopText, gOpts.maxLoops, FALSE);
SetDlgItemInt(CfgPlayback, FadeText, gOpts.fadeTime, FALSE);
SetDlgItemInt(CfgPlayback, PauseNlText, gOpts.pauseTime_jingle, FALSE);
SetDlgItemInt(CfgPlayback, PauseLpText, gOpts.pauseTime_loop, FALSE);
// Playback rate
switch(gOpts.pbRate)
{
case 0:
CheckRadioButton(CfgPlayback, RateRecRadio, RateOtherRadio, RateRecRadio);
break;
case 60:
CheckRadioButton(CfgPlayback, RateRecRadio, RateOtherRadio, Rate60HzRadio);
break;
case 50:
CheckRadioButton(CfgPlayback, RateRecRadio, RateOtherRadio, Rate50HzRadio);
break;
default:
CheckRadioButton(CfgPlayback, RateRecRadio, RateOtherRadio, RateOtherRadio);
break;
}
CTRL_SET_ENABLE(CfgPlayback, RateText, CHECK2BOOL(CfgPlayback, RateOtherRadio));
CTRL_SET_ENABLE(CfgPlayback, RateLabel, CHECK2BOOL(CfgPlayback, RateOtherRadio));
SetDlgItemInt(CfgPlayback, RateText, gOpts.pbRate, FALSE);
{
double dbVol = 6.0 * log(gOpts.volume) / M_LN2;
int sliderPos = (int)floor(dbVol * 10 + 0.5) + 120;
if (sliderPos < 0)
sliderPos = 0;
else if (sliderPos > 240)
sliderPos = 240;
// Slider from -12.0 db to +12.0 db, 0.1 db Steps (large Steps 2.0 db)
Slider_Setup(CfgPlayback, VolumeSlider, 0, 240, 20, 10);
SLIDER_SETPOS(CfgPlayback, VolumeSlider, sliderPos);
sprintf(tempStr, "%.3f (%+.1f db)", gOpts.volume, dbVol);
SetDlgItemTextA(CfgPlayback, VolumeText, tempStr);
}
SetDlgItemInt(CfgPlayback, SmplPbRateText, gOpts.smplRate, FALSE);
COMBO_SETPOS(CfgPlayback, ResmpModeList, gOpts.resmplMode);
SetDlgItemInt(CfgPlayback, SmplChipRateText, gOpts.chipSmplRate, FALSE);
COMBO_SETPOS(CfgPlayback, ChipSmpModeList, gOpts.chipSmplMode);
CheckDlgButton(CfgPlayback, SurroundCheck, gOpts.pseudoSurround ? BST_CHECKED : BST_UNCHECKED);
/*// Filter
switch(filter_type)
{
case FILTER_NONE:
CheckRadioButton(CfgPlayback, rbFilterNone, rbFilterWeighted, rbFilterNone);
break;
case FILTER_LOWPASS:
CheckRadioButton(CfgPlayback, rbFilterNone, rbFilterWeighted, rbFilterLowPass);
break;
case FILTER_WEIGHTED:
CheckRadioButton(CfgPlayback, rbFilterNone, rbFilterWeighted, rbFilterWeighted);
break;
}*/
// --- Tags Tab ---
SetDlgItemTextA(CfgTags, TitleFormatText, gOpts.titleFormat.c_str());
CheckDlgButton(CfgTags, PreferJapCheck, gOpts.preferJapTag);
CheckDlgButton(CfgTags, FM2413Check, gOpts.appendFM2413);
CheckDlgButton(CfgTags, TrimWhitespcCheck, gOpts.trimWhitespace);
CheckDlgButton(CfgTags, StdSeparatorsCheck, gOpts.stdSeparators);
CheckDlgButton(CfgTags, TagFallbackCheck, gOpts.fidTagFallback);
CheckDlgButton(CfgTags, NoInfoCacheCheck, gOpts.noInfoCache);
//CheckDlgButton(CfgTags, cbTagsStandardiseDates, TagsStandardiseDates);
SetDlgItemInt(CfgTags, MLTypeText, gOpts.mediaLibFileType, FALSE);
// --- Muting Tab and Options & Pan Tab ---
size_t curChp;
for (curChp = 0; curChp < pluginCfg.chipOpts.size(); curChp ++)
{
const ChipOptions& cOpts = pluginCfg.chipOpts[curChp][0];
const char* devName = SndEmu_GetDevName(cOpts.chipType, 0x00, NULL);
COMBO_ADDSTR(CfgMuting, MutingChipList, devName);
COMBO_ADDSTR(CfgOptPan, EmuOptChipList, devName);
}
COMBO_ADDSTR(CfgMuting, MutingChipNumList, "Chip #1");
COMBO_ADDSTR(CfgOptPan, EmuOptChipNumList, "Chip #1");
COMBO_ADDSTR(CfgMuting, MutingChipNumList, "Chip #2");
COMBO_ADDSTR(CfgOptPan, EmuOptChipNumList, "Chip #2");
COMBO_SETPOS(CfgMuting, MutingChipList, muteChipID);
COMBO_SETPOS(CfgOptPan, EmuOptChipList, muteChipID);
COMBO_SETPOS(CfgMuting, MutingChipNumList, muteChipSet);
COMBO_SETPOS(CfgOptPan, EmuOptChipNumList, muteChipSet);
CheckDlgButton(CfgMuting, ResetMuteCheck, gOpts.resetMuting);
int panSld;
for (panSld = PanChn1Slider; panSld <= PanChn15Slider; panSld ++)
Slider_Setup(CfgOptPan, panSld, 0x00, 0x40, 0x08, 0x08);
return 0;
}
// Dialogue box callback function
static BOOL CALLBACK ConfigDialogProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
switch(wMessage)
{
case WM_INITDIALOG:
// do nothing if this is a child window (tab page) callback, pass to the parent
if (GetWindowLong(hWndDlg, GWL_STYLE) & WS_CHILD)
{
assert(false);
return FALSE;
}
InitConfigDialog(hWndDlg);
SetWindowTextA(hWndDlg, INVGM_TITLE " configuration");
LoadConfigDialogInfo(hWndDlg);
SendMessage(hWndDlg, WM_HSCROLL, 0, 0); // trigger slider value change handlers
SendMessage(CfgPlayback, WM_COMMAND, MAKEWPARAM(ResmpModeList, CBN_SELCHANGE), 0);
SendMessage(CfgPlayback, WM_COMMAND, MAKEWPARAM(ChipSmpModeList, CBN_SELCHANGE), 0);
SendMessage(CfgMuting, WM_COMMAND, MAKEWPARAM(MutingChipList, CBN_SELCHANGE), 0);
SendMessage(CfgOptPan, WM_COMMAND, MAKEWPARAM(EmuOptChipList, CBN_SELCHANGE), 0);
SetFocus(hWndDlg);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
{
UINT8 CurTab;
for (CurTab = 0; CurTab < NUM_CFG_TABS; CurTab ++)
SendMessage(hWndCfgTab[CurTab], WM_COMMAND, IDOK, lParam);
}
EndDialog(hWndDlg, 0);
return TRUE;
case IDCANCEL: // [X] button, Alt+F4, etc
{
UINT8 CurTab;
for (CurTab = 0; CurTab < NUM_CFG_TABS; CurTab ++)
SendMessage(hWndCfgTab[CurTab], WM_COMMAND, IDCANCEL, lParam);
}
EndDialog(hWndDlg, 1);
return TRUE;
case ImmediateUpdCheck:
if (HIWORD(wParam) == BN_CLICKED)
pluginCfg.genOpts.immediateUpdate = CHECK2BOOL(hWndDlg, ImmediateUpdCheck);
break;
}
break; // end WM_COMMAND handling
case WM_NOTIFY:
switch(LOWORD(wParam))
{
case TabCollection:
{
int CurTab = TabCtrl_GetCurSel(GetDlgItem(hWndDlg, TabCollection));
if (CurTab == -1)
break;
#ifdef HIDE_VGM7Z
if (CurTab >= 2)
CurTab ++; // skip hidden VGM7Z tab
#endif
switch(((LPNMHDR)lParam)->code)
{
case TCN_SELCHANGING: // hide current window
ShowWindow(hWndCfgTab[CurTab], SW_HIDE);
EnableWindow(hWndCfgTab[CurTab], FALSE);
break;
case TCN_SELCHANGE: // show current window
if (hWndCfgTab[CurTab] == CfgMuting)
{
COMBO_SETPOS(CfgMuting, MutingChipList, muteChipID);
COMBO_SETPOS(CfgMuting, MutingChipNumList, muteChipSet);
ShowMutingCheckBoxes(muteChipID, muteChipSet);
}
else if (hWndCfgTab[CurTab] == CfgOptPan)
{
COMBO_SETPOS(CfgOptPan, EmuOptChipList, muteChipID);
COMBO_SETPOS(CfgOptPan, EmuOptChipNumList, muteChipSet);
ShowOptPanBoxes(muteChipID, muteChipSet);
}
EnableWindow(hWndCfgTab[CurTab], TRUE);
ShowWindow(hWndCfgTab[CurTab], SW_SHOW);
break;
}
break;
}
}
return TRUE;
}
return FALSE; // message not processed
}
static BOOL CALLBACK CfgDlgPlaybackProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
GeneralOptions& gOpts = pluginCfg.genOpts;
switch(wMessage)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
gOpts.maxLoops = GetDlgItemInt(CfgPlayback, LoopText, NULL, FALSE);
gOpts.fadeTime = GetDlgItemInt(CfgPlayback, FadeText, NULL, FALSE);
gOpts.pauseTime_jingle = GetDlgItemInt(CfgPlayback, PauseNlText, NULL, FALSE);
gOpts.pauseTime_loop = GetDlgItemInt(CfgPlayback, PauseLpText, NULL, FALSE);
if (IsDlgButtonChecked(CfgPlayback, RateRecRadio))
gOpts.pbRate = 0;
else if (IsDlgButtonChecked(CfgPlayback, Rate60HzRadio))
gOpts.pbRate = 60;
else if (IsDlgButtonChecked(CfgPlayback, Rate50HzRadio))
gOpts.pbRate = 50;
else if (IsDlgButtonChecked(CfgPlayback, RateOtherRadio))
gOpts.pbRate = GetDlgItemInt(CfgPlayback, RateText, NULL, FALSE);
gOpts.smplRate = GetDlgItemInt(CfgPlayback, SmplPbRateText, NULL, FALSE);
gOpts.resmplMode = (UINT8)COMBO_GETPOS(CfgPlayback, ResmpModeList);
gOpts.chipSmplRate = GetDlgItemInt(CfgPlayback, SmplChipRateText, NULL, FALSE);
gOpts.chipSmplMode = (UINT8)COMBO_GETPOS(CfgPlayback, ChipSmpModeList);
ApplyCfg_General(*GetMainPlayerFISScan()->GetPlayer(), gOpts, false);
ApplyCfg_General(*GetMainPlayerFIS()->GetPlayer(), gOpts, true);
RefreshPlaybackOptions();
QueueInfoReload(); // if the Playback Rate was changed, a refresh is needed
EndDialog(hWndDlg, 0);
return TRUE;
case IDCANCEL:
EndDialog(hWndDlg, 1);
return TRUE;
case RateRecRadio:
case Rate60HzRadio:
case Rate50HzRadio:
case RateOtherRadio:
// Windows already does the CheckRadioButton by itself
//CheckRadioButton(CfgPlayback, RateRecRadio, RateOtherRadio, LOWORD(wParam));
if (LOWORD(wParam) == RateOtherRadio)
{
CTRL_ENABLE(CfgPlayback, RateText);
CTRL_ENABLE(CfgPlayback, RateLabel);
//SetFocus(GetDlgItem(CfgPlayback, RateText));
}
else
{
CTRL_DISABLE(CfgPlayback, RateText);
CTRL_DISABLE(CfgPlayback, RateLabel);
}
break;
case ResmpModeList:
break;
case ChipSmpModeList:
if (HIWORD(wParam) == CBN_SELCHANGE)
{
BOOL CtrlEnable = (COMBO_GETPOS(CfgPlayback, ChipSmpModeList) > 0);
CTRL_SET_ENABLE(CfgPlayback, SmplChipRateLabel, CtrlEnable);
CTRL_SET_ENABLE(CfgPlayback, SmplChipRateText, CtrlEnable);
CTRL_SET_ENABLE(CfgPlayback, SmplChipRateHzLabel, CtrlEnable);
}
break;
case LoopText:
if (HIWORD(wParam) == EN_CHANGE)
{
// for correct grammar: "Play loop x time(s)"
BOOL Translated;
bool NewLTMode = (GetDlgItemInt(CfgPlayback, LoopText, &Translated, FALSE) == 1);
if (Translated && NewLTMode != LoopTimeMode)
{
char TimeStr[0x08];
LoopTimeMode = NewLTMode;
strcpy(TimeStr, "times");
if (LoopTimeMode)
TimeStr[4] = '\0';
SetDlgItemTextA(CfgPlayback, LoopTimesLabel, TimeStr);
}
}
break;
case SurroundCheck:
gOpts.pseudoSurround = CHECK2BOOL(CfgPlayback, SurroundCheck);
UpdatePlayback();
break;
}
break;
case WM_HSCROLL:
if (GetDlgCtrlID((HWND)lParam) == VolumeSlider)
{
double dbVol;
int sliderPos;
char tempStr[0x18];
if (LOWORD(wParam) == TB_THUMBPOSITION || LOWORD(wParam) == TB_THUMBTRACK)
sliderPos = HIWORD(wParam);
else
sliderPos = SLIDER_GETPOS(CfgPlayback, VolumeSlider);
dbVol = (sliderPos - 120) / 10.0f;
gOpts.volume = pow(2.0, dbVol / 6.0);
sprintf(tempStr, "%.3f (%+.1f db)", gOpts.volume, dbVol);
SetDlgItemTextA(CfgPlayback, VolumeText, tempStr);
RefreshPlaybackOptions();
if (LOWORD(wParam) != TB_THUMBTRACK) // prevent too many skips
UpdatePlayback();
}
break;
case WM_NOTIFY:
break;
}
return FALSE;
}
static BOOL CALLBACK CfgDlgTagsProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
GeneralOptions& gOpts = pluginCfg.genOpts;
switch(wMessage)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
{
char tempStr[0x80];
UINT charCnt = GetDlgItemTextA(CfgTags, TitleFormatText, tempStr, 0x7F); tempStr[0x7F] = '\0';
gOpts.titleFormat.assign(tempStr, tempStr + charCnt);
}
//TagsStandardiseDates = CHECK2BOOL(CfgTags, cbTagsStandardiseDates);
SetDlgItemInt(CfgTags, MLTypeText, gOpts.mediaLibFileType, FALSE);
EndDialog(hWndDlg, 0);
return TRUE;
case IDCANCEL:
EndDialog(hWndDlg, 1);
return TRUE;
case PreferJapCheck:
gOpts.preferJapTag = CHECK2BOOL(CfgTags, PreferJapCheck);
break;
case FM2413Check:
gOpts.appendFM2413 = CHECK2BOOL(CfgTags, FM2413Check);
break;
case TrimWhitespcCheck:
gOpts.trimWhitespace = CHECK2BOOL(CfgTags, TrimWhitespcCheck);
QueueInfoReload();
break;
case StdSeparatorsCheck:
gOpts.stdSeparators = CHECK2BOOL(CfgTags, StdSeparatorsCheck);
QueueInfoReload();
break;
case TagFallbackCheck:
gOpts.fidTagFallback = CHECK2BOOL(CfgTags, TagFallbackCheck);
break;
case NoInfoCacheCheck:
gOpts.noInfoCache = CHECK2BOOL(CfgTags, NoInfoCacheCheck);
break;
}
break;
case WM_NOTIFY:
break;
}
return FALSE;
}
static BOOL CALLBACK CfgDlgMutingProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
switch(wMessage)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hWndDlg, 0);
return TRUE;
case IDCANCEL:
EndDialog(hWndDlg, 1);
return TRUE;
case MutingChipList:
case MutingChipNumList:
if (HIWORD(wParam) == CBN_SELCHANGE)
{
ShowMutingCheckBoxes((UINT8)COMBO_GETPOS(CfgMuting, MutingChipList),
(UINT8)COMBO_GETPOS(CfgMuting, MutingChipNumList));
}
break;
case ResetMuteCheck:
if (HIWORD(wParam) == BN_CLICKED)
pluginCfg.genOpts.resetMuting = CHECK2BOOL(CfgMuting, ResetMuteCheck);
break;
case MuteChipCheck:
muteCOpts->chipDisable = CHECK2BOOL(CfgMuting, MuteChipCheck) ? 0xFF : 0x00;
RefreshMuting();
UpdatePlayback();
break;
}
// I'm NOT going to have 24 case-lines!
if (LOWORD(wParam) >= MuteChn1Check && LOWORD(wParam) <= MuteChn24Check)
{
if (HIWORD(wParam) == BN_CLICKED)
{
SetMutingData(LOWORD(wParam) - MuteChn1Check,
(bool)CHECK2BOOL(CfgMuting, LOWORD(wParam)));
}
}
break;
case WM_NOTIFY:
break;
}
return FALSE;
}
static BOOL CALLBACK CfgDlgOptPanProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
switch(wMessage)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hWndDlg, 0);
return TRUE;
case IDCANCEL:
EndDialog(hWndDlg, 1);
return TRUE;
case OpenINIButton:
{
const char* iniPath = GetIniFilePath();
int retVal = (int)ShellExecuteA(hWndDlg, "open", iniPath, NULL, NULL, SW_SHOW);
return (retVal >= 32) ? TRUE : FALSE;
}
case EmuCoreRadio1:
case EmuCoreRadio2:
case EmuCoreRadio3:
{
ChipOptions* cOpts = &pluginCfg.chipOpts[muteChipID][0];
bool isSub;
cOpts[0].emuType = LOWORD(wParam) - EmuCoreRadio1;
UINT32 fcc = EmuTypeNum2CoreFCC(cOpts[0].chipType, cOpts[0].emuType, &isSub);
if (isSub)
cOpts[0].emuCoreSub = fcc;
else
cOpts[0].emuCore = fcc;
// currently EmuCore affects both chip instances
cOpts[1].emuType = cOpts[0].emuType;
cOpts[1].emuCore = cOpts[0].emuCore;
cOpts[1].emuCoreSub = cOpts[0].emuCoreSub;
// enable/disable panning sliders, depending on the core's features
ShowOptPanBoxes(muteChipID, muteChipSet);
break;
}
case EmuOptChipList:
case EmuOptChipNumList:
if (HIWORD(wParam) == CBN_SELCHANGE)
{
ShowOptPanBoxes((UINT8)COMBO_GETPOS(CfgOptPan, EmuOptChipList),
(UINT8)COMBO_GETPOS(CfgOptPan, EmuOptChipNumList));
}
break;
}
break;
case WM_HSCROLL:
{
int sliderID = GetDlgCtrlID((HWND)lParam);
if (sliderID >= PanChn1Slider && sliderID <= PanChn15Slider)
{
int sliderPos;
bool dragging = (LOWORD(wParam) == TB_THUMBTRACK);
if (dragging || LOWORD(wParam) == TB_THUMBPOSITION)
sliderPos = HIWORD(wParam);
else
sliderPos = SLIDER_GETPOS(CfgOptPan, sliderID);
SetPanningData(sliderID - PanChn1Slider, sliderPos, dragging);
}
break;
}
case WM_NOTIFY:
break;
}
return FALSE;
}
static BOOL CALLBACK CfgDlgChildProc(HWND hWndDlg, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
// Generic Procedure for unused/unfinished tabs
switch(wMessage)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hWndDlg, 0);
return TRUE;
case IDCANCEL:
EndDialog(hWndDlg, 1);
return TRUE;
}
break;
case WM_NOTIFY:
break;
}
return FALSE;
}
static inline bool IsSongPlaying(void)
{
PlayerA* plr = GetMainPlayerFIS()->GetPlayer();
return !!(plr->GetState() & PLAYSTATE_PLAY);
}
static bool IsChipAvailable(const ChipOptions& cOpts)
{
if (! IsSongPlaying())
return true; // not playing -> "available" (= user may change settings)
PlayerBase* plr = GetMainPlayerFIS()->GetPlayer()->GetPlayer();
std::vector<PLR_DEV_INFO> diList;
plr->GetSongDeviceInfo(diList);
for (size_t curDev = 0; curDev < diList.size(); curDev ++)
{
const PLR_DEV_INFO& pdi = diList[curDev];
if (pdi.type == cOpts.chipType && pdi.instance == cOpts.chipInstance)
return true;
}
return false; // The current song doesn't use the chip - disable controls.
}
static UINT32 GetChipCore(const ChipOptions& cOpts)
{
if (! IsSongPlaying())
return EmuTypeNum2CoreFCC(cOpts.chipType, cOpts.emuType, NULL);
PlayerBase* plr = GetMainPlayerFIS()->GetPlayer()->GetPlayer();
std::vector<PLR_DEV_INFO> diList;
plr->GetSongDeviceInfo(diList);
for (size_t curDev = 0; curDev < diList.size(); curDev ++)
{
const PLR_DEV_INFO& pdi = diList[curDev];
if (pdi.type == cOpts.chipType && pdi.instance == cOpts.chipInstance)
{
if (pdi.type == DEVID_YM2203 || pdi.type == DEVID_YM2608 || pdi.type == DEVID_YM2610)
return EmuTypeNum2CoreFCC(cOpts.chipType, cOpts.emuType, NULL); // TODO: return sub-core
else
return pdi.core;
}
}
// return magic number for "not found" (avoid 0, just in case it is used by some core)
return 0xFFFFFFFF;
}
static void ShowMutingCheckBoxes(UINT8 ChipID, UINT8 ChipSet)
{
UINT8 ChnCount;
UINT8 ChnCntS[0x04];
const char* SpcName[0x40]; // Special Channel Names
UINT8 CurChn;
UINT8 SpcModes;
bool EnableChk;
bool Checked;
UINT8 CurMode;
UINT8 ChnBase;
UINT8 FnlChn;
char TempName[0x18];
for (CurChn = 0; CurChn < 0x40; CurChn ++)
SpcName[CurChn] = NULL;
muteCOpts = &pluginCfg.chipOpts[ChipID][ChipSet];
muteChipID = ChipID;
muteChipSet = ChipSet;
EnableChk = IsChipAvailable(*muteCOpts);
SpcModes = 0;
switch(muteCOpts->chipType)
{
case DEVID_SN76496:
ChnCount = 4;
SpcName[3] = "&Noise";
break;
case DEVID_YM2413:
case DEVID_YM3812:
case DEVID_YM3526:
case DEVID_Y8950:
ChnCount = 14; // 9 + 5
SpcName[ 9] = "&Bass Drum";
SpcName[10] = "S&nare Drum";
SpcName[11] = "&Tom Tom";
SpcName[12] = "C&ymbal";
SpcName[13] = "&Hi-Hat";
if (muteCOpts->chipType == DEVID_Y8950)
{
ChnCount = 15;
SpcName[14] = "&Delta-T";
}
break;
case DEVID_YM2612:
ChnCount = 7; // 6 + DAC
SpcName[6] = "&DAC";
break;
case DEVID_YM2151:
ChnCount = 8;
break;
case DEVID_SEGAPCM:
ChnCount = 16;
break;
case DEVID_RF5C68:
ChnCount = 8;
break;
case DEVID_YM2203:
ChnCount = 6; // 3 FM + 3 AY8910
SpcModes = 3;
ChnCntS[0] = 3;
SpcName[0] = "FM Chn";
ChnCntS[1] = 0;
ChnCntS[2] = 3;
SpcName[2] = "SSG Chn";
break;
case DEVID_YM2608:
case DEVID_YM2610:
ChnCount = 16; // 6 FM + 6 ADPCM + 1 DeltaT + 3 AY8910
SpcModes = 3;
ChnCntS[0] = 6;
SpcName[0] = "FM Chn";
ChnCntS[1] = 7;
SpcName[1] = "PCM Chn";
SpcName[14] = "&Delta-T";
ChnCntS[2] = 3;
SpcName[2] = "SSG Chn";
break;
case DEVID_YMF262:
ChnCount = 23; // 18 + 5
SpcName[18] = "&Bass Drum";
SpcName[19] = "S&nare Drum";
SpcName[20] = "&Tom Tom";
SpcName[21] = "C&ymbal";
SpcName[22] = "&Hi-Hat";
break;
case DEVID_YMF278B:
ChnCount = 24;
break;
case DEVID_YMF271:
ChnCount = 12;
break;
case DEVID_YMZ280B:
ChnCount = 8;
break;
case DEVID_32X_PWM:
ChnCount = 1;
EnableChk &= ! ChipSet;
break;
case DEVID_AY8910:
ChnCount = 3;
break;
case DEVID_GB_DMG:
SpcName[0] = "Square &1";
SpcName[1] = "Square &2";
SpcName[2] = "Progr. &Wave";
SpcName[3] = "&Noise";
ChnCount = 4;
break;
case DEVID_NES_APU:
SpcName[0] = "Square &1";
SpcName[1] = "Square &2";
SpcName[2] = "&Triangle";
SpcName[3] = "&Noise";
SpcName[4] = "&DPCM";
SpcName[5] = "&FDS";
ChnCount = 6;
break;
case DEVID_YMW258: // Multi PCM
ChnCount = 28;
break;
case DEVID_uPD7759:
ChnCount = 1;
break;
case DEVID_OKIM6258:
ChnCount = 1;
break;
case DEVID_OKIM6295:
ChnCount = 4;
break;
case DEVID_K051649:
ChnCount = 5;
break;
case DEVID_K054539:
ChnCount = 8;
break;
case DEVID_C6280:
ChnCount = 6;
break;
case DEVID_C140:
ChnCount = 24;
break;
case DEVID_C219:
ChnCount = 16;
break;
case DEVID_K053260:
ChnCount = 4;
break;
case DEVID_POKEY:
ChnCount = 4;
break;
case DEVID_QSOUND:
ChnCount = 16;
EnableChk &= ! ChipSet;
break;
case DEVID_SCSP: