Release 980927
[wine.git] / multimedia / init.c
blob0e3e0b08e76a30ed939ef93b43022eb51525e780
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * Initialization procedures for multimedia
6 * Copyright 1998 Luiz Otavio L. Zorzella
7 */
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <sys/ioctl.h>
12 #include "windows.h"
13 #include "multimedia.h"
14 #include "mmsystem.h"
15 #include "xmalloc.h"
16 #include "debug.h"
18 #ifdef HAVE_OSS
20 extern int MODM_NUMDEVS;
21 extern int MODM_NUMFMSYNTHDEVS;
22 extern int MODM_NUMMIDIDEVS;
23 extern LPMIDIOUTCAPS16 midiOutDevices[MAX_MIDIOUTDRV];
25 extern int MIDM_NUMDEVS;
26 extern LPMIDIINCAPS16 midiInDevices [MAX_MIDIINDRV];
28 #endif
30 /**************************************************************************
31 * unixToWindowsDeviceType [internal]
33 * return the Windows equivalent to a Unix Device Type
36 #ifdef HAVE_OSS
37 int unixToWindowsDeviceType(int type)
39 /* MOD_MIDIPORT output port
40 * MOD_SYNTH generic internal synth
41 * MOD_SQSYNTH square wave internal synth
42 * MOD_FMSYNTH FM internal synth
43 * MOD_MAPPER MIDI mapper
46 /* FIXME Is this really the correct equivalence from UNIX to
47 Windows Sound type */
49 switch (type) {
50 case SYNTH_TYPE_FM: return MOD_FMSYNTH;
51 case SYNTH_TYPE_SAMPLE: return MOD_SYNTH;
52 case SYNTH_TYPE_MIDI: return MOD_MIDIPORT;
53 default:
54 ERR(midi, "Cannot determine the type of this midi device. "
55 "Assuming FM Synth\n");
56 return MOD_FMSYNTH;
59 #endif
61 /**************************************************************************
62 * MultimediaInit [internal]
64 * Initializes the MIDI devices information variables
67 BOOL32 MULTIMEDIA_Init(void)
69 #ifdef HAVE_OSS
70 int i, status, numsynthdevs = 255, nummididevs = 255;
71 struct synth_info sinfo;
72 struct midi_info minfo;
73 int fd; /* file descriptor for MIDI_SEQ */
75 TRACE(midi, "Initializing the MIDI variables.\n");
77 /* try to open device */
78 /* FIXME: should use function midiOpenSeq() in midi.c */
79 fd = open(MIDI_SEQ, O_WRONLY);
80 if (fd == -1) {
81 TRACE(midi, "No sequencer found: unable to open `%s'.\n", MIDI_SEQ);
82 return TRUE;
85 /* find how many Synth devices are there in the system */
86 status = ioctl(fd, SNDCTL_SEQ_NRSYNTHS, &numsynthdevs);
88 if (status == -1) {
89 ERR(midi, "ioctl for nr synth failed.\n");
90 close(fd);
91 return TRUE;
94 if (numsynthdevs > MAX_MIDIOUTDRV) {
95 ERR(midi, "MAX_MIDIOUTDRV was enough for the number of devices. "
96 "Some FM devices will not be available.\n");
97 numsynthdevs = MAX_MIDIOUTDRV;
100 for (i = 0; i < numsynthdevs; i++) {
101 LPMIDIOUTCAPS16 tmplpCaps;
103 sinfo.device = i;
104 status = ioctl(fd, SNDCTL_SYNTH_INFO, &sinfo);
105 if (status == -1) {
106 ERR(midi, "ioctl for synth info failed.\n");
107 close(fd);
108 return TRUE;
111 tmplpCaps = xmalloc(sizeof(MIDIOUTCAPS16));
112 /* We also have the information sinfo.synth_subtype, not used here
115 /* Manufac ID. We do not have access to this with soundcard.h
116 * Does not seem to be a problem, because in mmsystem.h only
117 * Microsoft's ID is listed.
119 tmplpCaps->wMid = 0x00FF;
120 tmplpCaps->wPid = 0x0001; /* FIXME Product ID */
121 /* Product Version. We simply say "1" */
122 tmplpCaps->vDriverVersion = 0x001;
123 strcpy(tmplpCaps->szPname, sinfo.name);
125 tmplpCaps->wTechnology = unixToWindowsDeviceType(sinfo.synth_type);
126 tmplpCaps->wVoices = sinfo.nr_voices;
128 /* FIXME Is it possible to know the maximum
129 * number of simultaneous notes of a soundcard ?
130 * I believe we don't have this information, but
131 * it's probably equal or more than wVoices
133 tmplpCaps->wNotes = sinfo.nr_voices;
135 /* FIXME Do we have this information?
136 * Assuming the soundcards can handle
137 * MIDICAPS_VOLUME and MIDICAPS_LRVOLUME but
138 * not MIDICAPS_CACHE.
140 tmplpCaps->dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
142 midiOutDevices[i] = tmplpCaps;
144 if (sinfo.capabilities & SYNTH_CAP_INPUT) {
145 FIXME(midi, "Synthetizer support MIDI in. Not supported yet (please report)\n");
148 TRACE(midi, "name='%s', techn=%d voices=%d notes=%d support=%ld\n",
149 tmplpCaps->szPname, tmplpCaps->wTechnology,
150 tmplpCaps->wVoices, tmplpCaps->wNotes, tmplpCaps->dwSupport);
151 TRACE(midi,"OSS info: synth subtype=%d capa=%Xh\n",
152 sinfo.synth_subtype, sinfo.capabilities);
155 /* find how many MIDI devices are there in the system */
156 status = ioctl(fd, SNDCTL_SEQ_NRMIDIS, &nummididevs);
157 if (status == -1) {
158 ERR(midi, "ioctl on nr midi failed.\n");
159 return TRUE;
162 /* FIXME: the two restrictions below could be loosen in some cases */
163 if (numsynthdevs + nummididevs > MAX_MIDIOUTDRV) {
164 ERR(midi, "MAX_MIDIOUTDRV was not enough for the number of devices. "
165 "Some MIDI devices will not be available.\n");
166 nummididevs = MAX_MIDIOUTDRV - numsynthdevs;
169 if (nummididevs > MAX_MIDIINDRV) {
170 ERR(midi, "MAX_MIDIINDRV was not enough for the number of devices. "
171 "Some MIDI devices will not be available.\n");
172 nummididevs = MAX_MIDIINDRV;
175 for (i = 0; i < nummididevs; i++) {
176 LPMIDIOUTCAPS16 tmplpOutCaps;
177 LPMIDIINCAPS16 tmplpInCaps;
179 minfo.device = i;
180 status = ioctl(fd, SNDCTL_MIDI_INFO, &minfo);
181 if (status == -1) {
182 ERR(midi, "ioctl on midi info failed.\n");
183 close(fd);
184 return TRUE;
187 tmplpOutCaps = xmalloc(sizeof(MIDIOUTCAPS16));
188 /* This whole part is somewhat obscure to me. I'll keep trying to dig
189 info about it. If you happen to know, please tell us. The very
190 descritive minfo.dev_type was not used here.
192 /* Manufac ID. We do not have access to this with soundcard.h
193 Does not seem to be a problem, because in mmsystem.h only
194 Microsoft's ID is listed */
195 tmplpOutCaps->wMid = 0x00FF;
196 tmplpOutCaps->wPid = 0x0001; /* FIXME Product ID */
197 /* Product Version. We simply say "1" */
198 tmplpOutCaps->vDriverVersion = 0x001;
199 strcpy(tmplpOutCaps->szPname, minfo.name);
201 tmplpOutCaps->wTechnology = MOD_MIDIPORT; /* FIXME Is this right? */
202 /* Does it make any difference? */
203 tmplpOutCaps->wVoices = 16;
204 /* Does it make any difference? */
205 tmplpOutCaps->wNotes = 16;
206 /* FIXME Does it make any difference? */
207 tmplpOutCaps->dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
209 midiOutDevices[numsynthdevs + i] = tmplpOutCaps;
211 tmplpInCaps = xmalloc(sizeof(MIDIOUTCAPS16));
212 /* This whole part is somewhat obscure to me. I'll keep trying to dig
213 info about it. If you happen to know, please tell us. The very
214 descritive minfo.dev_type was not used here.
216 /* Manufac ID. We do not have access to this with soundcard.h
217 Does not seem to be a problem, because in mmsystem.h only
218 Microsoft's ID is listed */
219 tmplpInCaps->wMid = 0x00FF;
220 tmplpInCaps->wPid = 0x0001; /* FIXME Product ID */
221 /* Product Version. We simply say "1" */
222 tmplpInCaps->vDriverVersion = 0x001;
223 strcpy(tmplpInCaps->szPname, minfo.name);
225 /* FIXME : could we get better information than that ? */
226 tmplpInCaps->dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
228 midiInDevices[i] = tmplpInCaps;
230 TRACE(midi,"name='%s' techn=%d voices=%d notes=%d support=%ld\n",
231 tmplpOutCaps->szPname, tmplpOutCaps->wTechnology, tmplpOutCaps->wVoices,
232 tmplpOutCaps->wNotes, tmplpOutCaps->dwSupport);
233 TRACE(midi,"OSS info: midi dev-type=%d, capa=%d\n",
234 minfo.dev_type, minfo.capabilities);
237 /* windows does not seem to differentiate Synth from MIDI devices */
238 MODM_NUMFMSYNTHDEVS = numsynthdevs;
239 MODM_NUMMIDIDEVS = nummididevs;
240 MODM_NUMDEVS = numsynthdevs + nummididevs;
242 MIDM_NUMDEVS = nummididevs;
244 /* close file and exit */
245 close(fd);
246 #endif /* HAVE_OSS */
248 return TRUE;