2004-01-20 02:07:35 +00: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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-01-20 02:07:35 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-01-19 10:55:01 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2005-12-08 10:57:44 +00:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
2004-01-20 02:07:35 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-08-31 20:16:16 +00:00
|
|
|
#define COBJMACROS
|
2006-01-19 10:55:01 +00:00
|
|
|
#include <windows.h>
|
2004-01-20 02:07:35 +00:00
|
|
|
#include <wine/debug.h>
|
|
|
|
#include <shellapi.h>
|
|
|
|
#include <objbase.h>
|
|
|
|
#include <shlguid.h>
|
|
|
|
#include <shlwapi.h>
|
|
|
|
#include <shlobj.h>
|
2005-06-28 19:12:52 +00:00
|
|
|
#include <mmsystem.h>
|
2005-12-07 11:50:52 +00:00
|
|
|
#include <mmreg.h>
|
|
|
|
#include <mmddk.h>
|
2004-01-20 02:07:35 +00:00
|
|
|
|
2011-08-31 20:16:16 +00:00
|
|
|
#include "ole2.h"
|
|
|
|
#include "initguid.h"
|
2015-02-02 17:56:34 +00:00
|
|
|
#include "propkey.h"
|
2011-08-31 20:16:16 +00:00
|
|
|
#include "devpkey.h"
|
|
|
|
#include "mmdeviceapi.h"
|
|
|
|
#include "audioclient.h"
|
|
|
|
#include "audiopolicy.h"
|
|
|
|
|
2004-01-20 02:07:35 +00:00
|
|
|
#include "winecfg.h"
|
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
|
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
struct DeviceInfo {
|
|
|
|
WCHAR *id;
|
|
|
|
PROPVARIANT name;
|
2015-02-02 17:56:34 +00:00
|
|
|
int speaker_config;
|
2011-10-05 18:40:02 +00:00
|
|
|
};
|
|
|
|
|
2021-09-07 11:41:35 +00:00
|
|
|
static WCHAR g_drv_keyW[256] = L"Software\\Wine\\Drivers\\";
|
2011-10-05 18:40:02 +00:00
|
|
|
|
|
|
|
static UINT num_render_devs, num_capture_devs;
|
|
|
|
static struct DeviceInfo *render_devs, *capture_devs;
|
|
|
|
|
2015-02-02 17:56:34 +00:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
int text_id;
|
|
|
|
DWORD speaker_mask;
|
|
|
|
} speaker_configs[] =
|
|
|
|
{
|
|
|
|
{ IDS_AUDIO_SPEAKER_5POINT1, KSAUDIO_SPEAKER_5POINT1 },
|
|
|
|
{ IDS_AUDIO_SPEAKER_QUAD, KSAUDIO_SPEAKER_QUAD },
|
|
|
|
{ IDS_AUDIO_SPEAKER_STEREO, KSAUDIO_SPEAKER_STEREO },
|
|
|
|
{ IDS_AUDIO_SPEAKER_MONO, KSAUDIO_SPEAKER_MONO },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
static BOOL load_device(IMMDevice *dev, struct DeviceInfo *info)
|
2006-08-19 03:19:57 +00:00
|
|
|
{
|
2011-09-27 13:49:34 +00:00
|
|
|
IPropertyStore *ps;
|
|
|
|
HRESULT hr;
|
2015-02-02 17:56:34 +00:00
|
|
|
PROPVARIANT pv;
|
|
|
|
UINT i;
|
2011-09-27 13:49:34 +00:00
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
hr = IMMDevice_GetId(dev, &info->id);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
info->id = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-09-27 13:49:34 +00:00
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
hr = IMMDevice_OpenPropertyStore(dev, STGM_READ, &ps);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
CoTaskMemFree(info->id);
|
|
|
|
info->id = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropVariantInit(&info->name);
|
|
|
|
|
|
|
|
hr = IPropertyStore_GetValue(ps,
|
|
|
|
(PROPERTYKEY*)&DEVPKEY_Device_FriendlyName, &info->name);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
CoTaskMemFree(info->id);
|
|
|
|
info->id = NULL;
|
2015-02-02 17:56:34 +00:00
|
|
|
IPropertyStore_Release(ps);
|
2011-10-05 18:40:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-02 17:56:34 +00:00
|
|
|
PropVariantInit(&pv);
|
|
|
|
|
|
|
|
hr = IPropertyStore_GetValue(ps,
|
|
|
|
&PKEY_AudioEndpoint_PhysicalSpeakers, &pv);
|
|
|
|
|
2015-02-03 18:40:02 +00:00
|
|
|
info->speaker_config = -1;
|
2015-02-02 17:56:34 +00:00
|
|
|
if(SUCCEEDED(hr) && pv.vt == VT_UI4){
|
|
|
|
i = 0;
|
|
|
|
while (speaker_configs[i].text_id != 0) {
|
2021-03-22 23:31:30 +00:00
|
|
|
if ((speaker_configs[i].speaker_mask & pv.ulVal) == speaker_configs[i].speaker_mask) {
|
2015-02-02 17:56:34 +00:00
|
|
|
info->speaker_config = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fallback to stereo */
|
2015-02-03 18:40:02 +00:00
|
|
|
if(info->speaker_config == -1)
|
2015-02-02 17:56:34 +00:00
|
|
|
info->speaker_config = 2;
|
|
|
|
|
|
|
|
IPropertyStore_Release(ps);
|
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL load_devices(IMMDeviceEnumerator *devenum, EDataFlow dataflow,
|
|
|
|
UINT *ndevs, struct DeviceInfo **out)
|
|
|
|
{
|
|
|
|
IMMDeviceCollection *coll;
|
|
|
|
UINT i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IMMDeviceEnumerator_EnumAudioEndpoints(devenum, dataflow,
|
|
|
|
DEVICE_STATE_ACTIVE, &coll);
|
2011-09-27 13:49:34 +00:00
|
|
|
if(FAILED(hr))
|
|
|
|
return FALSE;
|
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
hr = IMMDeviceCollection_GetCount(coll, ndevs);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
IMMDeviceCollection_Release(coll);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ndevs > 0){
|
|
|
|
*out = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
sizeof(struct DeviceInfo) * (*ndevs));
|
|
|
|
if(!*out){
|
|
|
|
IMMDeviceCollection_Release(coll);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < *ndevs; ++i){
|
|
|
|
IMMDevice *dev;
|
|
|
|
|
|
|
|
hr = IMMDeviceCollection_Item(coll, i, &dev);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
(*out)[i].id = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
load_device(dev, &(*out)[i]);
|
|
|
|
|
|
|
|
IMMDevice_Release(dev);
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
*out = NULL;
|
|
|
|
|
|
|
|
IMMDeviceCollection_Release(coll);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL get_driver_name(IMMDeviceEnumerator *devenum, PROPVARIANT *pv)
|
|
|
|
{
|
|
|
|
IMMDevice *device;
|
|
|
|
IPropertyStore *ps;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2021-09-07 11:41:35 +00:00
|
|
|
hr = IMMDeviceEnumerator_GetDevice(devenum, L"Wine info device", &device);
|
2011-09-27 13:49:34 +00:00
|
|
|
if(FAILED(hr))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
IMMDevice_Release(device);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IPropertyStore_GetValue(ps,
|
|
|
|
(const PROPERTYKEY *)&DEVPKEY_Device_Driver, pv);
|
|
|
|
IPropertyStore_Release(ps);
|
|
|
|
IMMDevice_Release(device);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-04-06 00:53:02 +00:00
|
|
|
|
2005-12-17 11:30:06 +00:00
|
|
|
static void initAudioDlg (HWND hDlg)
|
|
|
|
{
|
2011-10-05 18:40:02 +00:00
|
|
|
WCHAR display_str[256], format_str[256], sysdefault_str[256], disabled_str[64];
|
|
|
|
IMMDeviceEnumerator *devenum;
|
|
|
|
BOOL have_driver = FALSE;
|
|
|
|
HRESULT hr;
|
2015-02-02 17:56:34 +00:00
|
|
|
UINT i;
|
2015-04-14 19:01:46 +00:00
|
|
|
LVCOLUMNW lvcol;
|
|
|
|
WCHAR colW[64], speaker_str[256];
|
|
|
|
RECT rect;
|
|
|
|
DWORD width;
|
2004-01-20 02:07:35 +00:00
|
|
|
|
2005-01-14 19:48:41 +00:00
|
|
|
WINE_TRACE("\n");
|
|
|
|
|
2018-05-17 22:17:06 +00:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_DRIVER, format_str, ARRAY_SIZE(format_str));
|
|
|
|
LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_DRIVER_NONE, disabled_str,
|
|
|
|
ARRAY_SIZE(disabled_str));
|
|
|
|
LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_SYSDEFAULT, sysdefault_str,
|
|
|
|
ARRAY_SIZE(sysdefault_str));
|
2011-09-27 13:49:34 +00:00
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&devenum);
|
|
|
|
if(SUCCEEDED(hr)){
|
|
|
|
PROPVARIANT pv;
|
|
|
|
|
|
|
|
load_devices(devenum, eRender, &num_render_devs, &render_devs);
|
|
|
|
load_devices(devenum, eCapture, &num_capture_devs, &capture_devs);
|
|
|
|
|
|
|
|
PropVariantInit(&pv);
|
2021-03-22 23:31:30 +00:00
|
|
|
if(get_driver_name(devenum, &pv) && pv.pwszVal[0] != '\0'){
|
2011-10-05 18:40:02 +00:00
|
|
|
have_driver = TRUE;
|
2021-09-07 15:14:22 +00:00
|
|
|
swprintf(display_str, ARRAY_SIZE(display_str), format_str, pv.pwszVal);
|
2021-03-22 23:31:30 +00:00
|
|
|
lstrcatW(g_drv_keyW, pv.pwszVal);
|
2011-10-05 18:40:02 +00:00
|
|
|
}
|
|
|
|
PropVariantClear(&pv);
|
|
|
|
|
|
|
|
IMMDeviceEnumerator_Release(devenum);
|
|
|
|
}
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_ADDSTRING,
|
|
|
|
0, (LPARAM)sysdefault_str);
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_SETCURSEL, 0, 0);
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_ADDSTRING,
|
|
|
|
0, (LPARAM)sysdefault_str);
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_SETCURSEL, 0, 0);
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_ADDSTRING,
|
|
|
|
0, (LPARAM)sysdefault_str);
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_SETCURSEL, 0, 0);
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_ADDSTRING,
|
|
|
|
0, (LPARAM)sysdefault_str);
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_SETCURSEL, 0, 0);
|
|
|
|
|
2015-02-02 17:56:34 +00:00
|
|
|
i = 0;
|
|
|
|
while (speaker_configs[i].text_id != 0) {
|
2018-05-17 22:17:06 +00:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), speaker_configs[i].text_id, speaker_str,
|
|
|
|
ARRAY_SIZE(speaker_str));
|
2015-02-02 17:56:34 +00:00
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_ADDSTRING,
|
|
|
|
0, (LPARAM)speaker_str);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2015-04-14 19:01:46 +00:00
|
|
|
GetClientRect(GetDlgItem(hDlg, IDC_LIST_AUDIO_DEVICES), &rect);
|
|
|
|
width = (rect.right - rect.left) * 3 / 5;
|
|
|
|
|
2018-05-17 22:17:06 +00:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_DEVICE, colW, ARRAY_SIZE(colW));
|
2015-04-14 19:01:46 +00:00
|
|
|
lvcol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
|
|
|
|
lvcol.pszText = colW;
|
|
|
|
lvcol.cchTextMax = lstrlenW(colW);
|
|
|
|
lvcol.cx = width;
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_INSERTCOLUMNW, 0, (LPARAM)&lvcol);
|
|
|
|
|
2018-05-17 22:17:06 +00:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_SPEAKER_CONFIG, colW, ARRAY_SIZE(colW));
|
2015-04-14 19:01:46 +00:00
|
|
|
lvcol.pszText = colW;
|
|
|
|
lvcol.cchTextMax = lstrlenW(colW);
|
|
|
|
lvcol.cx = rect.right - rect.left - width;
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_INSERTCOLUMNW, 1, (LPARAM)&lvcol);
|
|
|
|
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_SPEAKERCONFIG_SPEAKERS), 0);
|
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
if(have_driver){
|
|
|
|
WCHAR *reg_out_dev, *reg_vout_dev, *reg_in_dev, *reg_vin_dev;
|
|
|
|
|
2021-09-07 15:14:22 +00:00
|
|
|
reg_out_dev = get_reg_key(HKEY_CURRENT_USER, g_drv_keyW, L"DefaultOutput", NULL);
|
|
|
|
reg_vout_dev = get_reg_key(HKEY_CURRENT_USER, g_drv_keyW, L"DefaultVoiceOutput", NULL);
|
|
|
|
reg_in_dev = get_reg_key(HKEY_CURRENT_USER, g_drv_keyW, L"DefaultInput", NULL);
|
|
|
|
reg_vin_dev = get_reg_key(HKEY_CURRENT_USER, g_drv_keyW, L"DefaultVoiceInput", NULL);
|
2011-10-05 18:40:02 +00:00
|
|
|
|
|
|
|
for(i = 0; i < num_render_devs; ++i){
|
2015-04-14 19:01:46 +00:00
|
|
|
LVITEMW lvitem;
|
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
if(!render_devs[i].id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_ADDSTRING,
|
2021-03-22 23:31:30 +00:00
|
|
|
0, (LPARAM)render_devs[i].name.pwszVal);
|
2011-10-05 18:40:02 +00:00
|
|
|
SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_SETITEMDATA,
|
|
|
|
i + 1, (LPARAM)&render_devs[i]);
|
2015-02-02 17:56:34 +00:00
|
|
|
|
2021-09-07 11:23:32 +00:00
|
|
|
if(reg_out_dev && !wcscmp(render_devs[i].id, reg_out_dev)){
|
2011-10-05 18:40:02 +00:00
|
|
|
SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_SETCURSEL, i + 1, 0);
|
2015-02-02 17:56:34 +00:00
|
|
|
SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_SETCURSEL, render_devs[i].speaker_config, 0);
|
|
|
|
}
|
2011-10-05 18:40:02 +00:00
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_ADDSTRING,
|
2021-03-22 23:31:30 +00:00
|
|
|
0, (LPARAM)render_devs[i].name.pwszVal);
|
2011-10-05 18:40:02 +00:00
|
|
|
SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_SETITEMDATA,
|
|
|
|
i + 1, (LPARAM)&render_devs[i]);
|
2021-09-07 11:23:32 +00:00
|
|
|
if(reg_vout_dev && !wcscmp(render_devs[i].id, reg_vout_dev))
|
2011-10-05 18:40:02 +00:00
|
|
|
SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_SETCURSEL, i + 1, 0);
|
|
|
|
|
2015-04-14 19:01:46 +00:00
|
|
|
lvitem.mask = LVIF_TEXT | LVIF_PARAM;
|
|
|
|
lvitem.iItem = i;
|
|
|
|
lvitem.iSubItem = 0;
|
2021-03-22 23:31:30 +00:00
|
|
|
lvitem.pszText = render_devs[i].name.pwszVal;
|
2015-04-14 19:01:46 +00:00
|
|
|
lvitem.cchTextMax = lstrlenW(lvitem.pszText);
|
|
|
|
lvitem.lParam = (LPARAM)&render_devs[i];
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_INSERTITEMW, 0, (LPARAM)&lvitem);
|
|
|
|
|
|
|
|
LoadStringW(GetModuleHandleW(NULL), speaker_configs[render_devs[i].speaker_config].text_id,
|
2018-05-17 22:17:06 +00:00
|
|
|
speaker_str, ARRAY_SIZE(speaker_str));
|
2015-04-14 19:01:46 +00:00
|
|
|
|
|
|
|
lvitem.mask = LVIF_TEXT;
|
|
|
|
lvitem.iItem = i;
|
|
|
|
lvitem.iSubItem = 1;
|
|
|
|
lvitem.pszText = speaker_str;
|
|
|
|
lvitem.cchTextMax = lstrlenW(lvitem.pszText);
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_SETITEMW, 0, (LPARAM)&lvitem);
|
2015-02-02 17:56:34 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
for(i = 0; i < num_capture_devs; ++i){
|
|
|
|
if(!capture_devs[i].id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_ADDSTRING,
|
2021-03-22 23:31:30 +00:00
|
|
|
0, (LPARAM)capture_devs[i].name.pwszVal);
|
2011-10-05 18:40:02 +00:00
|
|
|
SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_SETITEMDATA,
|
|
|
|
i + 1, (LPARAM)&capture_devs[i]);
|
2021-09-07 11:23:32 +00:00
|
|
|
if(reg_in_dev && !wcscmp(capture_devs[i].id, reg_in_dev))
|
2011-10-05 18:40:02 +00:00
|
|
|
SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_SETCURSEL, i + 1, 0);
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_ADDSTRING,
|
2021-03-22 23:31:30 +00:00
|
|
|
0, (LPARAM)capture_devs[i].name.pwszVal);
|
2011-10-05 18:40:02 +00:00
|
|
|
SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_SETITEMDATA,
|
|
|
|
i + 1, (LPARAM)&capture_devs[i]);
|
2021-09-07 11:23:32 +00:00
|
|
|
if(reg_vin_dev && !wcscmp(capture_devs[i].id, reg_vin_dev))
|
2011-10-05 18:40:02 +00:00
|
|
|
SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_SETCURSEL, i + 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, reg_out_dev);
|
|
|
|
HeapFree(GetProcessHeap(), 0, reg_vout_dev);
|
|
|
|
HeapFree(GetProcessHeap(), 0, reg_in_dev);
|
|
|
|
HeapFree(GetProcessHeap(), 0, reg_vin_dev);
|
|
|
|
}else
|
2021-09-07 15:14:22 +00:00
|
|
|
swprintf(display_str, ARRAY_SIZE(display_str), format_str, disabled_str);
|
2011-09-27 13:49:34 +00:00
|
|
|
|
|
|
|
SetDlgItemTextW(hDlg, IDC_AUDIO_DRIVER, display_str);
|
2004-01-20 02:07:35 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 18:40:02 +00:00
|
|
|
static void set_reg_device(HWND hDlg, int dlgitem, const WCHAR *key_name)
|
|
|
|
{
|
|
|
|
UINT idx;
|
|
|
|
struct DeviceInfo *info;
|
|
|
|
|
|
|
|
idx = SendDlgItemMessageW(hDlg, dlgitem, CB_GETCURSEL, 0, 0);
|
|
|
|
|
|
|
|
info = (struct DeviceInfo *)SendDlgItemMessageW(hDlg, dlgitem,
|
|
|
|
CB_GETITEMDATA, idx, 0);
|
|
|
|
|
|
|
|
if(!info || info == (void*)CB_ERR)
|
2021-09-07 15:14:22 +00:00
|
|
|
set_reg_key(HKEY_CURRENT_USER, g_drv_keyW, key_name, NULL);
|
2011-10-05 18:40:02 +00:00
|
|
|
else
|
2021-09-07 15:14:22 +00:00
|
|
|
set_reg_key(HKEY_CURRENT_USER, g_drv_keyW, key_name, info->id);
|
2011-10-05 18:40:02 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 18:39:46 +00:00
|
|
|
static void test_sound(void)
|
|
|
|
{
|
2011-11-01 15:18:13 +00:00
|
|
|
if(!PlaySoundW(MAKEINTRESOURCEW(IDW_TESTSOUND), NULL, SND_RESOURCE | SND_ASYNC)){
|
2011-10-05 18:39:46 +00:00
|
|
|
WCHAR error_str[256], title_str[256];
|
|
|
|
|
2018-05-17 22:17:06 +00:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_TEST_FAILED, error_str,
|
|
|
|
ARRAY_SIZE(error_str));
|
|
|
|
LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_TEST_FAILED_TITLE, title_str,
|
|
|
|
ARRAY_SIZE(title_str));
|
2011-10-05 18:39:46 +00:00
|
|
|
|
|
|
|
MessageBoxW(NULL, error_str, title_str, MB_OK | MB_ICONERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-02 17:56:34 +00:00
|
|
|
static void apply_speaker_configs(void)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
IMMDeviceEnumerator *devenum;
|
|
|
|
IMMDevice *dev;
|
|
|
|
IPropertyStore *ps;
|
|
|
|
PROPVARIANT pv;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&devenum);
|
|
|
|
|
|
|
|
if(FAILED(hr)){
|
2022-02-07 07:40:37 +00:00
|
|
|
ERR("Unable to create MMDeviceEnumerator: 0x%08lx\n", hr);
|
2015-02-02 17:56:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropVariantInit(&pv);
|
|
|
|
pv.vt = VT_UI4;
|
|
|
|
|
|
|
|
for (i = 0; i < num_render_devs; i++) {
|
|
|
|
hr = IMMDeviceEnumerator_GetDevice(devenum, render_devs[i].id, &dev);
|
|
|
|
|
|
|
|
if(FAILED(hr)){
|
2022-02-07 07:40:37 +00:00
|
|
|
WARN("Could not get MMDevice for %s: 0x%08lx\n", wine_dbgstr_w(render_devs[i].id), hr);
|
2015-02-02 17:56:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IMMDevice_OpenPropertyStore(dev, STGM_WRITE, &ps);
|
|
|
|
|
|
|
|
if(FAILED(hr)){
|
2022-02-07 07:40:37 +00:00
|
|
|
WARN("Could not open property store for %s: 0x%08lx\n", wine_dbgstr_w(render_devs[i].id), hr);
|
2015-02-02 17:56:34 +00:00
|
|
|
IMMDevice_Release(dev);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-22 23:31:30 +00:00
|
|
|
pv.ulVal = speaker_configs[render_devs[i].speaker_config].speaker_mask;
|
2015-02-02 17:56:34 +00:00
|
|
|
|
|
|
|
hr = IPropertyStore_SetValue(ps, &PKEY_AudioEndpoint_PhysicalSpeakers, &pv);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
2022-02-07 07:40:37 +00:00
|
|
|
WARN("IPropertyStore_SetValue failed for %s: 0x%08lx\n", wine_dbgstr_w(render_devs[i].id), hr);
|
2015-02-02 17:56:34 +00:00
|
|
|
|
|
|
|
IPropertyStore_Release(ps);
|
|
|
|
IMMDevice_Release(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMMDeviceEnumerator_Release(devenum);
|
|
|
|
}
|
|
|
|
|
2015-04-14 19:01:46 +00:00
|
|
|
static void listview_changed(HWND hDlg)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
|
|
|
|
if(idx < 0) {
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_SPEAKERCONFIG_SPEAKERS), 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_SETCURSEL,
|
|
|
|
render_devs[idx].speaker_config, 0);
|
|
|
|
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_SPEAKERCONFIG_SPEAKERS), 1);
|
|
|
|
}
|
|
|
|
|
2004-01-20 02:07:35 +00:00
|
|
|
INT_PTR CALLBACK
|
|
|
|
AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_COMMAND:
|
2011-08-31 20:16:16 +00:00
|
|
|
switch (LOWORD(wParam)) {
|
2007-04-03 20:09:02 +00:00
|
|
|
case IDC_AUDIO_TEST:
|
2011-10-05 18:39:46 +00:00
|
|
|
test_sound();
|
2011-08-31 20:16:16 +00:00
|
|
|
break;
|
2011-10-05 18:40:02 +00:00
|
|
|
case IDC_AUDIOOUT_DEVICE:
|
|
|
|
if(HIWORD(wParam) == CBN_SELCHANGE){
|
2021-09-07 11:41:35 +00:00
|
|
|
set_reg_device(hDlg, IDC_AUDIOOUT_DEVICE, L"DefaultOutput");
|
2011-10-05 18:40:02 +00:00
|
|
|
SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_VOICEOUT_DEVICE:
|
|
|
|
if(HIWORD(wParam) == CBN_SELCHANGE){
|
2021-09-07 11:41:35 +00:00
|
|
|
set_reg_device(hDlg, IDC_VOICEOUT_DEVICE, L"DefaultVoiceOutput");
|
2011-10-05 18:40:02 +00:00
|
|
|
SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_AUDIOIN_DEVICE:
|
|
|
|
if(HIWORD(wParam) == CBN_SELCHANGE){
|
2021-09-07 11:41:35 +00:00
|
|
|
set_reg_device(hDlg, IDC_AUDIOIN_DEVICE, L"DefaultInput");
|
2011-10-05 18:40:02 +00:00
|
|
|
SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_VOICEIN_DEVICE:
|
|
|
|
if(HIWORD(wParam) == CBN_SELCHANGE){
|
2021-09-07 11:41:35 +00:00
|
|
|
set_reg_device(hDlg, IDC_VOICEIN_DEVICE, L"DefaultVoiceInput");
|
2011-10-05 18:40:02 +00:00
|
|
|
SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
|
|
|
|
}
|
|
|
|
break;
|
2015-02-02 17:56:34 +00:00
|
|
|
case IDC_SPEAKERCONFIG_SPEAKERS:
|
|
|
|
if(HIWORD(wParam) == CBN_SELCHANGE){
|
|
|
|
UINT dev, idx;
|
|
|
|
|
|
|
|
idx = SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_GETCURSEL, 0, 0);
|
2015-04-14 19:01:46 +00:00
|
|
|
dev = SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
|
2015-02-02 17:56:34 +00:00
|
|
|
|
|
|
|
if(dev < num_render_devs){
|
2015-04-14 19:01:46 +00:00
|
|
|
WCHAR speaker_str[256];
|
|
|
|
LVITEMW lvitem;
|
|
|
|
|
2015-02-02 17:56:34 +00:00
|
|
|
render_devs[dev].speaker_config = idx;
|
2015-04-14 19:01:46 +00:00
|
|
|
|
|
|
|
LoadStringW(GetModuleHandleW(NULL), speaker_configs[idx].text_id,
|
2018-05-17 22:17:06 +00:00
|
|
|
speaker_str, ARRAY_SIZE(speaker_str));
|
2015-04-14 19:01:46 +00:00
|
|
|
|
|
|
|
lvitem.mask = LVIF_TEXT;
|
|
|
|
lvitem.iItem = dev;
|
|
|
|
lvitem.iSubItem = 1;
|
|
|
|
lvitem.pszText = speaker_str;
|
|
|
|
lvitem.cchTextMax = lstrlenW(lvitem.pszText);
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hDlg, IDC_LIST_AUDIO_DEVICES, LVM_SETITEMW, 0, (LPARAM)&lvitem);
|
|
|
|
|
2015-02-02 17:56:34 +00:00
|
|
|
SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-08-31 20:16:16 +00:00
|
|
|
}
|
2011-10-16 11:04:35 +00:00
|
|
|
break;
|
|
|
|
|
2004-09-28 03:55:16 +00:00
|
|
|
case WM_SHOWWINDOW:
|
|
|
|
set_window_title(hDlg);
|
|
|
|
break;
|
2005-12-17 11:30:06 +00:00
|
|
|
|
2004-01-20 02:07:35 +00:00
|
|
|
case WM_NOTIFY:
|
2011-08-31 20:16:16 +00:00
|
|
|
switch(((LPNMHDR)lParam)->code) {
|
|
|
|
case PSN_KILLACTIVE:
|
2012-01-20 11:42:33 +00:00
|
|
|
SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, FALSE);
|
2011-08-31 20:16:16 +00:00
|
|
|
break;
|
|
|
|
case PSN_APPLY:
|
2015-02-02 17:56:34 +00:00
|
|
|
apply_speaker_configs();
|
2004-09-28 03:55:16 +00:00
|
|
|
apply();
|
2012-01-20 11:42:33 +00:00
|
|
|
SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
|
2005-12-17 11:30:06 +00:00
|
|
|
break;
|
2011-08-31 20:16:16 +00:00
|
|
|
case PSN_SETACTIVE:
|
|
|
|
break;
|
2015-04-14 19:01:46 +00:00
|
|
|
case LVN_ITEMCHANGED:
|
|
|
|
listview_changed(hDlg);
|
|
|
|
break;
|
2011-08-31 20:16:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
initAudioDlg(hDlg);
|
|
|
|
break;
|
2004-01-20 02:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|