-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabSound.cpp
350 lines (264 loc) · 8.84 KB
/
TabSound.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
// TabSound.cpp : implementation file
//
#include "stdafx.h"
#include "launcher.h"
#include "TabSound.h"
#include <mmsystem.h>
#include <vector>
#include <string>
#include <regstr.h>
#include "win32func.h"
#include "launcher_settings.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const int NUM_SND_MODES = 4;
char *sound_card_modes[NUM_SND_MODES] =
{
"DirectSound",
"EAX",
"Aureal A3D",
"No Sound"
};
// OpenAL stuff
typedef struct ALCdevice_struct ALCdevice;
typedef char ALCchar;
typedef int ALCenum;
#define ALC_DEFAULT_DEVICE_SPECIFIER 0x1004
#define ALC_DEVICE_SPECIFIER 0x1005
HINSTANCE hOAL;
const ALCchar* (*alcGetString)( ALCdevice *device, ALCenum param ) = NULL;
std::vector<std::string> OpenAL_sound_devices;
/////////////////////////////////////////////////////////////////////////////
// CTabSound dialog
CTabSound::CTabSound(CWnd* pParent /*=NULL*/)
: CDialog(CTabSound::IDD, pParent)
{
//{{AFX_DATA_INIT(CTabSound)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CTabSound::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTabSound)
DDX_Control(pDX, IDC_JOYSTICK, m_joystick_list);
DDX_Control(pDX, IDC_SOUND_CARD, m_sound_api_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTabSound, CDialog)
//{{AFX_MSG_MAP(CTabSound)
ON_BN_CLICKED(IDC_CALIBRATE, OnCalibrate)
ON_CBN_SELCHANGE(IDC_SOUND_CARD, OnSelChangeSoundDevice)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTabSound message handlers
void CTabSound::OnApply()
{
// Sound settings
int index = m_sound_api_list.GetCurSel();
char string[50];
m_sound_api_list.GetLBText(index, string);
if ( LauncherSettings::is_openal_build() ) {
reg_set_sz(LauncherSettings::get_reg_path(), "SoundDeviceOAL", string);
} else {
reg_set_sz(LauncherSettings::get_reg_path(), "Soundcard", string);
}
// Joystick settings
const int CHECKED = 1;
int ff = (((CButton *) GetDlgItem(IDC_FORCE_FREEDBACK))->GetCheck() == CHECKED) ? 1 : 0;
int dh = (((CButton *) GetDlgItem(IDC_DIR_HIT))->GetCheck() == CHECKED) ? 1 : 0;
reg_set_dword(LauncherSettings::get_reg_path(), "EnableJoystickFF", ff);
reg_set_dword(LauncherSettings::get_reg_path(), "EnableHitEffect", dh);
// Set joystick
index = m_joystick_list.GetCurSel();
if (index < 0)
index = 0;
int enum_id = m_joystick_list.GetItemData(index);
reg_set_dword(LauncherSettings::get_reg_path(), "CurrentJoystick", enum_id);
}
void CTabSound::SetupOpenAL()
{
if ( OpenAL_sound_devices.size() < 1 ) {
if ( (hOAL = LoadLibrary("OpenAL32.dll")) == 0 ) {
MessageBox("Build needs OpenAL but an OpenAL DLL cannot be found!", "Error", MB_OK);
return;
}
alcGetString = (const ALCchar* (*)(ALCdevice *device, ALCenum param)) GetProcAddress( hOAL, "alcGetString" );
if (alcGetString == NULL) {
FreeLibrary( hOAL );
MessageBox("Unable to acquire alcGetString pointer!", "Error", MB_OK);
return;
}
const char *my_devices = (const char*) alcGetString( NULL, ALC_DEVICE_SPECIFIER );
char *pos = NULL;
pos = (char*)my_devices;
while (*pos && (strlen(pos) > 0)) {
OpenAL_sound_devices.push_back(pos);
pos += (strlen(pos) + 1);
}
OpenAL_sound_devices.push_back("no sound");
FreeLibrary( hOAL );
}
m_sound_api_list.ResetContent();
unsigned int i;
int selection = 0;
for (i = 0; i < OpenAL_sound_devices.size(); i++) {
m_sound_api_list.InsertString(i, OpenAL_sound_devices[i].c_str());
if ( !stricmp(OpenAL_sound_devices[i].c_str(), "Generic Software") ) {
GetDlgItem(IDC_OAL_WARN_STATIC)->ShowWindow(false);
selection = i;
}
}
m_sound_api_list.SetCurSel(selection);
}
BOOL CTabSound::OnInitDialog()
{
int i, list_index;
JOYCAPS jc;
JOYINFO ji;
char joy_name[256];
TCHAR szKey[256];
TCHAR szValue[256];
UCHAR szOEMKey[256];
HKEY hKey;
DWORD dwcb;
LONG lr;
CDialog::OnInitDialog();
for (i = 0; i < NUM_SND_MODES; i++)
m_sound_api_list.InsertString(i, sound_card_modes[i]);
m_sound_api_list.SetCurSel(0);
GetDlgItem(IDC_OAL_WARN_STATIC)->ShowWindow(false);
// Joystick
list_index = m_joystick_list.AddString("No Joystick");
m_joystick_list.SetItemData(list_index, 99999);
int num_sticks = joyGetNumDevs();
for (i = 0; i < num_sticks; i++) {
memset( &jc, 0, sizeof(JOYCAPS) );
memset( joy_name, 0, sizeof(joy_name) );
MMRESULT mr = joyGetDevCaps( i, &jc, sizeof(JOYCAPS) );
// make sure that our device/driver is good
if (mr != JOYERR_NOERROR)
continue;
// if the joystick is unplugged or otherwise not available then just ignore it
if (joyGetPos(i, &ji) != JOYERR_NOERROR)
continue;
// copy basic device name, in case getting the OEM name from the registry fails
strcpy( joy_name, jc.szPname );
// now try to grab the full OEM name for this joystick ...
sprintf(szKey, "%s\\%s\\%s", REGSTR_PATH_JOYCONFIG, jc.szRegKey, REGSTR_KEY_JOYCURR);
lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPTSTR) &szKey, 0, KEY_QUERY_VALUE, &hKey);
if (lr != ERROR_SUCCESS)
goto Done;
dwcb = sizeof(szOEMKey);
// NOTE: normal joystick values are 0 based, but it's 1 based in the registry, hence the "+1"
sprintf(szValue, "Joystick%d%s", i+1, REGSTR_VAL_JOYOEMNAME);
lr = RegQueryValueEx(hKey, szValue, 0, 0, (LPBYTE) &szOEMKey, (LPDWORD) &dwcb);
RegCloseKey(hKey);
if (lr != ERROR_SUCCESS)
goto Done;
sprintf(szKey, "%s\\%s", REGSTR_PATH_JOYOEM, szOEMKey);
lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_QUERY_VALUE, &hKey);
if (lr != ERROR_SUCCESS)
goto Done;
// grab the OEM name
dwcb = sizeof(szValue);
lr = RegQueryValueEx(hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, (LPBYTE) joy_name, (LPDWORD) &dwcb);
RegCloseKey(hKey);
Done:
list_index = m_joystick_list.AddString(joy_name);
m_joystick_list.SetItemData(list_index, i);
}
m_joystick_list.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CTabSound::LoadSettings()
{
DWORD ff, dh;
if ( LauncherSettings::is_openal_build() ) {
GetDlgItem(IDC_OAL_WARN_STATIC)->ShowWindow(true);
GetDlgItem(IDC_EAX_STATIC)->ShowWindow(false);
GetDlgItem(IDC_SOUND_STATIC)->SetWindowText("Currently selected OpenAL Sound Device");
SetupOpenAL();
} else {
GetDlgItem(IDC_EAX_STATIC)->ShowWindow(true);
GetDlgItem(IDC_SOUND_STATIC)->SetWindowText("Currently selected Sound Card");
}
reg_get_dword(LauncherSettings::get_reg_path(), "EnableJoystickFF", &ff);
reg_get_dword(LauncherSettings::get_reg_path(), "EnableHitEffect", &dh);
((CButton *) GetDlgItem(IDC_FORCE_FREEDBACK))->SetCheck(ff ? 1 : 0);
((CButton *) GetDlgItem(IDC_DIR_HIT))->SetCheck(dh ? 1 : 0);
char local_port_text[50];
if ( LauncherSettings::is_openal_build() == false ) {
reg_get_sz(LauncherSettings::get_reg_path(), "SoundCard", local_port_text, 50);
for(int i = 0; i < NUM_SND_MODES; i++)
{
if(stricmp(sound_card_modes[i], local_port_text) == 0)
{
m_sound_api_list.SetCurSel(i);
break;;
}
}
} else {
reg_get_sz(LauncherSettings::get_reg_path(), "SoundDeviceOAL", local_port_text, 50);
for (unsigned int i = 0; i < OpenAL_sound_devices.size(); i++) {
if ( !stricmp(OpenAL_sound_devices[i].c_str(), local_port_text) ) {
m_sound_api_list.SetCurSel(i);
// if not software device then show warning message
if ( stricmp(OpenAL_sound_devices[i].c_str(), "no sound") &&
stricmp(OpenAL_sound_devices[i].c_str(), "Generic Software") )
{
GetDlgItem(IDC_OAL_WARN_STATIC)->ShowWindow(true);
}
break;
}
}
}
// Get joystick
DWORD enum_id = 0;
reg_get_dword(LauncherSettings::get_reg_path(), "CurrentJoystick", &enum_id);
int num_joy = m_joystick_list.GetCount();
for (int i = 0; i < num_joy; i++) {
if (m_joystick_list.GetItemData(i) == enum_id) {
m_joystick_list.SetCurSel(i);
break;
}
}
}
void CTabSound::OnCalibrate()
{
int index = m_joystick_list.GetCurSel();
if (index < 0)
return;
int enum_id = m_joystick_list.GetItemData(index);
if (enum_id == 99999) {
MessageBox("No Joystick is setup", "Error");
return;
}
// launch the joystick control panel applet
WinExec("rundll32.exe shell32.dll,Control_RunDLL joy.cpl", SW_SHOWNORMAL);
}
void CTabSound::OnDestroy()
{
CDialog::OnDestroy();
}
void CTabSound::OnSelChangeSoundDevice()
{
if ( LauncherSettings::is_openal_build() == false )
return;
char device_str[50];
int index = m_sound_api_list.GetCurSel();
m_sound_api_list.GetLBText(index, device_str);
// since anything other than the generic software device
// may not have enough sound sources to also use music/voices
// be sure to give a warning text to that effect
if ( stricmp(device_str, "no sound") && stricmp(device_str, "Generic Software") )
GetDlgItem(IDC_OAL_WARN_STATIC)->ShowWindow(true);
else
GetDlgItem(IDC_OAL_WARN_STATIC)->ShowWindow(false);
}