Release 990226.
[wine/gsoc-2012-control.git] / multimedia / init.c
blob92f7769c4e8840a035e1b4251f3b82c1dae5b5d2
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 "winbase.h"
13 #include "multimedia.h"
14 #include "xmalloc.h"
15 #include "debug.h"
17 #ifdef HAVE_OSS
19 extern int MODM_NUMDEVS;
20 extern int MODM_NUMFMSYNTHDEVS;
21 extern int MODM_NUMMIDIDEVS;
22 extern LPMIDIOUTCAPS16 midiOutDevices[MAX_MIDIOUTDRV];
24 extern int MIDM_NUMDEVS;
25 extern LPMIDIINCAPS16 midiInDevices [MAX_MIDIINDRV];
27 #endif
29 /**************************************************************************
30 * unixToWindowsDeviceType [internal]
32 * return the Windows equivalent to a Unix Device Type
35 #ifdef HAVE_OSS
36 int unixToWindowsDeviceType(int type)
38 #if !defined(__NetBSD__) && !defined(__OpenBSD__)
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;
58 #else
59 return MOD_FMSYNTH;
60 #endif
62 #endif
64 /**************************************************************************
65 * MULTIMEDIA_MidiInit [internal]
67 * Initializes the MIDI devices information variables
70 BOOL MULTIMEDIA_MidiInit(void)
72 #if defined(HAVE_OSS) && !defined(__NetBSD__) && !defined(__OpenBSD__)
73 int i, status, numsynthdevs = 255, nummididevs = 255;
74 struct synth_info sinfo;
75 struct midi_info minfo;
76 int fd; /* file descriptor for MIDI_SEQ */
78 TRACE(midi, "Initializing the MIDI variables.\n");
80 /* try to open device */
81 /* FIXME: should use function midiOpenSeq() in midi.c */
82 fd = open(MIDI_SEQ, O_WRONLY);
83 if (fd == -1) {
84 TRACE(midi, "No sequencer found: unable to open `%s'.\n", MIDI_SEQ);
85 return TRUE;
88 /* find how many Synth devices are there in the system */
89 status = ioctl(fd, SNDCTL_SEQ_NRSYNTHS, &numsynthdevs);
91 if (status == -1) {
92 ERR(midi, "ioctl for nr synth failed.\n");
93 close(fd);
94 return TRUE;
97 if (numsynthdevs > MAX_MIDIOUTDRV) {
98 ERR(midi, "MAX_MIDIOUTDRV (%d) was enough for the number of devices (%d). "
99 "Some FM devices will not be available.\n",MAX_MIDIOUTDRV,numsynthdevs);
100 numsynthdevs = MAX_MIDIOUTDRV;
103 for (i = 0; i < numsynthdevs; i++) {
104 LPMIDIOUTCAPS16 tmplpCaps;
106 sinfo.device = i;
107 status = ioctl(fd, SNDCTL_SYNTH_INFO, &sinfo);
108 if (status == -1) {
109 ERR(midi, "ioctl for synth info failed.\n");
110 close(fd);
111 return TRUE;
114 tmplpCaps = xmalloc(sizeof(MIDIOUTCAPS16));
115 /* We also have the information sinfo.synth_subtype, not used here
118 /* Manufac ID. We do not have access to this with soundcard.h
119 * Does not seem to be a problem, because in mmsystem.h only
120 * Microsoft's ID is listed.
122 tmplpCaps->wMid = 0x00FF;
123 tmplpCaps->wPid = 0x0001; /* FIXME Product ID */
124 /* Product Version. We simply say "1" */
125 tmplpCaps->vDriverVersion = 0x001;
126 strcpy(tmplpCaps->szPname, sinfo.name);
128 tmplpCaps->wTechnology = unixToWindowsDeviceType(sinfo.synth_type);
129 tmplpCaps->wVoices = sinfo.nr_voices;
131 /* FIXME Is it possible to know the maximum
132 * number of simultaneous notes of a soundcard ?
133 * I believe we don't have this information, but
134 * it's probably equal or more than wVoices
136 tmplpCaps->wNotes = sinfo.nr_voices;
138 /* FIXME Do we have this information?
139 * Assuming the soundcards can handle
140 * MIDICAPS_VOLUME and MIDICAPS_LRVOLUME but
141 * not MIDICAPS_CACHE.
143 tmplpCaps->dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
145 midiOutDevices[i] = tmplpCaps;
147 if (sinfo.capabilities & SYNTH_CAP_INPUT) {
148 FIXME(midi, "Synthetizer support MIDI in. Not supported yet (please report)\n");
151 TRACE(midi, "name='%s', techn=%d voices=%d notes=%d support=%ld\n",
152 tmplpCaps->szPname, tmplpCaps->wTechnology,
153 tmplpCaps->wVoices, tmplpCaps->wNotes, tmplpCaps->dwSupport);
154 TRACE(midi,"OSS info: synth subtype=%d capa=%Xh\n",
155 sinfo.synth_subtype, sinfo.capabilities);
158 /* find how many MIDI devices are there in the system */
159 status = ioctl(fd, SNDCTL_SEQ_NRMIDIS, &nummididevs);
160 if (status == -1) {
161 ERR(midi, "ioctl on nr midi failed.\n");
162 return TRUE;
165 /* FIXME: the two restrictions below could be loosen in some cases */
166 if (numsynthdevs + nummididevs > MAX_MIDIOUTDRV) {
167 ERR(midi, "MAX_MIDIOUTDRV was not enough for the number of devices. "
168 "Some MIDI devices will not be available.\n");
169 nummididevs = MAX_MIDIOUTDRV - numsynthdevs;
172 if (nummididevs > MAX_MIDIINDRV) {
173 ERR(midi, "MAX_MIDIINDRV (%d) was not enough for the number of devices (%d). "
174 "Some MIDI devices will not be available.\n",MAX_MIDIINDRV,nummididevs);
175 nummididevs = MAX_MIDIINDRV;
178 for (i = 0; i < nummididevs; i++) {
179 LPMIDIOUTCAPS16 tmplpOutCaps;
180 LPMIDIINCAPS16 tmplpInCaps;
182 minfo.device = i;
183 status = ioctl(fd, SNDCTL_MIDI_INFO, &minfo);
184 if (status == -1) {
185 ERR(midi, "ioctl on midi info failed.\n");
186 close(fd);
187 return TRUE;
190 tmplpOutCaps = xmalloc(sizeof(MIDIOUTCAPS16));
191 /* This whole part is somewhat obscure to me. I'll keep trying to dig
192 info about it. If you happen to know, please tell us. The very
193 descritive minfo.dev_type was not used here.
195 /* Manufac ID. We do not have access to this with soundcard.h
196 Does not seem to be a problem, because in mmsystem.h only
197 Microsoft's ID is listed */
198 tmplpOutCaps->wMid = 0x00FF;
199 tmplpOutCaps->wPid = 0x0001; /* FIXME Product ID */
200 /* Product Version. We simply say "1" */
201 tmplpOutCaps->vDriverVersion = 0x001;
202 strcpy(tmplpOutCaps->szPname, minfo.name);
204 tmplpOutCaps->wTechnology = MOD_MIDIPORT; /* FIXME Is this right? */
205 /* Does it make any difference? */
206 tmplpOutCaps->wVoices = 16;
207 /* Does it make any difference? */
208 tmplpOutCaps->wNotes = 16;
209 /* FIXME Does it make any difference? */
210 tmplpOutCaps->dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
212 midiOutDevices[numsynthdevs + i] = tmplpOutCaps;
214 tmplpInCaps = xmalloc(sizeof(MIDIOUTCAPS16));
215 /* This whole part is somewhat obscure to me. I'll keep trying to dig
216 info about it. If you happen to know, please tell us. The very
217 descritive minfo.dev_type was not used here.
219 /* Manufac ID. We do not have access to this with soundcard.h
220 Does not seem to be a problem, because in mmsystem.h only
221 Microsoft's ID is listed */
222 tmplpInCaps->wMid = 0x00FF;
223 tmplpInCaps->wPid = 0x0001; /* FIXME Product ID */
224 /* Product Version. We simply say "1" */
225 tmplpInCaps->vDriverVersion = 0x001;
226 strcpy(tmplpInCaps->szPname, minfo.name);
228 /* FIXME : could we get better information than that ? */
229 tmplpInCaps->dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
231 midiInDevices[i] = tmplpInCaps;
233 TRACE(midi,"name='%s' techn=%d voices=%d notes=%d support=%ld\n",
234 tmplpOutCaps->szPname, tmplpOutCaps->wTechnology, tmplpOutCaps->wVoices,
235 tmplpOutCaps->wNotes, tmplpOutCaps->dwSupport);
236 TRACE(midi,"OSS info: midi dev-type=%d, capa=%d\n",
237 minfo.dev_type, minfo.capabilities);
240 /* windows does not seem to differentiate Synth from MIDI devices */
241 MODM_NUMFMSYNTHDEVS = numsynthdevs;
242 MODM_NUMMIDIDEVS = nummididevs;
243 MODM_NUMDEVS = numsynthdevs + nummididevs;
245 MIDM_NUMDEVS = nummididevs;
247 /* close file and exit */
248 close(fd);
249 #endif /* HAVE_OSS */
251 return TRUE;
254 extern int mciInstalledCount;
255 extern int mciInstalledListLen;
256 extern LPSTR lpmciInstallNames;
258 BOOL MULTIMEDIA_MciInit(void)
260 int len;
261 LPSTR ptr;
262 LPSTR SysFile = "SYSTEM.INI";
264 mciInstalledCount = 0;
265 mciInstalledListLen = 0;
266 ptr = lpmciInstallNames = xmalloc(2048);
267 /* FIXME: should do also some registry diving here */
268 GetPrivateProfileStringA("mci", NULL, "", lpmciInstallNames, 2000, SysFile);
269 while (strlen(ptr) > 0) {
270 TRACE(mci, "---> '%s' \n", ptr);
271 len = strlen(ptr) + 1;
272 ptr += len;
273 mciInstalledListLen += len;
274 mciInstalledCount++;
276 return TRUE;
279 /**************************************************************************
280 * MULTIMEDIA_Init [internal]
282 * Initializes the multimedia information variables
285 BOOL MULTIMEDIA_Init(void)
287 return MULTIMEDIA_MidiInit() && MULTIMEDIA_MciInit();