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_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
= pAudioDrv
->hDriver
;
125 if (SendDriverMessage(hdrvr
, DRV_QUERYCONFIGURE
, 0, 0) != 0)
128 dci
.dwDCISize
= sizeof (dci
);
129 dci
.lpszDCISectionName
= NULL
;
130 dci
.lpszDCIAliasName
= NULL
;
131 SendDriverMessage(hdrvr
, DRV_CONFIGURE
, 0, (LONG_PTR
)&dci
);
136 WCHAR wine_driverW
[MAX_NAME_LENGTH
+9];
137 WCHAR messageStr
[256];
140 MultiByteToWideChar (CP_ACP
, 0, wine_driver
, -1, wine_driverW
,
141 sizeof (wine_driverW
)/sizeof(wine_driverW
[0]));
143 LoadStringW (GetModuleHandle (NULL
), IDS_OPEN_DRIVER_ERROR
, messageStr
,
144 sizeof(messageStr
)/sizeof(messageStr
[0]));
145 wsprintfW (str
, messageStr
, wine_driverW
);
146 MessageBoxW (hDlg
, str
, NULL
, MB_OK
| MB_ICONERROR
);
151 /* is driver in local copy of driver registry string */
152 static BOOL
isDriverSet(const char * driver
)
154 WINE_TRACE("driver = %s, curAudioDriver = %s\n", driver
, curAudioDriver
);
156 if (strstr(curAudioDriver
, driver
))
162 /* add driver to local copy of driver registry string */
163 static void addDriver(const char * driver
)
165 if (!isDriverSet(driver
))
167 if (strlen(curAudioDriver
))
168 strcat(curAudioDriver
, ",");
169 strcat(curAudioDriver
, driver
);
173 /* remove driver from local copy of driver registry string */
174 static void removeDriver(const char * driver
)
176 char pattern
[32], *p
;
179 strcpy(pattern
, ",");
180 strcat(pattern
, driver
);
181 strcat(pattern
, ",");
182 drvlen
= strlen(driver
);
183 listlen
= strlen(curAudioDriver
);
185 p
= strstr(curAudioDriver
, pattern
);
186 if (p
) /* somewhere in the middle */
187 memmove(p
, p
+drvlen
+1, strlen(p
+drvlen
+1)+1);
188 else if (!strncmp(curAudioDriver
, pattern
+1, drvlen
+1)) /* the head */
189 memmove(curAudioDriver
, curAudioDriver
+drvlen
+1, listlen
-drvlen
);
190 else if (!strncmp(curAudioDriver
+listlen
-drvlen
-1, pattern
, drvlen
+1)) /* the tail */
191 curAudioDriver
[listlen
-drvlen
-1] = 0;
192 else if (!strcmp(curAudioDriver
, driver
)) /* only one entry (head&tail) */
193 curAudioDriver
[0] = 0;
195 WINE_FIXME("driver '%s' is not in the list, please report!\n", driver
);
198 static void initAudioDeviceTree(HWND hDlg
)
200 AUDIO_DRIVER
*pAudioDrv
= NULL
;
202 TVINSERTSTRUCTW insert
;
203 HTREEITEM root
, driver
[10];
205 HIMAGELIST hImageList
;
208 WCHAR driver_type
[64], dev_type
[64];
210 tree
= GetDlgItem(hDlg
, IDC_AUDIO_TREE
);
215 /* set tree view style */
216 SetWindowLong(tree
, GWL_STYLE
, GetWindowLong(tree
, GWL_STYLE
) | TVS_HASBUTTONS
| TVS_HASLINES
| TVS_LINESATROOT
);
219 hImageList
= ImageList_Create(16, 16, FALSE
, 3, 0);
220 hBitMap
= LoadBitmap(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_CHECKBOX
));
221 ImageList_Add(hImageList
, hBitMap
, NULL
);
222 DeleteObject(hBitMap
);
223 SendMessageW( tree
, TVM_SETIMAGELIST
, TVSIL_STATE
, (LPARAM
)hImageList
);
226 LoadStringW (GetModuleHandle (NULL
), IDS_SOUNDDRIVERS
, driver_type
,
227 sizeof(driver_type
)/sizeof(driver_type
[0]));
228 insert
.hParent
= TVI_ROOT
;
229 insert
.hInsertAfter
= TVI_LAST
;
230 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
231 insert
.u
.item
.pszText
= driver_type
;
232 insert
.u
.item
.cChildren
= 1;
233 root
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
235 /* change to the wait cursor because this can take a while if there is a
236 * misbehaving driver that takes a long time to open
238 old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
240 /* iterate over list of loaded drivers */
241 for (pAudioDrv
= loadedAudioDrv
, i
= 0; pAudioDrv
->nameID
; i
++, pAudioDrv
++) {
244 WCHAR text
[MAX_PATH
];
246 sprintf(name
, "wine%s.drv", pAudioDrv
->szDriver
);
247 LoadStringW (GetModuleHandle (NULL
), pAudioDrv
->nameID
, text
,
248 sizeof(text
)/sizeof(text
[0]));
250 if ((hdrv
= pAudioDrv
->hDriver
))
253 if ((lib
= GetDriverModuleHandle(hdrv
)))
255 int num_wod
= 0, num_wid
= 0, num_mod
= 0, num_mid
= 0, num_aux
= 0, num_mxd
= 0;
256 MessagePtr wodMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "wodMessage");
257 MessagePtr widMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "widMessage");
258 MessagePtr modMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "modMessage");
259 MessagePtr midMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "midMessage");
260 MessagePtr auxMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "auxMessage");
261 MessagePtr mxdMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "mxdMessage");
264 num_wod
= wodMessagePtr(0, WODM_GETNUMDEVS
, 0, 0, 0);
267 num_wid
= widMessagePtr(0, WIDM_GETNUMDEVS
, 0, 0, 0);
270 num_mod
= modMessagePtr(0, MODM_GETNUMDEVS
, 0, 0, 0);
273 num_mid
= midMessagePtr(0, MIDM_GETNUMDEVS
, 0, 0, 0);
276 num_aux
= auxMessagePtr(0, AUXDM_GETNUMDEVS
, 0, 0, 0);
279 num_mxd
= mxdMessagePtr(0, MXDM_GETNUMDEVS
, 0, 0, 0);
281 if (num_wod
== 0 && num_wid
== 0 && num_mod
== 0 && num_mid
== 0 && num_aux
== 0 && num_mxd
== 0)
283 insert
.hParent
= root
;
284 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_STATE
| TVIF_PARAM
;
285 insert
.u
.item
.pszText
= text
;
286 insert
.u
.item
.stateMask
= TVIS_STATEIMAGEMASK
;
287 insert
.u
.item
.lParam
= i
+ DRIVER_MASK
;
288 if (isDriverSet(pAudioDrv
->szDriver
))
289 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(2);
291 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(1);
293 driver
[i
] = (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
299 insert
.hParent
= root
;
300 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
| TVIF_STATE
| TVIF_PARAM
;
301 insert
.u
.item
.pszText
= text
;
302 insert
.u
.item
.cChildren
= 1;
303 insert
.u
.item
.stateMask
= TVIS_STATEIMAGEMASK
;
304 insert
.u
.item
.lParam
= i
+ DRIVER_MASK
;
306 if (isDriverSet(pAudioDrv
->szDriver
))
307 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(2);
309 insert
.u
.item
.state
= INDEXTOSTATEIMAGEMASK(1);
311 driver
[i
] = (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
315 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_WAVEOUT
, dev_type
,
316 sizeof(dev_type
)/sizeof(dev_type
[0]));
318 insert
.hParent
= driver
[i
];
319 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
320 insert
.u
.item
.pszText
= dev_type
;
321 insert
.u
.item
.cChildren
= 1;
323 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
325 for (j
= 0; j
< num_wod
; j
++)
329 wodMessagePtr(j
, WODM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
331 insert
.hParent
= type
;
332 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
333 insert
.u
.item
.pszText
= caps
.szPname
;
334 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
336 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
342 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_WAVEIN
, dev_type
,
343 sizeof(dev_type
)/sizeof(dev_type
[0]));
345 insert
.hParent
= driver
[i
];
346 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
347 insert
.u
.item
.pszText
= dev_type
;
348 insert
.u
.item
.cChildren
= 1;
350 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
352 for (j
= 0; j
< num_wid
; j
++)
356 widMessagePtr(j
, WIDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
358 insert
.hParent
= type
;
359 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
360 insert
.u
.item
.pszText
= caps
.szPname
;
361 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
363 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
369 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIDIOUT
, dev_type
,
370 sizeof(dev_type
)/sizeof(dev_type
[0]));
372 insert
.hParent
= driver
[i
];
373 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
374 insert
.u
.item
.pszText
= dev_type
;
375 insert
.u
.item
.cChildren
= 1;
377 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
379 for (j
= 0; j
< num_mod
; j
++)
383 modMessagePtr(j
, MODM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
385 insert
.hParent
= type
;
386 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
387 insert
.u
.item
.pszText
= caps
.szPname
;
388 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
390 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
396 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIDIIN
, dev_type
,
397 sizeof(dev_type
)/sizeof(dev_type
[0]));
399 insert
.hParent
= driver
[i
];
400 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
401 insert
.u
.item
.pszText
= dev_type
;
402 insert
.u
.item
.cChildren
= 1;
404 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
406 for (j
= 0; j
< num_mid
; j
++)
410 midMessagePtr(j
, MIDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
412 insert
.hParent
= type
;
413 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
414 insert
.u
.item
.pszText
= caps
.szPname
;
415 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
417 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
423 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_AUX
, dev_type
,
424 sizeof(dev_type
)/sizeof(dev_type
[0]));
426 insert
.hParent
= driver
[i
];
427 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
428 insert
.u
.item
.pszText
= dev_type
;
429 insert
.u
.item
.cChildren
= 1;
431 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
433 for (j
= 0; j
< num_aux
; j
++)
437 auxMessagePtr(j
, AUXDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
439 insert
.hParent
= type
;
440 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
441 insert
.u
.item
.pszText
= caps
.szPname
;
442 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
444 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
450 LoadStringW (GetModuleHandle (NULL
), IDS_DEVICES_MIXER
, dev_type
,
451 sizeof(dev_type
)/sizeof(dev_type
[0]));
453 insert
.hParent
= driver
[i
];
454 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_CHILDREN
;
455 insert
.u
.item
.pszText
= dev_type
;
456 insert
.u
.item
.cChildren
= 1;
458 type
= (HTREEITEM
)SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
460 for (j
= 0; j
< num_mxd
; j
++)
464 mxdMessagePtr(j
, MXDM_GETDEVCAPS
, 0, (DWORD_PTR
)&caps
, sizeof(caps
));
466 insert
.hParent
= type
;
467 insert
.u
.item
.mask
= TVIF_TEXT
| TVIF_PARAM
;
468 insert
.u
.item
.pszText
= caps
.szPname
;
469 insert
.u
.item
.lParam
= j
+ DEVICE_MASK
;
471 SendDlgItemMessageW (hDlg
, IDC_AUDIO_TREE
, TVM_INSERTITEMW
, 0, (LPARAM
)&insert
);
479 /* restore the original cursor */
480 SetCursor(old_cursor
);
482 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_SELECTITEM
, 0, 0);
483 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)root
);
484 for (j
= 0; j
< i
; j
++)
485 SendDlgItemMessage(hDlg
, IDC_AUDIO_TREE
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)driver
[j
]);
488 /* find all drivers that can be loaded */
489 static void findAudioDrivers(void)
492 AUDIO_DRIVER
*pAudioDrv
= NULL
;
495 /* delete an existing list */
496 HeapFree(GetProcessHeap(), 0, loadedAudioDrv
);
499 /* change to the wait cursor because this can take a while if there is a
500 * misbehaving driver that takes a long time to open
502 old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
504 for (pAudioDrv
= sAudioDrivers
; pAudioDrv
->nameID
; pAudioDrv
++)
506 if (strlen(pAudioDrv
->szDriver
))
509 char driver
[MAX_PATH
];
511 sprintf(driver
, "wine%s.drv", pAudioDrv
->szDriver
);
513 hdrv
= pAudioDrv
->hDriver
;
514 if (!pAudioDrv
->hDriver
&& (hdrv
= OpenDriverA(driver
, 0, 0))) {
515 HMODULE lib
= GetDriverModuleHandle(hdrv
);
516 MessagePtr wodMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "wodMessage");
517 MessagePtr widMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "widMessage");
518 MessagePtr modMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "modMessage");
519 MessagePtr midMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "midMessage");
520 MessagePtr auxMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "auxMessage");
521 MessagePtr mxdMessagePtr
= (MessagePtr
)GetProcAddress(lib
, "mxdMessage");
523 pAudioDrv
->hDriver
= hdrv
;
526 wodMessagePtr(0, DRVM_INIT
, 0, 0, 0);
529 widMessagePtr(0, DRVM_INIT
, 0, 0, 0);
532 modMessagePtr(0, DRVM_INIT
, 0, 0, 0);
535 midMessagePtr(0, DRVM_INIT
, 0, 0, 0);
538 auxMessagePtr(0, DRVM_INIT
, 0, 0, 0);
541 mxdMessagePtr(0, DRVM_INIT
, 0, 0, 0);
546 loadedAudioDrv
= HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv
, (numFound
+ 1) * sizeof(AUDIO_DRIVER
));
548 loadedAudioDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER
));
550 CopyMemory(&loadedAudioDrv
[numFound
], pAudioDrv
, sizeof(AUDIO_DRIVER
));
556 /* restore the original cursor */
557 SetCursor(old_cursor
);
559 /* terminate list with empty driver */
561 loadedAudioDrv
= HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv
, (numFound
+ 1) * sizeof(AUDIO_DRIVER
));
562 CopyMemory(&loadedAudioDrv
[numFound
], pAudioDrv
, sizeof(AUDIO_DRIVER
));
564 loadedAudioDrv
= HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER
));
565 CopyMemory(&loadedAudioDrv
[0], pAudioDrv
, sizeof(AUDIO_DRIVER
));
569 /* check local copy of registry string for unloadable drivers */
570 static void checkRegistrySetting(HWND hDlg
)
572 const AUDIO_DRIVER
*pAudioDrv
;
573 char * token
, * tokens
;
575 tokens
= HeapAlloc(GetProcessHeap(), 0, strlen(curAudioDriver
)+1);
576 strcpy(tokens
, curAudioDriver
);
579 token
= strtok(tokens
, ",");
580 while (token
!= NULL
)
583 for (pAudioDrv
= loadedAudioDrv
; pAudioDrv
->nameID
; pAudioDrv
++)
585 if (strcmp(token
, pAudioDrv
->szDriver
) == 0)
593 WCHAR tokenW
[MAX_NAME_LENGTH
+1];
594 WCHAR messageStr
[256];
598 MultiByteToWideChar (CP_ACP
, 0, token
, -1, tokenW
, sizeof(tokenW
)/sizeof(tokenW
[0]));
600 LoadStringW (GetModuleHandle (NULL
), IDS_UNAVAILABLE_DRIVER
, messageStr
,
601 sizeof(messageStr
)/sizeof(messageStr
[0]));
602 wsprintfW (str
, messageStr
, tokenW
);
603 LoadStringW (GetModuleHandle (NULL
), IDS_WARNING
, caption
,
604 sizeof(caption
)/sizeof(caption
[0]));
605 if (MessageBoxW (hDlg
, str
, caption
, MB_ICONWARNING
| MB_YESNOCANCEL
) == IDYES
)
608 strcpy(tokens
, curAudioDriver
);
612 token
= strtok(NULL
, ",");
614 HeapFree(GetProcessHeap(), 0, tokens
);
617 static void selectDriver(HWND hDlg
, const char * driver
)
622 strcpy(curAudioDriver
, driver
);
623 set_reg_key(config_key
, "Drivers", "Audio", curAudioDriver
);
625 if (LoadStringW(GetModuleHandle(NULL
), IDS_AUDIO_MISSING
, text
, sizeof(text
)/sizeof(text
[0])))
627 if (LoadStringW(GetModuleHandle(NULL
), IDS_WINECFG_TITLE
, caption
, sizeof(caption
)/sizeof(caption
[0])))
628 MessageBoxW(hDlg
, text
, caption
, MB_OK
| MB_ICONINFORMATION
);
631 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
634 static void initAudioDlg (HWND hDlg
)
641 /* make a list of all drivers that can be loaded */
644 /* get current registry setting if available */
645 buf
= get_reg_key(config_key
, "Drivers", "Audio", NULL
);
647 /* check for first time install and set a default driver
648 * select first available driver, and if that fails: none
652 /* select first available driver */
653 if (*loadedAudioDrv
->szDriver
)
654 selectDriver(hDlg
, loadedAudioDrv
->szDriver
);
656 else /* make a local copy of the current registry setting */
657 strcpy(curAudioDriver
, buf
);
659 WINE_TRACE("curAudioDriver = %s\n", curAudioDriver
);
661 /* check for drivers that can't be loaded */
662 checkRegistrySetting(hDlg
);
664 initAudioDeviceTree(hDlg
);
666 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_RESETCONTENT
, 0, 0);
667 buf
= get_reg_key(config_key
, keypath("DirectSound"), "HardwareAcceleration", "Full");
670 for (i
= 0; 0 != DSound_HW_Accels
[i
].displayID
; ++i
) {
674 match
= (strcmp(buf
, DSound_HW_Accels
[i
].settingStr
) == 0);
677 DSound_HW_Accels
[i
].visible
= 1;
681 if (DSound_HW_Accels
[i
].visible
)
683 LoadStringW (GetModuleHandle (NULL
), DSound_HW_Accels
[i
].displayID
,
684 accelStr
, sizeof(accelStr
)/sizeof(accelStr
[0]));
685 SendDlgItemMessageW (hDlg
, IDC_DSOUND_HW_ACCEL
, CB_ADDSTRING
, 0, (LPARAM
)accelStr
);
687 SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_SETCURSEL
, j
, 0);
692 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf
);
694 HeapFree(GetProcessHeap(), 0, buf
);
696 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_RESETCONTENT
, 0, 0);
697 for (i
= 0; NULL
!= DSound_Rates
[i
]; ++i
) {
698 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_ADDSTRING
, 0, (LPARAM
) DSound_Rates
[i
]);
700 buf
= get_reg_key(config_key
, keypath("DirectSound"), "DefaultSampleRate", "44100");
701 for (i
= 0; NULL
!= DSound_Rates
[i
]; ++i
) {
702 if (strcmp(buf
, DSound_Rates
[i
]) == 0) {
703 SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_SETCURSEL
, i
, 0);
708 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_RESETCONTENT
, 0, 0);
709 for (i
= 0; NULL
!= DSound_Bits
[i
]; ++i
) {
710 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_ADDSTRING
, 0, (LPARAM
) DSound_Bits
[i
]);
712 buf
= get_reg_key(config_key
, keypath("DirectSound"), "DefaultBitsPerSample", "16");
713 for (i
= 0; NULL
!= DSound_Bits
[i
]; ++i
) {
714 if (strcmp(buf
, DSound_Bits
[i
]) == 0) {
715 SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_SETCURSEL
, i
, 0);
719 HeapFree(GetProcessHeap(), 0, buf
);
723 AudioDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
727 switch (LOWORD(wParam
)) {
728 case IDC_AUDIO_CONFIGURE
:
729 configureAudioDriver(hDlg
);
732 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND
), NULL
, SND_RESOURCE
| SND_SYNC
))
733 MessageBox(NULL
, "Audio test failed!", "Error", MB_OK
| MB_ICONERROR
);
735 case IDC_AUDIO_CONTROL_PANEL
:
736 MessageBox(NULL
, "Launching audio control panel not implemented yet!", "Fixme", MB_OK
| MB_ICONERROR
);
738 case IDC_DSOUND_HW_ACCEL
:
739 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
740 int selected_dsound_accel
;
743 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
744 selected_dsound_accel
= SendDlgItemMessage(hDlg
, IDC_DSOUND_HW_ACCEL
, CB_GETCURSEL
, 0, 0);
745 for (i
= 0; DSound_HW_Accels
[i
].settingStr
; ++i
)
747 if (DSound_HW_Accels
[i
].visible
)
749 if (j
== selected_dsound_accel
)
751 set_reg_key(config_key
, keypath("DirectSound"), "HardwareAcceleration",
752 DSound_HW_Accels
[i
].settingStr
);
760 case IDC_DSOUND_RATES
:
761 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
762 int selected_dsound_rate
;
763 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
764 selected_dsound_rate
= SendDlgItemMessage(hDlg
, IDC_DSOUND_RATES
, CB_GETCURSEL
, 0, 0);
765 set_reg_key(config_key
, keypath("DirectSound"), "DefaultSampleRate", DSound_Rates
[selected_dsound_rate
]);
768 case IDC_DSOUND_BITS
:
769 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
770 int selected_dsound_bits
;
771 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
772 selected_dsound_bits
= SendDlgItemMessage(hDlg
, IDC_DSOUND_BITS
, CB_GETCURSEL
, 0, 0);
773 set_reg_key(config_key
, keypath("DirectSound"), "DefaultBitsPerSample", DSound_Bits
[selected_dsound_bits
]);
780 set_window_title(hDlg
);
784 switch(((LPNMHDR
)lParam
)->code
) {
786 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
789 set_reg_key(config_key
, "Drivers", "Audio", curAudioDriver
);
791 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
796 if (((LPNMHDR
)lParam
)->idFrom
== IDC_AUDIO_TREE
)
799 DWORD dwPos
= GetMessagePos();
800 HWND tree
= ((LPNMHDR
)lParam
)->hwndFrom
;
801 ZeroMemory(&ht
, sizeof(ht
));
802 ht
.pt
.x
= (short)LOWORD(dwPos
);
803 ht
.pt
.y
= (short)HIWORD(dwPos
);
804 MapWindowPoints(HWND_DESKTOP
, tree
, &ht
.pt
, 1);
805 SendMessageW( tree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
806 if (TVHT_ONITEMSTATEICON
& ht
.flags
)
810 ZeroMemory(&tvItem
, sizeof(tvItem
));
811 tvItem
.hItem
= ht
.hItem
;
812 SendMessageW( tree
, TVM_GETITEMW
, 0, (LPARAM
) &tvItem
);
814 index
= TreeView_GetItemState(tree
, ht
.hItem
, TVIS_STATEIMAGEMASK
);
815 if (index
== INDEXTOSTATEIMAGEMASK(1))
817 TreeView_SetItemState(tree
, ht
.hItem
, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK
);
818 addDriver(loadedAudioDrv
[tvItem
.lParam
& 0xff].szDriver
);
819 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
821 else if (index
== INDEXTOSTATEIMAGEMASK(2))
823 TreeView_SetItemState(tree
, ht
.hItem
, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK
);
824 removeDriver(loadedAudioDrv
[tvItem
.lParam
& 0xff].szDriver
);
825 SendMessage(GetParent(hDlg
), PSM_CHANGED
, (WPARAM
) hDlg
, 0); /* enable apply button */
831 if (((LPNMHDR
)lParam
)->idFrom
== IDC_AUDIO_TREE
)
834 DWORD dwPos
= GetMessagePos();
835 HWND tree
= ((LPNMHDR
)lParam
)->hwndFrom
;
837 ZeroMemory(&ht
, sizeof(ht
));
838 pt
.x
= (short)LOWORD(dwPos
);
839 pt
.y
= (short)HIWORD(dwPos
);
841 MapWindowPoints(HWND_DESKTOP
, tree
, &ht
.pt
, 1);
842 SendMessageW( tree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
843 if (TVHT_ONITEMLABEL
& ht
.flags
)
846 ZeroMemory(&tvItem
, sizeof(tvItem
));
847 tvItem
.hItem
= ht
.hItem
;
848 tvItem
.mask
= TVIF_PARAM
;
850 if (TreeView_GetItem(tree
, &tvItem
))
852 if (tvItem
.lParam
& DRIVER_MASK
)
856 TrackPopupMenu(GetSubMenu(hPopupMenus
, 0), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, tree
, NULL
);
857 toConfigure
= tvItem
.lParam
& ~DRIVER_MASK
;
860 else if (tvItem
.lParam
& DEVICE_MASK
)