Remove unneeded casts.
[wine/multimedia.git] / programs / winecfg / audio.c
blob73f36f3a12e4e3a7685b3d80d7c0fcc90fea9531
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
31 #include <windef.h>
32 #include <winbase.h>
33 #include <winreg.h>
34 #include <wine/debug.h>
35 #include <shellapi.h>
36 #include <objbase.h>
37 #include <shlguid.h>
38 #include <shlwapi.h>
39 #include <shlobj.h>
40 #include <mmsystem.h>
42 #include "winecfg.h"
43 #include "resource.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)
50 int i;
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,
62 (WPARAM) i, 0);
68 static void configureAudioDriver(HWND hDlg, const char *drivername)
70 int i;
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)
81 HDRVR hdrvr;
82 char wine_driver[MAX_NAME_LENGTH + 8];
83 sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
84 hdrvr = OpenDriverA(wine_driver, 0, 0);
85 if (hdrvr != 0)
87 if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
89 DRVCONFIGINFO dci;
90 LONG lRes;
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);
98 else
100 char str[1024];
101 sprintf(str, "Couldn't open %s!", wine_driver);
102 MessageBox(NULL, str, "Fixme", MB_OK | MB_ICONERROR);
105 break;
111 static void initAudioDlg (HWND hDlg)
113 char *curAudioDriver = get_reg_key(config_key, "Drivers", "Audio", "alsa");
114 const AUDIO_DRIVER *pAudioDrv = NULL;
115 int i;
117 WINE_TRACE("\n");
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)
131 struct stat buf;
132 const char *argv_new[4];
133 int fd;
135 const char *driversFound[10];
136 const char *name[10];
137 int numFound = 0;
139 argv_new[0] = "/bin/sh";
140 argv_new[1] = "-c";
141 argv_new[3] = NULL;
143 /* try to detect oss */
144 fd = open("/dev/dsp", O_WRONLY | O_NONBLOCK);
145 if(fd)
147 close(fd);
148 driversFound[numFound] = "oss";
149 name[numFound] = "OSS";
150 numFound++;
153 /* try to detect alsa */
154 if(!stat("/proc/asound", &buf))
156 driversFound[numFound] = "alsa";
157 name[numFound] = "ALSA";
158 numFound++;
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";
167 numFound++;
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";
176 numFound++;
179 /* try to detect nas */
180 /* TODO */
182 /* try to detect audioIO (solaris) */
183 /* TODO */
185 if(numFound == 0)
187 MessageBox(NULL, "Could not detect any audio devices/servers", "Failed", MB_OK);
188 return "";
190 else
192 /* TODO: possibly smarter handling of multiple drivers? */
193 char text[128];
194 snprintf(text, sizeof(text), "Found %s", name[0]);
195 MessageBox(NULL, (LPCTSTR)text, "Successful", MB_OK);
196 return driversFound[0];
201 INT_PTR CALLBACK
202 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
204 switch (uMsg) {
205 case WM_COMMAND:
206 switch (LOWORD(wParam)) {
207 case IDC_AUDIO_AUTODETECT:
208 selectAudioDriver(hDlg, audioAutoDetect());
209 break;
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);
218 break;
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);
225 break;
226 case IDC_AUDIO_CONTROL_PANEL:
227 MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
228 break;
230 break;
232 case WM_SHOWWINDOW:
233 set_window_title(hDlg);
234 break;
236 case WM_NOTIFY:
237 switch(((LPNMHDR)lParam)->code) {
238 case PSN_KILLACTIVE:
239 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
240 break;
241 case PSN_APPLY:
242 apply();
243 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
244 break;
245 case PSN_SETACTIVE:
246 break;
248 break;
250 case WM_INITDIALOG:
251 initAudioDlg(hDlg);
252 break;
255 return FALSE;