riched20: Make richedit control IME aware.
[wine] / dlls / wineoss.drv / mmaux.c
1 /*
2  * Sample AUXILIARY Wine Driver
3  *
4  * Copyright 1994 Martin Ayotte
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #include <fcntl.h>
31 #ifdef HAVE_SYS_IOCTL_H
32 # include <sys/ioctl.h>
33 #endif
34
35 #include "windef.h"
36 #include "winbase.h"
37 #include "mmddk.h"
38 #include "oss.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(mmaux);
43
44 #ifdef HAVE_OSS
45
46 #define MIXER_DEV "/dev/mixer"
47
48 static int      NumDev = 6;
49
50 /*-----------------------------------------------------------------------*/
51
52 LRESULT OSS_AuxInit(void)
53 {
54     int mixer;
55     TRACE("()\n");
56
57     if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
58         WARN("mixer device not available !\n");
59         NumDev = 0;
60     } else {
61         close(mixer);
62         NumDev = 6;
63     }
64     return 0;
65 }
66
67 /*-----------------------------------------------------------------------*/
68
69 LRESULT OSS_AuxExit(void)
70 {
71     TRACE("()\n");
72     return 0;
73 }
74
75 /**************************************************************************
76  *                              AUX_GetDevCaps                  [internal]
77  */
78 static DWORD AUX_GetDevCaps(WORD wDevID, LPAUXCAPSW lpCaps, DWORD dwSize)
79 {
80     int         mixer, volume;
81     static const WCHAR ini[] = {'O','S','S',' ','A','u','x',0};
82
83     TRACE("(%04X, %p, %u);\n", wDevID, lpCaps, dwSize);
84     if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
85     if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
86         WARN("mixer device not available !\n");
87         return MMSYSERR_NOTENABLED;
88     }
89     if (ioctl(mixer, SOUND_MIXER_READ_LINE, &volume) == -1) {
90         close(mixer);
91         WARN("unable to read mixer !\n");
92         return MMSYSERR_NOTENABLED;
93     }
94     close(mixer);
95     lpCaps->wMid = 0xAA;
96     lpCaps->wPid = 0x55;
97     lpCaps->vDriverVersion = 0x0100;
98     strcpyW(lpCaps->szPname, ini);
99     lpCaps->wTechnology = AUXCAPS_CDAUDIO;
100     lpCaps->dwSupport = AUXCAPS_VOLUME | AUXCAPS_LRVOLUME;
101
102     return MMSYSERR_NOERROR;
103 }
104
105
106 /**************************************************************************
107  *                              AUX_GetVolume                   [internal]
108  */
109 static DWORD AUX_GetVolume(WORD wDevID, LPDWORD lpdwVol)
110 {
111     int         mixer, volume, left, right, cmd;
112
113     TRACE("(%04X, %p);\n", wDevID, lpdwVol);
114     if (lpdwVol == NULL) return MMSYSERR_NOTENABLED;
115     if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
116         WARN("mixer device not available !\n");
117         return MMSYSERR_NOTENABLED;
118     }
119     switch(wDevID) {
120     case 0:
121         TRACE("SOUND_MIXER_READ_PCM !\n");
122         cmd = SOUND_MIXER_READ_PCM;
123         break;
124     case 1:
125         TRACE("SOUND_MIXER_READ_SYNTH !\n");
126         cmd = SOUND_MIXER_READ_SYNTH;
127         break;
128     case 2:
129         TRACE("SOUND_MIXER_READ_CD !\n");
130         cmd = SOUND_MIXER_READ_CD;
131         break;
132     case 3:
133         TRACE("SOUND_MIXER_READ_LINE !\n");
134         cmd = SOUND_MIXER_READ_LINE;
135         break;
136     case 4:
137         TRACE("SOUND_MIXER_READ_MIC !\n");
138         cmd = SOUND_MIXER_READ_MIC;
139         break;
140     case 5:
141         TRACE("SOUND_MIXER_READ_VOLUME !\n");
142         cmd = SOUND_MIXER_READ_VOLUME;
143         break;
144     default:
145         WARN("invalid device id=%04X !\n", wDevID);
146         return MMSYSERR_NOTENABLED;
147     }
148     if (ioctl(mixer, cmd, &volume) == -1) {
149         WARN("unable to read mixer !\n");
150         return MMSYSERR_NOTENABLED;
151     }
152     close(mixer);
153     left  = LOBYTE(LOWORD(volume));
154     right = HIBYTE(LOWORD(volume));
155     TRACE("left=%d right=%d !\n", left, right);
156     *lpdwVol = MAKELONG((left * 0xFFFFL) / 100, (right * 0xFFFFL) / 100);
157     return MMSYSERR_NOERROR;
158 }
159
160 /**************************************************************************
161  *                              AUX_SetVolume                   [internal]
162  */
163 static DWORD AUX_SetVolume(WORD wDevID, DWORD dwParam)
164 {
165     int         mixer;
166     int         volume, left, right;
167     int         cmd;
168
169     TRACE("(%04X, %08X);\n", wDevID, dwParam);
170
171     left   = (LOWORD(dwParam) * 100) >> 16;
172     right  = (HIWORD(dwParam) * 100) >> 16;
173     volume = (right << 8) | left;
174
175     if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
176         WARN("mixer device not available !\n");
177         return MMSYSERR_NOTENABLED;
178     }
179
180     switch(wDevID) {
181     case 0:
182         TRACE("SOUND_MIXER_WRITE_PCM !\n");
183         cmd = SOUND_MIXER_WRITE_PCM;
184         break;
185     case 1:
186         TRACE("SOUND_MIXER_WRITE_SYNTH !\n");
187         cmd = SOUND_MIXER_WRITE_SYNTH;
188         break;
189     case 2:
190         TRACE("SOUND_MIXER_WRITE_CD !\n");
191         cmd = SOUND_MIXER_WRITE_CD;
192         break;
193     case 3:
194         TRACE("SOUND_MIXER_WRITE_LINE !\n");
195         cmd = SOUND_MIXER_WRITE_LINE;
196         break;
197     case 4:
198         TRACE("SOUND_MIXER_WRITE_MIC !\n");
199         cmd = SOUND_MIXER_WRITE_MIC;
200         break;
201     case 5:
202         TRACE("SOUND_MIXER_WRITE_VOLUME !\n");
203         cmd = SOUND_MIXER_WRITE_VOLUME;
204         break;
205     default:
206         WARN("invalid device id=%04X !\n", wDevID);
207         return MMSYSERR_NOTENABLED;
208     }
209     if (ioctl(mixer, cmd, &volume) == -1) {
210         WARN("unable to set mixer !\n");
211         return MMSYSERR_NOTENABLED;
212     }
213     close(mixer);
214     return MMSYSERR_NOERROR;
215 }
216
217 #endif
218
219 /**************************************************************************
220  *              auxMessage (WINEOSS.2)
221  */
222 DWORD WINAPI OSS_auxMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
223                             DWORD dwParam1, DWORD dwParam2)
224 {
225     TRACE("(%04X, %04X, %08X, %08X, %08X);\n",
226           wDevID, wMsg, dwUser, dwParam1, dwParam2);
227
228 #ifdef HAVE_OSS
229     switch (wMsg) {
230     case DRVM_INIT:
231     case DRVM_EXIT:
232     case DRVM_ENABLE:
233     case DRVM_DISABLE:
234         /* FIXME: Pretend this is supported */
235         return 0;
236     case AUXDM_GETDEVCAPS:
237         return AUX_GetDevCaps(wDevID, (LPAUXCAPSW)dwParam1, dwParam2);
238     case AUXDM_GETNUMDEVS:
239         TRACE("return %d;\n", NumDev);
240         return NumDev;
241     case AUXDM_GETVOLUME:
242         return AUX_GetVolume(wDevID, (LPDWORD)dwParam1);
243     case AUXDM_SETVOLUME:
244         return AUX_SetVolume(wDevID, dwParam1);
245     default:
246         WARN("unknown message !\n");
247     }
248     return MMSYSERR_NOTSUPPORTED;
249 #else
250     return MMSYSERR_NOTENABLED;
251 #endif
252 }