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