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_PTR
, DWORD_PTR
, DWORD_PTR
);
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
[] = {
92 static AUDIO_DRIVER sAudioDrivers
[] = {
93 {IDS_DRIVER_PULSE
, "pulse"},
94 {IDS_DRIVER_ALSA
, "alsa"},
95 {IDS_DRIVER_OSS
, "oss"},
96 {IDS_DRIVER_COREAUDIO
, "coreaudio"},
97 {IDS_DRIVER_JACK
, "jack"},
98 {IDS_DRIVER_NAS
, "nas"},
99 {IDS_DRIVER_ESOUND
, "esd"},
100 {IDS_DRIVER_AUDIOIO
, "audioio"},
104 /* list of available drivers */
105 static AUDIO_DRIVER
* loadedAudioDrv
;
107 /* local copy of registry setting */
108 static char curAudioDriver
[1024];
110 /* driver index to configure */
111 static int toConfigure
;
113 /* display a driver specific configuration dialog */
114 static void configureAudioDriver(HWND hDlg
)
116 const AUDIO_DRIVER
*pAudioDrv
= &loadedAudioDrv
[toConfigure
];
118 if (strlen(pAudioDrv
->szDriver
) != 0)
121 char wine_driver
[MAX_NAME_LENGTH
+ 9];
122 sprintf(wine_driver
, "wine%s.drv", pAudioDrv
->szDriver
);
123 hdrvr
= pAudioDrv
->hDriver
;
126 if (SendDriverMessage(hdrvr
, DRV_QUERYCONFIGURE
, 0, 0) != 0)
129 dci
.dwDCISize
= sizeof (dci
);
130 dci
.lpszDCISectionName
= NULL
;
131 dci
.lpszDCIAliasName
= NULL
;
132 SendDriverMessage(hdrvr
, DRV_CONFIGURE
, 0, (LONG_PTR
)&dci
);
137 WCHAR wine_driverW
[MAX_NAME_LENGTH
+9];
138 WCHAR messageStr
[256];
141 MultiByteToWideChar (CP_ACP
, 0, wine_driver
, -1, wine_driverW
,
142 sizeof (wine_driverW
)/sizeof(wine_driverW
[0]));
144 LoadStringW (GetModuleHandle (NULL
), IDS_OPEN_DRIVER_ERROR
, messageStr
,
145 sizeof(messageStr
)/sizeof(messageStr
[0]));
146 wsprintfW (str
, messageStr
, wine_driverW
);
147 MessageBoxW (hDlg
, str
, NULL
, MB_OK
| MB_ICONERROR
);
152 /* is driver in local copy of driver registry string */
153 static BOOL
isDriverSet(const char * driver
)
155 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver
, curAudioDriver
);
157 if (strstr(curAudioDriver
, driver
))
163 /* add driver to local copy of driver registry string */
164 static void addDriver(const char * driver
)
166 if (!isDriverSet(driver
))
168 if (strlen(curAudioDriver
))
169 strcat(curAudioDriver
, ",");
170 strcat(curAudioDriver
, driver
);
174 /* remove driver from local copy of driver registry string */
175 static void removeDriver(const char * driver
)
177 char pattern
[32], *p
;
180 strcpy(pattern
, ",");
181 strcat(pattern
, driver
);
182 strcat(pattern
, ",");
183 drvlen
= strlen(driver
);
184 listlen
= strlen(curAudioDriver
);
186 p
= strstr(curAudioDriver
, pattern
);
187 if (p
) /* somewhere in the middle */
188 memmove(p
, p
+drvlen
+1, strlen(p
+drvlen
+1)+1);
189 else if (!strncmp(curAudioDriver
, pattern
+1, drvlen
+1)) /* the head */
190 memmove(curAudioDriver
, curAudioDriver
+drvlen
+1, listlen
-drvlen
);
191 else if (!strncmp(curAudioDriver
+listlen
-drvlen
-1, pattern
, drvlen
+1)) /* the tail */
192 curAudioDriver
[listlen
-drvlen
-1] = 0;
193 else if (!strcmp(curAudioDriver
, driver
)) /* only one entry (head&tail) */
194 curAudioDriver
[0] = 0;
196 WINE_FIXME("driver '%s' is not in the list, please report!\n", driver
);
199 static void initAudioDeviceTree(HWND hDlg
)
201 AUDIO_DRIVER
*pAudioDrv
= NULL
;
203 TVINSERTSTRUCTW insert
;
204 HTREEITEM root
, driver
[10];
206 HIMAGELIST hImageList
;
209 WCHAR driver_type
[64], dev_type
[64];
211 tree
= GetDlgItem(hDlg
, IDC_AUDIO_TREE
);
216 /* set tree view style */
217 SetWindowLong(tree
, GWL_STYLE
, GetWindowLong(tree
, GWL_STYLE
) | TVS_HASBUTTONS
| TVS_HASLINES
| TVS_LINESATROOT
);
220 hImageList
= ImageList_Create(16, 16, FALSE
, 3, 0);
221 hBitMap
= LoadBitmap(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_CHECKBOX
));
222 ImageList_Add(hImageList
, hBitMap
, NULL
);
223 DeleteObject(hBitMap
);
224 SendMessageW( tree
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)hImageList
);
227 LoadStringW (GetModuleHandle (NULL
), IDS_SOUNDDRIVERS
, driver_type
,
228 sizeof(driver_type
)/sizeof(driver_type
[0]));
229 insert
.hParent
= TVI_ROOT
;
230 insert
.hInsertAfter
= TVI_LAST
;
231 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
232 insert
.u
.item
.pszText
= driver_type
;
233 insert
.u
.item
.cChildren
= 1;
234 root
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
236 /* change to the wait cursor because this can take a while if there is a
237 * misbehaving driver that takes a long time to open
239 old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
241 /* iterate over list of loaded drivers */
242 for (pAudioDrv
= loadedAudioDrv
, i
= 0; pAudioDrv
->nameID
; i
++, pAudioDrv
++) {
245 WCHAR text
[MAX_PATH
];
247 sprintf(name
, "wine%s.drv", pAudioDrv
->szDriver
);
248 LoadStringW (GetModuleHandle (NULL
), pAudioDrv
->nameID
, text
,
249 sizeof(text
)/sizeof(text
[0]));
251 if ((hdrv
= pAudioDrv
->hDriver
))
254 if ((lib
= GetDriverModuleHandle(hdrv
)))
256 int num_wod
= 0, num_wid
= 0, num_mod
= 0, num_mid
= 0, num_aux
= 0, num_mxd
= 0;
257 MessagePtr wodMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "wodMessage");
258 MessagePtr widMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "widMessage");
259 MessagePtr modMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "modMessage");
260 MessagePtr midMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "midMessage");
261 MessagePtr auxMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "auxMessage");
262 MessagePtr mxdMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "mxdMessage");
265 num_wod
= wodMessagePtr(0, WODM_GETNUMDEVS
, 0, 0, 0);
268 num_wid
= widMessagePtr(0, WIDM_GETNUMDEVS
, 0, 0, 0);
271 num_mod
= modMessagePtr(0, MODM_GETNUMDEVS
, 0, 0, 0);
274 num_mid
= midMessagePtr(0, MIDM_GETNUMDEVS
, 0, 0, 0);
277 num_aux
= auxMessagePtr(0, AUXDM_GETNUMDEVS
, 0, 0, 0);
280 num_mxd
= mxdMessagePtr(0, MXDM_GETNUMDEVS
, 0, 0, 0);
282 if (num_wod
== 0 && num_wid
== 0 && num_mod
== 0 && num_mid
== 0 && num_aux
== 0 && num_mxd
== 0)
284 insert
.hParent
= root
;
285 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_STATE
| TVIF_PARAM
;
286 insert
.u
.item
.pszText
= text
;
287 insert
.u
.item
.stateMask
= TVIS_STATEIMAGEMASK
;
288 insert
.u
.item
.lParam
= i
+ DRIVER_MASK
;
289 if (isDriverSet(pAudioDrv
->szDriver
))
290 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(2);
292 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(1);
294 driver
[i
] = (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
300 insert
.hParent
= root
;
301 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
| TVIF_STATE
| TVIF_PARAM
;
302 insert
.u
.item
.pszText
= text
;
303 insert
.u
.item
.cChildren
= 1;
304 insert
.u
.item
.stateMask
= TVIS_STATEIMAGEMASK
;
305 insert
.u
.item
.lParam
= i
+ DRIVER_MASK
;
307 if (isDriverSet(pAudioDrv
->szDriver
))
308 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(2);
310 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(1);
312 driver
[i
] = (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
316 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_WAVEOUT
, dev_type
,
317 sizeof(dev_type
)/sizeof(dev_type
[0]));
319 insert
.hParent
= driver
[i
];
320 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
321 insert
.u
.item
.pszText
= dev_type
;
322 insert
.u
.item
.cChildren
= 1;
324 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
326 for (j
= 0; j
< num_wod
; j
++)
330 wodMessagePtr(j
, WODM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
332 insert
.hParent
= type
;
333 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
334 insert
.u
.item
.pszText
= caps
.szPname
;
335 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
337 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
343 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_WAVEIN
, dev_type
,
344 sizeof(dev_type
)/sizeof(dev_type
[0]));
346 insert
.hParent
= driver
[i
];
347 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
348 insert
.u
.item
.pszText
= dev_type
;
349 insert
.u
.item
.cChildren
= 1;
351 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
353 for (j
= 0; j
< num_wid
; j
++)
357 widMessagePtr(j
, WIDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
359 insert
.hParent
= type
;
360 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
361 insert
.u
.item
.pszText
= caps
.szPname
;
362 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
364 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
370 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIDIOUT
, dev_type
,
371 sizeof(dev_type
)/sizeof(dev_type
[0]));
373 insert
.hParent
= driver
[i
];
374 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
375 insert
.u
.item
.pszText
= dev_type
;
376 insert
.u
.item
.cChildren
= 1;
378 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
380 for (j
= 0; j
< num_mod
; j
++)
384 modMessagePtr(j
, MODM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
386 insert
.hParent
= type
;
387 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
388 insert
.u
.item
.pszText
= caps
.szPname
;
389 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
391 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
397 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIDIIN
, dev_type
,
398 sizeof(dev_type
)/sizeof(dev_type
[0]));
400 insert
.hParent
= driver
[i
];
401 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
402 insert
.u
.item
.pszText
= dev_type
;
403 insert
.u
.item
.cChildren
= 1;
405 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
407 for (j
= 0; j
< num_mid
; j
++)
411 midMessagePtr(j
, MIDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
413 insert
.hParent
= type
;
414 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
415 insert
.u
.item
.pszText
= caps
.szPname
;
416 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
418 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
424 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_AUX
, dev_type
,
425 sizeof(dev_type
)/sizeof(dev_type
[0]));
427 insert
.hParent
= driver
[i
];
428 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
429 insert
.u
.item
.pszText
= dev_type
;
430 insert
.u
.item
.cChildren
= 1;
432 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
434 for (j
= 0; j
< num_aux
; j
++)
438 auxMessagePtr(j
, AUXDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
440 insert
.hParent
= type
;
441 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
442 insert
.u
.item
.pszText
= caps
.szPname
;
443 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
445 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
451 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIXER
, dev_type
,
452 sizeof(dev_type
)/sizeof(dev_type
[0]));
454 insert
.hParent
= driver
[i
];
455 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
456 insert
.u
.item
.pszText
= dev_type
;
457 insert
.u
.item
.cChildren
= 1;
459 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
461 for (j
= 0; j
< num_mxd
; j
++)
465 mxdMessagePtr(j
, MXDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
467 insert
.hParent
= type
;
468 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
469 insert
.u
.item
.pszText
= caps
.szPname
;
470 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
472 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
480 /* restore the original cursor */
481 SetCursor(old_cursor
);
483 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_SELECTITEM
, 0, 0);
484 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)root
);
485 for (j
= 0; j
< i
; j
++)
486 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)driver
[j
]);
489 /* find all drivers that can be loaded */
490 static void findAudioDrivers(void)
493 AUDIO_DRIVER
*pAudioDrv
= NULL
;
496 /* delete an existing list */
497 HeapFree(GetProcessHeap(), 0, loadedAudioDrv
);
500 /* change to the wait cursor because this can take a while if there is a
501 * misbehaving driver that takes a long time to open
503 old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
505 for (pAudioDrv
= sAudioDrivers
; pAudioDrv
->nameID
; pAudioDrv
++)
507 if (strlen(pAudioDrv
->szDriver
))
510 char driver
[MAX_PATH
];
512 sprintf(driver
, "wine%s.drv", pAudioDrv
->szDriver
);
514 hdrv
= pAudioDrv
->hDriver
;
515 if (!pAudioDrv
->hDriver
&& (hdrv
= OpenDriverA(driver
, 0, 0))) {
516 HMODULE lib
= GetDriverModuleHandle(hdrv
);
517 MessagePtr wodMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "wodMessage");
518 MessagePtr widMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "widMessage");
519 MessagePtr modMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "modMessage");
520 MessagePtr midMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "midMessage");
521 MessagePtr auxMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "auxMessage");
522 MessagePtr mxdMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "mxdMessage");
524 pAudioDrv
->hDriver
= hdrv
;
527 wodMessagePtr(0, DRVM_INIT
, 0, 0, 0);
530 widMessagePtr(0, DRVM_INIT
, 0, 0, 0);
533 modMessagePtr(0, DRVM_INIT
, 0, 0, 0);
536 midMessagePtr(0, DRVM_INIT
, 0, 0, 0);
539 auxMessagePtr(0, DRVM_INIT
, 0, 0, 0);
542 mxdMessagePtr(0, DRVM_INIT
, 0, 0, 0);
547 loadedAudioDrv
= HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv
, (numFound
+ 1) * sizeof(AUDIO_DRIVER
));
549 loadedAudioDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER
));
551 CopyMemory(&loadedAudioDrv
[numFound
], pAudioDrv
, sizeof(AUDIO_DRIVER
));
557 /* restore the original cursor */
558 SetCursor(old_cursor
);
560 /* terminate list with empty driver */
562 loadedAudioDrv
= HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv
, (numFound
+ 1) * sizeof(AUDIO_DRIVER
));
563 CopyMemory(&loadedAudioDrv
[numFound
], pAudioDrv
, sizeof(AUDIO_DRIVER
));
565 loadedAudioDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER
));
566 CopyMemory(&loadedAudioDrv
[0], pAudioDrv
, sizeof(AUDIO_DRIVER
));
570 /* check local copy of registry string for unloadable drivers */
571 static void checkRegistrySetting(HWND hDlg
)
573 const AUDIO_DRIVER
*pAudioDrv
;
574 char * token
, * tokens
;
576 tokens
= HeapAlloc(GetProcessHeap(), 0, strlen(curAudioDriver
)+1);
577 strcpy(tokens
, curAudioDriver
);
580 token
= strtok(tokens
, ",");
581 while (token
!= NULL
)
584 for (pAudioDrv
= loadedAudioDrv
; pAudioDrv
->nameID
; pAudioDrv
++)
586 if (strcmp(token
, pAudioDrv
->szDriver
) == 0)
594 WCHAR tokenW
[MAX_NAME_LENGTH
+1];
595 WCHAR messageStr
[256];
599 MultiByteToWideChar (CP_ACP
, 0, token
, -1, tokenW
, sizeof(tokenW
)/sizeof(tokenW
[0]));
601 LoadStringW (GetModuleHandle (NULL
), IDS_UNAVAILABLE_DRIVER
, messageStr
,
602 sizeof(messageStr
)/sizeof(messageStr
[0]));
603 wsprintfW (str
, messageStr
, tokenW
);
604 LoadStringW (GetModuleHandle (NULL
), IDS_WARNING
, caption
,
605 sizeof(caption
)/sizeof(caption
[0]));
606 if (MessageBoxW (hDlg
, str
, caption
, MB_ICONWARNING
| MB_YESNOCANCEL
) == IDYES
)
609 strcpy(tokens
, curAudioDriver
);
613 token
= strtok(NULL
, ",");
615 HeapFree(GetProcessHeap(), 0, tokens
);
618 static void selectDriver(HWND hDlg
, const char * driver
)
623 strcpy(curAudioDriver
, driver
);
624 set_reg_key(config_key
, "Drivers", "Audio", curAudioDriver
);
626 if (LoadStringW(GetModuleHandle(NULL
), IDS_AUDIO_MISSING
, text
, sizeof(text
)/sizeof(text
[0])))
628 if (LoadStringW(GetModuleHandle(NULL
), IDS_WINECFG_TITLE
, caption
, sizeof(caption
)/sizeof(caption
[0])))
629 MessageBoxW(hDlg
, text
, caption
, MB_OK
| MB_ICONINFORMATION
);
632 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
635 static void initAudioDlg (HWND hDlg
)
642 /* make a list of all drivers that can be loaded */
645 /* get current registry setting if available */
646 buf
= get_reg_key(config_key
, "Drivers", "Audio", NULL
);
648 /* check for first time install and set a default driver
649 * select first available driver, and if that fails: none
653 /* select first available driver */
654 if (*loadedAudioDrv
->szDriver
)
655 selectDriver(hDlg
, loadedAudioDrv
->szDriver
);
657 else /* make a local copy of the current registry setting */
658 strcpy(curAudioDriver
, buf
);
660 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver
);
662 /* check for drivers that can't be loaded */
663 checkRegistrySetting(hDlg
);
665 initAudioDeviceTree(hDlg
);
667 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_RESETCONTENT
, 0, 0);
668 buf
= get_reg_key(config_key
, keypath("DirectSound"), "HardwareAcceleration", "Full");
671 for (i
= 0; 0 != DSound_HW_Accels
[i
].displayID
; ++i
) {
675 match
= (strcmp(buf
, DSound_HW_Accels
[i
].settingStr
) == 0);
678 DSound_HW_Accels
[i
].visible
= 1;
682 if (DSound_HW_Accels
[i
].visible
)
684 LoadStringW (GetModuleHandle (NULL
), DSound_HW_Accels
[i
].displayID
,
685 accelStr
, sizeof(accelStr
)/sizeof(accelStr
[0]));
686 SendDlgItemMessageW (hDlg
, IDC_DSOUND_HW_ACCEL
, CB_ADDSTRING
, 0, (LPARAM
)accelStr
);
688 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_SETCURSEL
, j
, 0);
693 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf
);
695 HeapFree(GetProcessHeap(), 0, buf
);
697 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_RESETCONTENT
, 0, 0);
698 for (i
= 0; NULL
!= DSound_Rates
[i
]; ++i
) {
699 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_ADDSTRING
, 0, (LPARAM
) DSound_Rates
[i
]);
701 buf
= get_reg_key(config_key
, keypath("DirectSound"), "DefaultSampleRate", "44100");
702 for (i
= 0; NULL
!= DSound_Rates
[i
]; ++i
) {
703 if (strcmp(buf
, DSound_Rates
[i
]) == 0) {
704 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_SETCURSEL
, i
, 0);
709 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_RESETCONTENT
, 0, 0);
710 for (i
= 0; NULL
!= DSound_Bits
[i
]; ++i
) {
711 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_ADDSTRING
, 0, (LPARAM
) DSound_Bits
[i
]);
713 buf
= get_reg_key(config_key
, keypath("DirectSound"), "DefaultBitsPerSample", "16");
714 for (i
= 0; NULL
!= DSound_Bits
[i
]; ++i
) {
715 if (strcmp(buf
, DSound_Bits
[i
]) == 0) {
716 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_SETCURSEL
, i
, 0);
720 HeapFree(GetProcessHeap(), 0, buf
);
724 AudioDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
728 switch (LOWORD(wParam
)) {
729 case IDC_AUDIO_CONFIGURE
:
730 configureAudioDriver(hDlg
);
733 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND
), NULL
, SND_RESOURCE
| SND_SYNC
))
734 MessageBox(NULL
, "Audio test failed!", "Error", MB_OK
| MB_ICONERROR
);
736 case IDC_AUDIO_CONTROL_PANEL
:
737 MessageBox(NULL
, "Launching audio control panel not implemented yet!", "Fixme", MB_OK
| MB_ICONERROR
);
739 case IDC_DSOUND_HW_ACCEL
:
740 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
741 int selected_dsound_accel
;
744 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
745 selected_dsound_accel
= SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_GETCURSEL
, 0, 0);
746 for (i
= 0; DSound_HW_Accels
[i
].settingStr
; ++i
)
748 if (DSound_HW_Accels
[i
].visible
)
750 if (j
== selected_dsound_accel
)
752 set_reg_key(config_key
, keypath("DirectSound"), "HardwareAcceleration",
753 DSound_HW_Accels
[i
].settingStr
);
761 case IDC_DSOUND_RATES
:
762 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
763 int selected_dsound_rate
;
764 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
765 selected_dsound_rate
= SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_GETCURSEL
, 0, 0);
766 set_reg_key(config_key
, keypath("DirectSound"), "DefaultSampleRate", DSound_Rates
[selected_dsound_rate
]);
769 case IDC_DSOUND_BITS
:
770 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
771 int selected_dsound_bits
;
772 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
773 selected_dsound_bits
= SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_GETCURSEL
, 0, 0);
774 set_reg_key(config_key
, keypath("DirectSound"), "DefaultBitsPerSample", DSound_Bits
[selected_dsound_bits
]);
781 set_window_title(hDlg
);
785 switch(((LPNMHDR
)lParam
)->code
) {
787 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
790 set_reg_key(config_key
, "Drivers", "Audio", curAudioDriver
);
792 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
797 if (((LPNMHDR
)lParam
)->idFrom
== IDC_AUDIO_TREE
)
800 DWORD dwPos
= GetMessagePos();
801 HWND tree
= ((LPNMHDR
)lParam
)->hwndFrom
;
802 ZeroMemory(&ht
, sizeof(ht
));
803 ht
.pt
.x
= (short)LOWORD(dwPos
);
804 ht
.pt
.y
= (short)HIWORD(dwPos
);
805 MapWindowPoints(HWND_DESKTOP
, tree
, &ht
.pt
, 1);
806 SendMessageW( tree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
807 if (TVHT_ONITEMSTATEICON
& ht
.flags
)
811 ZeroMemory(&tvItem
, sizeof(tvItem
));
812 tvItem
.hItem
= ht
.hItem
;
813 SendMessageW( tree
, TVM_GETITEMW
, 0, (LPARAM
) &tvItem
);
815 index
= TreeView_GetItemState(tree
, ht
.hItem
, TVIS_STATEIMAGEMASK
);
816 if (index
== INDEXTOSTATEIMAGEMASK(1))
818 TreeView_SetItemState(tree
, ht
.hItem
, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK
);
819 addDriver(loadedAudioDrv
[tvItem
.lParam
& 0xff].szDriver
);
820 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
822 else if (index
== INDEXTOSTATEIMAGEMASK(2))
824 TreeView_SetItemState(tree
, ht
.hItem
, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK
);
825 removeDriver(loadedAudioDrv
[tvItem
.lParam
& 0xff].szDriver
);
826 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
832 if (((LPNMHDR
)lParam
)->idFrom
== IDC_AUDIO_TREE
)
835 DWORD dwPos
= GetMessagePos();
836 HWND tree
= ((LPNMHDR
)lParam
)->hwndFrom
;
838 ZeroMemory(&ht
, sizeof(ht
));
839 pt
.x
= (short)LOWORD(dwPos
);
840 pt
.y
= (short)HIWORD(dwPos
);
842 MapWindowPoints(HWND_DESKTOP
, tree
, &ht
.pt
, 1);
843 SendMessageW( tree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
844 if (TVHT_ONITEMLABEL
& ht
.flags
)
847 ZeroMemory(&tvItem
, sizeof(tvItem
));
848 tvItem
.hItem
= ht
.hItem
;
849 tvItem
.mask
= TVIF_PARAM
;
851 if (TreeView_GetItem(tree
, &tvItem
))
853 if (tvItem
.lParam
& DRIVER_MASK
)
857 TrackPopupMenu(GetSubMenu(hPopupMenus
, 0), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, tree
, NULL
);
858 toConfigure
= tvItem
.lParam
& ~DRIVER_MASK
;
861 else if (tvItem
.lParam
& DEVICE_MASK
)