Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbejy@wpi.edu>
[wine/multimedia.git] / multimedia / init.c
blobaf9b1e06c3c2d7f6caecbdb35b45996a146e6563
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 <string.h>
11 #include <fcntl.h>
12 #include <sys/ioctl.h>
13 #include "winbase.h"
14 #include "multimedia.h"
15 #include "xmalloc.h"
16 #include "options.h"
17 #include "debug.h"
19 DECLARE_DEBUG_CHANNEL(mci)
20 DECLARE_DEBUG_CHANNEL(midi)
22 #ifdef HAVE_OSS
24 extern int MODM_NUMDEVS;
25 extern int MODM_NUMFMSYNTHDEVS;
26 extern int MODM_NUMMIDIDEVS;
27 extern LPMIDIOUTCAPS16 midiOutDevices[MAX_MIDIOUTDRV];
29 extern int MIDM_NUMDEVS;
30 extern LPMIDIINCAPS16 midiInDevices [MAX_MIDIINDRV];
32 #endif
34 /**************************************************************************
35 * unixToWindowsDeviceType [internal]
37 * return the Windows equivalent to a Unix Device Type
40 #ifdef HAVE_OSS
41 int unixToWindowsDeviceType(int type)
43 #if !defined(__NetBSD__) && !defined(__OpenBSD__)
44 /* MOD_MIDIPORT output port
45 * MOD_SYNTH generic internal synth
46 * MOD_SQSYNTH square wave internal synth
47 * MOD_FMSYNTH FM internal synth
48 * MOD_MAPPER MIDI mapper
51 /* FIXME Is this really the correct equivalence from UNIX to
52 Windows Sound type */
54 switch (type) {
55 case SYNTH_TYPE_FM: return MOD_FMSYNTH;
56 case SYNTH_TYPE_SAMPLE: return MOD_SYNTH;
57 case SYNTH_TYPE_MIDI: return MOD_MIDIPORT;
58 default:
59 ERR(midi, "Cannot determine the type of this midi device. "
60 "Assuming FM Synth\n");
61 return MOD_FMSYNTH;
63 #else
64 return MOD_FMSYNTH;
65 #endif
67 #endif
69 /**************************************************************************
70 * MULTIMEDIA_MidiInit [internal]
72 * Initializes the MIDI devices information variables
75 BOOL MULTIMEDIA_MidiInit(void)
77 #if defined(HAVE_OSS) && !defined(__NetBSD__) && !defined(__OpenBSD__)
78 int i, status, numsynthdevs = 255, nummididevs = 255;
79 struct synth_info sinfo;
80 struct midi_info minfo;
81 int fd; /* file descriptor for MIDI_SEQ */
83 TRACE(midi, "Initializing the MIDI variables.\n");
85 /* try to open device */
86 /* FIXME: should use function midiOpenSeq() in midi.c */
87 fd = open(MIDI_SEQ, O_WRONLY);
88 if (fd == -1) {
89 TRACE(midi, "No sequencer found: unable to open `%s'.\n", MIDI_SEQ);
90 return TRUE;
93 /* find how many Synth devices are there in the system */
94 status = ioctl(fd, SNDCTL_SEQ_NRSYNTHS, &numsynthdevs);
96 if (status == -1) {
97 ERR(midi, "ioctl for nr synth failed.\n");
98 close(fd);
99 return TRUE;
102 if (numsynthdevs > MAX_MIDIOUTDRV) {
103 ERR(midi, "MAX_MIDIOUTDRV (%d) was enough for the number of devices (%d). "
104 "Some FM devices will not be available.\n",MAX_MIDIOUTDRV,numsynthdevs);
105 numsynthdevs = MAX_MIDIOUTDRV;
108 for (i = 0; i < numsynthdevs; i++) {
109 LPMIDIOUTCAPS16 tmplpCaps;
111 sinfo.device = i;
112 status = ioctl(fd, SNDCTL_SYNTH_INFO, &sinfo);
113 if (status == -1) {
114 ERR(midi, "ioctl for synth info failed.\n");
115 close(fd);
116 return TRUE;
119 tmplpCaps = xmalloc(sizeof(MIDIOUTCAPS16));
120 /* We also have the information sinfo.synth_subtype, not used here
123 /* Manufac ID. We do not have access to this with soundcard.h
124 * Does not seem to be a problem, because in mmsystem.h only
125 * Microsoft's ID is listed.
127 tmplpCaps->wMid = 0x00FF;
128 tmplpCaps->wPid = 0x0001; /* FIXME Product ID */
129 /* Product Version. We simply say "1" */
130 tmplpCaps->vDriverVersion = 0x001;
131 strcpy(tmplpCaps->szPname, sinfo.name);
133 tmplpCaps->wTechnology = unixToWindowsDeviceType(sinfo.synth_type);
134 tmplpCaps->wVoices = sinfo.nr_voices;
136 /* FIXME Is it possible to know the maximum
137 * number of simultaneous notes of a soundcard ?
138 * I believe we don't have this information, but
139 * it's probably equal or more than wVoices
141 tmplpCaps->wNotes = sinfo.nr_voices;
143 /* FIXME Do we have this information?
144 * Assuming the soundcards can handle
145 * MIDICAPS_VOLUME and MIDICAPS_LRVOLUME but
146 * not MIDICAPS_CACHE.
148 tmplpCaps->dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
150 midiOutDevices[i] = tmplpCaps;
152 if (sinfo.capabilities & SYNTH_CAP_INPUT) {
153 FIXME(midi, "Synthetizer support MIDI in. Not supported yet (please report)\n");
156 TRACE(midi, "name='%s', techn=%d voices=%d notes=%d support=%ld\n",
157 tmplpCaps->szPname, tmplpCaps->wTechnology,
158 tmplpCaps->wVoices, tmplpCaps->wNotes, tmplpCaps->dwSupport);
159 TRACE(midi,"OSS info: synth subtype=%d capa=%Xh\n",
160 sinfo.synth_subtype, sinfo.capabilities);
163 /* find how many MIDI devices are there in the system */
164 status = ioctl(fd, SNDCTL_SEQ_NRMIDIS, &nummididevs);
165 if (status == -1) {
166 ERR(midi, "ioctl on nr midi failed.\n");
167 return TRUE;
170 /* FIXME: the two restrictions below could be loosen in some cases */
171 if (numsynthdevs + nummididevs > MAX_MIDIOUTDRV) {
172 ERR(midi, "MAX_MIDIOUTDRV was not enough for the number of devices. "
173 "Some MIDI devices will not be available.\n");
174 nummididevs = MAX_MIDIOUTDRV - numsynthdevs;
177 if (nummididevs > MAX_MIDIINDRV) {
178 ERR(midi, "MAX_MIDIINDRV (%d) was not enough for the number of devices (%d). "
179 "Some MIDI devices will not be available.\n",MAX_MIDIINDRV,nummididevs);
180 nummididevs = MAX_MIDIINDRV;
183 for (i = 0; i < nummididevs; i++) {
184 LPMIDIOUTCAPS16 tmplpOutCaps;
185 LPMIDIINCAPS16 tmplpInCaps;
187 minfo.device = i;
188 status = ioctl(fd, SNDCTL_MIDI_INFO, &minfo);
189 if (status == -1) {
190 ERR(midi, "ioctl on midi info failed.\n");
191 close(fd);
192 return TRUE;
195 tmplpOutCaps = xmalloc(sizeof(MIDIOUTCAPS16));
196 /* This whole part is somewhat obscure to me. I'll keep trying to dig
197 info about it. If you happen to know, please tell us. The very
198 descritive minfo.dev_type was not used here.
200 /* Manufac ID. We do not have access to this with soundcard.h
201 Does not seem to be a problem, because in mmsystem.h only
202 Microsoft's ID is listed */
203 tmplpOutCaps->wMid = 0x00FF;
204 tmplpOutCaps->wPid = 0x0001; /* FIXME Product ID */
205 /* Product Version. We simply say "1" */
206 tmplpOutCaps->vDriverVersion = 0x001;
207 strcpy(tmplpOutCaps->szPname, minfo.name);
209 tmplpOutCaps->wTechnology = MOD_MIDIPORT; /* FIXME Is this right? */
210 /* Does it make any difference? */
211 tmplpOutCaps->wVoices = 16;
212 /* Does it make any difference? */
213 tmplpOutCaps->wNotes = 16;
214 /* FIXME Does it make any difference? */
215 tmplpOutCaps->dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
217 midiOutDevices[numsynthdevs + i] = tmplpOutCaps;
219 tmplpInCaps = xmalloc(sizeof(MIDIOUTCAPS16));
220 /* This whole part is somewhat obscure to me. I'll keep trying to dig
221 info about it. If you happen to know, please tell us. The very
222 descritive minfo.dev_type was not used here.
224 /* Manufac ID. We do not have access to this with soundcard.h
225 Does not seem to be a problem, because in mmsystem.h only
226 Microsoft's ID is listed */
227 tmplpInCaps->wMid = 0x00FF;
228 tmplpInCaps->wPid = 0x0001; /* FIXME Product ID */
229 /* Product Version. We simply say "1" */
230 tmplpInCaps->vDriverVersion = 0x001;
231 strcpy(tmplpInCaps->szPname, minfo.name);
233 /* FIXME : could we get better information than that ? */
234 tmplpInCaps->dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
236 midiInDevices[i] = tmplpInCaps;
238 TRACE(midi,"name='%s' techn=%d voices=%d notes=%d support=%ld\n",
239 tmplpOutCaps->szPname, tmplpOutCaps->wTechnology, tmplpOutCaps->wVoices,
240 tmplpOutCaps->wNotes, tmplpOutCaps->dwSupport);
241 TRACE(midi,"OSS info: midi dev-type=%d, capa=%d\n",
242 minfo.dev_type, minfo.capabilities);
245 /* windows does not seem to differentiate Synth from MIDI devices */
246 MODM_NUMFMSYNTHDEVS = numsynthdevs;
247 MODM_NUMMIDIDEVS = nummididevs;
248 MODM_NUMDEVS = numsynthdevs + nummididevs;
250 MIDM_NUMDEVS = nummididevs;
252 /* close file and exit */
253 close(fd);
254 #endif /* HAVE_OSS */
256 return TRUE;
259 BOOL MULTIMEDIA_MciInit(void)
261 LPSTR ptr1, ptr2;
262 char buffer[1024];
264 mciInstalledCount = 0;
265 ptr1 = lpmciInstallNames = xmalloc(2048);
267 /* FIXME: should do also some registry diving here */
268 if (PROFILE_GetWineIniString("options", "mci", "", lpmciInstallNames, 2048) > 0) {
269 TRACE(mci, "Wine => '%s' \n", ptr1);
270 while ((ptr2 = strchr(ptr1, ':')) != 0) {
271 *ptr2++ = 0;
272 TRACE(mci, "---> '%s' \n", ptr1);
273 mciInstalledCount++;
274 ptr1 = ptr2;
276 mciInstalledCount++;
277 TRACE(mci, "---> '%s' \n", ptr1);
278 ptr1 += strlen(ptr1) + 1;
279 } else {
280 GetPrivateProfileStringA("mci", NULL, "", lpmciInstallNames, 2048, "SYSTEM.INI");
281 while (strlen(ptr1) > 0) {
282 TRACE(mci, "---> '%s' \n", ptr1);
283 ptr1 += (strlen(ptr1) + 1);
284 mciInstalledCount++;
287 mciInstalledListLen = ptr1 - lpmciInstallNames;
289 if (PROFILE_GetWineIniString("options", "mciExternal", "", buffer, sizeof(buffer)) > 0) {
290 int i;
292 for (i = 0; MCI_InternalDescriptors[i].uDevType != 0xFFFF; i++) {
293 if (strstr(buffer, MCI_InternalDescriptors[i].lpstrName) != NULL) {
294 MCI_InternalDescriptors[i].uDevType = 0; /* disable slot */
298 return TRUE;
301 /**************************************************************************
302 * MULTIMEDIA_Init [internal]
304 * Initializes the multimedia information variables
307 BOOL MULTIMEDIA_Init(void)
309 return MULTIMEDIA_MidiInit() && MULTIMEDIA_MciInit();