Create a branch for working on csrss and co.
[reactos.git] / dll / cpl / mmsys / audio.c
1 /*
2 *
3 * PROJECT: ReactOS Multimedia Control Panel
4 * FILE: dll/cpl/mmsys/mmsys.c
5 * PURPOSE: ReactOS Multimedia Control Panel
6 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
7 * Johannes Anderwald <janderwald@reactos.com>
8 * Dmitry Chapyshev <dmitry@reactos.org>
9 */
10
11 #include "mmsys.h"
12
13 VOID
14 InitAudioDlg(HWND hwnd)
15 {
16 WAVEOUTCAPSW waveOutputPaps;
17 WAVEINCAPS waveInputPaps;
18 MIDIOUTCAPS midiOutCaps;
19 TCHAR szNoDevices[256];
20 UINT DevsNum;
21 UINT uIndex;
22 HWND hCB;
23 LRESULT Res;
24
25 LoadString(hApplet, IDS_NO_DEVICES, szNoDevices, sizeof(szNoDevices) / sizeof(TCHAR));
26
27 // Init sound playback devices list
28 hCB = GetDlgItem(hwnd, IDC_DEVICE_PLAY_LIST);
29
30 DevsNum = waveOutGetNumDevs();
31 if (DevsNum < 1)
32 {
33 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM)szNoDevices);
34 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0);
35 }
36 else
37 {
38 WCHAR DefaultDevice[MAX_PATH] = {0};
39 HKEY hKey;
40 DWORD dwSize = sizeof(DefaultDevice);
41 UINT DefaultIndex = 0;
42
43 if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Multimedia\\Sound Mapper", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
44 {
45 RegQueryValueExW(hKey, L"Playback", NULL, NULL, (LPBYTE)DefaultDevice, &dwSize);
46 DefaultDevice[MAX_PATH-1] = L'\0';
47 RegCloseKey(hKey);
48 }
49
50 for (uIndex = 0; uIndex < DevsNum; uIndex++)
51 {
52 if (waveOutGetDevCapsW(uIndex, &waveOutputPaps, sizeof(waveOutputPaps)))
53 continue;
54
55 Res = SendMessageW(hCB, CB_ADDSTRING, 0, (LPARAM) waveOutputPaps.szPname);
56
57 if (CB_ERR != Res)
58 {
59 SendMessage(hCB, CB_SETITEMDATA, Res, (LPARAM) uIndex);
60 if (!wcsicmp(waveOutputPaps.szPname, DefaultDevice))
61 DefaultIndex = Res;
62 }
63 }
64 SendMessage(hCB, CB_SETCURSEL, (WPARAM) DefaultIndex, 0);
65 }
66
67 // Init sound recording devices list
68 hCB = GetDlgItem(hwnd, IDC_DEVICE_REC_LIST);
69
70 DevsNum = waveInGetNumDevs();
71 if (DevsNum < 1)
72 {
73 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM)szNoDevices);
74 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0);
75 }
76 else
77 {
78 WCHAR DefaultDevice[MAX_PATH] = {0};
79 HKEY hKey;
80 DWORD dwSize = sizeof(DefaultDevice);
81 UINT DefaultIndex = 0;
82
83 if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Multimedia\\Sound Mapper", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
84 {
85 RegQueryValueExW(hKey, L"Record", NULL, NULL, (LPBYTE)DefaultDevice, &dwSize);
86 DefaultDevice[MAX_PATH-1] = L'\0';
87 RegCloseKey(hKey);
88 }
89
90
91 for (uIndex = 0; uIndex < DevsNum; uIndex++)
92 {
93 if (waveInGetDevCaps(uIndex, &waveInputPaps, sizeof(waveInputPaps)))
94 continue;
95
96 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM) waveInputPaps.szPname);
97
98 if (CB_ERR != Res)
99 {
100 SendMessage(hCB, CB_SETITEMDATA, Res, (LPARAM) uIndex);
101 if (!wcsicmp(waveInputPaps.szPname, DefaultDevice))
102 DefaultIndex = Res;
103 }
104 }
105 SendMessage(hCB, CB_SETCURSEL, (WPARAM) DefaultIndex, 0);
106 }
107
108 // Init MIDI devices list
109 hCB = GetDlgItem(hwnd, IDC_DEVICE_MIDI_LIST);
110
111 DevsNum = midiOutGetNumDevs();
112 if (DevsNum < 1)
113 {
114 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM)szNoDevices);
115 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0);
116 }
117 else
118 {
119 for (uIndex = 0; uIndex < DevsNum; uIndex++)
120 {
121 if (midiOutGetDevCaps(uIndex, &midiOutCaps, sizeof(midiOutCaps)))
122 continue;
123
124 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM) midiOutCaps.szPname);
125
126 if (CB_ERR != Res)
127 {
128 SendMessage(hCB, CB_SETITEMDATA, Res, (LPARAM) uIndex);
129 // TODO: Getting default device
130 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0);
131 }
132 }
133 }
134 }
135
136 static UINT
137 GetDevNum(HWND hControl, DWORD Id)
138 {
139 int iCurSel;
140 UINT DevNum;
141
142 iCurSel = SendMessage(hControl, CB_GETCURSEL, 0, 0);
143
144 if (iCurSel == CB_ERR)
145 return 0;
146
147 DevNum = (UINT) SendMessage(hControl, CB_GETITEMDATA, iCurSel, 0);
148 if (DevNum == (UINT) CB_ERR)
149 return 0;
150
151 if (mixerGetID((HMIXEROBJ)IntToPtr(DevNum), &DevNum, Id) != MMSYSERR_NOERROR)
152 return 0;
153
154 return DevNum;
155 }
156
157 /* Audio property page dialog callback */
158 INT_PTR CALLBACK
159 AudioDlgProc(HWND hwndDlg,
160 UINT uMsg,
161 WPARAM wParam,
162 LPARAM lParam)
163 {
164 UNREFERENCED_PARAMETER(lParam);
165 UNREFERENCED_PARAMETER(wParam);
166 UNREFERENCED_PARAMETER(hwndDlg);
167
168 switch(uMsg)
169 {
170 case WM_INITDIALOG:
171 {
172 UINT NumWavOut = waveOutGetNumDevs();
173
174 InitAudioDlg(hwndDlg);
175
176 if (!NumWavOut)
177 {
178 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_PLAY_LIST), FALSE);
179 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_REC_LIST), FALSE);
180 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_MIDI_LIST), FALSE);
181 EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_DEV_CHECKBOX), FALSE);
182 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME1_BTN), FALSE);
183 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV2_BTN), FALSE);
184 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME2_BTN), FALSE);
185 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV1_BTN), FALSE);
186 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME3_BTN), FALSE);
187 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV3_BTN), FALSE);
188 }
189 }
190 break;
191
192 case WM_COMMAND:
193 {
194 STARTUPINFO si;
195 PROCESS_INFORMATION pi;
196 WCHAR szPath[MAX_PATH];
197
198 switch(LOWORD(wParam))
199 {
200 case IDC_VOLUME1_BTN:
201 {
202 wsprintf(szPath, L"sndvol32.exe -d %d",
203 GetDevNum(GetDlgItem(hwndDlg, IDC_DEVICE_PLAY_LIST), MIXER_OBJECTF_WAVEOUT));
204
205 ZeroMemory(&si, sizeof(si));
206 si.cb = sizeof(si);
207 si.wShowWindow = SW_SHOW;
208
209 CreateProcess(NULL, szPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
210 }
211 break;
212
213 case IDC_ADV2_BTN:
214 {
215
216 }
217 break;
218
219 case IDC_VOLUME2_BTN:
220 {
221 wsprintf(szPath, L"sndvol32.exe -r -d %d",
222 GetDevNum(GetDlgItem(hwndDlg, IDC_DEVICE_REC_LIST), MIXER_OBJECTF_WAVEIN));
223
224 ZeroMemory(&si, sizeof(si));
225 si.cb = sizeof(si);
226 si.wShowWindow = SW_SHOW;
227
228 CreateProcess(NULL, szPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
229 }
230 break;
231
232 case IDC_ADV1_BTN:
233 {
234
235 }
236 break;
237
238 case IDC_VOLUME3_BTN:
239 {
240 wsprintf(szPath, L"sndvol32.exe -d %d",
241 GetDevNum(GetDlgItem(hwndDlg, IDC_DEVICE_MIDI_LIST), MIXER_OBJECTF_MIDIOUT));
242
243 ZeroMemory(&si, sizeof(si));
244 si.cb = sizeof(si);
245 si.wShowWindow = SW_SHOW;
246
247 CreateProcess(NULL, szPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
248 }
249 break;
250
251 case IDC_ADV3_BTN:
252 {
253
254 }
255 break;
256 }
257 }
258 break;
259 }
260
261 return FALSE;
262 }