Sync to trunk head(r38096)
[reactos.git] / reactos / dll / cpl / mmsys / audio.c
1 /*
2 *
3 * PROJECT: ReactOS Multimedia Control Panel
4 * FILE: lib/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 <windows.h>
12 #include <commctrl.h>
13 #include <cpl.h>
14 #include <tchar.h>
15 #include <stdio.h>
16 #include "mmsys.h"
17 #include "resource.h"
18
19
20 VOID
21 InitAudioDlg(HWND hwnd)
22 {
23 WAVEOUTCAPS waveOutputPaps;
24 WAVEINCAPS waveInputPaps;
25 MIDIOUTCAPS midiOutCaps;
26 UINT DevsNum;
27 UINT uIndex;
28 HWND hCB;
29 LRESULT Res;
30
31 // Init sound playback devices list
32 hCB = GetDlgItem(hwnd, IDC_DEVICE_PLAY_LIST);
33
34 DevsNum = waveOutGetNumDevs();
35 if (DevsNum < 1) return;
36
37 for (uIndex = 0; uIndex < DevsNum; uIndex++)
38 {
39 if (waveOutGetDevCaps(uIndex, &waveOutputPaps, sizeof(waveOutputPaps)))
40 continue;
41
42 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM) waveOutputPaps.szPname);
43
44 if (CB_ERR != Res)
45 {
46 SendMessage(hCB, CB_SETITEMDATA, Res, (LPARAM) uIndex);
47 // TODO: Getting default device
48 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0);
49 }
50 }
51
52 // Init sound recording devices list
53 hCB = GetDlgItem(hwnd, IDC_DEVICE_REC_LIST);
54
55 DevsNum = waveInGetNumDevs();
56 if (DevsNum < 1) return;
57
58 for (uIndex = 0; uIndex < DevsNum; uIndex++)
59 {
60 if (waveInGetDevCaps(uIndex, &waveInputPaps, sizeof(waveInputPaps)))
61 continue;
62
63 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM) waveInputPaps.szPname);
64
65 if (CB_ERR != Res)
66 {
67 SendMessage(hCB, CB_SETITEMDATA, Res, (LPARAM) uIndex);
68 // TODO: Getting default device
69 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0);
70 }
71 }
72
73 // Init MIDI devices list
74 hCB = GetDlgItem(hwnd, IDC_DEVICE_MIDI_LIST);
75
76 DevsNum = midiOutGetNumDevs();
77 if (DevsNum < 1) return;
78
79 for (uIndex = 0; uIndex < DevsNum; uIndex++)
80 {
81 if (midiOutGetDevCaps(uIndex, &midiOutCaps, sizeof(midiOutCaps)))
82 continue;
83
84 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM) midiOutCaps.szPname);
85
86 if (CB_ERR != Res)
87 {
88 SendMessage(hCB, CB_SETITEMDATA, Res, (LPARAM) uIndex);
89 // TODO: Getting default device
90 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0);
91 }
92 }
93 }
94
95 static UINT
96 GetDevNum(HWND hControl, DWORD Id)
97 {
98 int iCurSel;
99 UINT DevNum;
100
101 iCurSel = SendMessage(hControl, CB_GETCURSEL, 0, 0);
102
103 if (iCurSel == CB_ERR)
104 return 0;
105
106 DevNum = (UINT) SendMessage(hControl, CB_GETITEMDATA, iCurSel, 0);
107 if (DevNum == (UINT) CB_ERR)
108 return 0;
109
110 if (mixerGetID((HMIXEROBJ)IntToPtr(DevNum), &DevNum, Id) != MMSYSERR_NOERROR)
111 return 0;
112
113 return DevNum;
114 }
115
116 /* Audio property page dialog callback */
117 INT_PTR CALLBACK
118 AudioDlgProc(HWND hwndDlg,
119 UINT uMsg,
120 WPARAM wParam,
121 LPARAM lParam)
122 {
123 UNREFERENCED_PARAMETER(lParam);
124 UNREFERENCED_PARAMETER(wParam);
125 UNREFERENCED_PARAMETER(hwndDlg);
126
127 switch(uMsg)
128 {
129 case WM_INITDIALOG:
130 {
131 UINT NumWavOut;
132
133 NumWavOut = waveOutGetNumDevs();
134 if (!NumWavOut)
135 {
136 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_PLAY_LIST), FALSE);
137 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_REC_LIST), FALSE);
138 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_MIDI_LIST), FALSE);
139 EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_DEV_CHECKBOX), FALSE);
140 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME1_BTN), FALSE);
141 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV2_BTN), FALSE);
142 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME2_BTN), FALSE);
143 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV1_BTN), FALSE);
144 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME3_BTN), FALSE);
145 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV3_BTN), FALSE);
146 }
147 else
148 {
149 InitAudioDlg(hwndDlg);
150 }
151 }
152 break;
153
154 case WM_COMMAND:
155 {
156 STARTUPINFO si;
157 PROCESS_INFORMATION pi;
158 WCHAR szPath[MAX_PATH];
159
160 switch(LOWORD(wParam))
161 {
162 case IDC_VOLUME1_BTN:
163 {
164 wsprintf(szPath, L"sndvol32.exe -d %d",
165 GetDevNum(GetDlgItem(hwndDlg, IDC_DEVICE_PLAY_LIST), MIXER_OBJECTF_WAVEOUT));
166
167 ZeroMemory(&si, sizeof(si));
168 si.cb = sizeof(si);
169 si.wShowWindow = SW_SHOW;
170
171 CreateProcess(NULL, szPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
172 }
173 break;
174
175 case IDC_ADV2_BTN:
176 {
177
178 }
179 break;
180
181 case IDC_VOLUME2_BTN:
182 {
183 wsprintf(szPath, L"sndvol32.exe -r -d %d",
184 GetDevNum(GetDlgItem(hwndDlg, IDC_DEVICE_REC_LIST), MIXER_OBJECTF_WAVEIN));
185
186 ZeroMemory(&si, sizeof(si));
187 si.cb = sizeof(si);
188 si.wShowWindow = SW_SHOW;
189
190 CreateProcess(NULL, szPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
191 }
192 break;
193
194 case IDC_ADV1_BTN:
195 {
196
197 }
198 break;
199
200 case IDC_VOLUME3_BTN:
201 {
202 wsprintf(szPath, L"sndvol32.exe -d %d",
203 GetDevNum(GetDlgItem(hwndDlg, IDC_DEVICE_MIDI_LIST), MIXER_OBJECTF_MIDIOUT));
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_ADV3_BTN:
214 {
215
216 }
217 break;
218 }
219 }
220 break;
221 }
222
223 return FALSE;
224 }