1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * Sample MIDI Wine Driver for ALSA (basically Linux)
6 * Copyright 1994 Martin Ayotte
7 * Copyright 1998 Luiz Otavio L. Zorzella (init procedures)
8 * Copyright 1998/1999 Eric POUECH :
9 * 98/7 changes for making this MIDI driver work on OSS
10 * current support is limited to MIDI ports of OSS systems
11 * 98/9 rewriting MCI code for MIDI
12 * 98/11 splitted in midi.c and mcimidi.c
13 * Copyright 2003 Christian Costa :
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 * TODO: Finish midi record
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(midi);
57 #if defined(HAVE_ALSA) && ((SND_LIB_MAJOR == 0 && SND_LIB_MINOR >= 9) || SND_LIB_MAJOR >= 1)
60 int state; /* -1 disabled, 0 is no recording started, 1 in recording, bit 2 set if in sys exclusive recording */
62 MIDIOPENDESC midiDesc;
66 unsigned char incoming[3];
67 unsigned char incPrev;
77 MIDIOPENDESC midiDesc;
81 void* lpExtra; /* according to port type (MIDI, FM...), extra data when needed */
86 static WINE_MIDIIN MidiInDev [MAX_MIDIINDRV ];
87 static WINE_MIDIOUT MidiOutDev[MAX_MIDIOUTDRV];
89 /* this is the total number of MIDI out devices found (synth and port) */
90 static int MODM_NumDevs = 0;
91 /* this is the total number of MIDI out devices found */
92 static int MIDM_NumDevs = 0;
94 static snd_seq_t* midiSeq = NULL;
95 static int numOpenMidiSeq = 0;
96 static int numStartedMidiIn = 0;
101 static CRITICAL_SECTION crit_sect; /* protects all MidiIn buffer queues */
102 static CRITICAL_SECTION_DEBUG critsect_debug =
105 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
106 0, 0, { 0, (DWORD)(__FILE__ ": crit_sect") }
108 static CRITICAL_SECTION crit_sect = { &critsect_debug, -1, 0, 0, 0, 0 };
110 static int end_thread;
111 static HANDLE hThread;
113 /*======================================================================*
114 * Low level MIDI implementation *
115 *======================================================================*/
117 static int midiOpenSeq(int);
118 static int midiCloseSeq(void);
120 #if 0 /* Debug Purpose */
121 static void error_handler(const char* file, int line, const char* function, int err, const char* fmt, ...)
127 fprintf(stderr, "ALSA lib %s:%i:(%s) ", file, line, function);
128 vfprintf(stderr, fmt, arg);
130 fprintf(stderr, ": %s", snd_strerror(err));
136 /**************************************************************************
137 * MIDI_unixToWindowsDeviceType [internal]
139 * return the Windows equivalent to a Unix Device Type
142 static int MIDI_AlsaToWindowsDeviceType(int type)
144 /* MOD_MIDIPORT output port
145 * MOD_SYNTH generic internal synth
146 * MOD_SQSYNTH square wave internal synth
147 * MOD_FMSYNTH FM internal synth
148 * MOD_MAPPER MIDI mapper
149 * MOD_WAVETABLE hardware watetable internal synth
150 * MOD_SWSYNTH software internal synth
153 /* FIXME Is this really the correct equivalence from ALSA to
154 Windows Sound type */
156 if (type & SND_SEQ_PORT_TYPE_SYNTH)
159 if (type & (SND_SEQ_PORT_TYPE_DIRECT_SAMPLE|SND_SEQ_PORT_TYPE_SAMPLE))
162 if (type & SND_SEQ_PORT_TYPE_MIDI_GENERIC)
165 ERR("Cannot determine the type of this midi device. Assuming FM Synth\n");
169 /**************************************************************************
170 * MIDI_NotifyClient [internal]
172 static DWORD MIDI_NotifyClient(UINT wDevID, WORD wMsg,
173 DWORD dwParam1, DWORD dwParam2)
180 TRACE("wDevID = %04X wMsg = %d dwParm1 = %04lX dwParam2 = %04lX\n",
181 wDevID, wMsg, dwParam1, dwParam2);
188 if (wDevID > MODM_NumDevs)
189 return MMSYSERR_BADDEVICEID;
191 dwCallBack = MidiOutDev[wDevID].midiDesc.dwCallback;
192 uFlags = MidiOutDev[wDevID].wFlags;
193 hDev = MidiOutDev[wDevID].midiDesc.hMidi;
194 dwInstance = MidiOutDev[wDevID].midiDesc.dwInstance;
204 if (wDevID > MIDM_NumDevs)
205 return MMSYSERR_BADDEVICEID;
207 dwCallBack = MidiInDev[wDevID].midiDesc.dwCallback;
208 uFlags = MidiInDev[wDevID].wFlags;
209 hDev = MidiInDev[wDevID].midiDesc.hMidi;
210 dwInstance = MidiInDev[wDevID].midiDesc.dwInstance;
213 WARN("Unsupported MSW-MIDI message %u\n", wMsg);
214 return MMSYSERR_ERROR;
217 return DriverCallback(dwCallBack, uFlags, hDev, wMsg, dwInstance, dwParam1, dwParam2) ?
221 static int midi_warn = 1;
222 /**************************************************************************
223 * midiOpenSeq [internal]
225 static int midiOpenSeq(int create_client)
227 if (numOpenMidiSeq == 0) {
228 if (snd_seq_open(&midiSeq, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0)
232 WARN("Error opening ALSA sequencer.\n");
239 /* Setting the client name is the only init to do */
240 snd_seq_set_client_name(midiSeq, "WINE midi driver");
242 #if 0 /* FIXME: Is it possible to use a port for READ & WRITE ops */
243 port_in = port_out = snd_seq_create_simple_port(midiSeq, "WINE ALSA Input/Output", SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_WRITE,
244 SND_SEQ_PORT_TYPE_APPLICATION);
246 TRACE("Unable to create output port\n");
248 TRACE("Outport port created successfully (%d)\n", port_out);
250 port_out = snd_seq_create_simple_port(midiSeq, "WINE ALSA Output", SND_SEQ_PORT_CAP_READ,
251 SND_SEQ_PORT_TYPE_APPLICATION);
253 TRACE("Unable to create output port\n");
255 TRACE("Outport port created successfully (%d)\n", port_out);
257 port_in = snd_seq_create_simple_port(midiSeq, "WINE ALSA Input", SND_SEQ_PORT_CAP_WRITE,
258 SND_SEQ_PORT_TYPE_APPLICATION);
260 TRACE("Unable to create input port\n");
262 TRACE("Input port created successfully (%d)\n", port_in);
270 /**************************************************************************
271 * midiCloseSeq [internal]
273 static int midiCloseSeq(void)
275 if (--numOpenMidiSeq == 0) {
276 snd_seq_delete_simple_port(midiSeq, port_out);
277 snd_seq_delete_simple_port(midiSeq, port_in);
278 snd_seq_close(midiSeq);
284 static DWORD WINAPI midRecThread(LPVOID arg)
289 TRACE("Thread startup\n");
292 TRACE("Thread loop\n");
293 npfd = snd_seq_poll_descriptors_count(midiSeq, POLLIN);
294 pfd = (struct pollfd *)HeapAlloc(GetProcessHeap(), 0, npfd * sizeof(struct pollfd));
295 snd_seq_poll_descriptors(midiSeq, pfd, npfd, POLLIN);
297 /* Check if a event is present */
298 if (poll(pfd, npfd, 250) < 0) {
299 HeapFree(GetProcessHeap(), 0, pfd);
303 /* Note: This definitely does not work.
304 * while(snd_seq_event_input_pending(midiSeq, 0) > 0) {
306 snd_seq_event_input(midiSeq, &ev);
308 snd_seq_free_event(ev);
314 snd_seq_event_input(midiSeq, &ev);
315 /* Find the target device */
316 for (wDevID = 0; wDevID < MIDM_NumDevs; wDevID++)
317 if ( (ev->source.client == MidiInDev[wDevID].addr.client) && (ev->source.port == MidiInDev[wDevID].addr.port) )
319 if ((wDevID == MIDM_NumDevs) || (MidiInDev[wDevID].state != 1))
320 FIXME("Unexpected event received, type = %x from %d:%d\n", ev->type, ev->source.client, ev->source.port);
322 DWORD dwTime, toSend = 0;
323 /* FIXME: Should use ev->time instead for better accuracy */
324 dwTime = GetTickCount() - MidiInDev[wDevID].startTime;
325 TRACE("Event received, type = %x, device = %d\n", ev->type, wDevID);
328 case SND_SEQ_EVENT_NOTEOFF:
329 toSend = (ev->data.note.velocity << 16) | (ev->data.note.note << 8) | MIDI_CMD_NOTE_OFF | ev->data.control.channel;
331 case SND_SEQ_EVENT_NOTEON:
332 toSend = (ev->data.note.velocity << 16) | (ev->data.note.note << 8) | MIDI_CMD_NOTE_ON | ev->data.control.channel;
334 case SND_SEQ_EVENT_KEYPRESS:
335 toSend = (ev->data.note.velocity << 16) | (ev->data.note.note << 8) | MIDI_CMD_NOTE_PRESSURE | ev->data.control.channel;
337 case SND_SEQ_EVENT_CONTROLLER:
338 toSend = (ev->data.control.value << 16) | (ev->data.control.param << 8) | MIDI_CMD_CONTROL | ev->data.control.channel;
340 case SND_SEQ_EVENT_PITCHBEND:
341 toSend = (ev->data.control.value << 16) | (ev->data.control.param << 8) | MIDI_CMD_BENDER | ev->data.control.channel;
343 case SND_SEQ_EVENT_PGMCHANGE:
344 toSend = (ev->data.control.value << 16) | (ev->data.control.param << 8) | MIDI_CMD_PGM_CHANGE | ev->data.control.channel;
346 case SND_SEQ_EVENT_CHANPRESS:
347 toSend = (ev->data.control.value << 16) | (ev->data.control.param << 8) | MIDI_CMD_CHANNEL_PRESSURE | ev->data.control.channel;
349 case SND_SEQ_EVENT_SYSEX:
351 int len = ev->data.ext.len;
352 LPBYTE ptr = (BYTE*) ev->data.ext.ptr;
355 /* FIXME: Should handle sysex greater that a single buffer */
356 EnterCriticalSection(&crit_sect);
357 if ((lpMidiHdr = MidiInDev[wDevID].lpQueueHdr) != NULL) {
358 if (len <= lpMidiHdr->dwBufferLength) {
359 lpMidiHdr->dwBytesRecorded = len;
360 memcpy(lpMidiHdr->lpData, ptr, len);
361 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
362 lpMidiHdr->dwFlags |= MHDR_DONE;
363 MidiInDev[wDevID].lpQueueHdr = (LPMIDIHDR)lpMidiHdr->lpNext;
364 if (MIDI_NotifyClient(wDevID, MIM_LONGDATA, (DWORD)lpMidiHdr, dwTime) != MMSYSERR_NOERROR)
365 WARN("Couldn't notify client\n");
367 FIXME("No enough space in the buffer to store sysex!\n");
369 FIXME("Sysex received but no buffer to store it!\n");
370 LeaveCriticalSection(&crit_sect);
373 case SND_SEQ_EVENT_SENSING:
377 FIXME("Unhandled event received, type = %x\n", ev->type);
381 TRACE("Sending event %08lx (from %d %d)\n", toSend, ev->source.client, ev->source.port);
382 if (MIDI_NotifyClient(wDevID, MIM_DATA, toSend, dwTime) != MMSYSERR_NOERROR) {
383 WARN("Couldn't notify client\n");
387 snd_seq_free_event(ev);
388 } while(snd_seq_event_input_pending(midiSeq, 0) > 0);
390 HeapFree(GetProcessHeap(), 0, pfd);
395 /**************************************************************************
396 * midGetDevCaps [internal]
398 static DWORD midGetDevCaps(WORD wDevID, LPMIDIINCAPSA lpCaps, DWORD dwSize)
400 TRACE("(%04X, %p, %08lX);\n", wDevID, lpCaps, dwSize);
402 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
403 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
405 memcpy(lpCaps, &MidiInDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
407 return MMSYSERR_NOERROR;
411 /**************************************************************************
414 static DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
416 TRACE("(%04X, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
418 if (lpDesc == NULL) {
419 WARN("Invalid Parameter !\n");
420 return MMSYSERR_INVALPARAM;
424 * how to check that content of lpDesc is correct ?
426 if (wDevID >= MIDM_NumDevs) {
427 WARN("wDevID too large (%u) !\n", wDevID);
428 return MMSYSERR_BADDEVICEID;
430 if (MidiInDev[wDevID].state == -1) {
431 WARN("device disabled\n");
432 return MIDIERR_NODEVICE;
434 if (MidiInDev[wDevID].midiDesc.hMidi != 0) {
435 WARN("device already open !\n");
436 return MMSYSERR_ALLOCATED;
438 if ((dwFlags & MIDI_IO_STATUS) != 0) {
439 WARN("No support for MIDI_IO_STATUS in dwFlags yet, ignoring it\n");
440 dwFlags &= ~MIDI_IO_STATUS;
442 if ((dwFlags & ~CALLBACK_TYPEMASK) != 0) {
443 FIXME("Bad dwFlags\n");
444 return MMSYSERR_INVALFLAG;
447 if (midiOpenSeq(1) < 0) {
448 return MMSYSERR_ERROR;
451 /* Connect our app port to the device port */
452 if (snd_seq_connect_from(midiSeq, port_in, MidiInDev[wDevID].addr.client, MidiInDev[wDevID].addr.port) < 0)
453 return MMSYSERR_NOTENABLED;
455 TRACE("input port connected %d %d %d\n",port_in,MidiInDev[wDevID].addr.client,MidiInDev[wDevID].addr.port);
457 if (numStartedMidiIn++ == 0) {
459 hThread = CreateThread(NULL, 0, midRecThread, NULL, 0, NULL);
461 numStartedMidiIn = 0;
462 WARN("Couldn't create thread for midi-in\n");
464 return MMSYSERR_ERROR;
466 TRACE("Created thread for midi-in\n");
469 MidiInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
471 MidiInDev[wDevID].lpQueueHdr = NULL;
472 MidiInDev[wDevID].dwTotalPlayed = 0;
473 MidiInDev[wDevID].bufsize = 0x3FFF;
474 MidiInDev[wDevID].midiDesc = *lpDesc;
475 MidiInDev[wDevID].state = 0;
476 MidiInDev[wDevID].incLen = 0;
477 MidiInDev[wDevID].startTime = 0;
479 if (MIDI_NotifyClient(wDevID, MIM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
480 WARN("can't notify client !\n");
481 return MMSYSERR_INVALPARAM;
483 return MMSYSERR_NOERROR;
486 /**************************************************************************
487 * midClose [internal]
489 static DWORD midClose(WORD wDevID)
491 int ret = MMSYSERR_NOERROR;
493 TRACE("(%04X);\n", wDevID);
495 if (wDevID >= MIDM_NumDevs) {
496 WARN("wDevID too big (%u) !\n", wDevID);
497 return MMSYSERR_BADDEVICEID;
499 if (MidiInDev[wDevID].midiDesc.hMidi == 0) {
500 WARN("device not opened !\n");
501 return MMSYSERR_ERROR;
503 if (MidiInDev[wDevID].lpQueueHdr != 0) {
504 return MIDIERR_STILLPLAYING;
507 if (midiSeq == NULL) {
509 return MMSYSERR_ERROR;
511 if (--numStartedMidiIn == 0) {
512 TRACE("Stopping thread for midi-in\n");
514 if (WaitForSingleObject(hThread, 5000) != WAIT_OBJECT_0) {
515 WARN("Thread end not signaled, force termination\n");
516 TerminateThread(hThread, 0);
518 TRACE("Stopped thread for midi-in\n");
521 snd_seq_disconnect_from(midiSeq, port_in, MidiInDev[wDevID].addr.client, MidiInDev[wDevID].addr.port);
524 MidiInDev[wDevID].bufsize = 0;
525 if (MIDI_NotifyClient(wDevID, MIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
526 WARN("can't notify client !\n");
527 ret = MMSYSERR_INVALPARAM;
529 MidiInDev[wDevID].midiDesc.hMidi = 0;
535 /**************************************************************************
536 * midAddBuffer [internal]
538 static DWORD midAddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
540 TRACE("(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
542 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
543 if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
545 if (lpMidiHdr == NULL) return MMSYSERR_INVALPARAM;
546 if (sizeof(MIDIHDR) > dwSize) return MMSYSERR_INVALPARAM;
547 if (lpMidiHdr->dwBufferLength == 0) return MMSYSERR_INVALPARAM;
548 if (lpMidiHdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING;
549 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED)) return MIDIERR_UNPREPARED;
551 EnterCriticalSection(&crit_sect);
552 if (MidiInDev[wDevID].lpQueueHdr == 0) {
553 MidiInDev[wDevID].lpQueueHdr = lpMidiHdr;
557 for (ptr = MidiInDev[wDevID].lpQueueHdr;
559 ptr = (LPMIDIHDR)ptr->lpNext);
560 ptr->lpNext = (struct midihdr_tag*)lpMidiHdr;
562 LeaveCriticalSection(&crit_sect);
564 return MMSYSERR_NOERROR;
567 /**************************************************************************
568 * midPrepare [internal]
570 static DWORD midPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
572 TRACE("(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
574 if (dwSize < sizeof(MIDIHDR) || lpMidiHdr == 0 ||
575 lpMidiHdr->lpData == 0 || (lpMidiHdr->dwFlags & MHDR_INQUEUE) != 0 ||
576 lpMidiHdr->dwBufferLength >= 0x10000ul)
577 return MMSYSERR_INVALPARAM;
579 lpMidiHdr->lpNext = 0;
580 lpMidiHdr->dwFlags |= MHDR_PREPARED;
581 lpMidiHdr->dwBytesRecorded = 0;
583 return MMSYSERR_NOERROR;
586 /**************************************************************************
587 * midUnprepare [internal]
589 static DWORD midUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
591 TRACE("(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
593 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
594 if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
596 if (dwSize < sizeof(MIDIHDR) || lpMidiHdr == 0 ||
597 lpMidiHdr->lpData == 0 || lpMidiHdr->dwBufferLength >= 0x10000ul)
598 return MMSYSERR_INVALPARAM;
600 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED)) return MIDIERR_UNPREPARED;
601 if (lpMidiHdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING;
603 lpMidiHdr->dwFlags &= ~MHDR_PREPARED;
605 return MMSYSERR_NOERROR;
608 /**************************************************************************
609 * midReset [internal]
611 static DWORD midReset(WORD wDevID)
613 DWORD dwTime = GetTickCount();
615 TRACE("(%04X);\n", wDevID);
617 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
618 if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
620 EnterCriticalSection(&crit_sect);
621 while (MidiInDev[wDevID].lpQueueHdr) {
622 MidiInDev[wDevID].lpQueueHdr->dwFlags &= ~MHDR_INQUEUE;
623 MidiInDev[wDevID].lpQueueHdr->dwFlags |= MHDR_DONE;
624 /* FIXME: when called from 16 bit, lpQueueHdr needs to be a segmented ptr */
625 if (MIDI_NotifyClient(wDevID, MIM_LONGDATA,
626 (DWORD)MidiInDev[wDevID].lpQueueHdr, dwTime) != MMSYSERR_NOERROR) {
627 WARN("Couldn't notify client\n");
629 MidiInDev[wDevID].lpQueueHdr = (LPMIDIHDR)MidiInDev[wDevID].lpQueueHdr->lpNext;
631 LeaveCriticalSection(&crit_sect);
633 return MMSYSERR_NOERROR;
636 /**************************************************************************
637 * midStart [internal]
639 static DWORD midStart(WORD wDevID)
641 TRACE("(%04X);\n", wDevID);
643 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
644 if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
646 MidiInDev[wDevID].state = 1;
647 MidiInDev[wDevID].startTime = GetTickCount();
648 return MMSYSERR_NOERROR;
651 /**************************************************************************
654 static DWORD midStop(WORD wDevID)
656 TRACE("(%04X);\n", wDevID);
658 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
659 if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
661 MidiInDev[wDevID].state = 0;
662 return MMSYSERR_NOERROR;
665 /**************************************************************************
666 * modGetDevCaps [internal]
668 static DWORD modGetDevCaps(WORD wDevID, LPMIDIOUTCAPSA lpCaps, DWORD dwSize)
670 TRACE("(%04X, %p, %08lX);\n", wDevID, lpCaps, dwSize);
672 if (wDevID >= MODM_NumDevs) return MMSYSERR_BADDEVICEID;
673 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
675 memcpy(lpCaps, &MidiOutDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
677 return MMSYSERR_NOERROR;
680 /**************************************************************************
683 static DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
685 TRACE("(%04X, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
686 if (lpDesc == NULL) {
687 WARN("Invalid Parameter !\n");
688 return MMSYSERR_INVALPARAM;
690 if (wDevID >= MODM_NumDevs) {
691 TRACE("MAX_MIDIOUTDRV reached !\n");
692 return MMSYSERR_BADDEVICEID;
694 if (MidiOutDev[wDevID].midiDesc.hMidi != 0) {
695 WARN("device already open !\n");
696 return MMSYSERR_ALLOCATED;
698 if (!MidiOutDev[wDevID].bEnabled) {
699 WARN("device disabled !\n");
700 return MIDIERR_NODEVICE;
702 if ((dwFlags & ~CALLBACK_TYPEMASK) != 0) {
703 WARN("bad dwFlags\n");
704 return MMSYSERR_INVALFLAG;
706 if (!MidiOutDev[wDevID].bEnabled) {
707 TRACE("disabled wDevID\n");
708 return MMSYSERR_NOTENABLED;
711 MidiOutDev[wDevID].lpExtra = 0;
713 switch (MidiOutDev[wDevID].caps.wTechnology) {
717 if (midiOpenSeq(1) < 0) {
718 return MMSYSERR_ALLOCATED;
722 WARN("Technology not supported (yet) %d !\n",
723 MidiOutDev[wDevID].caps.wTechnology);
724 return MMSYSERR_NOTENABLED;
727 MidiOutDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
729 MidiOutDev[wDevID].lpQueueHdr = NULL;
730 MidiOutDev[wDevID].dwTotalPlayed = 0;
731 MidiOutDev[wDevID].bufsize = 0x3FFF;
732 MidiOutDev[wDevID].midiDesc = *lpDesc;
734 /* Connect our app port to the device port */
735 if (snd_seq_connect_to(midiSeq, port_out, MidiOutDev[wDevID].addr.client, MidiOutDev[wDevID].addr.port) < 0)
736 return MMSYSERR_NOTENABLED;
738 if (MIDI_NotifyClient(wDevID, MOM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
739 WARN("can't notify client !\n");
740 return MMSYSERR_INVALPARAM;
742 TRACE("Successful !\n");
743 return MMSYSERR_NOERROR;
747 /**************************************************************************
748 * modClose [internal]
750 static DWORD modClose(WORD wDevID)
752 int ret = MMSYSERR_NOERROR;
754 TRACE("(%04X);\n", wDevID);
756 if (MidiOutDev[wDevID].midiDesc.hMidi == 0) {
757 WARN("device not opened !\n");
758 return MMSYSERR_ERROR;
760 /* FIXME: should test that no pending buffer is still in the queue for
763 if (midiSeq == NULL) {
764 WARN("can't close !\n");
765 return MMSYSERR_ERROR;
768 switch (MidiOutDev[wDevID].caps.wTechnology) {
772 snd_seq_disconnect_to(midiSeq, port_out, MidiOutDev[wDevID].addr.client, MidiOutDev[wDevID].addr.port);
776 WARN("Technology not supported (yet) %d !\n",
777 MidiOutDev[wDevID].caps.wTechnology);
778 return MMSYSERR_NOTENABLED;
781 if (MidiOutDev[wDevID].lpExtra != 0) {
782 HeapFree(GetProcessHeap(), 0, MidiOutDev[wDevID].lpExtra);
783 MidiOutDev[wDevID].lpExtra = 0;
786 MidiOutDev[wDevID].bufsize = 0;
787 if (MIDI_NotifyClient(wDevID, MOM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
788 WARN("can't notify client !\n");
789 ret = MMSYSERR_INVALPARAM;
791 MidiOutDev[wDevID].midiDesc.hMidi = 0;
795 /**************************************************************************
798 static DWORD modData(WORD wDevID, DWORD dwParam)
800 BYTE evt = LOBYTE(LOWORD(dwParam));
801 BYTE d1 = HIBYTE(LOWORD(dwParam));
802 BYTE d2 = LOBYTE(HIWORD(dwParam));
804 TRACE("(%04X, %08lX);\n", wDevID, dwParam);
806 if (wDevID >= MODM_NumDevs) return MMSYSERR_BADDEVICEID;
807 if (!MidiOutDev[wDevID].bEnabled) return MIDIERR_NODEVICE;
809 if (midiSeq == NULL) {
810 WARN("can't play !\n");
811 return MIDIERR_NODEVICE;
813 switch (MidiOutDev[wDevID].caps.wTechnology) {
817 int handled = 1; /* Assume event is handled */
818 snd_seq_event_t event;
819 snd_seq_ev_clear(&event);
820 snd_seq_ev_set_direct(&event);
821 snd_seq_ev_set_source(&event, port_out);
822 snd_seq_ev_set_dest(&event, MidiOutDev[wDevID].addr.client, MidiOutDev[wDevID].addr.port);
824 switch (evt & 0xF0) {
825 case MIDI_CMD_NOTE_OFF:
826 snd_seq_ev_set_noteoff(&event, evt&0x0F, d1, d2);
828 case MIDI_CMD_NOTE_ON:
829 snd_seq_ev_set_noteon(&event, evt&0x0F, d1, d2);
831 case MIDI_CMD_NOTE_PRESSURE:
832 snd_seq_ev_set_keypress(&event, evt&0x0F, d1, d2);
834 case MIDI_CMD_CONTROL:
835 snd_seq_ev_set_controller(&event, evt&0x0F, d1, d2);
837 case MIDI_CMD_BENDER:
838 snd_seq_ev_set_pitchbend(&event, evt&0x0F, ((WORD)d1 << 7) | (WORD)d2);
840 case MIDI_CMD_PGM_CHANGE:
841 snd_seq_ev_set_pgmchange(&event, evt&0x0F, d1);
843 case MIDI_CMD_CHANNEL_PRESSURE:
844 snd_seq_ev_set_chanpress(&event, evt&0x0F, d1);
846 case MIDI_CMD_COMMON_SYSEX:
847 switch (evt & 0x0F) {
848 case 0x00: /* System Exclusive, don't do it on modData,
849 * should require modLongData*/
850 case 0x01: /* Undefined */
851 case 0x04: /* Undefined. */
852 case 0x05: /* Undefined. */
853 case 0x07: /* End of Exclusive. */
854 case 0x09: /* Undefined. */
855 case 0x0D: /* Undefined. */
858 case 0x06: /* Tune Request */
859 case 0x08: /* Timing Clock. */
860 case 0x0A: /* Start. */
861 case 0x0B: /* Continue */
862 case 0x0C: /* Stop */
863 case 0x0E: /* Active Sensing. */
864 /* FIXME: Is this function suitable for these purposes
865 (and also Song Select and Song Position Pointer) */
866 snd_seq_ev_set_sysex(&event, 1, &evt);
868 case 0x0F: /* Reset */
869 /* snd_seq_ev_set_sysex(&event, 1, &evt);
870 this other way may be better */
872 BYTE reset_sysex_seq[] = {MIDI_CMD_COMMON_SYSEX, 0x7e, 0x7f, 0x09, 0x01, 0xf7};
873 snd_seq_ev_set_sysex(&event, sizeof(reset_sysex_seq), reset_sysex_seq);
876 case 0x03: /* Song Select. */
881 snd_seq_ev_set_sysex(&event, sizeof(buf), buf);
884 case 0x02: /* Song Position Pointer. */
890 snd_seq_ev_set_sysex(&event, sizeof(buf), buf);
897 snd_seq_event_output_direct(midiSeq, &event);
901 WARN("Technology not supported (yet) %d !\n",
902 MidiOutDev[wDevID].caps.wTechnology);
903 return MMSYSERR_NOTENABLED;
906 return MMSYSERR_NOERROR;
909 /**************************************************************************
910 * modLongData [internal]
912 static DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
915 LPBYTE lpData, lpNewData = NULL;
916 snd_seq_event_t event;
918 TRACE("(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
920 /* Note: MS doc does not say much about the dwBytesRecorded member of the MIDIHDR structure
921 * but it seems to be used only for midi input.
922 * Taking a look at the WAVEHDR structure (which is quite similar) confirms this assumption.
925 if (wDevID >= MODM_NumDevs) return MMSYSERR_BADDEVICEID;
926 if (!MidiOutDev[wDevID].bEnabled) return MIDIERR_NODEVICE;
928 if (midiSeq == NULL) {
929 WARN("can't play !\n");
930 return MIDIERR_NODEVICE;
933 lpData = lpMidiHdr->lpData;
936 return MIDIERR_UNPREPARED;
937 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED))
938 return MIDIERR_UNPREPARED;
939 if (lpMidiHdr->dwFlags & MHDR_INQUEUE)
940 return MIDIERR_STILLPLAYING;
941 lpMidiHdr->dwFlags &= ~MHDR_DONE;
942 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
944 /* FIXME: MS doc is not 100% clear. Will lpData only contain system exclusive
945 * data, or can it also contain raw MIDI data, to be split up and sent to
947 * If the latest is true, then the following WARNing will fire up
949 if (lpData[0] != 0xF0 || lpData[lpMidiHdr->dwBufferLength - 1] != 0xF7) {
950 WARN("Alledged system exclusive buffer is not correct\n\tPlease report with MIDI file\n");
951 lpNewData = HeapAlloc(GetProcessHeap, 0, lpMidiHdr->dwBufferLength + 2);
954 TRACE("dwBufferLength=%lu !\n", lpMidiHdr->dwBufferLength);
955 TRACE(" %02X %02X %02X ... %02X %02X %02X\n",
956 lpData[0], lpData[1], lpData[2], lpData[lpMidiHdr->dwBufferLength-3],
957 lpData[lpMidiHdr->dwBufferLength-2], lpData[lpMidiHdr->dwBufferLength-1]);
959 switch (MidiOutDev[wDevID].caps.wTechnology) {
961 /* FIXME: I don't think there is much to do here */
964 if (lpData[0] != 0xF0) {
965 /* Send start of System Exclusive */
968 memcpy(lpNewData, lpData, lpMidiHdr->dwBufferLength);
969 WARN("Adding missing 0xF0 marker at the beginning of "
970 "system exclusive byte stream\n");
972 if (lpData[lpMidiHdr->dwBufferLength-1] != 0xF7) {
973 /* Send end of System Exclusive */
974 memcpy(lpData + len_add, lpData, lpMidiHdr->dwBufferLength);
975 lpNewData[lpMidiHdr->dwBufferLength + len_add - 1] = 0xF0;
977 WARN("Adding missing 0xF7 marker at the end of "
978 "system exclusive byte stream\n");
980 snd_seq_ev_clear(&event);
981 snd_seq_ev_set_direct(&event);
982 snd_seq_ev_set_source(&event, port_out);
983 snd_seq_ev_set_dest(&event, MidiOutDev[wDevID].addr.client, MidiOutDev[wDevID].addr.port);
984 TRACE("client = %d port = %d\n", MidiOutDev[wDevID].addr.client, MidiOutDev[wDevID].addr.port);
985 snd_seq_ev_set_sysex(&event, lpMidiHdr->dwBufferLength + len_add, lpNewData ? lpNewData : lpData);
986 snd_seq_event_output_direct(midiSeq, &event);
988 HeapFree(GetProcessHeap(), 0, lpData);
991 WARN("Technology not supported (yet) %d !\n",
992 MidiOutDev[wDevID].caps.wTechnology);
993 return MMSYSERR_NOTENABLED;
996 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
997 lpMidiHdr->dwFlags |= MHDR_DONE;
998 if (MIDI_NotifyClient(wDevID, MOM_DONE, (DWORD)lpMidiHdr, 0L) != MMSYSERR_NOERROR) {
999 WARN("can't notify client !\n");
1000 return MMSYSERR_INVALPARAM;
1002 return MMSYSERR_NOERROR;
1005 /**************************************************************************
1006 * modPrepare [internal]
1008 static DWORD modPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1010 TRACE("(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
1012 if (midiSeq == NULL) {
1013 WARN("can't prepare !\n");
1014 return MMSYSERR_NOTENABLED;
1017 /* MS doc says that dwFlags must be set to zero, but (kinda funny) MS mciseq drivers
1018 * asks to prepare MIDIHDR which dwFlags != 0.
1019 * So at least check for the inqueue flag
1021 if (dwSize < sizeof(MIDIHDR) || lpMidiHdr == 0 ||
1022 lpMidiHdr->lpData == 0 || (lpMidiHdr->dwFlags & MHDR_INQUEUE) != 0 ||
1023 lpMidiHdr->dwBufferLength >= 0x10000ul) {
1024 WARN("%p %p %08lx %d/%ld\n", lpMidiHdr, lpMidiHdr->lpData,
1025 lpMidiHdr->dwFlags, sizeof(MIDIHDR), dwSize);
1026 return MMSYSERR_INVALPARAM;
1029 lpMidiHdr->lpNext = 0;
1030 lpMidiHdr->dwFlags |= MHDR_PREPARED;
1031 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1032 return MMSYSERR_NOERROR;
1035 /**************************************************************************
1036 * modUnprepare [internal]
1038 static DWORD modUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1040 TRACE("(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
1042 if (midiSeq == NULL) {
1043 WARN("can't unprepare !\n");
1044 return MMSYSERR_NOTENABLED;
1047 if (dwSize < sizeof(MIDIHDR) || lpMidiHdr == 0)
1048 return MMSYSERR_INVALPARAM;
1049 if (lpMidiHdr->dwFlags & MHDR_INQUEUE)
1050 return MIDIERR_STILLPLAYING;
1051 lpMidiHdr->dwFlags &= ~MHDR_PREPARED;
1052 return MMSYSERR_NOERROR;
1055 /**************************************************************************
1056 * modReset [internal]
1058 static DWORD modReset(WORD wDevID)
1062 TRACE("(%04X);\n", wDevID);
1064 if (wDevID >= MODM_NumDevs) return MMSYSERR_BADDEVICEID;
1065 if (!MidiOutDev[wDevID].bEnabled) return MIDIERR_NODEVICE;
1067 /* stop all notes */
1068 /* FIXME: check if 0x78B0 is channel dependent or not. I coded it so that
1069 * it's channel dependent...
1071 for (chn = 0; chn < 16; chn++) {
1072 /* turn off every note */
1073 modData(wDevID, 0x7800 | MIDI_CMD_CONTROL | chn);
1074 /* remove sustain on all channels */
1075 modData(wDevID, (MIDI_CTL_SUSTAIN << 8) | MIDI_CMD_CONTROL | chn);
1077 /* FIXME: the LongData buffers must also be returned to the app */
1078 return MMSYSERR_NOERROR;
1082 /**************************************************************************
1083 * ALSA_AddMidiPort [internal]
1085 * Helper for ALSA_MidiInit
1087 void ALSA_AddMidiPort(snd_seq_client_info_t* cinfo, snd_seq_port_info_t* pinfo, int cap, int type)
1089 if (cap & SND_SEQ_PORT_CAP_WRITE) {
1090 TRACE("OUT (%d:%s:%s:%d:%s:%x)\n",snd_seq_client_info_get_client(cinfo),
1091 snd_seq_client_info_get_name(cinfo),
1092 snd_seq_client_info_get_type(cinfo) == SND_SEQ_USER_CLIENT ? "user" : "kernel",
1093 snd_seq_port_info_get_port(pinfo),
1094 snd_seq_port_info_get_name(pinfo),
1097 if (MODM_NumDevs >= MAX_MIDIOUTDRV)
1102 memcpy(&MidiOutDev[MODM_NumDevs].addr, snd_seq_port_info_get_addr(pinfo), sizeof(snd_seq_addr_t));
1104 /* Manufac ID. We do not have access to this with soundcard.h
1105 * Does not seem to be a problem, because in mmsystem.h only
1106 * Microsoft's ID is listed.
1108 MidiOutDev[MODM_NumDevs].caps.wMid = 0x00FF;
1109 MidiOutDev[MODM_NumDevs].caps.wPid = 0x0001; /* FIXME Product ID */
1110 /* Product Version. We simply say "1" */
1111 MidiOutDev[MODM_NumDevs].caps.vDriverVersion = 0x001;
1112 MidiOutDev[MODM_NumDevs].caps.wChannelMask = 0xFFFF;
1114 /* FIXME Do we have this information?
1115 * Assuming the soundcards can handle
1116 * MIDICAPS_VOLUME and MIDICAPS_LRVOLUME but
1117 * not MIDICAPS_CACHE.
1119 MidiOutDev[MODM_NumDevs].caps.dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
1120 strcpy(MidiOutDev[MODM_NumDevs].caps.szPname, snd_seq_client_info_get_name(cinfo));
1122 MidiOutDev[MODM_NumDevs].caps.wTechnology = MIDI_AlsaToWindowsDeviceType(type);
1123 MidiOutDev[MODM_NumDevs].caps.wVoices = 16;
1125 /* FIXME Is it possible to know the maximum
1126 * number of simultaneous notes of a soundcard ?
1127 * I believe we don't have this information, but
1128 * it's probably equal or more than wVoices
1130 MidiOutDev[MODM_NumDevs].caps.wNotes = 16;
1131 MidiOutDev[MODM_NumDevs].bEnabled = TRUE;
1133 TRACE("MidiOut[%d]\tname='%s' techn=%d voices=%d notes=%d chnMsk=%04x support=%ld\n"
1134 "\tALSA info: midi dev-type=%lx, capa=%lx\n",
1135 MODM_NumDevs, MidiOutDev[MODM_NumDevs].caps.szPname, MidiOutDev[MODM_NumDevs].caps.wTechnology,
1136 MidiOutDev[MODM_NumDevs].caps.wVoices, MidiOutDev[MODM_NumDevs].caps.wNotes,
1137 MidiOutDev[MODM_NumDevs].caps.wChannelMask, MidiOutDev[MODM_NumDevs].caps.dwSupport,
1138 (long)type, (long)0);
1142 if (cap & SND_SEQ_PORT_CAP_READ) {
1143 TRACE("IN (%d:%s:%s:%d:%s:%x)\n",snd_seq_client_info_get_client(cinfo),
1144 snd_seq_client_info_get_name(cinfo),
1145 snd_seq_client_info_get_type(cinfo) == SND_SEQ_USER_CLIENT ? "user" : "kernel",
1146 snd_seq_port_info_get_port(pinfo),
1147 snd_seq_port_info_get_name(pinfo),
1150 if (MIDM_NumDevs >= MAX_MIDIINDRV)
1155 memcpy(&MidiInDev[MIDM_NumDevs].addr, snd_seq_port_info_get_addr(pinfo), sizeof(snd_seq_addr_t));
1157 /* Manufac ID. We do not have access to this with soundcard.h
1158 * Does not seem to be a problem, because in mmsystem.h only
1159 * Microsoft's ID is listed.
1161 MidiInDev[MIDM_NumDevs].caps.wMid = 0x00FF;
1162 MidiInDev[MIDM_NumDevs].caps.wPid = 0x0001; /* FIXME Product ID */
1163 /* Product Version. We simply say "1" */
1164 MidiInDev[MIDM_NumDevs].caps.vDriverVersion = 0x001;
1166 /* FIXME Do we have this information?
1167 * Assuming the soundcards can handle
1168 * MIDICAPS_VOLUME and MIDICAPS_LRVOLUME but
1169 * not MIDICAPS_CACHE.
1171 MidiInDev[MIDM_NumDevs].caps.dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
1172 strcpy(MidiInDev[MIDM_NumDevs].caps.szPname, snd_seq_client_info_get_name(cinfo));
1174 MidiInDev[MIDM_NumDevs].state = 0;
1176 TRACE("MidiIn [%d]\tname='%s' support=%ld\n"
1177 "\tALSA info: midi dev-type=%lx, capa=%lx\n",
1178 MIDM_NumDevs, MidiInDev[MIDM_NumDevs].caps.szPname, MidiInDev[MIDM_NumDevs].caps.dwSupport,
1179 (long)type, (long)0);
1185 #endif /* defined(HAVE_ALSA) && ((SND_LIB_MAJOR == 0 && SND_LIB_MINOR >= 9) || SND_LIB_MAJOR >= 1) */
1188 /*======================================================================*
1189 * MIDI entry points *
1190 *======================================================================*/
1192 /**************************************************************************
1193 * ALSA_MidiInit [internal]
1195 * Initializes the MIDI devices information variables
1197 LONG ALSA_MidiInit(void)
1199 #if defined(HAVE_ALSA) && ((SND_LIB_MAJOR == 0 && SND_LIB_MINOR >= 9) || SND_LIB_MAJOR >= 1)
1200 static BOOL bInitDone = FALSE;
1201 snd_seq_client_info_t *cinfo;
1202 snd_seq_port_info_t *pinfo;
1207 TRACE("Initializing the MIDI variables.\n");
1210 /* try to open device */
1211 if (midiOpenSeq(0) == -1) {
1215 #if 0 /* Debug purpose */
1216 snd_lib_error_set_handler(error_handler);
1219 snd_seq_client_info_alloca(&cinfo);
1220 snd_seq_port_info_alloca(&pinfo);
1222 /* First, search for all internal midi devices */
1223 snd_seq_client_info_set_client(cinfo, -1);
1224 while(snd_seq_query_next_client(midiSeq, cinfo) >= 0) {
1225 snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
1226 snd_seq_port_info_set_port(pinfo, -1);
1227 while (snd_seq_query_next_port(midiSeq, pinfo) >= 0) {
1228 int cap = snd_seq_port_info_get_capability(pinfo);
1229 int type = snd_seq_port_info_get_type(pinfo);
1230 if (type != SND_SEQ_PORT_TYPE_MIDI_GENERIC)
1231 ALSA_AddMidiPort(cinfo, pinfo, cap, type);
1235 /* Second, search for all external ports */
1236 snd_seq_client_info_set_client(cinfo, -1);
1237 while(snd_seq_query_next_client(midiSeq, cinfo) >= 0) {
1238 snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
1239 snd_seq_port_info_set_port(pinfo, -1);
1240 while (snd_seq_query_next_port(midiSeq, pinfo) >= 0) {
1241 int cap = snd_seq_port_info_get_capability(pinfo);
1242 int type = snd_seq_port_info_get_type(pinfo);
1243 if (type == SND_SEQ_PORT_TYPE_MIDI_GENERIC)
1244 ALSA_AddMidiPort(cinfo, pinfo, cap, type);
1248 /* close file and exit */
1256 /**************************************************************************
1257 * midMessage (WINEOSS.4)
1259 DWORD WINAPI ALSA_midMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
1260 DWORD dwParam1, DWORD dwParam2)
1262 TRACE("(%04X, %04X, %08lX, %08lX, %08lX);\n",
1263 wDevID, wMsg, dwUser, dwParam1, dwParam2);
1265 #if defined(HAVE_ALSA) && ((SND_LIB_MAJOR == 0 && SND_LIB_MINOR >= 9) || SND_LIB_MAJOR >= 1)
1270 /* FIXME: Pretend this is supported */
1273 return midOpen(wDevID, (LPMIDIOPENDESC)dwParam1, dwParam2);
1275 return midClose(wDevID);
1276 case MIDM_ADDBUFFER:
1277 return midAddBuffer(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1279 return midPrepare(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1280 case MIDM_UNPREPARE:
1281 return midUnprepare(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1282 case MIDM_GETDEVCAPS:
1283 return midGetDevCaps(wDevID, (LPMIDIINCAPSA)dwParam1,dwParam2);
1284 case MIDM_GETNUMDEVS:
1285 return MIDM_NumDevs;
1287 return midReset(wDevID);
1289 return midStart(wDevID);
1291 return midStop(wDevID);
1294 TRACE("Unsupported message\n");
1296 return MMSYSERR_NOTSUPPORTED;
1299 /**************************************************************************
1300 * modMessage (WINEOSS.5)
1302 DWORD WINAPI ALSA_modMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
1303 DWORD dwParam1, DWORD dwParam2)
1305 TRACE("(%04X, %04X, %08lX, %08lX, %08lX);\n",
1306 wDevID, wMsg, dwUser, dwParam1, dwParam2);
1309 #if defined(HAVE_ALSA) && ((SND_LIB_MAJOR == 0 && SND_LIB_MINOR >= 9) || SND_LIB_MAJOR >= 1)
1314 /* FIXME: Pretend this is supported */
1317 return modOpen(wDevID, (LPMIDIOPENDESC)dwParam1, dwParam2);
1319 return modClose(wDevID);
1321 return modData(wDevID, dwParam1);
1323 return modLongData(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1325 return modPrepare(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1326 case MODM_UNPREPARE:
1327 return modUnprepare(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1328 case MODM_GETDEVCAPS:
1329 return modGetDevCaps(wDevID, (LPMIDIOUTCAPSA)dwParam1, dwParam2);
1330 case MODM_GETNUMDEVS:
1331 return MODM_NumDevs;
1332 case MODM_GETVOLUME:
1334 case MODM_SETVOLUME:
1337 return modReset(wDevID);
1340 TRACE("Unsupported message\n");
1342 return MMSYSERR_NOTSUPPORTED;
1345 /*-----------------------------------------------------------------------*/