1
0

options_playback.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author: Ben Allison [email protected]
  6. ** Created:
  7. **/
  8. #include "Main.h"
  9. #include "resource.h"
  10. #include "options.h"
  11. #include "WinampAttributes.h"
  12. #include "../Plugins/General/gen_ml/ml.h"
  13. static void EnableDisableReplayGain(HWND hwndDlg)
  14. {
  15. BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_USE_REPLAY);
  16. EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_SOURCE), enabled);
  17. EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_MODE), enabled);
  18. EnableWindow(GetDlgItem(hwndDlg, IDC_REPLAY_SOURCE), enabled);
  19. EnableWindow(GetDlgItem(hwndDlg, IDC_REPLAY_MODE), enabled);
  20. EnableWindow(GetDlgItem(hwndDlg, IDC_REPLAY_PREFERRED), enabled);
  21. EnableWindow(GetDlgItem(hwndDlg, IDC_NON_REPLAYGAIN), enabled);
  22. EnableWindow(GetDlgItem(hwndDlg, IDC_NON_REPLAYGAIN_DB), enabled);
  23. EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_ADJ), enabled);
  24. EnableWindow(GetDlgItem(hwndDlg, IDC_REPLAYGAIN_PREAMP), enabled);
  25. EnableWindow(GetDlgItem(hwndDlg, IDC_REPLAYGAIN_PREAMP_DB), enabled);
  26. EnableWindow(GetDlgItem(hwndDlg, IDC_REPLAY_ADJ), enabled);
  27. }
  28. static DWORD ml_rg_config_ipc;
  29. static DLGPROC ml_rg_config_dlg;
  30. static void EnableReplayGainAnalyzer(HWND hwndDlg)
  31. {
  32. pluginMessage message_build = {(int)ml_rg_config_ipc,0,0};
  33. BOOL enabled = sendMlIpc(ML_IPC_SEND_PLUGIN_MESSAGE,(WPARAM)&message_build);
  34. ShowWindow(GetDlgItem(hwndDlg, IDC_RGAS), enabled);
  35. ShowWindow(GetDlgItem(hwndDlg, IDC_RG_ASK), enabled);
  36. ShowWindow(GetDlgItem(hwndDlg, IDC_RG_ALBUM), enabled);
  37. ShowWindow(GetDlgItem(hwndDlg, IDC_RG_ALL), enabled);
  38. ShowWindow(GetDlgItem(hwndDlg, IDC_RGC), enabled);
  39. message_build.param1 = 1;
  40. ml_rg_config_dlg = (DLGPROC)sendMlIpc(ML_IPC_SEND_PLUGIN_MESSAGE,(WPARAM)&message_build);
  41. }
  42. #define NON_RG_MIN_DB 14
  43. #define NON_RG_MAX_DB 6
  44. #define NON_RG_SCALE 10
  45. #define HAS_RG_MIN_DB 14
  46. #define HAS_RG_MAX_DB 6
  47. #define HAS_RG_SCALE 10
  48. static HWND subWnd;
  49. static LRESULT CALLBACK PlaybackUIProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  50. {
  51. if (uMsg == WM_INITDIALOG)
  52. {
  53. SendMessageW(GetDlgItem(hwndDlg, IDC_PRIORITY), TBM_SETRANGEMAX, 0, THREAD_PRIORITY_HIGHEST-THREAD_PRIORITY_LOWEST);
  54. SendMessageW(GetDlgItem(hwndDlg, IDC_PRIORITY), TBM_SETRANGEMIN, 0, 0);
  55. SendMessageW(GetDlgItem(hwndDlg, IDC_PRIORITY), TBM_SETPOS, 1, config_playback_thread_priority-THREAD_PRIORITY_LOWEST);
  56. CheckDlgButton(hwndDlg,IDC_MONO,config_audio_mono);
  57. CheckDlgButton(hwndDlg,IDC_SURROUND,config_audio_surround);
  58. CheckDlgButton(hwndDlg,IDC_DITHER,config_audio_dither);
  59. CheckDlgButton(hwndDlg,IDC_24BIT,config_audio_bits==24);
  60. }
  61. if (uMsg == WM_HSCROLL)
  62. {
  63. HWND swnd = (HWND) lParam;
  64. if (swnd == GetDlgItem(hwndDlg,IDC_PRIORITY))
  65. {
  66. config_playback_thread_priority = (INT_PTR)SendMessageW(GetDlgItem(hwndDlg, IDC_PRIORITY), TBM_GETPOS, 0, 0)+THREAD_PRIORITY_LOWEST;
  67. }
  68. }
  69. if (uMsg == WM_COMMAND)
  70. {
  71. switch (LOWORD(wParam))
  72. {
  73. case IDC_MONO: config_audio_mono = IsDlgButtonChecked(hwndDlg,IDC_MONO)?true:false; break;
  74. case IDC_SURROUND: config_audio_surround = IsDlgButtonChecked(hwndDlg,IDC_SURROUND)?true:false; break;
  75. case IDC_DITHER: config_audio_dither = IsDlgButtonChecked(hwndDlg,IDC_DITHER)?true:false; break;
  76. case IDC_24BIT:
  77. {
  78. BOOL allow24 = IsDlgButtonChecked(hwndDlg,IDC_24BIT);
  79. wchar_t title[64] = {0};
  80. getStringW(IDS_P_24BIT_WARNING_TITLE,title,64);
  81. if (allow24 && MessageBoxW(hwndDlg, getStringW(IDS_P_24BIT_WARNING,NULL,0), title, MB_YESNO | MB_DEFBUTTON2) == IDNO)
  82. {
  83. allow24 = FALSE;
  84. CheckDlgButton(hwndDlg,IDC_24BIT, BST_UNCHECKED);
  85. }
  86. config_audio_bits = allow24?24:16;
  87. }
  88. break;
  89. }
  90. }
  91. const int controls[] =
  92. {
  93. IDC_PRIORITY,
  94. };
  95. if (FALSE != DirectMouseWheel_ProcessDialogMessage(hwndDlg, uMsg, wParam, lParam, controls, ARRAYSIZE(controls)))
  96. return TRUE;
  97. return FALSE;
  98. }
  99. int first_eq_type = -1, prev_eq_type = EQ_TYPE_4FRONT;
  100. static LRESULT CALLBACK EqualizerUIProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  101. {
  102. if (uMsg == WM_INITDIALOG)
  103. {
  104. if(first_eq_type != -1 && first_eq_type != config_eq_type)
  105. {
  106. ShowWindow(GetDlgItem(hwndDlg,IDC_EQ_RESTART_TEXT),SW_SHOW);
  107. }
  108. else if(first_eq_type == -1)
  109. {
  110. first_eq_type = config_eq_type;
  111. }
  112. prev_eq_type = config_eq_type;
  113. SendDlgItemMessageW(hwndDlg,IDC_EQ,CB_ADDSTRING,0,(LPARAM)getStringW(IDS_P_4FRONT_EQ,NULL,0));
  114. SendDlgItemMessageW(hwndDlg,IDC_EQ,CB_ADDSTRING,0,(LPARAM)getStringW(IDS_P_CONSTANT_Q,NULL,0));
  115. SendDlgItemMessage(hwndDlg,IDC_EQ,CB_SETCURSEL,(config_eq_type==EQ_TYPE_CONSTANT_Q),0);
  116. wchar_t *name = 0;
  117. int width = 0;
  118. SendDlgItemMessageW(hwndDlg,IDC_FREQ_BANDS,CB_ADDSTRING,0,(LPARAM)(name = getStringW(IDS_P_WA_FREQ_BANDS,NULL,0)));
  119. width = ResizeComboBoxDropDownW(hwndDlg, IDC_FREQ_BANDS, name, width);
  120. SendDlgItemMessageW(hwndDlg,IDC_FREQ_BANDS,CB_ADDSTRING,0,(LPARAM)(name = getStringW(IDS_P_ISO_FREQ_BANDS,NULL,0)));
  121. ResizeComboBoxDropDownW(hwndDlg, IDC_FREQ_BANDS, name, width);
  122. SendDlgItemMessage(hwndDlg,IDC_FREQ_BANDS,CB_SETCURSEL,(config_eq_frequencies==EQ_FREQUENCIES_ISO),0);
  123. CheckDlgButton(hwndDlg,IDC_LIMITER,config_eq_limiter);
  124. }
  125. else if (uMsg == WM_COMMAND)
  126. {
  127. switch (LOWORD(wParam))
  128. {
  129. case IDC_EQ:
  130. config_eq_type=SendDlgItemMessage(hwndDlg,IDC_EQ,CB_GETCURSEL,0,0);
  131. break;
  132. case IDC_FREQ_BANDS:
  133. config_eq_frequencies=SendDlgItemMessage(hwndDlg,IDC_FREQ_BANDS,CB_GETCURSEL,0,0);
  134. set_aot(0);
  135. draw_eq_init();
  136. eq_set(config_use_eq, (char*)eq_tab, config_preamp);
  137. PostMessageW(hMainWindow,WM_WA_IPC,IPC_CB_MISC_EQ,IPC_CB_MISC);
  138. InvalidateRect(hEQWindow, NULL, TRUE);
  139. break;
  140. case IDC_LIMITER:
  141. config_eq_limiter = IsDlgButtonChecked(hwndDlg,IDC_LIMITER)?true:false;
  142. break;
  143. }
  144. }
  145. else if (uMsg == WM_DESTROY)
  146. {
  147. if(config_eq_type != prev_eq_type)
  148. {
  149. if((first_eq_type != config_eq_type) &&
  150. LPMessageBox(hwndDlg,IDS_P_EQ_TYPE_CHANGE_MSG,IDS_P_EQ_TYPE_CHANGE,MB_YESNO|MB_ICONQUESTION) == IDYES)
  151. {
  152. _w_i("show_prefs", 42);
  153. PostMessageW(hMainWindow,WM_USER,0,IPC_RESTARTWINAMP);
  154. }
  155. }
  156. }
  157. return FALSE;
  158. }
  159. static LRESULT CALLBACK ReplayGainUIProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  160. {
  161. if (uMsg == WM_INITDIALOG)
  162. {
  163. SendDlgItemMessageW(hwndDlg,IDC_REPLAY_SOURCE,CB_ADDSTRING,0,(LPARAM)getStringW(IDS_P_PLAYBACK_RG_SOURCE_TRACK,NULL,0));
  164. SendDlgItemMessageW(hwndDlg,IDC_REPLAY_SOURCE,CB_ADDSTRING,0,(LPARAM)getStringW(IDS_P_PLAYBACK_RG_SOURCE_ALBUM,NULL,0));
  165. SendDlgItemMessage(hwndDlg,IDC_REPLAY_SOURCE, CB_SETCURSEL, config_replaygain_source,0);
  166. SendDlgItemMessageW(hwndDlg,IDC_REPLAY_MODE,CB_ADDSTRING,0,(LPARAM)getStringW(IDS_P_PLAYBACK_RG_MODE_AG,NULL,0));
  167. SendDlgItemMessageW(hwndDlg,IDC_REPLAY_MODE,CB_ADDSTRING,0,(LPARAM)getStringW(IDS_P_PLAYBACK_RG_MODE_AG_PC,NULL,0));
  168. SendDlgItemMessageW(hwndDlg,IDC_REPLAY_MODE,CB_ADDSTRING,0,(LPARAM)getStringW(IDS_P_PLAYBACK_RG_MODE_N,NULL,0));
  169. SendDlgItemMessageW(hwndDlg,IDC_REPLAY_MODE,CB_ADDSTRING,0,(LPARAM)getStringW(IDS_P_PLAYBACK_RG_MODE_PC,NULL,0));
  170. SendDlgItemMessage(hwndDlg,IDC_REPLAY_MODE, CB_SETCURSEL, config_replaygain_mode,0);
  171. CheckDlgButton(hwndDlg,IDC_REPLAY_PREFERRED,config_replaygain_preferred_only);
  172. CheckDlgButton(hwndDlg,IDC_USE_REPLAY, config_replaygain);
  173. SendMessageW(GetDlgItem(hwndDlg,IDC_NON_REPLAYGAIN),TBM_SETRANGEMAX,0,(NON_RG_MIN_DB+NON_RG_MAX_DB)*NON_RG_SCALE);
  174. SendMessageW(GetDlgItem(hwndDlg,IDC_NON_REPLAYGAIN),TBM_SETRANGEMIN,0,0);
  175. SendMessageW(GetDlgItem(hwndDlg,IDC_NON_REPLAYGAIN),TBM_SETPOS,1,(LPARAM)((NON_RG_MIN_DB*NON_RG_SCALE)+config_replaygain_non_rg_gain.GetFloat()*(float)NON_RG_SCALE));
  176. SendMessageW(GetDlgItem(hwndDlg,IDC_REPLAYGAIN_PREAMP),TBM_SETRANGEMAX,0,(HAS_RG_MIN_DB+HAS_RG_MAX_DB)*HAS_RG_SCALE);
  177. SendMessageW(GetDlgItem(hwndDlg,IDC_REPLAYGAIN_PREAMP),TBM_SETRANGEMIN,0,0);
  178. SendMessageW(GetDlgItem(hwndDlg,IDC_REPLAYGAIN_PREAMP),TBM_SETPOS,1,(LPARAM)((HAS_RG_MIN_DB*HAS_RG_SCALE)+config_replaygain_preamp.GetFloat()*(float)HAS_RG_SCALE));
  179. wchar_t dummy[64] = {0};
  180. StringCchPrintfW(dummy, 64, L"%+6.1f %s", config_replaygain_non_rg_gain.GetFloat(), getStringW(IDS_EQ_DB,NULL,0));
  181. SetDlgItemTextW(hwndDlg, IDC_NON_REPLAYGAIN_DB, dummy);
  182. StringCchPrintfW(dummy, 64, L"%+6.1f %s", config_replaygain_preamp.GetFloat(), getStringW(IDS_EQ_DB,NULL,0));
  183. SetDlgItemTextW(hwndDlg, IDC_REPLAYGAIN_PREAMP_DB, dummy);
  184. EnableDisableReplayGain(hwndDlg);
  185. EnableReplayGainAnalyzer(hwndDlg);
  186. }
  187. if (uMsg == WM_COMMAND)
  188. {
  189. switch (LOWORD(wParam))
  190. {
  191. case IDC_USE_REPLAY:
  192. config_replaygain = IsDlgButtonChecked(hwndDlg,IDC_USE_REPLAY)?true:false;
  193. EnableDisableReplayGain(hwndDlg); break;
  194. case IDC_REPLAY_SOURCE:
  195. config_replaygain_source=SendDlgItemMessage(hwndDlg,IDC_REPLAY_SOURCE,CB_GETCURSEL,0,0);
  196. break;
  197. case IDC_REPLAY_MODE:
  198. config_replaygain_mode=SendDlgItemMessage(hwndDlg,IDC_REPLAY_MODE,CB_GETCURSEL,0,0);
  199. break;
  200. case IDC_REPLAY_PREFERRED:
  201. config_replaygain_preferred_only = IsDlgButtonChecked(hwndDlg,IDC_REPLAY_PREFERRED)?true:false;
  202. break;
  203. }
  204. }
  205. if (uMsg == WM_HSCROLL)
  206. {
  207. HWND swnd = (HWND) lParam;
  208. if (swnd == GetDlgItem(hwndDlg,IDC_NON_REPLAYGAIN))
  209. {
  210. config_replaygain_non_rg_gain = (float)((int)SendMessageW(GetDlgItem(hwndDlg,IDC_NON_REPLAYGAIN),TBM_GETPOS,0,0)-NON_RG_MIN_DB*NON_RG_SCALE) / (float)NON_RG_SCALE;
  211. wchar_t dummy[64] = {0};
  212. StringCchPrintfW(dummy, 64, L"%+6.1f %s", config_replaygain_non_rg_gain.GetFloat(), getStringW(IDS_EQ_DB,NULL,0));
  213. SetDlgItemTextW(hwndDlg, IDC_NON_REPLAYGAIN_DB, dummy);
  214. }
  215. else if (swnd == GetDlgItem(hwndDlg,IDC_REPLAYGAIN_PREAMP))
  216. {
  217. config_replaygain_preamp = (float)((int)SendMessageW(GetDlgItem(hwndDlg,IDC_REPLAYGAIN_PREAMP),TBM_GETPOS,0,0)-HAS_RG_MIN_DB*HAS_RG_SCALE) / (float)HAS_RG_SCALE;
  218. wchar_t dummy[64] = {0};
  219. StringCchPrintfW(dummy, 64, L"%+6.1f %s", config_replaygain_preamp.GetFloat(), getStringW(IDS_EQ_DB,NULL,0));
  220. SetDlgItemTextW(hwndDlg, IDC_REPLAYGAIN_PREAMP_DB, dummy);
  221. }
  222. }
  223. // call the ml_rg config dialog (if we've got a dlgproc for the embedded options)
  224. if(ml_rg_config_dlg) ml_rg_config_dlg(hwndDlg,uMsg,wParam,lParam);
  225. const int controls[] =
  226. {
  227. IDC_NON_REPLAYGAIN,
  228. IDC_REPLAYGAIN_PREAMP,
  229. };
  230. if (FALSE != DirectMouseWheel_ProcessDialogMessage(hwndDlg, uMsg, wParam, lParam, controls, ARRAYSIZE(controls)))
  231. return TRUE;
  232. return FALSE;
  233. }
  234. multiPage playbackPages[] = {
  235. {IDD_PLAYBACK, PlaybackUIProc},
  236. {IDD_EQUALIZER_UI, EqualizerUIProc},
  237. {IDD_REPLAY_GAIN_UI, ReplayGainUIProc},
  238. //{IDD_SILENCE_DETECT, 0},
  239. };
  240. #define TabCtrl_InsertItemW(hwnd, iItem, pitem) \
  241. (int)SNDMSG((hwnd), TCM_INSERTITEMW, (WPARAM)(int)(iItem), (LPARAM)(const TC_ITEMW *)(pitem))
  242. INT_PTR CALLBACK PlaybackProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  243. {
  244. switch (uMsg)
  245. {
  246. case WM_INITDIALOG:
  247. {
  248. TCITEMW item = {0};
  249. HWND tabwnd=GetDlgItem(hwndDlg,IDC_TAB1);
  250. item.mask=TCIF_TEXT;
  251. item.pszText=getStringW(IDS_PREFS_PLAYBACK,NULL,0);
  252. TabCtrl_InsertItemW(tabwnd,0,&item);
  253. item.pszText=getStringW(IDS_P_EQUALIZER,NULL,0);
  254. TabCtrl_InsertItemW(tabwnd,1,&item);
  255. item.pszText=getStringW(IDS_P_REPLAY_GAIN,NULL,0);
  256. TabCtrl_InsertItemW(tabwnd,2,&item);
  257. #if 0
  258. item.pszText=getStringW(IDS_P_SILENCE_DETECT,NULL,0);
  259. TabCtrl_InsertItemW(tabwnd,3,&item);
  260. #endif
  261. ml_rg_config_ipc = wa_register_ipc((WPARAM)&"ml_rg_config");
  262. pluginMessage message_build = {(int)ml_rg_config_ipc,2,0};
  263. BOOL select_rg_page = sendMlIpc(ML_IPC_SEND_PLUGIN_MESSAGE,(WPARAM)&message_build);
  264. if(select_rg_page) config_last_playback_page = 2;
  265. TabCtrl_SetCurSel(tabwnd,config_last_playback_page);
  266. subWnd = _dosetsel(hwndDlg,subWnd,&config_last_playback_page,playbackPages,sizeof(playbackPages)/sizeof(playbackPages[0]));
  267. }
  268. break;
  269. case WM_NOTIFY:
  270. {
  271. LPNMHDR p=(LPNMHDR) lParam;
  272. if (p->idFrom == IDC_TAB1 && p->code == TCN_SELCHANGE)
  273. subWnd = _dosetsel(hwndDlg,subWnd,&config_last_playback_page,playbackPages,sizeof(playbackPages)/sizeof(playbackPages[0]));
  274. }
  275. break;
  276. case WM_DESTROY:
  277. subWnd=NULL;
  278. break;
  279. }
  280. return 0;
  281. } // playback