2 * Audio management UI code
4 * Copyright 2004 Chris Morgan
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_LEAN_AND_MEAN
23 #define NONAMELESSSTRUCT
24 #define NONAMELESSUNION
27 #include "wine/port.h"
35 #include <wine/debug.h>
48 WINE_DEFAULT_DEBUG_CHANNEL(winecfg
);
50 #define DRIVER_MASK 0x80000000
51 #define DEVICE_MASK 0x40000000
52 #define MAX_NAME_LENGTH 64
54 typedef DWORD (WINAPI
* MessagePtr
)(UINT
, UINT
, DWORD
, DWORD
, DWORD
);
56 static struct DSOUNDACCEL
60 const char* settingStr
;
61 } DSound_HW_Accels
[] = {
62 {IDS_ACCEL_FULL
, 1, "Full"},
63 {IDS_ACCEL_STANDARD
, 0, "Standard"},
64 {IDS_ACCEL_BASIC
, 0, "Basic"},
65 {IDS_ACCEL_EMULATION
, 1, "Emulation"},
69 static const char* DSound_Rates
[] = {
79 static const char* DSound_Bits
[] = {
91 static const AUDIO_DRIVER sAudioDrivers
[] = {
92 {IDS_DRIVER_PULSE
, "pulse"},
93 {IDS_DRIVER_ALSA
, "alsa"},
94 {IDS_DRIVER_OSS
, "oss"},
95 {IDS_DRIVER_COREAUDIO
, "coreaudio"},
96 {IDS_DRIVER_JACK
, "jack"},
97 {IDS_DRIVER_NAS
, "nas"},
98 {IDS_DRIVER_ESOUND
, "esd"},
99 {IDS_DRIVER_AUDIOIO
, "audioio"},
103 /* list of available drivers */
104 static AUDIO_DRIVER
* loadedAudioDrv
;
106 /* local copy of registry setting */
107 static char curAudioDriver
[1024];
109 /* driver index to configure */
110 static int toConfigure
;
112 /* display a driver specific configuration dialog */
113 static void configureAudioDriver(HWND hDlg
)
115 const AUDIO_DRIVER
*pAudioDrv
= &loadedAudioDrv
[toConfigure
];
117 if (strlen(pAudioDrv
->szDriver
) != 0)
120 char wine_driver
[MAX_NAME_LENGTH
+ 9];
121 sprintf(wine_driver
, "wine%s.drv", pAudioDrv
->szDriver
);
122 hdrvr
= OpenDriverA(wine_driver
, 0, 0);
125 if (SendDriverMessage(hdrvr
, DRV_QUERYCONFIGURE
, 0, 0) != 0)
129 dci
.dwDCISize
= sizeof (dci
);
130 dci
.lpszDCISectionName
= NULL
;
131 dci
.lpszDCIAliasName
= NULL
;
132 lRes
= SendDriverMessage(hdrvr
, DRV_CONFIGURE
, 0, (LONG_PTR
)&dci
);
134 CloseDriver(hdrvr
, 0, 0);
138 WCHAR wine_driverW
[MAX_NAME_LENGTH
+9];
139 WCHAR messageStr
[256];
142 MultiByteToWideChar (CP_ACP
, 0, wine_driver
, -1, wine_driverW
,
143 sizeof (wine_driverW
)/sizeof(wine_driverW
[0]));
145 LoadStringW (GetModuleHandle (NULL
), IDS_OPEN_DRIVER_ERROR
, messageStr
,
146 sizeof(messageStr
)/sizeof(messageStr
[0]));
147 wsprintfW (str
, messageStr
, wine_driverW
);
148 MessageBoxW (hDlg
, str
, NULL
, MB_OK
| MB_ICONERROR
);
153 /* is driver in local copy of driver registry string */
154 static BOOL
isDriverSet(const char * driver
)
156 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver
, curAudioDriver
);
158 if (strstr(curAudioDriver
, driver
))
164 /* add driver to local copy of driver registry string */
165 static void addDriver(const char * driver
)
167 if (!isDriverSet(driver
))
169 if (strlen(curAudioDriver
))
170 strcat(curAudioDriver
, ",");
171 strcat(curAudioDriver
, driver
);
175 /* remove driver from local copy of driver registry string */
176 static void removeDriver(const char * driver
)
178 char pattern
[32], *p
;
181 strcpy(pattern
, ",");
182 strcat(pattern
, driver
);
183 strcat(pattern
, ",");
184 drvlen
= strlen(driver
);
185 listlen
= strlen(curAudioDriver
);
187 p
= strstr(curAudioDriver
, pattern
);
188 if (p
) /* somewhere in the middle */
189 memmove(p
, p
+drvlen
+1, strlen(p
+drvlen
+1)+1);
190 else if (!strncmp(curAudioDriver
, pattern
+1, drvlen
+1)) /* the head */
191 memmove(curAudioDriver
, curAudioDriver
+drvlen
+1, listlen
-drvlen
);
192 else if (!strncmp(curAudioDriver
+listlen
-drvlen
-1, pattern
, drvlen
+1)) /* the tail */
193 curAudioDriver
[listlen
-drvlen
-1] = 0;
194 else if (!strcmp(curAudioDriver
, driver
)) /* only one entry (head&tail) */
195 curAudioDriver
[0] = 0;
197 WINE_FIXME("driver '%s' is not in the list, please report!\n", driver
);
200 static void initAudioDeviceTree(HWND hDlg
)
202 const AUDIO_DRIVER
*pAudioDrv
= NULL
;
204 TVINSERTSTRUCTW insert
;
205 HTREEITEM root
, driver
[10];
207 HIMAGELIST hImageList
;
210 WCHAR driver_type
[64], dev_type
[64];
212 tree
= GetDlgItem(hDlg
, IDC_AUDIO_TREE
);
217 /* set tree view style */
218 SetWindowLong(tree
, GWL_STYLE
, GetWindowLong(tree
, GWL_STYLE
) | TVS_HASBUTTONS
| TVS_HASLINES
| TVS_LINESATROOT
);
221 hImageList
= ImageList_Create(16, 16, FALSE
, 3, 0);
222 hBitMap
= LoadBitmap(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_CHECKBOX
));
223 ImageList_Add(hImageList
, hBitMap
, NULL
);
224 DeleteObject(hBitMap
);
225 SendMessageW( tree
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)hImageList
);
228 LoadStringW (GetModuleHandle (NULL
), IDS_SOUNDDRIVERS
, driver_type
,
229 sizeof(driver_type
)/sizeof(driver_type
[0]));
230 insert
.hParent
= TVI_ROOT
;
231 insert
.hInsertAfter
= TVI_LAST
;
232 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
233 insert
.u
.item
.pszText
= driver_type
;
234 insert
.u
.item
.cChildren
= 1;
235 root
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
237 /* change to the wait cursor because this can take a while if there is a
238 * misbehaving driver that takes a long time to open
240 old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
242 /* iterate over list of loaded drivers */
243 for (pAudioDrv
= loadedAudioDrv
, i
= 0; pAudioDrv
->nameID
; i
++, pAudioDrv
++) {
246 WCHAR text
[MAX_PATH
];
248 sprintf(name
, "wine%s.drv", pAudioDrv
->szDriver
);
249 LoadStringW (GetModuleHandle (NULL
), pAudioDrv
->nameID
, text
,
250 sizeof(text
)/sizeof(text
[0]));
252 if ((hdrv
= OpenDriverA(name
, 0, 0)))
255 if ((lib
= GetDriverModuleHandle(hdrv
)))
257 int num_wod
= 0, num_wid
= 0, num_mod
= 0, num_mid
= 0, num_aux
= 0, num_mxd
= 0;
258 MessagePtr wodMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "wodMessage");
259 MessagePtr widMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "widMessage");
260 MessagePtr modMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "modMessage");
261 MessagePtr midMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "midMessage");
262 MessagePtr auxMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "auxMessage");
263 MessagePtr mxdMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "mxdMessage");
266 num_wod
= wodMessagePtr(0, WODM_GETNUMDEVS
, 0, 0, 0);
269 num_wid
= widMessagePtr(0, WIDM_GETNUMDEVS
, 0, 0, 0);
272 num_mod
= modMessagePtr(0, MODM_GETNUMDEVS
, 0, 0, 0);
275 num_mid
= midMessagePtr(0, MIDM_GETNUMDEVS
, 0, 0, 0);
278 num_aux
= auxMessagePtr(0, AUXDM_GETNUMDEVS
, 0, 0, 0);
281 num_mxd
= mxdMessagePtr(0, MXDM_GETNUMDEVS
, 0, 0, 0);
283 if (num_wod
== 0 && num_wid
== 0 && num_mod
== 0 && num_mid
== 0 && num_aux
== 0 && num_mxd
== 0)
285 insert
.hParent
= root
;
286 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_STATE
| TVIF_PARAM
;
287 insert
.u
.item
.pszText
= text
;
288 insert
.u
.item
.stateMask
= TVIS_STATEIMAGEMASK
;
289 insert
.u
.item
.lParam
= i
+ DRIVER_MASK
;
290 if (isDriverSet(pAudioDrv
->szDriver
))
291 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(2);
293 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(1);
295 driver
[i
] = (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
301 insert
.hParent
= root
;
302 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
| TVIF_STATE
| TVIF_PARAM
;
303 insert
.u
.item
.pszText
= text
;
304 insert
.u
.item
.cChildren
= 1;
305 insert
.u
.item
.stateMask
= TVIS_STATEIMAGEMASK
;
306 insert
.u
.item
.lParam
= i
+ DRIVER_MASK
;
308 if (isDriverSet(pAudioDrv
->szDriver
))
309 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(2);
311 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(1);
313 driver
[i
] = (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
317 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_WAVEOUT
, dev_type
,
318 sizeof(dev_type
)/sizeof(dev_type
[0]));
320 insert
.hParent
= driver
[i
];
321 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
322 insert
.u
.item
.pszText
= dev_type
;
323 insert
.u
.item
.cChildren
= 1;
325 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
327 for (j
= 0; j
< num_wod
; j
++)
331 wodMessagePtr(j
, WODM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
333 insert
.hParent
= type
;
334 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
335 insert
.u
.item
.pszText
= caps
.szPname
;
336 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
338 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
344 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_WAVEIN
, dev_type
,
345 sizeof(dev_type
)/sizeof(dev_type
[0]));
347 insert
.hParent
= driver
[i
];
348 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
349 insert
.u
.item
.pszText
= dev_type
;
350 insert
.u
.item
.cChildren
= 1;
352 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
354 for (j
= 0; j
< num_wid
; j
++)
358 widMessagePtr(j
, WIDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
360 insert
.hParent
= type
;
361 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
362 insert
.u
.item
.pszText
= caps
.szPname
;
363 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
365 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
371 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIDIOUT
, dev_type
,
372 sizeof(dev_type
)/sizeof(dev_type
[0]));
374 insert
.hParent
= driver
[i
];
375 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
376 insert
.u
.item
.pszText
= dev_type
;
377 insert
.u
.item
.cChildren
= 1;
379 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
381 for (j
= 0; j
< num_mod
; j
++)
385 modMessagePtr(j
, MODM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
387 insert
.hParent
= type
;
388 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
389 insert
.u
.item
.pszText
= caps
.szPname
;
390 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
392 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
398 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIDIIN
, dev_type
,
399 sizeof(dev_type
)/sizeof(dev_type
[0]));
401 insert
.hParent
= driver
[i
];
402 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
403 insert
.u
.item
.pszText
= dev_type
;
404 insert
.u
.item
.cChildren
= 1;
406 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
408 for (j
= 0; j
< num_mid
; j
++)
412 midMessagePtr(j
, MIDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
414 insert
.hParent
= type
;
415 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
416 insert
.u
.item
.pszText
= caps
.szPname
;
417 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
419 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
425 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_AUX
, dev_type
,
426 sizeof(dev_type
)/sizeof(dev_type
[0]));
428 insert
.hParent
= driver
[i
];
429 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
430 insert
.u
.item
.pszText
= dev_type
;
431 insert
.u
.item
.cChildren
= 1;
433 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
435 for (j
= 0; j
< num_aux
; j
++)
439 auxMessagePtr(j
, AUXDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
441 insert
.hParent
= type
;
442 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
443 insert
.u
.item
.pszText
= caps
.szPname
;
444 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
446 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
452 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIXER
, dev_type
,
453 sizeof(dev_type
)/sizeof(dev_type
[0]));
455 insert
.hParent
= driver
[i
];
456 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
457 insert
.u
.item
.pszText
= dev_type
;
458 insert
.u
.item
.cChildren
= 1;
460 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
462 for (j
= 0; j
< num_mxd
; j
++)
466 mxdMessagePtr(j
, MXDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
468 insert
.hParent
= type
;
469 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
470 insert
.u
.item
.pszText
= caps
.szPname
;
471 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
473 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
478 CloseDriver(hdrv
, 0, 0);
482 /* restore the original cursor */
483 SetCursor(old_cursor
);
485 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_SELECTITEM
, 0, 0);
486 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)root
);
487 for (j
= 0; j
< i
; j
++)
488 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)driver
[j
]);
491 /* find all drivers that can be loaded */
492 static void findAudioDrivers(void)
495 const AUDIO_DRIVER
*pAudioDrv
= NULL
;
498 /* delete an existing list */
499 HeapFree(GetProcessHeap(), 0, loadedAudioDrv
);
502 /* change to the wait cursor because this can take a while if there is a
503 * misbehaving driver that takes a long time to open
505 old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
507 for (pAudioDrv
= sAudioDrivers
; pAudioDrv
->nameID
; pAudioDrv
++)
509 if (strlen(pAudioDrv
->szDriver
))
512 char driver
[MAX_PATH
];
514 sprintf(driver
, "wine%s.drv", pAudioDrv
->szDriver
);
516 if ((hdrv
= OpenDriverA(driver
, 0, 0)))
518 CloseDriver(hdrv
, 0, 0);
521 loadedAudioDrv
= HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv
, (numFound
+ 1) * sizeof(AUDIO_DRIVER
));
523 loadedAudioDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER
));
525 CopyMemory(&loadedAudioDrv
[numFound
], pAudioDrv
, sizeof(AUDIO_DRIVER
));
531 /* restore the original cursor */
532 SetCursor(old_cursor
);
534 /* terminate list with empty driver */
536 loadedAudioDrv
= HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv
, (numFound
+ 1) * sizeof(AUDIO_DRIVER
));
537 CopyMemory(&loadedAudioDrv
[numFound
], pAudioDrv
, sizeof(AUDIO_DRIVER
));
539 loadedAudioDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER
));
540 CopyMemory(&loadedAudioDrv
[0], pAudioDrv
, sizeof(AUDIO_DRIVER
));
544 /* check local copy of registry string for unloadable drivers */
545 static void checkRegistrySetting(HWND hDlg
)
547 const AUDIO_DRIVER
*pAudioDrv
;
548 char * token
, * tokens
;
550 tokens
= HeapAlloc(GetProcessHeap(), 0, strlen(curAudioDriver
)+1);
551 strcpy(tokens
, curAudioDriver
);
554 token
= strtok(tokens
, ",");
555 while (token
!= NULL
)
558 for (pAudioDrv
= loadedAudioDrv
; pAudioDrv
->nameID
; pAudioDrv
++)
560 if (strcmp(token
, pAudioDrv
->szDriver
) == 0)
568 WCHAR tokenW
[MAX_NAME_LENGTH
+1];
569 WCHAR messageStr
[256];
573 MultiByteToWideChar (CP_ACP
, 0, token
, -1, tokenW
, sizeof(tokenW
)/sizeof(tokenW
[0]));
575 LoadStringW (GetModuleHandle (NULL
), IDS_UNAVAILABLE_DRIVER
, messageStr
,
576 sizeof(messageStr
)/sizeof(messageStr
[0]));
577 wsprintfW (str
, messageStr
, tokenW
);
578 LoadStringW (GetModuleHandle (NULL
), IDS_WARNING
, caption
,
579 sizeof(caption
)/sizeof(caption
[0]));
580 if (MessageBoxW (hDlg
, str
, caption
, MB_ICONWARNING
| MB_YESNOCANCEL
) == IDYES
)
583 strcpy(tokens
, curAudioDriver
);
587 token
= strtok(NULL
, ",");
589 HeapFree(GetProcessHeap(), 0, tokens
);
592 static void selectDriver(HWND hDlg
, const char * driver
)
597 strcpy(curAudioDriver
, driver
);
598 set_reg_key(config_key
, "Drivers", "Audio", curAudioDriver
);
600 if (LoadStringW(GetModuleHandle(NULL
), IDS_AUDIO_MISSING
, text
, sizeof(text
)/sizeof(text
[0])))
602 if (LoadStringW(GetModuleHandle(NULL
), IDS_WINECFG_TITLE
, caption
, sizeof(caption
)/sizeof(caption
[0])))
603 MessageBoxW(hDlg
, text
, caption
, MB_OK
| MB_ICONINFORMATION
);
606 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
609 static void initAudioDlg (HWND hDlg
)
616 /* make a list of all drivers that can be loaded */
619 /* get current registry setting if available */
620 buf
= get_reg_key(config_key
, "Drivers", "Audio", NULL
);
622 /* check for first time install and set a default driver
623 * select first available driver, and if that fails: none
627 /* select first available driver */
628 if (*loadedAudioDrv
->szDriver
)
629 selectDriver(hDlg
, loadedAudioDrv
->szDriver
);
631 else /* make a local copy of the current registry setting */
632 strcpy(curAudioDriver
, buf
);
634 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver
);
636 /* check for drivers that can't be loaded */
637 checkRegistrySetting(hDlg
);
639 initAudioDeviceTree(hDlg
);
641 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_RESETCONTENT
, 0, 0);
642 buf
= get_reg_key(config_key
, keypath("DirectSound"), "HardwareAcceleration", "Full");
645 for (i
= 0; 0 != DSound_HW_Accels
[i
].displayID
; ++i
) {
649 match
= (strcmp(buf
, DSound_HW_Accels
[i
].settingStr
) == 0);
652 DSound_HW_Accels
[i
].visible
= 1;
656 if (DSound_HW_Accels
[i
].visible
)
658 LoadStringW (GetModuleHandle (NULL
), DSound_HW_Accels
[i
].displayID
,
659 accelStr
, sizeof(accelStr
)/sizeof(accelStr
[0]));
660 SendDlgItemMessageW (hDlg
, IDC_DSOUND_HW_ACCEL
, CB_ADDSTRING
, 0, (LPARAM
)accelStr
);
662 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_SETCURSEL
, j
, 0);
667 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf
);
669 HeapFree(GetProcessHeap(), 0, buf
);
671 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_RESETCONTENT
, 0, 0);
672 for (i
= 0; NULL
!= DSound_Rates
[i
]; ++i
) {
673 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_ADDSTRING
, 0, (LPARAM
) DSound_Rates
[i
]);
675 buf
= get_reg_key(config_key
, keypath("DirectSound"), "DefaultSampleRate", "44100");
676 for (i
= 0; NULL
!= DSound_Rates
[i
]; ++i
) {
677 if (strcmp(buf
, DSound_Rates
[i
]) == 0) {
678 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_SETCURSEL
, i
, 0);
683 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_RESETCONTENT
, 0, 0);
684 for (i
= 0; NULL
!= DSound_Bits
[i
]; ++i
) {
685 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_ADDSTRING
, 0, (LPARAM
) DSound_Bits
[i
]);
687 buf
= get_reg_key(config_key
, keypath("DirectSound"), "DefaultBitsPerSample", "16");
688 for (i
= 0; NULL
!= DSound_Bits
[i
]; ++i
) {
689 if (strcmp(buf
, DSound_Bits
[i
]) == 0) {
690 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_SETCURSEL
, i
, 0);
694 HeapFree(GetProcessHeap(), 0, buf
);
698 AudioDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
702 switch (LOWORD(wParam
)) {
703 case IDC_AUDIO_CONFIGURE
:
704 configureAudioDriver(hDlg
);
707 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND
), NULL
, SND_RESOURCE
| SND_SYNC
))
708 MessageBox(NULL
, "Audio test failed!", "Error", MB_OK
| MB_ICONERROR
);
710 case IDC_AUDIO_CONTROL_PANEL
:
711 MessageBox(NULL
, "Launching audio control panel not implemented yet!", "Fixme", MB_OK
| MB_ICONERROR
);
713 case IDC_DSOUND_HW_ACCEL
:
714 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
715 int selected_dsound_accel
;
718 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
719 selected_dsound_accel
= SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_GETCURSEL
, 0, 0);
720 for (i
= 0; DSound_HW_Accels
[i
].settingStr
; ++i
)
722 if (DSound_HW_Accels
[i
].visible
)
724 if (j
== selected_dsound_accel
)
726 set_reg_key(config_key
, keypath("DirectSound"), "HardwareAcceleration",
727 DSound_HW_Accels
[i
].settingStr
);
735 case IDC_DSOUND_RATES
:
736 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
737 int selected_dsound_rate
;
738 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
739 selected_dsound_rate
= SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_GETCURSEL
, 0, 0);
740 set_reg_key(config_key
, keypath("DirectSound"), "DefaultSampleRate", DSound_Rates
[selected_dsound_rate
]);
743 case IDC_DSOUND_BITS
:
744 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
745 int selected_dsound_bits
;
746 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
747 selected_dsound_bits
= SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_GETCURSEL
, 0, 0);
748 set_reg_key(config_key
, keypath("DirectSound"), "DefaultBitsPerSample", DSound_Bits
[selected_dsound_bits
]);
755 set_window_title(hDlg
);
759 switch(((LPNMHDR
)lParam
)->code
) {
761 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
764 set_reg_key(config_key
, "Drivers", "Audio", curAudioDriver
);
766 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
771 if (((LPNMHDR
)lParam
)->idFrom
== IDC_AUDIO_TREE
)
774 DWORD dwPos
= GetMessagePos();
775 HWND tree
= ((LPNMHDR
)lParam
)->hwndFrom
;
776 ZeroMemory(&ht
, sizeof(ht
));
777 ht
.pt
.x
= (short)LOWORD(dwPos
);
778 ht
.pt
.y
= (short)HIWORD(dwPos
);
779 MapWindowPoints(HWND_DESKTOP
, tree
, &ht
.pt
, 1);
780 SendMessageW( tree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
781 if (TVHT_ONITEMSTATEICON
& ht
.flags
)
785 ZeroMemory(&tvItem
, sizeof(tvItem
));
786 tvItem
.hItem
= ht
.hItem
;
787 SendMessageW( tree
, TVM_GETITEMW
, 0, (LPARAM
) &tvItem
);
789 index
= TreeView_GetItemState(tree
, ht
.hItem
, TVIS_STATEIMAGEMASK
);
790 if (index
== INDEXTOSTATEIMAGEMASK(1))
792 TreeView_SetItemState(tree
, ht
.hItem
, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK
);
793 addDriver(loadedAudioDrv
[tvItem
.lParam
& 0xff].szDriver
);
794 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
796 else if (index
== INDEXTOSTATEIMAGEMASK(2))
798 TreeView_SetItemState(tree
, ht
.hItem
, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK
);
799 removeDriver(loadedAudioDrv
[tvItem
.lParam
& 0xff].szDriver
);
800 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
806 if (((LPNMHDR
)lParam
)->idFrom
== IDC_AUDIO_TREE
)
809 DWORD dwPos
= GetMessagePos();
810 HWND tree
= ((LPNMHDR
)lParam
)->hwndFrom
;
812 ZeroMemory(&ht
, sizeof(ht
));
813 pt
.x
= (short)LOWORD(dwPos
);
814 pt
.y
= (short)HIWORD(dwPos
);
816 MapWindowPoints(HWND_DESKTOP
, tree
, &ht
.pt
, 1);
817 SendMessageW( tree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
818 if (TVHT_ONITEMLABEL
& ht
.flags
)
821 ZeroMemory(&tvItem
, sizeof(tvItem
));
822 tvItem
.hItem
= ht
.hItem
;
823 tvItem
.mask
= TVIF_PARAM
;
825 if (TreeView_GetItem(tree
, &tvItem
))
827 if (tvItem
.lParam
& DRIVER_MASK
)
831 TrackPopupMenu(GetSubMenu(hPopupMenus
, 0), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, tree
, NULL
);
832 toConfigure
= tvItem
.lParam
& ~DRIVER_MASK
;
835 else if (tvItem
.lParam
& DEVICE_MASK
)