winepulse.drv: add a pulseaudio driver
[wine/hacks.git] / programs / winecfg / audio.c
blob1d70c03a1de54f5ce8e63b96e4c66a8e21d756fd
1 /*
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
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
34 #include <windows.h>
35 #include <wine/debug.h>
36 #include <shellapi.h>
37 #include <objbase.h>
38 #include <shlguid.h>
39 #include <shlwapi.h>
40 #include <shlobj.h>
41 #include <mmsystem.h>
42 #include <mmreg.h>
43 #include <mmddk.h>
45 #include "winecfg.h"
46 #include "resource.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
58 UINT displayID;
59 UINT visible;
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"},
66 {0, 0, 0}
69 static const char* DSound_Rates[] = {
70 "48000",
71 "44100",
72 "22050",
73 "16000",
74 "11025",
75 "8000",
76 NULL
79 static const char* DSound_Bits[] = {
80 "8",
81 "16",
82 NULL
85 typedef struct
87 UINT nameID;
88 const char *szDriver;
89 HDRVR hDriver;
90 } AUDIO_DRIVER;
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"},
101 {0, ""}
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)
120 HDRVR hdrvr;
121 char wine_driver[MAX_NAME_LENGTH + 9];
122 sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
123 hdrvr = pAudioDrv->hDriver;
124 if (hdrvr != 0)
126 if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
128 DRVCONFIGINFO dci;
129 dci.dwDCISize = sizeof (dci);
130 dci.lpszDCISectionName = NULL;
131 dci.lpszDCIAliasName = NULL;
132 SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG_PTR)&dci);
135 else
137 WCHAR wine_driverW[MAX_NAME_LENGTH+9];
138 WCHAR messageStr[256];
139 WCHAR str[1024];
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))
158 return TRUE;
160 return FALSE;
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;
178 int drvlen, listlen;
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;
195 else
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;
202 int i, j;
203 TVINSERTSTRUCTW insert;
204 HTREEITEM root, driver[10];
205 HWND tree = NULL;
206 HIMAGELIST hImageList;
207 HBITMAP hBitMap;
208 HCURSOR old_cursor;
209 WCHAR driver_type[64], dev_type[64];
211 tree = GetDlgItem(hDlg, IDC_AUDIO_TREE);
213 if (!tree)
214 return;
216 /* set tree view style */
217 SetWindowLong(tree, GWL_STYLE, GetWindowLong(tree, GWL_STYLE) | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
219 /* state checkbox */
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 );
226 /* root item */
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++) {
243 HDRVR hdrv;
244 char name[MAX_PATH];
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))
253 HMODULE lib;
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");
264 if (wodMessagePtr)
265 num_wod = wodMessagePtr(0, WODM_GETNUMDEVS, 0, 0, 0);
267 if (widMessagePtr)
268 num_wid = widMessagePtr(0, WIDM_GETNUMDEVS, 0, 0, 0);
270 if (modMessagePtr)
271 num_mod = modMessagePtr(0, MODM_GETNUMDEVS, 0, 0, 0);
273 if (midMessagePtr)
274 num_mid = midMessagePtr(0, MIDM_GETNUMDEVS, 0, 0, 0);
276 if (auxMessagePtr)
277 num_aux = auxMessagePtr(0, AUXDM_GETNUMDEVS, 0, 0, 0);
279 if (mxdMessagePtr)
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);
291 else
292 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
294 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
296 else
298 HTREEITEM type;
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);
309 else
310 insert.u.item.state = INDEXTOSTATEIMAGEMASK(1);
312 driver[i] = (HTREEITEM)SendDlgItemMessageW (hDlg, IDC_AUDIO_TREE, TVM_INSERTITEMW, 0, (LPARAM)&insert);
314 if (num_wod)
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++)
328 WAVEOUTCAPSW caps;
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);
341 if (num_wid)
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++)
355 WAVEINCAPSW caps;
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);
368 if (num_mod)
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++)
382 MIDIOUTCAPSW caps;
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);
395 if (num_mid)
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++)
409 MIDIINCAPSW caps;
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);
422 if (num_aux)
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++)
436 AUXCAPSW caps;
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);
449 if (num_mxd)
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++)
463 MIXERCAPSW caps;
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)
492 int numFound = 0;
493 AUDIO_DRIVER *pAudioDrv = NULL;
494 HCURSOR old_cursor;
496 /* delete an existing list */
497 HeapFree(GetProcessHeap(), 0, loadedAudioDrv);
498 loadedAudioDrv = 0;
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))
509 HDRVR hdrv;
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;
526 if (wodMessagePtr)
527 wodMessagePtr(0, DRVM_INIT, 0, 0, 0);
529 if (widMessagePtr)
530 widMessagePtr(0, DRVM_INIT, 0, 0, 0);
532 if (modMessagePtr)
533 modMessagePtr(0, DRVM_INIT, 0, 0, 0);
535 if (midMessagePtr)
536 midMessagePtr(0, DRVM_INIT, 0, 0, 0);
538 if (auxMessagePtr)
539 auxMessagePtr(0, DRVM_INIT, 0, 0, 0);
541 if (mxdMessagePtr)
542 mxdMessagePtr(0, DRVM_INIT, 0, 0, 0);
544 if (hdrv)
546 if (loadedAudioDrv)
547 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
548 else
549 loadedAudioDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(AUDIO_DRIVER));
551 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
552 numFound++;
557 /* restore the original cursor */
558 SetCursor(old_cursor);
560 /* terminate list with empty driver */
561 if (numFound) {
562 loadedAudioDrv = HeapReAlloc(GetProcessHeap(), 0, loadedAudioDrv, (numFound + 1) * sizeof(AUDIO_DRIVER));
563 CopyMemory(&loadedAudioDrv[numFound], pAudioDrv, sizeof(AUDIO_DRIVER));
564 } else {
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);
579 start_over:
580 token = strtok(tokens, ",");
581 while (token != NULL)
583 BOOL found = FALSE;
584 for (pAudioDrv = loadedAudioDrv; pAudioDrv->nameID; pAudioDrv++)
586 if (strcmp(token, pAudioDrv->szDriver) == 0)
588 found = TRUE;
589 break;
592 if (found == FALSE)
594 WCHAR tokenW[MAX_NAME_LENGTH+1];
595 WCHAR messageStr[256];
596 WCHAR str[1024];
597 WCHAR caption[64];
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)
608 removeDriver(token);
609 strcpy(tokens, curAudioDriver);
610 goto start_over;
613 token = strtok(NULL, ",");
615 HeapFree(GetProcessHeap(), 0, tokens);
618 static void selectDriver(HWND hDlg, const char * driver)
620 WCHAR text[1024];
621 WCHAR caption[64];
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)
637 int i, j, found;
638 char* buf = NULL;
640 WINE_TRACE("\n");
642 /* make a list of all drivers that can be loaded */
643 findAudioDrivers();
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
651 if (buf == NULL)
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");
670 j = found = 0;
671 for (i = 0; 0 != DSound_HW_Accels[i].displayID; ++i) {
672 WCHAR accelStr[64];
673 int match;
675 match = (strcmp(buf, DSound_HW_Accels[i].settingStr) == 0);
676 if (match)
678 DSound_HW_Accels[i].visible = 1;
679 found = 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);
687 if (match)
688 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_SETCURSEL, j, 0);
689 j++;
692 if (!found) {
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);
705 break ;
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);
717 break ;
720 HeapFree(GetProcessHeap(), 0, buf);
723 INT_PTR CALLBACK
724 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
726 switch (uMsg) {
727 case WM_COMMAND:
728 switch (LOWORD(wParam)) {
729 case IDC_AUDIO_CONFIGURE:
730 configureAudioDriver(hDlg);
731 break;
732 case IDC_AUDIO_TEST:
733 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND), NULL, SND_RESOURCE | SND_SYNC))
734 MessageBox(NULL, "Audio test failed!", "Error", MB_OK | MB_ICONERROR);
735 break;
736 case IDC_AUDIO_CONTROL_PANEL:
737 MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
738 break;
739 case IDC_DSOUND_HW_ACCEL:
740 if (HIWORD(wParam) == CBN_SELCHANGE) {
741 int selected_dsound_accel;
742 int i, j = 0;
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);
754 break;
756 j++;
760 break;
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]);
768 break;
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]);
776 break;
778 break;
780 case WM_SHOWWINDOW:
781 set_window_title(hDlg);
782 break;
784 case WM_NOTIFY:
785 switch(((LPNMHDR)lParam)->code) {
786 case PSN_KILLACTIVE:
787 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
788 break;
789 case PSN_APPLY:
790 set_reg_key(config_key, "Drivers", "Audio", curAudioDriver);
791 apply();
792 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
793 break;
794 case PSN_SETACTIVE:
795 break;
796 case NM_CLICK:
797 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
799 TVHITTESTINFO ht;
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)
809 TVITEM tvItem;
810 int index;
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 */
830 break;
831 case NM_RCLICK:
832 if (((LPNMHDR)lParam)->idFrom == IDC_AUDIO_TREE)
834 TVHITTESTINFO ht;
835 DWORD dwPos = GetMessagePos();
836 HWND tree = ((LPNMHDR)lParam)->hwndFrom;
837 POINT pt;
838 ZeroMemory(&ht, sizeof(ht));
839 pt.x = (short)LOWORD(dwPos);
840 pt.y = (short)HIWORD(dwPos);
841 ht.pt = pt;
842 MapWindowPoints(HWND_DESKTOP, tree, &ht.pt, 1);
843 SendMessageW( tree, TVM_HITTEST, 0, (LPARAM)&ht );
844 if (TVHT_ONITEMLABEL & ht.flags)
846 TVITEM tvItem;
847 ZeroMemory(&tvItem, sizeof(tvItem));
848 tvItem.hItem = ht.hItem;
849 tvItem.mask = TVIF_PARAM;
850 tvItem.lParam = -1;
851 if (TreeView_GetItem(tree, &tvItem))
853 if (tvItem.lParam & DRIVER_MASK)
855 if (hPopupMenus)
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)
863 /* FIXME TBD */
870 break;
872 case WM_INITDIALOG:
873 initAudioDlg(hDlg);
874 break;
877 return FALSE;