2004-01-20 03:07:35 +01:00
|
|
|
/*
|
|
|
|
* Audio management UI code
|
|
|
|
*
|
|
|
|
* Copyright 2004 Chris Morgan
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winreg.h>
|
|
|
|
#include <wine/debug.h>
|
|
|
|
#include <shellapi.h>
|
|
|
|
#include <objbase.h>
|
|
|
|
#include <shlguid.h>
|
|
|
|
#include <shlwapi.h>
|
|
|
|
#include <shlobj.h>
|
2005-06-28 21:12:52 +02:00
|
|
|
#include <mmsystem.h>
|
2004-01-20 03:07:35 +01:00
|
|
|
|
|
|
|
#include "winecfg.h"
|
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
|
|
|
|
|
2005-07-11 12:24:28 +02:00
|
|
|
static const char* DSound_HW_Accels[] = {
|
|
|
|
"Full",
|
|
|
|
"Standard",
|
|
|
|
"Basic",
|
|
|
|
"Emulation",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2004-01-20 03:07:35 +01:00
|
|
|
/* Select the correct entry in the combobox based on drivername */
|
2005-06-02 17:11:32 +02:00
|
|
|
static void selectAudioDriver(HWND hDlg, const char *drivername)
|
2004-01-20 03:07:35 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const AUDIO_DRIVER *pAudioDrv = NULL;
|
|
|
|
|
|
|
|
if ((pAudioDrv = getAudioDrivers()))
|
|
|
|
{
|
|
|
|
for (i = 0; *pAudioDrv->szName; i++, pAudioDrv++)
|
|
|
|
{
|
|
|
|
if (!strcmp (pAudioDrv->szDriver, drivername))
|
|
|
|
{
|
2005-06-23 13:42:54 +02:00
|
|
|
set_reg_key(config_key, "Drivers", "Audio", (char *) pAudioDrv->szDriver);
|
2004-09-28 05:55:16 +02:00
|
|
|
SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
|
2004-01-20 03:07:35 +01:00
|
|
|
SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_SETCURSEL,
|
|
|
|
(WPARAM) i, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-28 21:12:52 +02:00
|
|
|
static void configureAudioDriver(HWND hDlg, const char *drivername)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const AUDIO_DRIVER *pAudioDrv = NULL;
|
|
|
|
|
|
|
|
if ((pAudioDrv = getAudioDrivers()))
|
|
|
|
{
|
|
|
|
for (i = 0; *pAudioDrv->szName; i++, pAudioDrv++)
|
|
|
|
{
|
|
|
|
if (!strcmp (pAudioDrv->szDriver, drivername))
|
|
|
|
{
|
|
|
|
if (strlen(pAudioDrv->szDriver) != 0)
|
|
|
|
{
|
|
|
|
HDRVR hdrvr;
|
|
|
|
char wine_driver[MAX_NAME_LENGTH + 8];
|
|
|
|
sprintf(wine_driver, "wine%s.drv", pAudioDrv->szDriver);
|
|
|
|
hdrvr = OpenDriverA(wine_driver, 0, 0);
|
|
|
|
if (hdrvr != 0)
|
|
|
|
{
|
|
|
|
if (SendDriverMessage(hdrvr, DRV_QUERYCONFIGURE, 0, 0) != 0)
|
|
|
|
{
|
|
|
|
DRVCONFIGINFO dci;
|
|
|
|
LONG lRes;
|
|
|
|
dci.dwDCISize = sizeof (dci);
|
2005-06-30 20:09:00 +02:00
|
|
|
dci.lpszDCISectionName = NULL;
|
|
|
|
dci.lpszDCIAliasName = NULL;
|
2005-06-28 21:12:52 +02:00
|
|
|
lRes = SendDriverMessage(hdrvr, DRV_CONFIGURE, 0, (LONG)&dci);
|
|
|
|
}
|
|
|
|
CloseDriver(hdrvr, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char str[1024];
|
|
|
|
sprintf(str, "Couldn't open %s!", wine_driver);
|
|
|
|
MessageBox(NULL, str, "Fixme", MB_OK | MB_ICONERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-02 17:11:32 +02:00
|
|
|
static void initAudioDlg (HWND hDlg)
|
2004-01-20 03:07:35 +01:00
|
|
|
{
|
2005-06-23 13:42:54 +02:00
|
|
|
char *curAudioDriver = get_reg_key(config_key, "Drivers", "Audio", "alsa");
|
2005-01-14 20:48:41 +01:00
|
|
|
const AUDIO_DRIVER *pAudioDrv = NULL;
|
|
|
|
int i;
|
2005-07-11 12:24:28 +02:00
|
|
|
char* buf = NULL;
|
2004-01-20 03:07:35 +01:00
|
|
|
|
2005-01-14 20:48:41 +01:00
|
|
|
WINE_TRACE("\n");
|
|
|
|
|
|
|
|
pAudioDrv = getAudioDrivers ();
|
|
|
|
for (i = 0; *pAudioDrv->szName; i++, pAudioDrv++) {
|
|
|
|
SendDlgItemMessage (hDlg, IDC_AUDIO_DRIVER, CB_ADDSTRING,
|
|
|
|
0, (LPARAM) pAudioDrv->szName);
|
|
|
|
if (!strcmp (pAudioDrv->szDriver, curAudioDriver)) {
|
|
|
|
SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_SETCURSEL, i, 0);
|
|
|
|
}
|
2004-01-20 03:07:35 +01:00
|
|
|
}
|
2005-07-11 12:24:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_RESETCONTENT, 0, 0);
|
|
|
|
for (i = 0; NULL != DSound_HW_Accels[i]; ++i) {
|
|
|
|
SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_ADDSTRING, 0, (LPARAM) DSound_HW_Accels[i]);
|
|
|
|
}
|
|
|
|
buf = get_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration", "Full");
|
|
|
|
for (i = 0; NULL != DSound_HW_Accels[i]; ++i) {
|
|
|
|
if (strcmp(buf, DSound_HW_Accels[i]) == 0) {
|
|
|
|
SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_SETCURSEL, i, 0);
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NULL == DSound_HW_Accels[i]) {
|
|
|
|
WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
|
|
|
|
buf = get_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "N");
|
|
|
|
if (IS_OPTION_TRUE(*buf))
|
|
|
|
CheckDlgButton(hDlg, IDC_DSOUND_DRV_EMUL, BST_CHECKED);
|
|
|
|
else
|
|
|
|
CheckDlgButton(hDlg, IDC_DSOUND_DRV_EMUL, BST_UNCHECKED);
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
|
2004-01-20 03:07:35 +01:00
|
|
|
}
|
|
|
|
|
2005-06-02 17:11:32 +02:00
|
|
|
static const char *audioAutoDetect(void)
|
2004-01-20 03:07:35 +01:00
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
const char *argv_new[4];
|
|
|
|
int fd;
|
|
|
|
|
2005-06-02 17:11:32 +02:00
|
|
|
const char *driversFound[10];
|
|
|
|
const char *name[10];
|
2004-01-20 03:07:35 +01:00
|
|
|
int numFound = 0;
|
|
|
|
|
|
|
|
argv_new[0] = "/bin/sh";
|
|
|
|
argv_new[1] = "-c";
|
|
|
|
argv_new[3] = NULL;
|
|
|
|
|
2005-02-16 18:51:37 +01:00
|
|
|
/* try to detect oss */
|
|
|
|
fd = open("/dev/dsp", O_WRONLY | O_NONBLOCK);
|
|
|
|
if(fd)
|
|
|
|
{
|
|
|
|
close(fd);
|
2005-06-20 20:35:57 +02:00
|
|
|
driversFound[numFound] = "oss";
|
2005-02-16 18:51:37 +01:00
|
|
|
name[numFound] = "OSS";
|
|
|
|
numFound++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to detect alsa */
|
|
|
|
if(!stat("/proc/asound", &buf))
|
|
|
|
{
|
2005-06-20 20:35:57 +02:00
|
|
|
driversFound[numFound] = "alsa";
|
2005-06-27 11:48:06 +02:00
|
|
|
name[numFound] = "ALSA";
|
2005-02-16 18:51:37 +01:00
|
|
|
numFound++;
|
|
|
|
}
|
|
|
|
|
2004-01-20 03:07:35 +01:00
|
|
|
/* try to detect arts */
|
|
|
|
argv_new[2] = "ps awx|grep artsd|grep -v grep|grep artsd > /dev/null";
|
|
|
|
if(!spawnvp(_P_WAIT, "/bin/sh", argv_new))
|
|
|
|
{
|
2005-06-20 20:35:57 +02:00
|
|
|
driversFound[numFound] = "arts";
|
2004-01-20 03:07:35 +01:00
|
|
|
name[numFound] = "aRts";
|
|
|
|
numFound++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to detect jack */
|
|
|
|
argv_new[2] = "ps awx|grep jackd|grep -v grep|grep jackd > /dev/null";
|
|
|
|
if(!spawnvp(_P_WAIT, "/bin/sh", argv_new))
|
|
|
|
{
|
2005-06-20 20:35:57 +02:00
|
|
|
driversFound[numFound] = "jack";
|
2005-06-27 11:48:06 +02:00
|
|
|
name[numFound] = "JACK";
|
2004-01-20 03:07:35 +01:00
|
|
|
numFound++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to detect nas */
|
|
|
|
/* TODO */
|
|
|
|
|
|
|
|
/* try to detect audioIO (solaris) */
|
|
|
|
/* TODO */
|
|
|
|
|
|
|
|
if(numFound == 0)
|
|
|
|
{
|
|
|
|
MessageBox(NULL, "Could not detect any audio devices/servers", "Failed", MB_OK);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* TODO: possibly smarter handling of multiple drivers? */
|
|
|
|
char text[128];
|
|
|
|
snprintf(text, sizeof(text), "Found %s", name[0]);
|
|
|
|
MessageBox(NULL, (LPCTSTR)text, "Successful", MB_OK);
|
|
|
|
return driversFound[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INT_PTR CALLBACK
|
|
|
|
AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
case IDC_AUDIO_AUTODETECT:
|
|
|
|
selectAudioDriver(hDlg, audioAutoDetect());
|
|
|
|
break;
|
|
|
|
case IDC_AUDIO_DRIVER:
|
|
|
|
if ((HIWORD(wParam) == CBN_SELCHANGE) ||
|
|
|
|
(HIWORD(wParam) == CBN_SELCHANGE))
|
|
|
|
{
|
|
|
|
const AUDIO_DRIVER *pAudioDrv = getAudioDrivers();
|
|
|
|
int selected_driver = SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_GETCURSEL, 0, 0);
|
|
|
|
selectAudioDriver(hDlg, (char*)pAudioDrv[selected_driver].szDriver);
|
|
|
|
}
|
|
|
|
break;
|
2005-06-28 21:12:52 +02:00
|
|
|
case IDC_AUDIO_CONFIGURE:
|
|
|
|
{
|
|
|
|
const AUDIO_DRIVER *pAudioDrv = getAudioDrivers();
|
|
|
|
int selected_driver = SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_GETCURSEL, 0, 0);
|
|
|
|
configureAudioDriver(hDlg, (char*)pAudioDrv[selected_driver].szDriver);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_AUDIO_CONTROL_PANEL:
|
|
|
|
MessageBox(NULL, "Launching audio control panel not implemented yet!", "Fixme", MB_OK | MB_ICONERROR);
|
|
|
|
break;
|
2005-07-11 12:24:28 +02:00
|
|
|
case IDC_DSOUND_HW_ACCEL:
|
|
|
|
if (HIWORD(wParam) == CBN_SELCHANGE) {
|
|
|
|
int selected_dsound_accel;
|
|
|
|
SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
|
|
|
|
selected_dsound_accel = SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_GETCURSEL, 0, 0);
|
|
|
|
set_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration", DSound_HW_Accels[selected_dsound_accel]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_DSOUND_DRV_EMUL:
|
|
|
|
if (HIWORD(wParam) == BN_CLICKED) {
|
|
|
|
SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
|
|
|
|
if (IsDlgButtonChecked(hDlg, IDC_DSOUND_DRV_EMUL) == BST_CHECKED)
|
|
|
|
set_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "Y");
|
|
|
|
else
|
|
|
|
set_reg_key(config_key, keypath("DirectSound"), "EmulDriver", "N");
|
|
|
|
}
|
|
|
|
break;
|
2004-01-20 03:07:35 +01:00
|
|
|
}
|
|
|
|
break;
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
case WM_SHOWWINDOW:
|
|
|
|
set_window_title(hDlg);
|
|
|
|
break;
|
|
|
|
|
2004-01-20 03:07:35 +01:00
|
|
|
case WM_NOTIFY:
|
|
|
|
switch(((LPNMHDR)lParam)->code) {
|
|
|
|
case PSN_KILLACTIVE:
|
2005-02-15 22:51:06 +01:00
|
|
|
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
|
2004-01-20 03:07:35 +01:00
|
|
|
break;
|
|
|
|
case PSN_APPLY:
|
2004-09-28 05:55:16 +02:00
|
|
|
apply();
|
2005-02-15 22:51:06 +01:00
|
|
|
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
|
2004-01-20 03:07:35 +01:00
|
|
|
break;
|
|
|
|
case PSN_SETACTIVE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
initAudioDlg(hDlg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|