wa2_config.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #include "out_wave.h"
  2. #include "api.h"
  3. #include <commctrl.h>
  4. #include "resource.h"
  5. #include <math.h>
  6. #include "../winamp/wa_ipc.h"
  7. #pragma intrinsic(log)
  8. #ifndef _WIN64
  9. //__inline long int lrint (double flt)
  10. //{
  11. // int intgr;
  12. //
  13. // _asm
  14. // {
  15. // fld flt
  16. // fistp intgr
  17. // }
  18. //
  19. // return intgr;
  20. //}
  21. #else
  22. //__inline long int lrint (double flt)
  23. //{
  24. // return (int)flt;
  25. //}
  26. #endif
  27. #pragma warning(disable:4800)
  28. extern Out_Module mod;
  29. extern UINT cfg_buf_ms,cfg_dev,cfg_prebuf;
  30. extern bool cfg_volume,cfg_altvol,cfg_resetvol;
  31. extern UINT cfg_trackhack;
  32. bool get_waveout_state(char * z) throw();
  33. void _init();
  34. #define BUFFER_SCALE 4000.0
  35. static UINT cur_buffer;
  36. static UINT get_buffer(HWND wnd)
  37. {
  38. if (cur_buffer) return cur_buffer;
  39. //0-BUFFER_SCALE => 200-20000
  40. LRESULT z=SendDlgItemMessage(wnd,IDC_BUFFER,TBM_GETPOS,0,0);
  41. //return cur_buffer=lrint( 0.5 + 200.0*pow(100.0,((double)z)/BUFFER_SCALE) );
  42. }
  43. #define LOG100 4.6051701859880913680359829093687
  44. static void set_buffer(HWND wnd,UINT b)
  45. {
  46. cur_buffer=b;
  47. SendDlgItemMessage(wnd,IDC_BUFFER,TBM_SETPOS,1,lrint( 0.5 + BUFFER_SCALE * log( (double)b/200.0 ) / LOG100 /* / log( 100.0 )*/ ));
  48. }
  49. static void update_prebuf_1(HWND wnd)
  50. {
  51. WCHAR zz[128] = { 0 };
  52. wsprintf(zz, WASABI_API_LNGSTRINGW(IDS_WAVE_U_MS), SendDlgItemMessage(wnd, IDC_PREBUFFER_1, TBM_GETPOS, 0, 0));
  53. SetDlgItemText(wnd,IDC_PREBUF_DISP_1,zz);
  54. }
  55. static void update_prebuf_2(HWND wnd)
  56. {
  57. WCHAR zz[128] = { 0 };
  58. wsprintf(zz, WASABI_API_LNGSTRINGW(IDS_WAVE_U_MS), SendDlgItemMessage(wnd, IDC_PREBUFFER_2, TBM_GETPOS, 0, 0));
  59. SetDlgItemText(wnd,IDC_PREBUF_DISP_2,zz);
  60. }
  61. static void update_prebuf_range(HWND wnd)
  62. {
  63. UINT max=get_buffer(wnd);
  64. if (max>0x7FFF) max=0x7FFF;
  65. SendDlgItemMessage(wnd,IDC_PREBUFFER_1,TBM_SETRANGE,1,MAKELONG(0,max));
  66. SendDlgItemMessage(wnd,IDC_PREBUFFER_2,TBM_SETRANGE,1,MAKELONG(0,max));
  67. }
  68. static void update_buf(HWND wnd)
  69. {
  70. WCHAR zz[128] = { 0 };
  71. wsprintf(zz, WASABI_API_LNGSTRINGW(IDS_WAVE_U_MS), get_buffer(wnd));
  72. SetDlgItemText(wnd,IDC_BUF_DISP,zz);
  73. }
  74. static INT_PTR WINAPI CfgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
  75. {
  76. switch(msg)
  77. {
  78. case WM_INITDIALOG:
  79. {
  80. wchar_t title[128] = {0}, temp[128] = {0};
  81. swprintf(title,128,WASABI_API_LNGSTRINGW(IDS_PREFS_TITLE),WASABI_API_LNGSTRINGW_BUF(IDS_NULLSOFT_WAVEOUT_OLD,temp,128));
  82. SetWindowTextW(wnd,title);
  83. SendDlgItemMessage(wnd,IDC_VOL_ENABLE,BM_SETCHECK,(long)cfg_volume,0);
  84. SendDlgItemMessage(wnd,IDC_ALT_VOL,BM_SETCHECK,(long)cfg_altvol,0);
  85. SendDlgItemMessage(wnd,IDC_VOL_RESET,BM_SETCHECK,(long)cfg_resetvol,0);
  86. {
  87. int dev;
  88. HWND w=GetDlgItem(wnd,IDC_DEV);
  89. UINT max=waveOutGetNumDevs();
  90. WAVEOUTCAPS caps;
  91. for(dev=-1;dev<(int)max;dev++)
  92. {
  93. if (waveOutGetDevCaps((UINT)dev,&caps,sizeof(caps)) == MMSYSERR_NOERROR)
  94. SendMessage(w,CB_ADDSTRING,0,(LPARAM)caps.szPname);
  95. }
  96. SendMessage(w,CB_SETCURSEL,cfg_dev,0);
  97. }
  98. SendDlgItemMessage(wnd,IDC_BUFFER,TBM_SETRANGE,0,MAKELONG(0,(int)BUFFER_SCALE));
  99. set_buffer(wnd,cfg_buf_ms);
  100. update_prebuf_range(wnd);
  101. SendDlgItemMessage(wnd,IDC_PREBUFFER_1,TBM_SETPOS,1,cfg_prebuf);
  102. SendDlgItemMessage(wnd,IDC_PREBUFFER_2,TBM_SETPOS,1,cfg_trackhack);
  103. update_prebuf_1(wnd);
  104. update_prebuf_2(wnd);
  105. update_buf(wnd);
  106. SetTimer(wnd,1,500,0);
  107. CfgProc(wnd,WM_TIMER,0,0);
  108. }
  109. return 1;
  110. case WM_COMMAND:
  111. switch(wp)
  112. {
  113. case IDC_RESET:
  114. SendDlgItemMessage(wnd,IDC_VOL_ENABLE,BM_SETCHECK,1,0);
  115. SendDlgItemMessage(wnd,IDC_ALT_VOL,BM_SETCHECK,0,0);
  116. SendDlgItemMessage(wnd,IDC_VOL_RESET,BM_SETCHECK,0,0);
  117. SendDlgItemMessage(wnd,IDC_DEV,CB_SETCURSEL,0,0);
  118. set_buffer(wnd,2000);
  119. update_prebuf_range(wnd);
  120. SendDlgItemMessage(wnd,IDC_PREBUFFER_1,TBM_SETPOS,1,200);
  121. SendDlgItemMessage(wnd,IDC_PREBUFFER_2,TBM_SETPOS,1,200);
  122. update_prebuf_1(wnd);
  123. update_prebuf_2(wnd);
  124. update_buf(wnd);
  125. break;
  126. case IDOK:
  127. KillTimer(wnd,1);
  128. cfg_dev=(UINT)SendDlgItemMessage(wnd,IDC_DEV,CB_GETCURSEL,0,0);
  129. cfg_buf_ms=get_buffer(wnd);
  130. cfg_prebuf= (UINT)SendDlgItemMessage(wnd,IDC_PREBUFFER_1,TBM_GETPOS,0,0);
  131. cfg_trackhack=(UINT)SendDlgItemMessage(wnd,IDC_PREBUFFER_2,TBM_GETPOS,0,0);
  132. cfg_volume=(bool)SendDlgItemMessage(wnd,IDC_VOL_ENABLE,BM_GETCHECK,0,0);
  133. cfg_altvol=(bool)SendDlgItemMessage(wnd,IDC_ALT_VOL,BM_GETCHECK,0,0);
  134. cfg_resetvol=(bool)SendDlgItemMessage(wnd,IDC_VOL_RESET,BM_GETCHECK,0,0);
  135. EndDialog(wnd,1);
  136. break;
  137. case IDCANCEL:
  138. KillTimer(wnd,1);
  139. EndDialog(wnd,0);
  140. break;
  141. }
  142. break;
  143. case WM_HSCROLL:
  144. switch(GetWindowLong((HWND)lp,GWL_ID))
  145. {
  146. case IDC_BUFFER:
  147. cur_buffer=0;
  148. update_buf(wnd);
  149. update_prebuf_range(wnd);
  150. update_prebuf_1(wnd);
  151. update_prebuf_2(wnd);
  152. break;
  153. case IDC_PREBUFFER_1:
  154. update_prebuf_1(wnd);
  155. break;
  156. case IDC_PREBUFFER_2:
  157. update_prebuf_2(wnd);
  158. break;
  159. }
  160. break;
  161. case WM_TIMER:
  162. {
  163. char poo[512] = {0};
  164. bool z=get_waveout_state(poo);
  165. SetDlgItemTextA(wnd,IDC_STATE,z ? poo : WASABI_API_LNGSTRING(IDS_NOT_ACTIVE));
  166. EnableWindow(GetDlgItem(wnd,IDC_BLAH),z);
  167. }
  168. break;
  169. }
  170. const int controls[] =
  171. {
  172. IDC_BUFFER,
  173. IDC_PREBUFFER_1,
  174. IDC_PREBUFFER_2,
  175. };
  176. if (FALSE != WASABI_API_APP->DirectMouseWheel_ProcessDialogMessage(wnd, msg, wp, lp, controls, ARRAYSIZE(controls)))
  177. {
  178. return TRUE;
  179. }
  180. return 0;
  181. }
  182. void Config(HWND w)
  183. {
  184. _init();
  185. WASABI_API_DIALOGBOXW(IDD_CONFIG,w,CfgProc);
  186. }
  187. static char _dllfile[MAX_PATH];
  188. static char * dllfile;
  189. char *inifile=0;
  190. static UINT atoui(char* s)
  191. {
  192. int ret=0;
  193. while(s && *s>='0' && *s<='9') {ret=10*ret+(*s-'0');s++;}
  194. return ret;
  195. }
  196. static int _do_var(unsigned int v,char* n,bool s)
  197. {
  198. if (s)
  199. {
  200. char tmp[2*sizeof(unsigned int) + 1] = {0}; // max 32 bit unsigned int == 4 294 967 296 == 10 digits, 11 if signed
  201. wsprintfA(tmp,"%u",v);
  202. WritePrivateProfileStringA(dllfile,n,tmp,inifile);
  203. return v;
  204. }
  205. else
  206. {
  207. char tmp[64],tmp_s[2*sizeof(unsigned int) + 1] = {0};
  208. wsprintfA(tmp_s,"%u",v);
  209. GetPrivateProfileStringA(dllfile,n,tmp_s,tmp,64,inifile);
  210. return atoui(tmp);
  211. }
  212. }
  213. #define do_var(V) {V=_do_var(V,#V,s);}
  214. void do_cfg(bool s)
  215. {
  216. if (!inifile)
  217. inifile =(char *)SendMessage(mod.hMainWindow, WM_WA_IPC, 0, IPC_GETINIFILE);
  218. if (!dllfile)
  219. {
  220. GetModuleFileNameA(mod.hDllInstance,_dllfile,sizeof(_dllfile));
  221. dllfile=strrchr(_dllfile,'\\');
  222. if (!dllfile) dllfile=_dllfile;
  223. else dllfile++;
  224. char * p=strchr(dllfile,'.');
  225. if (p) *p=0;
  226. }
  227. do_var(cfg_buf_ms);
  228. do_var(cfg_dev);
  229. do_var(cfg_volume);
  230. do_var(cfg_altvol);
  231. do_var(cfg_resetvol);
  232. do_var(cfg_prebuf);
  233. do_var(cfg_trackhack);
  234. }