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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
34 #include <wine/debug.h>
45 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
47 /* Select the correct entry in the combobox based on drivername */
48 static void selectAudioDriver(HWND hDlg, const char *drivername)
51 const AUDIO_DRIVER *pAudioDrv = NULL;
53 if ((pAudioDrv = getAudioDrivers()))
55 for (i = 0; *pAudioDrv->szName; i++, pAudioDrv++)
57 if (!strcmp (pAudioDrv->szDriver, drivername))
59 set_reg_key(config_key, "Drivers", "Audio", (char *) pAudioDrv->szDriver);
60 SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
61 SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_SETCURSEL,
68 static void configureAudioDriver(HWND hDlg, const char *drivername)
71 const AUDIO_DRIVER *pAudioDrv = NULL;
73 if ((pAudioDrv = getAudioDrivers()))
75 for (i = 0; *pAudioDrv->szName; i++, pAudioDrv++)
77 if (!strcmp (pAudioDrv->szDriver, drivername))
79 if (strlen(pAudioDrv->szDriver) != 0)
82 char wine_driver[MAX_NAME_LENGTH + 8];
83 sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
84 hdrvr = OpenDriverA(wine_driver, 0, 0);
87 if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
91 dci.dwDCISize = sizeof (dci);
92 dci.lpszDCISectionName = NULL;
93 dci.lpszDCIAliasName = NULL;
94 lRes = SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG)&dci);
96 CloseDriver(hdrvr, 0, 0);
101 sprintf(str, "Couldn't open %s!", wine_driver);
102 MessageBox(NULL, str, "Fixme", MB_OK | MB_ICONERROR);
111 static void initAudioDlg (HWND hDlg)
113 char *curAudioDriver = get_reg_key(config_key, "Drivers", "Audio", "alsa");
114 const AUDIO_DRIVER *pAudioDrv = NULL;
119 pAudioDrv = getAudioDrivers ();
120 for (i = 0; *pAudioDrv->szName; i++, pAudioDrv++) {
121 SendDlgItemMessage (hDlg, IDC_AUDIO_DRIVER, CB_ADDSTRING,
122 0, (LPARAM) pAudioDrv->szName);
123 if (!strcmp (pAudioDrv->szDriver, curAudioDriver)) {
124 SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_SETCURSEL, i, 0);
129 static const char *audioAutoDetect(void)
132 const char *argv_new[4];
135 const char *driversFound[10];
136 const char *name[10];
139 argv_new[0] = "/bin/sh";
143 /* try to detect oss */
144 fd = open("/dev/dsp", O_WRONLY | O_NONBLOCK);
148 driversFound[numFound] = "oss";
149 name[numFound] = "OSS";
153 /* try to detect alsa */
154 if(!stat("/proc/asound", &buf))
156 driversFound[numFound] = "alsa";
157 name[numFound] = "ALSA";
161 /* try to detect arts */
162 argv_new[2] = "ps awx|grep artsd|grep -v grep|grep artsd > /dev/null";
163 if(!spawnvp(_P_WAIT, "/bin/sh", argv_new))
165 driversFound[numFound] = "arts";
166 name[numFound] = "aRts";
170 /* try to detect jack */
171 argv_new[2] = "ps awx|grep jackd|grep -v grep|grep jackd > /dev/null";
172 if(!spawnvp(_P_WAIT, "/bin/sh", argv_new))
174 driversFound[numFound] = "jack";
175 name[numFound] = "JACK";
179 /* try to detect nas */
182 /* try to detect audioIO (solaris) */
187 MessageBox(NULL, "Could not detect any audio devices/servers", "Failed", MB_OK);
192 /* TODO: possibly smarter handling of multiple drivers? */
194 snprintf(text, sizeof(text), "Found %s", name[0]);
195 MessageBox(NULL, (LPCTSTR)text, "Successful", MB_OK);
196 return driversFound[0];
202 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
206 switch (LOWORD(wParam)) {
207 case IDC_AUDIO_AUTODETECT:
208 selectAudioDriver(hDlg, audioAutoDetect());
210 case IDC_AUDIO_DRIVER:
211 if ((HIWORD(wParam) == CBN_SELCHANGE) ||
212 (HIWORD(wParam) == CBN_SELCHANGE))
214 const AUDIO_DRIVER *pAudioDrv = getAudioDrivers();
215 int selected_driver = SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_GETCURSEL, 0, 0);
216 selectAudioDriver(hDlg, (char*)pAudioDrv[selected_driver].szDriver);
219 case IDC_AUDIO_CONFIGURE:
221 const AUDIO_DRIVER *pAudioDrv = getAudioDrivers();
222 int selected_driver = SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_GETCURSEL, 0, 0);
223 configureAudioDriver(hDlg, (char*)pAudioDrv[selected_driver].szDriver);
226 case IDC_AUDIO_CONTROL_PANEL:
227 MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
233 set_window_title(hDlg);
237 switch(((LPNMHDR)lParam)->code) {
239 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
243 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);