1
0

wa2_config.cpp 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. #include "out_ds.h"
  2. #include <windowsx.h>
  3. #include <commctrl.h>
  4. #include "res_wa2/resource.h"
  5. #include "ds2.h"
  6. #include <math.h>
  7. #include <stdio.h>
  8. #include "ds_ipc.h"
  9. #include "api.h"
  10. #include "../winamp/wa_ipc.h"
  11. bool wa2_GetRealtimeStat(DS2_REALTIME_STAT * stat);
  12. void wa2_sync_in();//hack, use critical section on config changes
  13. void wa2_sync_out();
  14. #ifdef HAVE_SSRC
  15. bool wa2_IsResampling(RESAMPLING_STATUS *);
  16. #endif
  17. FadeCfg
  18. cfg_fade_start(L"start",L"cfg_fade_start",333,0,1),
  19. cfg_fade_firststart(L"first start",L"cfg_fade_firststart",333,0,1),
  20. cfg_fade_stop(L"end of song", L"cfg_fade_stop",333,0,1),
  21. cfg_fade_pause(L"pause/stop", L"cfg_fade_pause",333,1,1),
  22. cfg_fade_seek(L"seek", L"cfg_fade_seek",333,1,1);
  23. #define N_FADES 5
  24. static FadeCfg * fades[N_FADES]={&cfg_fade_start,&cfg_fade_firststart,&cfg_fade_stop,&cfg_fade_pause,&cfg_fade_seek};
  25. int FadeNames[N_FADES] = {IDS_FADE_START, IDS_FADE_FIRSTSTART, IDS_FADE_STOP, IDS_FADE_PAUSE, IDS_FADE_SEEK};
  26. HWND buffer_config_wnd = NULL;
  27. HWND fades_config_wnd = NULL;
  28. extern HWND ipcWnd;
  29. extern Out_Module mod;
  30. cfg_int cfg_def_fade("cfg_def_fade",333);
  31. static DWORD config_start_time;
  32. extern cfg_int cfg_oldpause;
  33. extern cfg_int cfg_volmode;
  34. extern cfg_int cfg_logvol_min;
  35. extern cfg_int cfg_logfades;
  36. extern cfg_int cfg_fadevol;
  37. extern cfg_int cfg_buf_ms,cfg_prebuf2,cfg_sil_db,cfg_trackhack;
  38. extern cfg_struct_t<GUID> cfg_dev2;
  39. extern cfg_int cfg_wait,cfg_killsil,cfg_volume;
  40. extern cfg_int cfg_hw_mix;
  41. extern cfg_int cfg_createprimary,cfg_override;
  42. extern cfg_int cfg_override_freq,cfg_override_bps,cfg_override_nch;
  43. extern cfg_struct_t<__int64> cfg_total_time;
  44. extern cfg_int cfg_autocpu;
  45. static cfg_int cfg_status_update_freq("cfg_status_update_freq",50);
  46. extern cfg_int cfg_cur_tab;
  47. static wchar_t* rstrcpy(wchar_t* s1, wchar_t * s2)
  48. {
  49. while(s2 && *s2) *(s1++)=*(s2++);
  50. return s1;
  51. }
  52. typedef struct
  53. {
  54. const wchar_t* name;
  55. int on,usedef;
  56. int time;
  57. } FadeCfgCopy;
  58. void format_fade(wchar_t * txt,FadeCfgCopy * c, int idx)
  59. {
  60. txt=rstrcpy(txt, WASABI_API_LNGSTRINGW(IDS_ON));
  61. txt=rstrcpy(txt, WASABI_API_LNGSTRINGW(FadeNames[idx]));
  62. if (!c->on) txt=rstrcpy(txt,WASABI_API_LNGSTRINGW(IDS_DISABLED));
  63. else if (!c->usedef)
  64. {
  65. wchar_t tmp[16], fmt[16];
  66. wsprintfW(fmt,L" (%s)",WASABI_API_LNGSTRINGW(IDS_DS_U_MS));
  67. wsprintfW(tmp,fmt,c->time);
  68. txt=rstrcpy(txt,tmp);
  69. }
  70. *txt=0;
  71. }
  72. static void add_fade(HWND w,FadeCfg * cfg, int n)
  73. {
  74. FadeCfgCopy * c=new FadeCfgCopy;
  75. c->name=cfg->name;
  76. c->time=cfg->time;
  77. c->on=cfg->on;
  78. c->usedef=cfg->usedef;
  79. wchar_t txt[256];
  80. format_fade(txt,c,n);
  81. UINT i=(UINT)SendMessage(w,LB_ADDSTRING,0,(LPARAM)txt);
  82. SendMessage(w,LB_SETITEMDATA,i,(LPARAM)c);
  83. }
  84. static void update_prebuf_1(HWND wnd)
  85. {
  86. wchar_t zz[128];
  87. wsprintfW(zz,WASABI_API_LNGSTRINGW(IDS_DS_U_MS),SendDlgItemMessage(wnd,IDC_PREBUFFER_1,TBM_GETPOS,0,0));
  88. SetDlgItemTextW(wnd,IDC_PREBUF_DISP_1,zz);
  89. }
  90. static void update_prebuf_2(HWND wnd)
  91. {
  92. wchar_t zz[128];
  93. wsprintfW(zz,WASABI_API_LNGSTRINGW(IDS_DS_U_MS),SendDlgItemMessage(wnd,IDC_PREBUFFER_2,TBM_GETPOS,0,0));
  94. SetDlgItemTextW(wnd,IDC_PREBUF_DISP_2,zz);
  95. }
  96. #define BUFFER_SCALE 4000.0
  97. UINT cur_buffer;
  98. static UINT get_buffer(HWND wnd)
  99. {
  100. if (cur_buffer) return cur_buffer;
  101. //0-BUFFER_SCALE => 200-20000
  102. int z=(int)SendDlgItemMessage(wnd,IDC_BUFFER,TBM_GETPOS,0,0);
  103. return cur_buffer=(UINT) ( 0.5 + 200.0*pow(100.0,(double)z/BUFFER_SCALE) );
  104. }
  105. void set_buffer(HWND wnd,UINT b)
  106. {
  107. cur_buffer=b;
  108. SendDlgItemMessage(wnd,IDC_BUFFER,TBM_SETPOS,1,(long) ( 0.5 + BUFFER_SCALE * log( (double)b/200.0 ) / log( 100.0 ) ));
  109. }
  110. void update_prebuf_range(HWND wnd)
  111. {
  112. UINT max=get_buffer(wnd);
  113. if (max>0x7FFF) max=0x7FFF;
  114. SendDlgItemMessage(wnd,IDC_PREBUFFER_1,TBM_SETRANGE,1,MAKELONG(0,max));
  115. SendDlgItemMessage(wnd,IDC_PREBUFFER_2,TBM_SETRANGE,1,MAKELONG(0,max));
  116. }
  117. void update_buf(HWND wnd)
  118. {
  119. wchar_t zz[128];
  120. wsprintfW(zz,WASABI_API_LNGSTRINGW(IDS_DS_U_MS),get_buffer(wnd));
  121. SetDlgItemTextW(wnd,IDC_BUF_DISP,zz);
  122. }
  123. static void _switch_dlgitems(HWND wnd,const UINT * ids,UINT n_ids,int b)
  124. {
  125. UINT n;
  126. for(n=0;n<n_ids;n++)
  127. {
  128. EnableWindow(GetDlgItem(wnd,ids[n]),b);
  129. }
  130. }
  131. #define switch_dlgitems(W,X,B) _switch_dlgitems(W,X,sizeof(X)/sizeof(X[0]),B)
  132. #pragma warning(disable:4800)
  133. static void cfgSetDevice(HWND wnd,const GUID * guid,const wchar_t * name)
  134. {
  135. HWND w=GetDlgItem(wnd,IDC_DEVICE);
  136. SendMessageW(w,CB_RESETCONTENT,0,0);
  137. DsDevEnum e;
  138. bool dev_set=0;
  139. UINT n=0;
  140. while(e)
  141. {
  142. SendMessageW(w,CB_ADDSTRING,0,(LPARAM)e.GetName());
  143. if (!dev_set)
  144. {
  145. if (name)
  146. {
  147. if (!lstrcmpiW(e.GetName(),(LPCWSTR)name)) dev_set=1;
  148. }
  149. else
  150. {
  151. if (e.GetGuid()==*guid) dev_set=1;
  152. }
  153. if (dev_set) SendMessageW(w,CB_SETCURSEL,n,0);
  154. }
  155. n++;
  156. e++;
  157. }
  158. if (!dev_set) SendMessageW(w,CB_SETCURSEL,0,0);
  159. SendMessageW(wnd,WM_COMMAND,(CBN_SELCHANGE<<16)|IDC_DEVICE,0);
  160. }
  161. static INT_PTR CALLBACK CfgProc1(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
  162. {//device
  163. switch(msg)
  164. {
  165. case WM_INITDIALOG:
  166. SendDlgItemMessageW(wnd,IDC_HW_MIX,BM_SETCHECK,cfg_hw_mix,0);
  167. SendDlgItemMessageW(wnd,IDC_CREATE_PRIMARY,BM_SETCHECK,cfg_createprimary,0);
  168. cfgSetDevice(wnd,&(GUID)cfg_dev2,0);
  169. {
  170. DsDevEnum dev_enum;
  171. if (dev_enum.FindDefault())
  172. {
  173. wchar_t blah[512];
  174. wsprintfW(blah,WASABI_API_LNGSTRINGW(IDS_FAQ_PREFERRED_DEVICE),dev_enum.GetName());
  175. SetDlgItemTextW(wnd,IDC_PDS_FAQ,blah);
  176. }
  177. else
  178. {
  179. SetDlgItemTextW(wnd,IDC_PDS_FAQ,WASABI_API_LNGSTRINGW((IDC_PDS_FAQ,DS2::InitDLL() ? IDS_NO_DS_DEVICES_PRESENT : IDS_DS_DOES_NOT_APPEAR_TO_BE_INSTALLED)));
  180. ShowWindow(GetDlgItem(wnd,IDC_STATIC_BLEH),SW_HIDE);
  181. }
  182. }
  183. return 1;
  184. case WM_COMMAND:
  185. switch(LOWORD(wp))
  186. {
  187. case IDC_REFRESH:
  188. {
  189. wchar_t name[256];
  190. GetDlgItemTextW(wnd,IDC_DEVICE,name,256);
  191. cfgSetDevice(wnd,0,name);
  192. }
  193. break;
  194. case IDC_DEVICE:
  195. if(HIWORD(wp) == CBN_SELCHANGE)
  196. {
  197. DSCAPS caps;
  198. DWORD speakercfg;
  199. wchar_t name[256];
  200. GetDlgItemTextW(wnd,IDC_DEVICE,name,256);
  201. DsDevEnum dev_enum;
  202. EnableWindow(GetDlgItem(wnd,IDC_HW_MIX),1);
  203. if (!dev_enum)
  204. {
  205. SetDlgItemTextW(wnd,IDC_DEVICE_INFO,WASABI_API_LNGSTRINGW(IDS_NO_DEVICES_FOUND));
  206. }
  207. else if (!dev_enum.FindName((LPCTSTR)name))
  208. {
  209. SetDlgItemTextW(wnd,IDC_DEVICE_INFO,WASABI_API_LNGSTRINGW(IDS_DEVICE_NOT_FOUND));
  210. }
  211. else if (!dev_enum.GetCaps(&caps,&speakercfg))
  212. {
  213. SetDlgItemTextW(wnd,IDC_DEVICE_INFO,WASABI_API_LNGSTRINGW(IDS_ERROR_GETTING_DEVICE_INFO));
  214. }
  215. else
  216. {
  217. wchar_t mixblah[256];
  218. bool canmix=caps.dwMaxHwMixingStreamingBuffers>1;
  219. if (!canmix) WASABI_API_LNGSTRINGW_BUF(IDS_UNSUPPORTED,mixblah,256);
  220. else wsprintfW(mixblah,WASABI_API_LNGSTRINGW(IDS_SUPPORTED_X_FREE_STREAMS),caps.dwFreeHwMixingStreamingBuffers,caps.dwMaxHwMixingStreamingBuffers);
  221. wchar_t memblah[256];
  222. if (caps.dwTotalHwMemBytes>0) wsprintfW(memblah,WASABI_API_LNGSTRINGW(IDS_X_BYTES),caps.dwTotalHwMemBytes,caps.dwFreeHwMemBytes);
  223. else WASABI_API_LNGSTRINGW_BUF(IDS_NA,memblah,256);
  224. wchar_t spkcfg[64];
  225. const wchar_t*p_speakercfg = spkcfg;
  226. switch(DSSPEAKER_CONFIG(speakercfg))
  227. {
  228. case DSSPEAKER_5POINT1:
  229. WASABI_API_LNGSTRINGW_BUF(IDS_5_1,spkcfg,64);
  230. break;
  231. case DSSPEAKER_HEADPHONE:
  232. WASABI_API_LNGSTRINGW_BUF(IDS_HEADPHONES,spkcfg,64);
  233. break;
  234. case DSSPEAKER_MONO:
  235. WASABI_API_LNGSTRINGW_BUF(IDS_MONO,spkcfg,64);
  236. break;
  237. case DSSPEAKER_QUAD:
  238. WASABI_API_LNGSTRINGW_BUF(IDS_QUAD,spkcfg,64);
  239. break;
  240. case DSSPEAKER_STEREO:
  241. WASABI_API_LNGSTRINGW_BUF(IDS_STEREO,spkcfg,64);
  242. break;
  243. case DSSPEAKER_SURROUND:
  244. WASABI_API_LNGSTRINGW_BUF(IDS_SURROUND,spkcfg,64);
  245. break;
  246. case DSSPEAKER_7POINT1_SURROUND:
  247. WASABI_API_LNGSTRINGW_BUF(IDS_7_1,spkcfg,64);
  248. break;
  249. default:
  250. WASABI_API_LNGSTRINGW_BUF(IDS_UNKNOWN,spkcfg,64);
  251. break;
  252. }
  253. wchar_t blah[1024], t1[16], t2[16], t3[32];
  254. wsprintfW(blah,
  255. WASABI_API_LNGSTRINGW(IDS_DS_INFO),
  256. WASABI_API_LNGSTRINGW_BUF((caps.dwFlags&DSCAPS_CERTIFIED?IDS_YES:IDS_NO),t1,8),
  257. WASABI_API_LNGSTRINGW_BUF((caps.dwFlags&DSCAPS_EMULDRIVER?IDS_YES:IDS_NO),t2,8),
  258. caps.dwMinSecondarySampleRate,caps.dwMaxSecondarySampleRate,
  259. (caps.dwFlags&DSCAPS_CONTINUOUSRATE) ? WASABI_API_LNGSTRINGW_BUF(IDS_CONTINUOUS,t3,16) : L"",
  260. memblah,
  261. mixblah,
  262. p_speakercfg);
  263. SetDlgItemTextW(wnd,IDC_DEVICE_INFO,blah);
  264. }
  265. }
  266. break;
  267. case IDC_APPLY:
  268. case IDOK:
  269. {
  270. wchar_t name[256];
  271. GetDlgItemTextW(wnd,IDC_DEVICE,name,256);
  272. cfg_dev2=DsDevEnumName((LPCTSTR)name).GetGuid();
  273. }
  274. cfg_hw_mix=(bool)SendDlgItemMessage(wnd,IDC_HW_MIX,BM_GETCHECK,0,0);
  275. cfg_createprimary=(bool)SendDlgItemMessage(wnd,IDC_CREATE_PRIMARY,BM_GETCHECK,0,0);
  276. break;
  277. case IDCANCEL:
  278. break;
  279. }
  280. break;
  281. }
  282. return 0;
  283. }
  284. static const UINT prebuf_ctrls[]={IDC_PREBUFFER_1,IDC_PREBUF_DISP_1};
  285. static INT_PTR CALLBACK CfgProc2(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
  286. {//buffering
  287. switch(msg)
  288. {
  289. case WM_INITDIALOG:
  290. buffer_config_wnd = wnd;
  291. SendDlgItemMessageW(wnd,IDC_BUFFER,TBM_SETRANGE,0,MAKELONG(0,(int)BUFFER_SCALE));
  292. set_buffer(wnd,cfg_buf_ms);
  293. update_prebuf_range(wnd);
  294. SendDlgItemMessageW(wnd,IDC_PREBUF_AUTO,BM_SETCHECK,cfg_autocpu,0);
  295. SendDlgItemMessageW(wnd,IDC_PREBUFFER_1,TBM_SETPOS,1,cfg_prebuf2);
  296. SendDlgItemMessageW(wnd,IDC_PREBUFFER_2,TBM_SETPOS,1,cfg_trackhack);
  297. update_prebuf_1(wnd);
  298. update_prebuf_2(wnd);
  299. update_buf(wnd);
  300. return 1;
  301. case WM_DESTROY:
  302. buffer_config_wnd = NULL;
  303. return 0;
  304. case WM_HSCROLL:
  305. switch(GetWindowLongW((HWND)lp,GWL_ID))
  306. {
  307. case IDC_BUFFER:
  308. cur_buffer=0;
  309. update_buf(wnd);
  310. update_prebuf_range(wnd);
  311. update_prebuf_1(wnd);
  312. update_prebuf_2(wnd);
  313. break;
  314. case IDC_PREBUFFER_1:
  315. update_prebuf_1(wnd);
  316. break;
  317. case IDC_PREBUFFER_2:
  318. update_prebuf_2(wnd);
  319. break;
  320. }
  321. break;
  322. case WM_COMMAND:
  323. switch(wp)
  324. {
  325. case IDC_BUF_RESET:
  326. set_buffer(wnd,cfg_buf_ms.get_def());
  327. update_prebuf_range(wnd);
  328. SendDlgItemMessageW(wnd,IDC_PREBUFFER_1,TBM_SETPOS,1,cfg_prebuf2.get_def());
  329. SendDlgItemMessageW(wnd,IDC_PREBUFFER_2,TBM_SETPOS,1,cfg_trackhack.get_def());
  330. update_prebuf_1(wnd);
  331. update_prebuf_2(wnd);
  332. update_buf(wnd);
  333. break;
  334. case IDC_APPLY:
  335. case IDOK:
  336. cfg_buf_ms=get_buffer(wnd);
  337. cfg_prebuf2=(int)SendDlgItemMessageW(wnd,IDC_PREBUFFER_1,TBM_GETPOS,0,0);
  338. cfg_trackhack=(int)SendDlgItemMessageW(wnd,IDC_PREBUFFER_2,TBM_GETPOS,0,0);
  339. cfg_autocpu=(int)SendDlgItemMessageW(wnd,IDC_PREBUF_AUTO,BM_GETCHECK,0,0);
  340. break;
  341. case IDCANCEL:
  342. break;
  343. }
  344. break;
  345. }
  346. const int controls[] =
  347. {
  348. IDC_DB,
  349. IDC_BUFFER,
  350. IDC_PREBUFFER_1,
  351. IDC_PREBUFFER_2,
  352. };
  353. if (FALSE != WASABI_API_APP->DirectMouseWheel_ProcessDialogMessage(wnd, msg, wp, lp, controls, ARRAYSIZE(controls)))
  354. {
  355. return TRUE;
  356. }
  357. return 0;
  358. }
  359. static const UINT customfade_ids[]={IDC_FADE_GROUP,IDC_USE_CUSTOM_FADE,IDC_CUSTOM_FADE,IDC_CUSTOM_FADE_SPIN,IDC_STATIC_MS,IDC_FADE_ENABLED};
  360. static INT_PTR CALLBACK CfgProc3(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
  361. {//fading
  362. switch(msg)
  363. {
  364. case WM_INITDIALOG:
  365. fades_config_wnd = wnd;
  366. SendDlgItemMessageW(wnd,IDC_CUSTOM_FADE_SPIN,UDM_SETRANGE,0,MAKELONG(20000,0));
  367. SendDlgItemMessageW(wnd,IDC_FADE_SPIN,UDM_SETRANGE,0,MAKELONG(0x7FFF,0));
  368. SetDlgItemInt(wnd,IDC_FADE,cfg_def_fade,0);
  369. SendDlgItemMessageW(wnd,IDC_PAUSEFADE2,BM_SETCHECK,cfg_oldpause,0);
  370. {
  371. HWND w;
  372. UINT n;
  373. w=GetDlgItem(wnd,IDC_LIST);
  374. for(n=0;n<N_FADES;n++)
  375. {
  376. add_fade(w,fades[n],n);
  377. }
  378. }
  379. SendDlgItemMessageW(wnd,IDC_WAITx,BM_SETCHECK,cfg_wait,0);
  380. if (NULL != WASABI_API_APP)
  381. WASABI_API_APP->DirectMouseWheel_EnableConvertToMouseWheel(GetDlgItem(wnd, IDC_LIST), TRUE);
  382. return 1;
  383. case WM_DESTROY:
  384. fades_config_wnd = NULL;
  385. if (NULL != WASABI_API_APP)
  386. WASABI_API_APP->DirectMouseWheel_EnableConvertToMouseWheel(GetDlgItem(wnd, IDC_LIST), FALSE);
  387. break;
  388. case WM_COMMAND:
  389. switch(wp)
  390. {
  391. case (LBN_DBLCLK<<16)|IDC_LIST:
  392. {
  393. int idx=(int)SendMessage((HWND)lp,LB_GETCURSEL,0,0);
  394. if (idx!=-1)
  395. {
  396. FadeCfgCopy * c=(FadeCfgCopy*)SendMessage((HWND)lp,LB_GETITEMDATA,idx,0);
  397. c->on=!c->on;
  398. wchar_t txt[256];
  399. format_fade(txt,c,idx);
  400. SendMessage((HWND)lp,LB_DELETESTRING,idx,0);
  401. SendMessage((HWND)lp,LB_INSERTSTRING,idx,(LPARAM)txt);
  402. SendMessage((HWND)lp,LB_SETITEMDATA,idx,(LPARAM)c);
  403. SendMessage((HWND)lp,LB_SETCURSEL,idx,0);
  404. SendDlgItemMessage(wnd,IDC_FADE_ENABLED,BM_SETCHECK,c->on,0);
  405. }
  406. }
  407. break;
  408. case (LBN_SELCHANGE<<16)|IDC_LIST:
  409. {
  410. int idx=(int)SendMessage((HWND)lp,LB_GETCURSEL,0,0);
  411. if (idx!=-1)
  412. {
  413. FadeCfgCopy * c=(FadeCfgCopy*)SendMessage((HWND)lp,LB_GETITEMDATA,idx,0);
  414. SendDlgItemMessage(wnd,IDC_USE_CUSTOM_FADE,BM_SETCHECK,!c->usedef,0);
  415. SetDlgItemInt(wnd,IDC_CUSTOM_FADE,c->time,0);
  416. wchar_t boo[128], tmp[32];
  417. wsprintfW(boo,WASABI_API_LNGSTRINGW(IDS_FADE_ON_X_SETTINGS),WASABI_API_LNGSTRINGW_BUF(FadeNames[idx],tmp,32));
  418. SetDlgItemTextW(wnd,IDC_FADE_GROUP,boo);
  419. SendDlgItemMessage(wnd,IDC_FADE_ENABLED,BM_SETCHECK,c->on,0);
  420. switch_dlgitems(wnd,customfade_ids,1);
  421. }
  422. else
  423. {
  424. SendDlgItemMessage(wnd,IDC_USE_CUSTOM_FADE,BM_SETCHECK,0,0);
  425. SendDlgItemMessage(wnd,IDC_FADE_ENABLED,BM_SETCHECK,0,0);
  426. SetDlgItemText(wnd,IDC_CUSTOM_FADE,L"");
  427. SetDlgItemText(wnd,IDC_FADE_GROUP,L"");
  428. switch_dlgitems(wnd,customfade_ids,0);
  429. }
  430. }
  431. break;
  432. case (EN_CHANGE<<16)|IDC_CUSTOM_FADE:
  433. {
  434. HWND list=GetDlgItem(wnd,IDC_LIST);
  435. int idx=(int)SendMessage(list,LB_GETCURSEL,0,0);
  436. if (idx>=0)
  437. {
  438. FadeCfgCopy * c=(FadeCfgCopy*)SendMessage(list,LB_GETITEMDATA,idx,0);
  439. c->time=GetDlgItemInt(wnd,IDC_CUSTOM_FADE,0,0);
  440. if (!c->usedef)
  441. {
  442. wchar_t txt[256];
  443. format_fade(txt,c,idx);
  444. SendMessageW(list,LB_DELETESTRING,idx,0);
  445. SendMessageW(list,LB_INSERTSTRING,idx,(LPARAM)txt);
  446. SendMessageW(list,LB_SETITEMDATA,idx,(LPARAM)c);
  447. SendMessageW(list,LB_SETCURSEL,idx,0);
  448. }
  449. }
  450. }
  451. break;
  452. case IDC_USE_CUSTOM_FADE:
  453. {
  454. HWND list=GetDlgItem(wnd,IDC_LIST);
  455. int idx=(int)SendMessageW(list,LB_GETCURSEL,0,0);
  456. if (idx>=0)
  457. {
  458. FadeCfgCopy * c=(FadeCfgCopy*)SendMessageW(list,LB_GETITEMDATA,idx,0);
  459. c->usedef=!SendMessageW((HWND)lp,BM_GETCHECK,0,0);
  460. wchar_t txt[256];
  461. format_fade(txt,c,idx);
  462. SendMessageW(list,LB_DELETESTRING,idx,0);
  463. SendMessageW(list,LB_INSERTSTRING,idx,(LPARAM)txt);
  464. SendMessageW(list,LB_SETITEMDATA,idx,(LPARAM)c);
  465. SendMessageW(list,LB_SETCURSEL,idx,0);
  466. }
  467. }
  468. break;
  469. case IDC_FADE_ENABLED:
  470. {
  471. HWND list=GetDlgItem(wnd,IDC_LIST);
  472. int idx=(int)SendMessageW(list,LB_GETCURSEL,0,0);
  473. if (idx>=0)
  474. {
  475. FadeCfgCopy * c=(FadeCfgCopy*)SendMessageW(list,LB_GETITEMDATA,idx,0);
  476. c->on=(int)SendMessageW((HWND)lp,BM_GETCHECK,0,0);
  477. wchar_t txt[256];
  478. format_fade(txt,c,idx);
  479. SendMessageW(list,LB_DELETESTRING,idx,0);
  480. SendMessageW(list,LB_INSERTSTRING,idx,(long long)txt);
  481. SendMessageW(list,LB_SETITEMDATA,idx,(long long)c);
  482. SendMessageW(list,LB_SETCURSEL,idx,0);
  483. }
  484. }
  485. break;
  486. case IDC_APPLY:
  487. case IDOK:
  488. {
  489. UINT n=GetDlgItemInt(wnd,IDC_FADE,0,0);
  490. /*if (n<0) n=0;
  491. else */if (n>50000) n=50000;
  492. cfg_def_fade=n;
  493. HWND w=GetDlgItem(wnd,IDC_LIST);
  494. for(n=0;n<N_FADES;n++)
  495. {
  496. FadeCfgCopy* c=(FadeCfgCopy*)SendMessage(w,LB_GETITEMDATA,n,0);
  497. fades[n]->time=c->time;
  498. fades[n]->on=c->on;
  499. fades[n]->usedef=c->usedef;
  500. if (wp==IDOK) delete c;
  501. }
  502. }
  503. cfg_oldpause=(bool)SendDlgItemMessage(wnd,IDC_PAUSEFADE2,BM_GETCHECK,0,0);
  504. cfg_wait=(bool)SendDlgItemMessage(wnd,IDC_WAITx,BM_GETCHECK,0,0);
  505. SendMessage(ipcWnd, WM_DS_IPC, 0, DS_IPC_CB_CFGREFRESH);
  506. break;
  507. case IDCANCEL:
  508. {
  509. HWND w=GetDlgItem(wnd,IDC_LIST);
  510. UINT n;
  511. for(n=0;n<N_FADES;n++)
  512. {
  513. delete (FadeCfgCopy*)SendMessage(w,LB_GETITEMDATA,n,0);
  514. }
  515. SendMessage(w,LB_RESETCONTENT,0,0);
  516. }
  517. break;
  518. }
  519. break;
  520. }
  521. return 0;
  522. }
  523. static const UINT logvol_ids[]={IDC_LOGVOL_STATIC,IDC_LOGVOL_MIN,IDC_LOGVOL_STATIC2,IDC_LOGVOL_SPIN};
  524. static INT_PTR CALLBACK CfgProc4(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
  525. {//other
  526. switch(msg)
  527. {
  528. case WM_INITDIALOG:
  529. SendDlgItemMessage(wnd,IDC_VOLUME,BM_SETCHECK,cfg_volume,0);
  530. {
  531. HWND w=GetDlgItem(wnd,IDC_VOLMODE);
  532. SendMessageW(w,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_LINEAR));
  533. SendMessageW(w,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_LOGARITHMIC));
  534. SendMessageW(w,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_HYBRID));
  535. SendMessageW(w,CB_SETCURSEL,cfg_volmode,0);
  536. }
  537. SendDlgItemMessageW(wnd,IDC_LOGVOL_SPIN,UDM_SETRANGE,0,MAKELONG(100,1));
  538. SetDlgItemInt(wnd,IDC_LOGVOL_MIN,cfg_logvol_min,0);
  539. if (cfg_volmode!=1) switch_dlgitems(wnd,logvol_ids,0);
  540. SendDlgItemMessageW(wnd,IDC_LOGFADES,BM_SETCHECK,cfg_logfades,0);
  541. {
  542. HWND w;
  543. w=GetDlgItem(wnd,IDC_DB);
  544. SendMessageW(w,TBM_SETRANGE,0,MAKELONG(150,2000));
  545. SendMessageW(w,TBM_SETPOS,1,cfg_sil_db);
  546. }
  547. SendDlgItemMessageW(wnd,IDC_KILLSIL,BM_SETCHECK,cfg_killsil,0);
  548. SendDlgItemMessageW(wnd,IDC_FADEVOL,BM_SETCHECK,cfg_fadevol,0);
  549. CfgProc4(wnd,WM_HSCROLL,0,(long long)GetDlgItem(wnd,IDC_DB));
  550. return 1;
  551. case WM_HSCROLL:
  552. switch(GetWindowLong((HWND)lp,GWL_ID))
  553. {
  554. case IDC_DB:
  555. {
  556. UINT foo=(UINT)SendDlgItemMessage(wnd,IDC_DB,TBM_GETPOS,0,0);
  557. wchar_t zz[16];
  558. _snwprintf(zz,16,L"-%.1f %s", foo / 10.0f, WASABI_API_LNGSTRINGW(IDS_DS_DB));
  559. SetDlgItemTextW(wnd,IDC_DB_DISPLAY,zz);
  560. }
  561. break;
  562. }
  563. break;
  564. case WM_COMMAND:
  565. switch(wp)
  566. {
  567. case IDC_VOLMODE|(CBN_SELCHANGE<<16):
  568. switch_dlgitems(wnd,logvol_ids,SendMessage((HWND)lp,CB_GETCURSEL,0,0)==1);
  569. break;
  570. case IDC_APPLY:
  571. case IDOK:
  572. cfg_volume=(bool)SendDlgItemMessage(wnd,IDC_VOLUME,BM_GETCHECK,0,0);
  573. cfg_fadevol=(bool)SendDlgItemMessage(wnd,IDC_FADEVOL,BM_GETCHECK,0,0);
  574. cfg_volmode=(int)SendDlgItemMessage(wnd,IDC_VOLMODE,CB_GETCURSEL,0,0);
  575. cfg_logvol_min=GetDlgItemInt(wnd,IDC_LOGVOL_MIN,0,0);
  576. if (cfg_logvol_min<10) cfg_logvol_min=10;
  577. if (cfg_logvol_min>100) cfg_logvol_min=100;
  578. cfg_killsil=(int)SendDlgItemMessage(wnd,IDC_KILLSIL,BM_GETCHECK,0,0);
  579. cfg_sil_db=(int)SendDlgItemMessage(wnd,IDC_DB,TBM_GETPOS,0,0);
  580. cfg_logfades=(int)SendDlgItemMessage(wnd,IDC_LOGFADES,BM_GETCHECK,0,0);
  581. break;
  582. case IDCANCEL:
  583. break;
  584. }
  585. break;
  586. }
  587. const int controls[] =
  588. {
  589. IDC_DB,
  590. IDC_BUFFER,
  591. IDC_PREBUFFER_1,
  592. IDC_PREBUFFER_2,
  593. };
  594. if (FALSE != WASABI_API_APP->DirectMouseWheel_ProcessDialogMessage(wnd, msg, wp, lp, controls, ARRAYSIZE(controls)))
  595. {
  596. return TRUE;
  597. }
  598. return 0;
  599. }
  600. static void FormatProgress(UINT pos,UINT max,UINT len,wchar_t * out)
  601. {
  602. UINT pos1=MulDiv(pos,len,max);
  603. UINT n;
  604. *(out++)=L'[';
  605. for(n=0;n<len;n++)
  606. {
  607. *(out++)= (n==pos1) ? L'#' : L'=';
  608. }
  609. *(out++)=L']';
  610. *(out++)=0;
  611. }
  612. static void FormatTime(__int64 t,wchar_t * out)
  613. {
  614. __int64 w, d, h, m, s;
  615. w = (t / (1000ll * 60ll * 60ll * 24ll * 7ll));
  616. d = (t / (1000ll * 60ll * 60ll * 24ll)) % 7ll;
  617. h = (t / (1000ll * 60ll * 60ll)) % 24ll;
  618. m = (t / (1000ll * 60ll)) % 60ll;
  619. s = (t / (1000ll)) % 60ll;
  620. if (w)
  621. {
  622. _snwprintf(out, 32, L"%I64uw ", w);
  623. while (out && *out) out++;
  624. }
  625. if (d)
  626. {
  627. _snwprintf(out, 32, L"%I64ud ", d);
  628. while (out && *out) out++;
  629. }
  630. if (h)
  631. {
  632. _snwprintf(out, 32, L"%I64u:", h);
  633. while (out && *out) out++;
  634. }
  635. _snwprintf(out, 32,h ? L"%02I64u:" : L"%I64u:", m);
  636. while (out && *out) out++;
  637. _snwprintf(out, 32, L"%02I64u.%03I64u", s, (t % 1000ll));
  638. }
  639. static INT_PTR CALLBACK CfgProc_stat(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
  640. {
  641. if(msg == WM_ERASEBKGND)
  642. {
  643. return 1;
  644. }
  645. return 0;
  646. }
  647. static INT_PTR CALLBACK CfgProc6(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
  648. {//status
  649. static wchar_t display[1024];
  650. static wchar_t disp_devname[256];
  651. static GUID devguid;
  652. switch(msg)
  653. {
  654. case WM_INITDIALOG:
  655. {
  656. HWND w=WASABI_API_CREATEDIALOGPARAMW(IDD_CONFIG_STATUS,wnd,CfgProc_stat,0);
  657. SendMessage(mod.hMainWindow,WM_WA_IPC,(WPARAM)w,IPC_USE_UXTHEME_FUNC);
  658. SetWindowLong(w, GWL_ID, IDC_STATUS);
  659. }
  660. disp_devname[0]=0;
  661. SendDlgItemMessage(wnd,IDC_REFRESH_SPIN,UDM_SETRANGE,0,MAKELONG(10000,10));
  662. SetDlgItemInt(wnd,IDC_REFRESH,cfg_status_update_freq,0);
  663. SetTimer(wnd,1,cfg_status_update_freq,0);
  664. case WM_TIMER:
  665. {
  666. wchar_t total[256];
  667. __int64 time_total=DS2::GetTotalTime();
  668. FormatTime(time_total,total);
  669. DS2_REALTIME_STAT stat;
  670. if (wa2_GetRealtimeStat(&stat))
  671. {
  672. wchar_t bigint1[32],bigint2[32];
  673. _i64tow_s(stat.bytes_written,bigint1,32,10);
  674. _i64tow_s(stat.bytes_played,bigint2,32,10);
  675. wchar_t time1[256],time2[256];
  676. FormatTime(stat.bytes_written/(stat.bps/8*stat.nch)*1000/stat.sr,time1);
  677. __int64 time_played=stat.bytes_played/(stat.bps/8*stat.nch)*1000/stat.sr;
  678. FormatTime(time_played,time2);
  679. wchar_t prog1[256],prog2[256];
  680. FormatProgress(stat.pos_play,stat.buf_size_bytes,50,prog1);
  681. FormatProgress(stat.pos_write,stat.buf_size_bytes,50,prog2);
  682. #ifdef HAVE_SSRC
  683. char res_status[128];
  684. RESAMPLING_STATUS resfoo;
  685. if (!wa2_IsResampling(&resfoo)) lstrcpy(res_status,"inactive");
  686. else wsprintf(res_status,"active, %u Hz / %u bps => %u Hz / %u bps",resfoo.src_freq,resfoo.src_bps,resfoo.dst_freq,resfoo.dst_bps);
  687. #endif
  688. if (!disp_devname[0] || devguid!=stat.current_device)
  689. {
  690. lstrcpy(disp_devname,DsDevEnumGuid(stat.current_device).GetName());
  691. devguid=stat.current_device;
  692. }
  693. // note:
  694. // with the HAVE_SSRC stuff, a new formatting string would be needed to be added to
  695. // the dll resources otherwise it gets complicated with string management of things
  696. wchar_t s1[16], s2[16], s3[16], s4[16], s5[16];
  697. swprintf_s(display,1024,WASABI_API_LNGSTRINGW(IDS_STATUS_TEXT)
  698. /*#ifdef HAVE_SSRC
  699. EOL "Resampling: %s"
  700. #endif*/
  701. ,
  702. stat.sr,
  703. stat.bps,
  704. stat.nch,
  705. WASABI_API_LNGSTRINGW_BUF(stat.nch>1 ? IDS_CHANNELS : IDS_CHANNEL,s1,16),
  706. stat.buf_size_ms,stat.buf_size_bytes,
  707. disp_devname,
  708. WASABI_API_LNGSTRINGW_BUF(((stat.dscaps_flags&DSBCAPS_LOCHARDWARE) ? IDS_HARDWARE : (stat.dscaps_flags&DSBCAPS_LOCSOFTWARE) ? IDS_SOFTWARE : IDS_UNKNOWN),s2,16),
  709. WASABI_API_LNGSTRINGW_BUF((stat.have_primary_buffer ? IDS_ACTIVE : IDS_INACTIVE),s3,16),
  710. WASABI_API_LNGSTRINGW_BUF(((stat.dscaps_flags_primary&DSBCAPS_LOCHARDWARE) ? IDS_HARDWARE_BRACKETED : (stat.dscaps_flags_primary&DSBCAPS_LOCSOFTWARE) ? IDS_SOFTWARE_BRACKETED : IDS_EMPTY),s4,16),
  711. stat.pos_play,
  712. WASABI_API_LNGSTRINGW_BUF((stat.paused?IDS_PAUSED_BRACKETED:IDS_EMPTY),s5,16),
  713. prog1,
  714. stat.pos_write,
  715. prog2,
  716. stat.latency_ms,
  717. stat.latency,
  718. MulDiv((int)stat.bytes_async,1000,stat.sr*stat.nch*(stat.bps>>3)),
  719. stat.bytes_async,
  720. stat.lock_count,
  721. stat.underruns,
  722. time2,bigint2,
  723. time1,bigint1,
  724. total,
  725. stat.vol_left,
  726. stat.vol_right
  727. /*#ifdef HAVE_SSRC
  728. ,res_status
  729. #endif*/
  730. );
  731. }
  732. else wsprintfW(display,WASABI_API_LNGSTRINGW(IDS_NOT_ACTIVE_TOTAL_PLAYED),total);
  733. HWND s = GetDlgItem(wnd, IDC_STATUS);
  734. SetWindowRedraw(s, 0);
  735. SetDlgItemTextW(s, IDC_STATUS, display);
  736. SetWindowRedraw(s, 1);
  737. InvalidateRect(s, 0, 0);
  738. }
  739. break;
  740. case WM_COMMAND:
  741. switch(wp)
  742. {
  743. case IDOK:
  744. case IDCANCEL:
  745. KillTimer(wnd,1);
  746. break;
  747. case IDC_STAT_COPY:
  748. {
  749. if (OpenClipboard(wnd))
  750. {
  751. // due to quirks with the more common resource editors, is easier to just store the string
  752. // internally only with \n and post-process to be \r\n (as here) so it will appear correctly
  753. // on new lines as is wanted (silly multiline edit controls) when copying to the clipboard
  754. int len = 0;
  755. static wchar_t tmp2[1024] = {0};
  756. wchar_t *t1 = display, *t2 = tmp2;
  757. while(t1 && *t1 && (t2 - tmp2 < 1024))
  758. {
  759. if(*t1 == L'\n')
  760. {
  761. *t2 = L'\r';
  762. t2 = CharNextW(t2);
  763. len++;
  764. }
  765. *t2 = *t1;
  766. t1 = CharNextW(t1);
  767. t2 = CharNextW(t2);
  768. len++;
  769. }
  770. HANDLE hMem=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,len+1);
  771. lstrcpynW((wchar_t*)GlobalLock(hMem),tmp2,len+1);
  772. GlobalUnlock(hMem);
  773. EmptyClipboard();
  774. SetClipboardData(CF_TEXT,hMem);
  775. CloseClipboard();
  776. }
  777. }
  778. break;
  779. case (EN_CHANGE<<16)|IDC_REFRESH:
  780. {
  781. int t=GetDlgItemInt(wnd,IDC_REFRESH,0,0);
  782. if (t>0)
  783. {
  784. if (t<10) t=10;
  785. else if (t>10000) t=10000;
  786. KillTimer(wnd,1);
  787. SetTimer(wnd,1,t,0);
  788. cfg_status_update_freq=t;
  789. }
  790. }
  791. break;
  792. }
  793. break;
  794. }
  795. return 0;
  796. }
  797. #ifdef HAVE_SSRC
  798. static UINT sr_tab[]={8000,11025,16000,22050,24000,32000,44100,48000,56000,64000,88200,96000};
  799. static const char * dither_tab[]={"none","no noise shaping","triangular spectral shape"};//,"ATH based noise shaping","ATH based noise shaping(less amplitude)"};
  800. static const char * pdf_tab[3] = {"rectangular","triangular","gaussian"};
  801. extern cfg_int cfg_use_resample;
  802. extern cfg_int cfg_dither,cfg_resample_freq,cfg_resample_bps,cfg_pdf;
  803. extern cfg_int cfg_fast;
  804. static cfg_int cfg_resample_faqd("cfg_resample_faqd",0);
  805. static INT_PTR CALLBACK CfgProc_SSRC(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
  806. {//resampling
  807. switch(msg)
  808. {
  809. case WM_INITDIALOG:
  810. {
  811. HWND w;
  812. UINT n;
  813. w=GetDlgItem(wnd,IDC_RESAMPLE_FREQ);
  814. for(n=0;n<sizeof(sr_tab)/sizeof(sr_tab[0]);n++)
  815. {
  816. char foo[16];
  817. wsprintf(foo,"%u",sr_tab[n]);
  818. SendMessage(w,CB_ADDSTRING,0,(long)foo);
  819. }
  820. SetDlgItemInt(wnd,IDC_RESAMPLE_FREQ,cfg_resample_freq,0);
  821. w=GetDlgItem(wnd,IDC_RESAMPLE_BPS);
  822. SendMessage(w,CB_ADDSTRING,0,(long)"8");
  823. SendMessage(w,CB_ADDSTRING,0,(long)"16");
  824. SendMessage(w,CB_ADDSTRING,0,(long)"24");
  825. SendMessage(w,CB_SETCURSEL,(cfg_resample_bps>>3)-1,0);
  826. w=GetDlgItem(wnd,IDC_DITHER);
  827. for(n=0;n<3;n++)//5
  828. {
  829. SendMessage(w,CB_ADDSTRING,0,(long)dither_tab[n]);
  830. }
  831. SendMessage(w,CB_SETCURSEL,cfg_dither,0);
  832. w=GetDlgItem(wnd,IDC_PDF);
  833. for(n=0;n<3;n++)
  834. {
  835. SendMessage(w,CB_ADDSTRING,0,(long)pdf_tab[n]);
  836. }
  837. SendMessage(w,CB_SETCURSEL,cfg_pdf,0);
  838. }
  839. SendDlgItemMessage(wnd,IDC_FAST,BM_SETCHECK,cfg_fast,0);
  840. SendDlgItemMessage(wnd,IDC_RESAMPLE,BM_SETCHECK,cfg_use_resample,0);
  841. return 1;
  842. case WM_COMMAND:
  843. switch(wp)
  844. {
  845. case IDC_RESAMPLE:
  846. if (!cfg_resample_faqd)
  847. {
  848. MessageBox(wnd,"Resampling feature is intended only to workaround sound quality problems with certain kinds of sound hardware.\nUsing resampling on other soundcards will only lead to quality degradation (no matter what settings you use) and increased CPU usage.\nRefer to your soundcard specifications for exact info.\nIf you are not sure what to do, simply leave resampling disabled.","One-time FAQ reminder / config kiddie alert",MB_ICONWARNING);
  849. cfg_resample_faqd=1;
  850. SendMessage((HWND)lp,BM_SETCHECK,0,0);
  851. }
  852. break;
  853. case IDC_APPLY:
  854. case IDOK:
  855. cfg_resample_freq=GetDlgItemInt(wnd,IDC_RESAMPLE_FREQ,0,0);
  856. cfg_resample_bps=GetDlgItemInt(wnd,IDC_RESAMPLE_BPS,0,0);
  857. cfg_dither=SendDlgItemMessage(wnd,IDC_DITHER,CB_GETCURSEL,0,0);
  858. cfg_pdf=SendDlgItemMessage(wnd,IDC_PDF,CB_GETCURSEL,0,0);
  859. cfg_fast=SendDlgItemMessage(wnd,IDC_FAST,BM_GETCHECK,0,0);
  860. cfg_use_resample=SendDlgItemMessage(wnd,IDC_RESAMPLE,BM_GETCHECK,0,0);
  861. break;
  862. case IDCANCEL:
  863. break;
  864. }
  865. break;
  866. }
  867. return 0;
  868. }
  869. #endif
  870. typedef struct
  871. {
  872. UINT ctrl_id, dlg_id, name;
  873. DLGPROC proc;
  874. } TABDESC;
  875. static TABDESC tabs[]=
  876. {
  877. {IDC_CONFIG_TAB1,IDD_CONFIG_TAB1,IDS_DEVICE,CfgProc1},
  878. {IDC_CONFIG_TAB2,IDD_CONFIG_TAB2,IDS_BUFFERING,CfgProc2},
  879. {IDC_CONFIG_TAB3,IDD_CONFIG_TAB3,IDS_FADING,CfgProc3},
  880. {IDC_CONFIG_TAB4,IDD_CONFIG_TAB4,IDS_OTHER,CfgProc4},
  881. {IDC_CONFIG_TAB6,IDD_CONFIG_TAB6,IDS_STATUS,CfgProc6},
  882. #ifdef HAVE_SSRC
  883. {IDC_CONFIG_TAB_SSRC,IDD_CONFIG_TAB_SSRC,"Resampling",CfgProc_SSRC},
  884. #endif
  885. };
  886. #define N_TABS (sizeof(tabs)/sizeof(tabs[0]))
  887. static INT_PTR CALLBACK CfgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
  888. {
  889. switch(msg)
  890. {
  891. case WM_INITDIALOG:
  892. config_start_time=GetTickCount();
  893. {
  894. HWND hTab=GetDlgItem(wnd,IDC_TAB);
  895. TC_ITEM it=
  896. {
  897. TCIF_TEXT,
  898. 0,0,
  899. 0, //pszText
  900. 0,
  901. -1,0
  902. };
  903. RECT r = {0};
  904. for(UINT n=0;n<N_TABS;n++)
  905. {
  906. it.pszText=WASABI_API_LNGSTRINGW(tabs[n].name);
  907. SendMessage(hTab,TCM_INSERTITEM,n,(LPARAM)&it);
  908. }
  909. SendMessage(hTab,TCM_SETCURFOCUS,cfg_cur_tab,0);
  910. GetClientRect(hTab,&r);
  911. TabCtrl_AdjustRect(hTab,0,&r);
  912. wchar_t title[128] = {0}, temp[128] = {0};
  913. swprintf(title,128,WASABI_API_LNGSTRINGW(IDS_PREFS_TITLE),WASABI_API_LNGSTRINGW_BUF(IDS_NULLSOFT_DS_OUTPUT_OLD,temp,128));
  914. SetWindowTextW(wnd,title);
  915. for(UINT n=0;n<N_TABS;n++)
  916. {
  917. HWND w=WASABI_API_CREATEDIALOGW(tabs[n].dlg_id,wnd,tabs[n].proc);
  918. SendMessage(mod.hMainWindow,WM_WA_IPC,(WPARAM)w,IPC_USE_UXTHEME_FUNC);
  919. SetWindowPos(w,0,r.left,r.top,r.right-r.left,r.bottom-r.top,SWP_NOZORDER);
  920. SetWindowLong(w, GWL_ID, tabs[n].ctrl_id);
  921. ShowWindow(w,n==cfg_cur_tab ? SW_SHOW : SW_HIDE);
  922. }
  923. SetDlgItemTextW(wnd,IDC_VER,DS2_ENGINE_VER);
  924. SetFocus(hTab);
  925. }
  926. return 0;
  927. case WM_NOTIFY:
  928. switch(wp)
  929. {
  930. case IDC_TAB:
  931. if (((NMHDR*)lp)->code==TCN_SELCHANGE)
  932. {
  933. UINT n;
  934. HWND hTab=((NMHDR*)lp)->hwndFrom;
  935. cfg_cur_tab=(int)SendMessage(hTab,TCM_GETCURSEL,0,0);
  936. for(n=0;n<N_TABS;n++)
  937. {
  938. HWND w=GetDlgItem(wnd,tabs[n].ctrl_id);
  939. ShowWindow(w,n==cfg_cur_tab ? SW_SHOW : SW_HIDE);
  940. }
  941. }
  942. break;
  943. }
  944. break;
  945. case WM_COMMAND:
  946. switch(wp)
  947. {
  948. case IDC_RESET:
  949. {
  950. char warn[16];
  951. if (MessageBoxA(wnd,WASABI_API_LNGSTRING(IDS_RESET_ALL_SETTINGS_TO_DEFAULTS),
  952. WASABI_API_LNGSTRING_BUF(IDS_WARNING,warn,16),MB_ICONWARNING|MB_YESNO)==IDYES)
  953. {
  954. wa2_sync_in();
  955. HWND hTab=GetDlgItem(wnd,IDC_TAB);
  956. UINT n;
  957. HWND w;
  958. RECT r;
  959. GetClientRect(hTab,&r);
  960. TabCtrl_AdjustRect(hTab,0,&r);
  961. for(n=0;n<N_TABS;n++)
  962. {
  963. w=GetDlgItem(wnd,tabs[n].ctrl_id);
  964. SendMessage(w,WM_COMMAND,IDCANCEL,0);
  965. DestroyWindow(w);
  966. }
  967. cfg_var::config_reset();
  968. for(n=0;n<N_TABS;n++)
  969. {
  970. w=WASABI_API_CREATEDIALOGW(tabs[n].dlg_id,wnd,tabs[n].proc);
  971. SendMessage(mod.hMainWindow,WM_WA_IPC,(WPARAM)w,IPC_USE_UXTHEME_FUNC);
  972. SetWindowPos(w,0,r.left,r.top,r.right-r.left,r.bottom-r.top,SWP_NOZORDER);
  973. SetWindowLong(w, GWL_ID, tabs[n].ctrl_id);
  974. ShowWindow(w,n==cfg_cur_tab ? SW_SHOW : SW_HIDE);
  975. }
  976. wa2_sync_out();
  977. }
  978. }
  979. break;
  980. case IDC_APPLY:
  981. case IDOK:
  982. wa2_sync_in();
  983. {
  984. UINT n;
  985. for(n=0;n<N_TABS;n++)
  986. {
  987. SendDlgItemMessage(wnd,tabs[n].ctrl_id,WM_COMMAND,wp,0);
  988. }
  989. }
  990. wa2_sync_out();
  991. if (wp==IDOK) EndDialog(wnd,1);
  992. break;
  993. case IDCANCEL:
  994. {
  995. UINT n;
  996. for(n=0;n<N_TABS;n++)
  997. {
  998. SendDlgItemMessage(wnd,tabs[n].ctrl_id,WM_COMMAND,IDCANCEL,0);
  999. }
  1000. }
  1001. EndDialog(wnd,0);
  1002. break;
  1003. }
  1004. break;
  1005. }
  1006. return 0;
  1007. }
  1008. void Config(HWND w)
  1009. {
  1010. if (WASABI_API_DIALOGBOXW(IDD_DS_CONFIG,w,CfgProc))
  1011. {
  1012. int maxfade=cfg_fade_firststart;
  1013. int f1=cfg_fade_start;
  1014. if (f1>maxfade) maxfade=f1;
  1015. f1=cfg_fade_seek;
  1016. if (f1>maxfade) maxfade=f1;
  1017. f1=cfg_fade_pause;
  1018. if (f1>maxfade) maxfade=f1;
  1019. if (maxfade>cfg_buf_ms)
  1020. {
  1021. // cfg_buf_ms=maxfade;
  1022. wchar_t foo[256];
  1023. wsprintfW(foo,WASABI_API_LNGSTRINGW(IDS_SOME_FADE_TIMES_ARE_BIGGER_THAN_BUFFER),maxfade);
  1024. if (MessageBoxW(w,foo,WASABI_API_LNGSTRINGW(IDS_WARNING),MB_ICONEXCLAMATION|MB_YESNO)==IDYES)
  1025. {
  1026. wa2_sync_in();
  1027. cfg_buf_ms=maxfade;
  1028. wa2_sync_out();
  1029. }
  1030. }
  1031. }
  1032. }
  1033. class FooString//ghey. no StringPrintf().
  1034. {
  1035. private:
  1036. wchar_t foo[32];
  1037. public:
  1038. operator const wchar_t*() {return foo;}
  1039. FooString(const wchar_t* s1,const wchar_t* s2)
  1040. {
  1041. lstrcpyW(foo,s1);
  1042. lstrcatW(foo,s2);
  1043. }
  1044. };
  1045. FadeCfg::FadeCfg(const wchar_t* _name,const wchar_t* vname,int vtime,bool von,bool vusedef)
  1046. : time(FooString(vname,L".time"),vtime)
  1047. , on(FooString(vname,L".on"),von)
  1048. , usedef(FooString(vname,L".usedef"),vusedef)
  1049. {
  1050. name=_name;
  1051. }