winecfg: Remove driver selection from Audio tab.
[wine/multimedia.git] / programs / winecfg / audio.c
blobf8b84d44b24ea5f98d0d59a124bb941121933e1e
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 #define COBJMACROS
35 #include <windows.h>
36 #include <wine/debug.h>
37 #include <shellapi.h>
38 #include <objbase.h>
39 #include <shlguid.h>
40 #include <shlwapi.h>
41 #include <shlobj.h>
42 #include <mmsystem.h>
43 #include <mmreg.h>
44 #include <mmddk.h>
46 #include "ole2.h"
47 #include "initguid.h"
48 #include "devpkey.h"
49 #include "mmdeviceapi.h"
50 #include "audioclient.h"
51 #include "audiopolicy.h"
53 #include "winecfg.h"
54 #include "resource.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
58 static struct DSOUNDACCEL
60 UINT displayID;
61 UINT visible;
62 const char* settingStr;
63 } DSound_HW_Accels[] = {
64 {IDS_ACCEL_FULL, 1, "Full"},
65 {IDS_ACCEL_STANDARD, 0, "Standard"},
66 {IDS_ACCEL_BASIC, 0, "Basic"},
67 {IDS_ACCEL_EMULATION, 1, "Emulation"},
68 {0, 0, 0}
71 static const char* DSound_Rates[] = {
72 "48000",
73 "44100",
74 "22050",
75 "16000",
76 "11025",
77 "8000",
78 NULL
81 static const char* DSound_Bits[] = {
82 "8",
83 "16",
84 NULL
87 static void initAudioDlg (HWND hDlg)
89 int i, j, found;
90 char* buf = NULL;
92 WINE_TRACE("\n");
94 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_RESETCONTENT, 0, 0);
95 buf = get_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration", "Full");
97 j = found = 0;
98 for (i = 0; 0 != DSound_HW_Accels[i].displayID; ++i) {
99 WCHAR accelStr[64];
100 int match;
102 match = (strcmp(buf, DSound_HW_Accels[i].settingStr) == 0);
103 if (match)
105 DSound_HW_Accels[i].visible = 1;
106 found = 1;
109 if (DSound_HW_Accels[i].visible)
111 LoadStringW (GetModuleHandle (NULL), DSound_HW_Accels[i].displayID,
112 accelStr, sizeof(accelStr)/sizeof(accelStr[0]));
113 SendDlgItemMessageW (hDlg, IDC_DSOUND_HW_ACCEL, CB_ADDSTRING, 0, (LPARAM)accelStr);
114 if (match)
115 SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_SETCURSEL, j, 0);
116 j++;
119 if (!found) {
120 WINE_ERR("Invalid Direct Sound HW Accel read from registry (%s)\n", buf);
122 HeapFree(GetProcessHeap(), 0, buf);
124 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_RESETCONTENT, 0, 0);
125 for (i = 0; NULL != DSound_Rates[i]; ++i) {
126 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_ADDSTRING, 0, (LPARAM) DSound_Rates[i]);
128 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", "44100");
129 for (i = 0; NULL != DSound_Rates[i]; ++i) {
130 if (strcmp(buf, DSound_Rates[i]) == 0) {
131 SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_SETCURSEL, i, 0);
132 break ;
136 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_RESETCONTENT, 0, 0);
137 for (i = 0; NULL != DSound_Bits[i]; ++i) {
138 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_ADDSTRING, 0, (LPARAM) DSound_Bits[i]);
140 buf = get_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", "16");
141 for (i = 0; NULL != DSound_Bits[i]; ++i) {
142 if (strcmp(buf, DSound_Bits[i]) == 0) {
143 SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_SETCURSEL, i, 0);
144 break ;
147 HeapFree(GetProcessHeap(), 0, buf);
150 INT_PTR CALLBACK
151 AudioDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
153 switch (uMsg) {
154 case WM_COMMAND:
155 switch (LOWORD(wParam)) {
156 case IDC_AUDIO_TEST:
157 if(!PlaySound(MAKEINTRESOURCE(IDW_TESTSOUND), NULL, SND_RESOURCE | SND_SYNC))
158 MessageBox(NULL, "Audio test failed!", "Error", MB_OK | MB_ICONERROR);
159 break;
160 case IDC_DSOUND_HW_ACCEL:
161 if (HIWORD(wParam) == CBN_SELCHANGE) {
162 int selected_dsound_accel;
163 int i, j = 0;
165 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
166 selected_dsound_accel = SendDlgItemMessage(hDlg, IDC_DSOUND_HW_ACCEL, CB_GETCURSEL, 0, 0);
167 for (i = 0; DSound_HW_Accels[i].settingStr; ++i)
169 if (DSound_HW_Accels[i].visible)
171 if (j == selected_dsound_accel)
173 set_reg_key(config_key, keypath("DirectSound"), "HardwareAcceleration",
174 DSound_HW_Accels[i].settingStr);
175 break;
177 j++;
181 break;
182 case IDC_DSOUND_RATES:
183 if (HIWORD(wParam) == CBN_SELCHANGE) {
184 int selected_dsound_rate;
185 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
186 selected_dsound_rate = SendDlgItemMessage(hDlg, IDC_DSOUND_RATES, CB_GETCURSEL, 0, 0);
187 set_reg_key(config_key, keypath("DirectSound"), "DefaultSampleRate", DSound_Rates[selected_dsound_rate]);
189 break;
190 case IDC_DSOUND_BITS:
191 if (HIWORD(wParam) == CBN_SELCHANGE) {
192 int selected_dsound_bits;
193 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
194 selected_dsound_bits = SendDlgItemMessage(hDlg, IDC_DSOUND_BITS, CB_GETCURSEL, 0, 0);
195 set_reg_key(config_key, keypath("DirectSound"), "DefaultBitsPerSample", DSound_Bits[selected_dsound_bits]);
197 break;
199 break;
200 case WM_SHOWWINDOW:
201 set_window_title(hDlg);
202 break;
204 case WM_NOTIFY:
205 switch(((LPNMHDR)lParam)->code) {
206 case PSN_KILLACTIVE:
207 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
208 break;
209 case PSN_APPLY:
210 apply();
211 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
212 break;
213 case PSN_SETACTIVE:
214 break;
216 break;
217 case WM_INITDIALOG:
218 initAudioDlg(hDlg);
219 break;
222 return FALSE;