Fix <return> key (somehow we get a control keystate).
[wine] / multimedia / mmaux.c
1 /*
2  * Sample AUXILARY Wine Driver
3  *
4  * Copyright 1994 Martin Ayotte
5  */
6
7 #define EMULATE_SB16
8
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <fcntl.h>
13 #include <sys/ioctl.h>
14 #include "windef.h"
15 #include "driver.h"
16 #include "multimedia.h"
17 #include "debugtools.h"
18
19 DEFAULT_DEBUG_CHANNEL(mmaux)
20
21 #define MIXER_DEV "/dev/mixer"
22
23 static int      NumDev = 6;
24
25 /*-----------------------------------------------------------------------*/
26
27
28 /**************************************************************************
29  *                              AUX_GetDevCaps                  [internal]
30  */
31 static DWORD AUX_GetDevCaps(WORD wDevID, LPAUXCAPS16 lpCaps, DWORD dwSize)
32 {
33 #ifdef HAVE_OSS
34         int     mixer,volume;
35         
36         TRACE("(%04X, %p, %lu);\n", wDevID, lpCaps, dwSize);
37         if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
38         if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
39                 WARN("mixer device not available !\n");
40                 return MMSYSERR_NOTENABLED;
41         }
42         if (ioctl(mixer, SOUND_MIXER_READ_LINE, &volume) == -1) {
43                 close(mixer);
44                 WARN("unable read mixer !\n");
45                 return MMSYSERR_NOTENABLED;
46         }
47         close(mixer);
48 #ifdef EMULATE_SB16
49         lpCaps->wMid = 0x0002;
50         lpCaps->vDriverVersion = 0x0200;
51         lpCaps->dwSupport = AUXCAPS_VOLUME | AUXCAPS_LRVOLUME;
52         switch (wDevID) {
53         case 0:
54                 lpCaps->wPid = 0x0196;
55                 strcpy(lpCaps->szPname, "SB16 Aux: Wave");
56                 lpCaps->wTechnology = AUXCAPS_AUXIN;
57                 break;
58         case 1:
59                 lpCaps->wPid = 0x0197;
60                 strcpy(lpCaps->szPname, "SB16 Aux: Midi Synth");
61                 lpCaps->wTechnology = AUXCAPS_AUXIN;
62                 break;
63         case 2:
64                 lpCaps->wPid = 0x0191;
65                 strcpy(lpCaps->szPname, "SB16 Aux: CD");
66                 lpCaps->wTechnology = AUXCAPS_CDAUDIO;
67                 break;
68         case 3:
69                 lpCaps->wPid = 0x0192;
70                 strcpy(lpCaps->szPname, "SB16 Aux: Line-In");
71                 lpCaps->wTechnology = AUXCAPS_AUXIN;
72                 break;
73         case 4:
74                 lpCaps->wPid = 0x0193;
75                 strcpy(lpCaps->szPname, "SB16 Aux: Mic");
76                 lpCaps->wTechnology = AUXCAPS_AUXIN;
77                 break;
78         case 5:
79                 lpCaps->wPid = 0x0194;
80                 strcpy(lpCaps->szPname, "SB16 Aux: Master");
81                 lpCaps->wTechnology = AUXCAPS_AUXIN;
82                 break;
83         }
84 #else
85         lpCaps->wMid = 0xAA;
86         lpCaps->wPid = 0x55;
87         lpCaps->vDriverVersion = 0x0100;
88         strcpy(lpCaps->szPname, "Generic Linux Auxiliary Driver");
89         lpCaps->wTechnology = AUXCAPS_CDAUDIO;
90         lpCaps->dwSupport = AUXCAPS_VOLUME | AUXCAPS_LRVOLUME;
91 #endif
92         return MMSYSERR_NOERROR;
93 #else
94         return MMSYSERR_NOTENABLED;
95 #endif
96 }
97
98
99 /**************************************************************************
100  *                              AUX_GetVolume                   [internal]
101  */
102 static DWORD AUX_GetVolume(WORD wDevID, LPDWORD lpdwVol)
103 {
104 #ifdef HAVE_OSS
105         int     mixer, volume, left, right, cmd;
106         
107         TRACE("(%04X, %p);\n", wDevID, lpdwVol);
108         if (lpdwVol == NULL) return MMSYSERR_NOTENABLED;
109         if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
110                 WARN("mixer device not available !\n");
111                 return MMSYSERR_NOTENABLED;
112         }
113         switch(wDevID) {
114         case 0:
115                 TRACE("SOUND_MIXER_READ_PCM !\n");
116                 cmd = SOUND_MIXER_READ_PCM;
117                 break;
118         case 1:
119                 TRACE("SOUND_MIXER_READ_SYNTH !\n");
120                 cmd = SOUND_MIXER_READ_SYNTH;
121                 break;
122         case 2:
123                 TRACE("SOUND_MIXER_READ_CD !\n");
124                 cmd = SOUND_MIXER_READ_CD;
125                 break;
126         case 3:
127                 TRACE("SOUND_MIXER_READ_LINE !\n");
128                 cmd = SOUND_MIXER_READ_LINE;
129                 break;
130         case 4:
131                 TRACE("SOUND_MIXER_READ_MIC !\n");
132                 cmd = SOUND_MIXER_READ_MIC;
133                 break;
134         case 5:
135                 TRACE("SOUND_MIXER_READ_VOLUME !\n");
136                 cmd = SOUND_MIXER_READ_VOLUME;
137                 break;
138         default:
139                 WARN("invalid device id=%04X !\n", wDevID);
140                 return MMSYSERR_NOTENABLED;
141         }
142         if (ioctl(mixer, cmd, &volume) == -1) {
143                 WARN("unable read mixer !\n");
144                 return MMSYSERR_NOTENABLED;
145         }
146         close(mixer);
147         left  = LOBYTE(LOWORD(volume));
148         right = HIBYTE(LOWORD(volume));
149         TRACE("left=%d right=%d !\n", left, right);
150         *lpdwVol = MAKELONG((left * 0xFFFFL) / 100, (right * 0xFFFFL) / 100);
151         return MMSYSERR_NOERROR;
152 #else
153         return MMSYSERR_NOTENABLED;
154 #endif
155 }
156
157 /**************************************************************************
158  *                              AUX_SetVolume                   [internal]
159  */
160 static DWORD AUX_SetVolume(WORD wDevID, DWORD dwParam)
161 {
162 #ifdef HAVE_OSS
163         int             mixer;
164         int             volume, left, right;
165         int             cmd;
166
167         TRACE("(%04X, %08lX);\n", wDevID, dwParam);
168
169         left   = (LOWORD(dwParam) * 100) >> 16;
170         right  = (HIWORD(dwParam) * 100) >> 16;
171         volume = (right << 8) | left;
172
173         if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
174                 WARN("mixer device not available !\n");
175                 return MMSYSERR_NOTENABLED;
176         }
177
178         switch(wDevID) {
179         case 0:
180                 TRACE("SOUND_MIXER_WRITE_PCM !\n");
181                 cmd = SOUND_MIXER_WRITE_PCM;
182                 break;
183         case 1:
184                 TRACE("SOUND_MIXER_WRITE_SYNTH !\n");
185                 cmd = SOUND_MIXER_WRITE_SYNTH;
186                 break;
187         case 2:
188                 TRACE("SOUND_MIXER_WRITE_CD !\n");
189                 cmd = SOUND_MIXER_WRITE_CD;
190                 break;
191         case 3:
192                 TRACE("SOUND_MIXER_WRITE_LINE !\n");
193                 cmd = SOUND_MIXER_WRITE_LINE;
194                 break;
195         case 4:
196                 TRACE("SOUND_MIXER_WRITE_MIC !\n");
197                 cmd = SOUND_MIXER_WRITE_MIC;
198                 break;
199         case 5:
200                 TRACE("SOUND_MIXER_WRITE_VOLUME !\n");
201                 cmd = SOUND_MIXER_WRITE_VOLUME;
202                 break;
203         default:
204                 WARN("invalid device id=%04X !\n", wDevID);
205                 return MMSYSERR_NOTENABLED;
206         }
207         if (ioctl(mixer, cmd, &volume) == -1) {
208                 WARN("unable set mixer !\n");
209                 return MMSYSERR_NOTENABLED;
210         }
211         close(mixer);
212         return MMSYSERR_NOERROR;
213 #else
214         return MMSYSERR_NOTENABLED;
215 #endif
216 }
217
218
219 /**************************************************************************
220  *                              auxMessage                      [sample driver]
221  */
222 DWORD WINAPI auxMessage(WORD wDevID, WORD wMsg, DWORD dwUser, 
223                                                                 DWORD dwParam1, DWORD dwParam2)
224 {
225         TRACE("(%04X, %04X, %08lX, %08lX, %08lX);\n", 
226                         wDevID, wMsg, dwUser, dwParam1, dwParam2);
227         switch(wMsg) {
228         case AUXDM_GETDEVCAPS:
229                 return AUX_GetDevCaps(wDevID,(LPAUXCAPS16)dwParam1,dwParam2);
230         case AUXDM_GETNUMDEVS:
231                 TRACE("return %d;\n", NumDev);
232                 return NumDev;
233         case AUXDM_GETVOLUME:
234                 return AUX_GetVolume(wDevID,(LPDWORD)dwParam1);
235         case AUXDM_SETVOLUME:
236                 return AUX_SetVolume(wDevID,dwParam1);
237         default:
238                 WARN("unknown message !\n");
239         }
240         return MMSYSERR_NOTSUPPORTED;
241 }