AudioConfigDialog.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // AudioConfigDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "wwconfig.h"
  22. #include "audioconfigdialog.h"
  23. #include "wwaudio.h"
  24. #include "locale_api.h"
  25. #include "wwconfig_ids.h"
  26. #include "..\..\combat\specialbuilds.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Constants
  34. /////////////////////////////////////////////////////////////////////////////
  35. enum
  36. {
  37. COL_DRIVER_NAME = 0,
  38. };
  39. /*
  40. #ifdef MULTIPLAYERDEMO
  41. const char *RENEGADE_SUB_KEY_NAME_AUDIO = "Software\\Westwood\\RenegadeMPDemo\\Sound";
  42. #else
  43. const char *RENEGADE_SUB_KEY_NAME_AUDIO = "Software\\Westwood\\Renegade\\Sound";
  44. #endif // MULTIPLAYERDEMO
  45. */
  46. #if defined(FREEDEDICATEDSERVER)
  47. const char *RENEGADE_SUB_KEY_NAME_AUDIO = "Software\\Westwood\\RenegadeFDS\\Sound";
  48. #elif defined(MULTIPLAYERDEMO)
  49. const char *RENEGADE_SUB_KEY_NAME_AUDIO = "Software\\Westwood\\RenegadeMPDemo\\Sound";
  50. #elif defined(BETACLIENT)
  51. const char *RENEGADE_SUB_KEY_NAME_AUDIO = "Software\\Westwood\\RenegadeBeta\\Sound";
  52. #else
  53. const char *RENEGADE_SUB_KEY_NAME_AUDIO = "Software\\Westwood\\Renegade\\Sound";
  54. #endif
  55. /////////////////////////////////////////////////////////////////////////////
  56. //
  57. // AudioConfigDialogClass
  58. //
  59. /////////////////////////////////////////////////////////////////////////////
  60. AudioConfigDialogClass::AudioConfigDialogClass(CWnd* pParent /*=NULL*/)
  61. : CDialog(AudioConfigDialogClass::IDD, pParent)
  62. {
  63. //{{AFX_DATA_INIT(AudioConfigDialogClass)
  64. // NOTE: the ClassWizard will add member initialization here
  65. //}}AFX_DATA_INIT
  66. CDialog::Create (AudioConfigDialogClass::IDD, pParent);
  67. return ;
  68. }
  69. /////////////////////////////////////////////////////////////////////////////
  70. //
  71. // DoDataExchange
  72. //
  73. /////////////////////////////////////////////////////////////////////////////
  74. void
  75. AudioConfigDialogClass::DoDataExchange (CDataExchange *pDX)
  76. {
  77. CDialog::DoDataExchange(pDX);
  78. //{{AFX_DATA_MAP(AudioConfigDialogClass)
  79. DDX_Control(pDX, IDC_SOUND_EFFECTS_SLIDER, m_SoundVolSlider);
  80. DDX_Control(pDX, IDC_MUSIC_SLIDER, m_MusicVolSlider);
  81. DDX_Control(pDX, IDC_DIALOG_SLIDER, m_DialogVolSlider);
  82. DDX_Control(pDX, IDC_CINEMATIC_SLIDER, m_CinematicVolSlider);
  83. DDX_Control(pDX, IDC_DRIVER_LIST, m_ListCtrl);
  84. //}}AFX_DATA_MAP
  85. return ;
  86. }
  87. BEGIN_MESSAGE_MAP(AudioConfigDialogClass, CDialog)
  88. //{{AFX_MSG_MAP(AudioConfigDialogClass)
  89. ON_WM_DESTROY()
  90. //}}AFX_MSG_MAP
  91. END_MESSAGE_MAP()
  92. /////////////////////////////////////////////////////////////////////////////
  93. //
  94. // OnInitDialog
  95. //
  96. // Modified: 12/06/2001 by MML - Retrieving strings from Locomoto file.
  97. /////////////////////////////////////////////////////////////////////////////
  98. BOOL
  99. AudioConfigDialogClass::OnInitDialog (void)
  100. {
  101. char string [_MAX_PATH];
  102. CDialog::OnInitDialog ();
  103. //
  104. // Set all the static strings for this dialog.
  105. //
  106. Locale_GetString( IDS_DRIVER, string );
  107. SetDlgItemText( IDC_DRIVER, string );
  108. Locale_GetString( IDS_VOLUME, string );
  109. SetDlgItemText( IDC_VOLUME, string );
  110. Locale_GetString( IDS_SOUND_EFFECTS, string );
  111. SetDlgItemText( IDC_SOUND_EFFECTS_CHECK, string );
  112. Locale_GetString( IDS_MUSIC, string );
  113. SetDlgItemText( IDC_MUSIC_CHECK, string );
  114. Locale_GetString( IDS_DIALOG, string );
  115. SetDlgItemText( IDC_DIALOG_CHECK, string );
  116. Locale_GetString( IDS_CINEMATIC, string);
  117. SetDlgItemText( IDC_CINEMATIC_CHECK, string );
  118. Locale_GetString( IDS_QUALITY, string );
  119. SetDlgItemText( IDC_QUALITY, string );
  120. SendDlgItemMessage (IDC_QUALITY_COMBO, CB_RESETCONTENT, 0, 0);
  121. SendDlgItemMessage (IDC_QUALITY_COMBO, CB_ADDSTRING, 0, (LPARAM)Locale_GetString (IDS_8_BIT, string));
  122. SendDlgItemMessage (IDC_QUALITY_COMBO, CB_ADDSTRING, 0, (LPARAM)Locale_GetString (IDS_16_BIT, string));
  123. Locale_GetString( IDS_PLAYBACK_RATE, string );
  124. SetDlgItemText( IDC_PLAYBACK_RATE, string );
  125. SendDlgItemMessage (IDC_RATE_COMBO, CB_RESETCONTENT, 0, 0);
  126. SendDlgItemMessage (IDC_RATE_COMBO, CB_ADDSTRING, 0, (LPARAM)Locale_GetString (IDS_11_KHZ, string));
  127. SendDlgItemMessage (IDC_RATE_COMBO, CB_ADDSTRING, 0, (LPARAM)Locale_GetString (IDS_22_KHZ, string));
  128. SendDlgItemMessage (IDC_RATE_COMBO, CB_ADDSTRING, 0, (LPARAM)Locale_GetString (IDS_44_KHZ, string));
  129. Locale_GetString( IDS_SPEAKER_SETUP, string );
  130. SetDlgItemText( IDC_SPEAKER_SETUP, string );
  131. SendDlgItemMessage (IDC_SPEAKER_COMBO, CB_RESETCONTENT, 0, 0);
  132. SendDlgItemMessage (IDC_SPEAKER_COMBO, CB_ADDSTRING, 0, (LPARAM)Locale_GetString (IDS_2_SPEAKER, string));
  133. SendDlgItemMessage (IDC_SPEAKER_COMBO, CB_ADDSTRING, 0, (LPARAM)Locale_GetString (IDS_HEADPHONE, string));
  134. SendDlgItemMessage (IDC_SPEAKER_COMBO, CB_ADDSTRING, 0, (LPARAM)Locale_GetString (IDS_SURROUND_SOUND, string));
  135. SendDlgItemMessage (IDC_SPEAKER_COMBO, CB_ADDSTRING, 0, (LPARAM)Locale_GetString (IDS_4_SPEAKER, string));
  136. Locale_GetString( IDS_STEREO, string );
  137. SetDlgItemText( IDC_STEREO_CHECK, string );
  138. //
  139. // Startup the audio library
  140. //
  141. new WWAudioClass;
  142. WWAudioClass::Get_Instance ()->Initialize ();
  143. //
  144. // Read the audio library's settings from the registry
  145. //
  146. StringClass device_name;
  147. bool is_stereo = true;
  148. int bits = 16;
  149. int hertz = 44100;
  150. bool sound_on = true;
  151. bool music_on = true;
  152. bool dialog_on = true;
  153. bool cinematic_on = true;
  154. float sound_vol = 1.0F;
  155. float music_vol = 1.0F;
  156. float dialog_vol = 1.0F;
  157. float cinematic_vol = 1.0F;
  158. int speaker_type = 0;
  159. WWAudioClass::Get_Instance ()->Load_From_Registry (RENEGADE_SUB_KEY_NAME_AUDIO,
  160. device_name, is_stereo, bits, hertz, sound_on,
  161. music_on, dialog_on, cinematic_on, sound_vol,
  162. music_vol, dialog_vol, cinematic_vol, speaker_type);
  163. //
  164. // Setup the sound volume controls
  165. //
  166. m_SoundVolSlider.SetRange (0, 100);
  167. m_SoundVolSlider.SetPos (static_cast<int>(sound_vol * 100));
  168. SendDlgItemMessage (IDC_SOUND_EFFECTS_CHECK, BM_SETCHECK, (WPARAM)sound_on);
  169. //
  170. // Setup the music volume controls
  171. //
  172. m_MusicVolSlider.SetRange (0, 100);
  173. m_MusicVolSlider.SetPos (static_cast<int>(music_vol * 100));
  174. SendDlgItemMessage (IDC_MUSIC_CHECK, BM_SETCHECK, (WPARAM)music_on);
  175. //
  176. // Setup the dialog volume controls
  177. //
  178. m_DialogVolSlider.SetRange (0, 100);
  179. m_DialogVolSlider.SetPos (static_cast<int>(dialog_vol * 100));
  180. SendDlgItemMessage (IDC_DIALOG_CHECK, BM_SETCHECK, (WPARAM)dialog_on);
  181. //
  182. // Setup the cinematic volume controls
  183. //
  184. m_CinematicVolSlider.SetRange (0, 100);
  185. m_CinematicVolSlider.SetPos (static_cast<int>(cinematic_vol * 100));
  186. SendDlgItemMessage (IDC_CINEMATIC_CHECK, BM_SETCHECK, (WPARAM)cinematic_on);
  187. //
  188. // Check the stereo box if necessary
  189. //
  190. SendDlgItemMessage (IDC_STEREO_CHECK, BM_SETCHECK, (WPARAM)is_stereo);
  191. //
  192. // Select the appropriate quality combobox entry
  193. //
  194. switch (bits)
  195. {
  196. case 8:
  197. SendDlgItemMessage (IDC_QUALITY_COMBO, CB_SETCURSEL, (WPARAM)0);
  198. break;
  199. default:
  200. case 16:
  201. SendDlgItemMessage (IDC_QUALITY_COMBO, CB_SETCURSEL, (WPARAM)1);
  202. break;
  203. }
  204. //
  205. // Select the appropriate kHz combobox entry
  206. //
  207. switch (hertz)
  208. {
  209. case 11025:
  210. SendDlgItemMessage (IDC_RATE_COMBO, CB_SETCURSEL, (WPARAM)0);
  211. break;
  212. case 22050:
  213. SendDlgItemMessage (IDC_RATE_COMBO, CB_SETCURSEL, (WPARAM)1);
  214. break;
  215. default:
  216. case 44100:
  217. SendDlgItemMessage (IDC_RATE_COMBO, CB_SETCURSEL, (WPARAM)2);
  218. break;
  219. }
  220. // Select the appropriate speaker setup combobox entry
  221. switch (speaker_type) {
  222. default:
  223. case 0:
  224. SendDlgItemMessage (IDC_SPEAKER_COMBO, CB_SETCURSEL, (WPARAM)0);
  225. break;
  226. case 1:
  227. SendDlgItemMessage (IDC_SPEAKER_COMBO, CB_SETCURSEL, (WPARAM)1);
  228. break;
  229. case 2:
  230. SendDlgItemMessage (IDC_SPEAKER_COMBO, CB_SETCURSEL, (WPARAM)2);
  231. break;
  232. case 3:
  233. SendDlgItemMessage (IDC_SPEAKER_COMBO, CB_SETCURSEL, (WPARAM)3);
  234. break;
  235. }
  236. //
  237. // Configure the list control
  238. //
  239. m_ListCtrl.SetExtendedStyle (m_ListCtrl.GetExtendedStyle () | LVS_EX_FULLROWSELECT);
  240. m_ListCtrl.InsertColumn (COL_DRIVER_NAME, "Driver Name");
  241. //
  242. // Size the columns
  243. //
  244. CRect rect;
  245. m_ListCtrl.GetClientRect (&rect);
  246. int width = rect.Width () - ::GetSystemMetrics (SM_CXVSCROLL);
  247. m_ListCtrl.SetColumnWidth (0, width);
  248. //
  249. // Loop over all the drivers
  250. //
  251. bool selected_default = false;
  252. int driver_count = WWAudioClass::Get_Instance ()->Get_3D_Device_Count ();
  253. for (int index = 0; index < driver_count; index ++) {
  254. //
  255. // Get information about this sound driver
  256. //
  257. WWAudioClass::DRIVER_INFO_STRUCT *driver_info = NULL;
  258. if (WWAudioClass::Get_Instance ()->Get_3D_Device (index, &driver_info)) {
  259. //
  260. // Add an entry to the list for this driver
  261. //
  262. int item_index = m_ListCtrl.InsertItem (0xFF, driver_info->name);
  263. if (item_index >= 0) {
  264. m_ListCtrl.SetItemData (item_index, (DWORD)driver_info->driver);
  265. //
  266. // Select this entry if its the default
  267. //
  268. if (::lstrcmpi (device_name, driver_info->name) == 0) {
  269. m_ListCtrl.SetItemState (item_index, LVIS_SELECTED, LVIS_SELECTED);
  270. selected_default = true;
  271. }
  272. }
  273. }
  274. }
  275. //
  276. // Select the first entry by default (if necessary)
  277. //
  278. if (selected_default == false) {
  279. m_ListCtrl.SetItemState (0, LVIS_SELECTED, LVIS_SELECTED);
  280. }
  281. //
  282. // Update the enabled state of the volume sliders
  283. //
  284. Update_Slider_Enable_State ();
  285. return TRUE;
  286. }
  287. /////////////////////////////////////////////////////////////////////////////
  288. //
  289. // OnDestroy
  290. //
  291. /////////////////////////////////////////////////////////////////////////////
  292. void
  293. AudioConfigDialogClass::OnDestroy (void)
  294. {
  295. //
  296. // Shutdown the audio library
  297. //
  298. WWAudioClass::Get_Instance ()->Shutdown ();
  299. delete WWAudioClass::Get_Instance ();
  300. CDialog::OnDestroy ();
  301. return ;
  302. }
  303. /////////////////////////////////////////////////////////////////////////////
  304. //
  305. // Apply_Changes
  306. //
  307. /////////////////////////////////////////////////////////////////////////////
  308. void
  309. AudioConfigDialogClass::Apply_Changes (void)
  310. {
  311. StringClass device_name;
  312. int hertz = 44100;
  313. int bits = 16;
  314. int speaker_type = 0;
  315. bool is_stereo = true;
  316. bool sound_on = true;
  317. bool music_on = true;
  318. bool dialog_on = true;
  319. bool cinematic_on = true;
  320. float sound_vol = 1.0F;
  321. float music_vol = 1.0F;
  322. float dialog_vol = 1.0F;
  323. float cinematic_vol = 1.0F;
  324. //
  325. // Get the volume settings
  326. //
  327. sound_vol = m_SoundVolSlider.GetPos () / 100.0F;
  328. music_vol = m_MusicVolSlider.GetPos () / 100.0F;
  329. dialog_vol = m_DialogVolSlider.GetPos () / 100.0F;
  330. cinematic_vol = m_CinematicVolSlider.GetPos() / 100.0F;
  331. //
  332. // Get the volume controls
  333. //
  334. sound_on = (SendDlgItemMessage (IDC_SOUND_EFFECTS_CHECK, BM_GETCHECK) == 1);
  335. music_on = (SendDlgItemMessage (IDC_MUSIC_CHECK, BM_GETCHECK) == 1);
  336. dialog_on = (SendDlgItemMessage (IDC_DIALOG_CHECK, BM_GETCHECK) == 1);
  337. cinematic_on = (SendDlgItemMessage (IDC_CINEMATIC_CHECK, BM_GETCHECK) == 1);
  338. //
  339. // Get the name of the selected device
  340. //
  341. int selected_item = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  342. if (selected_item >= 0) {
  343. device_name = (const char *)m_ListCtrl.GetItemText (selected_item, 0);
  344. }
  345. //
  346. // Get the stereo flag from the dialog
  347. //
  348. is_stereo = bool(SendDlgItemMessage (IDC_STEREO_CHECK, BM_GETCHECK) == 1);
  349. //
  350. // Get the playback bit rate from the dialog
  351. //
  352. int quality_cursel = SendDlgItemMessage (IDC_QUALITY_COMBO, CB_GETCURSEL);
  353. if (quality_cursel == 0) {
  354. bits = 8;
  355. } else if (quality_cursel == 1) {
  356. bits = 16;
  357. }
  358. //
  359. // Get the playback rate from the controls
  360. //
  361. int rate_cursel = SendDlgItemMessage (IDC_RATE_COMBO, CB_GETCURSEL);
  362. if (rate_cursel == 0) {
  363. hertz = 11025;
  364. } else if (rate_cursel == 1) {
  365. hertz = 22050;
  366. } else if (rate_cursel == 2) {
  367. hertz = 44100;
  368. }
  369. // Get the speaker setup from the controls.
  370. speaker_type = SendDlgItemMessage (IDC_SPEAKER_COMBO, CB_GETCURSEL);
  371. //
  372. // Store these settings in the registry
  373. //
  374. WWAudioClass::Get_Instance ()->Save_To_Registry (RENEGADE_SUB_KEY_NAME_AUDIO,
  375. device_name, is_stereo, bits, hertz,
  376. sound_on, music_on, dialog_on, cinematic_on,
  377. sound_vol, music_vol, dialog_vol, cinematic_vol, speaker_type);
  378. return ;
  379. }
  380. /////////////////////////////////////////////////////////////////////////////
  381. //
  382. // WindowProc
  383. //
  384. /////////////////////////////////////////////////////////////////////////////
  385. LRESULT
  386. AudioConfigDialogClass::WindowProc
  387. (
  388. UINT message,
  389. WPARAM wParam,
  390. LPARAM lParam
  391. )
  392. {
  393. if (message == (WM_USER + 101)) {
  394. Apply_Changes ();
  395. }
  396. return CDialog::WindowProc(message, wParam, lParam);
  397. }
  398. /////////////////////////////////////////////////////////////////////////////
  399. //
  400. // Update_Slider_Enable_State
  401. //
  402. /////////////////////////////////////////////////////////////////////////////
  403. void
  404. AudioConfigDialogClass::Update_Slider_Enable_State (void)
  405. {
  406. BOOL sound_enabled = IsDlgButtonChecked (IDC_SOUND_EFFECTS_CHECK);
  407. BOOL music_enabled = IsDlgButtonChecked (IDC_MUSIC_CHECK);
  408. BOOL dialog_enabled = IsDlgButtonChecked (IDC_DIALOG_CHECK);
  409. BOOL cinematic_enabled = IsDlgButtonChecked (IDC_CINEMATIC_CHECK);
  410. //
  411. // Enable the slider's based on the state of the check boxes
  412. //
  413. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SOUND_EFFECTS_SLIDER), sound_enabled);
  414. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_MUSIC_SLIDER), music_enabled);
  415. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_DIALOG_SLIDER), dialog_enabled);
  416. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_CINEMATIC_SLIDER), cinematic_enabled);
  417. return ;
  418. }
  419. /////////////////////////////////////////////////////////////////////////////
  420. //
  421. // OnCommand
  422. //
  423. /////////////////////////////////////////////////////////////////////////////
  424. BOOL
  425. AudioConfigDialogClass::OnCommand (WPARAM wParam, LPARAM lParam)
  426. {
  427. switch (LOWORD (wParam)) {
  428. //
  429. // Update the enabled state of the volume sliders
  430. //
  431. case IDC_SOUND_EFFECTS_CHECK:
  432. case IDC_MUSIC_CHECK:
  433. case IDC_DIALOG_CHECK:
  434. case IDC_CINEMATIC_CHECK:
  435. Update_Slider_Enable_State();
  436. break;
  437. }
  438. return CDialog::OnCommand (wParam, lParam);
  439. }