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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 * TODO: Finish midi record
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(midi);
59 int state; /* -1 disabled, 0 is no recording started, 1 in recording, bit 2 set if in sys exclusive recording */
61 MIDIOPENDESC midiDesc;
65 unsigned char incoming[3];
66 unsigned char incPrev;
76 MIDIOPENDESC midiDesc;
80 void* lpExtra; /* according to port type (MIDI, FM...), extra data when needed */
85 static WINE_MIDIIN MidiInDev [MAX_MIDIINDRV ];
86 static WINE_MIDIOUT MidiOutDev[MAX_MIDIOUTDRV];
88 /* this is the total number of MIDI out devices found (synth and port) */
89 static int MODM_NumDevs = 0;
90 /* this is the total number of MIDI out devices found */
91 static int MIDM_NumDevs = 0;
93 static snd_seq_t* midiSeq = NULL;
94 static int numOpenMidiSeq = 0;
95 static int numStartedMidiIn = 0;
100 static CRITICAL_SECTION crit_sect; /* protects all MidiIn buffer queues */
101 static CRITICAL_SECTION_DEBUG critsect_debug =
104 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
105 0, 0, { (DWORD_PTR)(__FILE__ ": crit_sect") }
107 static CRITICAL_SECTION crit_sect = { &critsect_debug, -1, 0, 0, 0, 0 };
109 static int end_thread;
110 static HANDLE hThread;
112 /*======================================================================*
113 * Low level MIDI implementation *
114 *======================================================================*/
116 static int midiOpenSeq(int);
117 static int midiCloseSeq(void);
119 #if 0 /* Debug Purpose */
120 static void error_handler(const char* file, int line, const char* function, int err, const char* fmt, ...)
126 fprintf(stderr, "ALSA lib %s:%i:(%s) ", file, line, function);
127 vfprintf(stderr, fmt, arg);
129 fprintf(stderr, ": %s", snd_strerror(err));
135 /**************************************************************************
136 * MIDI_unixToWindowsDeviceType [internal]
138 * return the Windows equivalent to a Unix Device Type
141 static int MIDI_AlsaToWindowsDeviceType(int type)
143 /* MOD_MIDIPORT output port
144 * MOD_SYNTH generic internal synth
145 * MOD_SQSYNTH square wave internal synth
146 * MOD_FMSYNTH FM internal synth
147 * MOD_MAPPER MIDI mapper
148 * MOD_WAVETABLE hardware watetable internal synth
149 * MOD_SWSYNTH software internal synth
152 /* FIXME Is this really the correct equivalence from ALSA to
153 Windows Sound type */
155 if (type & SND_SEQ_PORT_TYPE_SYNTH)
158 if (type & (SND_SEQ_PORT_TYPE_DIRECT_SAMPLE|SND_SEQ_PORT_TYPE_SAMPLE))
161 if (type & (SND_SEQ_PORT_TYPE_MIDI_GENERIC|SND_SEQ_PORT_TYPE_APPLICATION))
164 ERR("Cannot determine the type (alsa type is %x) of this midi device. Assuming FM Synth\n", type);
168 /**************************************************************************
169 * MIDI_NotifyClient [internal]
171 static DWORD MIDI_NotifyClient(UINT wDevID, WORD wMsg,
172 DWORD dwParam1, DWORD dwParam2)
179 TRACE("wDevID = %04X wMsg = %d dwParm1 = %04X dwParam2 = %04X\n",
180 wDevID, wMsg, dwParam1, dwParam2);
187 if (wDevID > MODM_NumDevs)
188 return MMSYSERR_BADDEVICEID;
190 dwCallBack = MidiOutDev[wDevID].midiDesc.dwCallback;
191 uFlags = MidiOutDev[wDevID].wFlags;
192 hDev = MidiOutDev[wDevID].midiDesc.hMidi;
193 dwInstance = MidiOutDev[wDevID].midiDesc.dwInstance;
203 if (wDevID > MIDM_NumDevs)
204 return MMSYSERR_BADDEVICEID;
206 dwCallBack = MidiInDev[wDevID].midiDesc.dwCallback;
207 uFlags = MidiInDev[wDevID].wFlags;
208 hDev = MidiInDev[wDevID].midiDesc.hMidi;
209 dwInstance = MidiInDev[wDevID].midiDesc.dwInstance;
212 WARN("Unsupported MSW-MIDI message %u\n", wMsg);
213 return MMSYSERR_ERROR;
216 return DriverCallback(dwCallBack, uFlags, hDev, wMsg, dwInstance, dwParam1, dwParam2) ?
220 static int midi_warn = 1;
221 /**************************************************************************
222 * midiOpenSeq [internal]
224 static int midiOpenSeq(int create_client)
226 if (numOpenMidiSeq == 0) {
227 if (snd_seq_open(&midiSeq, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0)
231 WARN("Error opening ALSA sequencer.\n");
238 /* Setting the client name is the only init to do */
239 snd_seq_set_client_name(midiSeq, "WINE midi driver");
241 #if 0 /* FIXME: Is it possible to use a port for READ & WRITE ops */
242 port_in = port_out = snd_seq_create_simple_port(midiSeq, "WINE ALSA Input/Output", SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_WRITE,
243 SND_SEQ_PORT_TYPE_APPLICATION);
245 TRACE("Unable to create output port\n");
247 TRACE("Outport port created successfully (%d)\n", port_out);
249 port_out = snd_seq_create_simple_port(midiSeq, "WINE ALSA Output", SND_SEQ_PORT_CAP_READ,
250 SND_SEQ_PORT_TYPE_APPLICATION);
252 TRACE("Unable to create output port\n");
254 TRACE("Outport port created successfully (%d)\n", port_out);
256 port_in = snd_seq_create_simple_port(midiSeq, "WINE ALSA Input", SND_SEQ_PORT_CAP_WRITE,
257 SND_SEQ_PORT_TYPE_APPLICATION);
259 TRACE("Unable to create input port\n");
261 TRACE("Input port created successfully (%d)\n", port_in);
269 /**************************************************************************
270 * midiCloseSeq [internal]
272 static int midiCloseSeq(void)
274 if (--numOpenMidiSeq == 0) {
275 snd_seq_delete_simple_port(midiSeq, port_out);
276 snd_seq_delete_simple_port(midiSeq, port_in);
277 snd_seq_close(midiSeq);
283 static DWORD WINAPI midRecThread(LPVOID arg)
288 TRACE("Thread startup\n");
291 TRACE("Thread loop\n");
292 npfd = snd_seq_poll_descriptors_count(midiSeq, POLLIN);
293 pfd = HeapAlloc(GetProcessHeap(), 0, npfd * sizeof(struct pollfd));
294 snd_seq_poll_descriptors(midiSeq, pfd, npfd, POLLIN);
296 /* Check if an event is present */
297 if (poll(pfd, npfd, 250) < 0) {
298 HeapFree(GetProcessHeap(), 0, pfd);
302 /* Note: This definitely does not work.
303 * while(snd_seq_event_input_pending(midiSeq, 0) > 0) {
305 snd_seq_event_input(midiSeq, &ev);
307 snd_seq_free_event(ev);
313 snd_seq_event_input(midiSeq, &ev);
314 /* Find the target device */
315 for (wDevID = 0; wDevID < MIDM_NumDevs; wDevID++)
316 if ( (ev->source.client == MidiInDev[wDevID].addr.client) && (ev->source.port == MidiInDev[wDevID].addr.port) )
318 if ((wDevID == MIDM_NumDevs) || (MidiInDev[wDevID].state != 1))
319 FIXME("Unexpected event received, type = %x from %d:%d\n", ev->type, ev->source.client, ev->source.port);
321 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 value = ev->data.control.value + 0x2000;
342 toSend = (((value >> 7) & 0x7f) << 16) | ((value & 0x7f) << 8) | MIDI_CMD_BENDER | ev->data.control.channel;
344 case SND_SEQ_EVENT_PGMCHANGE:
345 toSend = (ev->data.control.value << 16) | (ev->data.control.param << 8) | MIDI_CMD_PGM_CHANGE | ev->data.control.channel;
347 case SND_SEQ_EVENT_CHANPRESS:
348 toSend = (ev->data.control.value << 16) | (ev->data.control.param << 8) | MIDI_CMD_CHANNEL_PRESSURE | ev->data.control.channel;
350 case SND_SEQ_EVENT_CLOCK:
353 case SND_SEQ_EVENT_START:
356 case SND_SEQ_EVENT_CONTINUE:
359 case SND_SEQ_EVENT_STOP:
362 case SND_SEQ_EVENT_SONGPOS:
363 toSend = (((ev->data.control.value >> 7) & 0x7f) << 16) | ((ev->data.control.value & 0x7f) << 8) | 0xF2;
365 case SND_SEQ_EVENT_SONGSEL:
366 toSend = ((ev->data.control.value & 0x7f) << 8) | 0xF3;
368 case SND_SEQ_EVENT_RESET:
371 case SND_SEQ_EVENT_SYSEX:
373 int len = ev->data.ext.len;
374 LPBYTE ptr = (BYTE*) ev->data.ext.ptr;
377 /* FIXME: Should handle sysex greater than lpMidiHdr->dwBufferLength */
378 EnterCriticalSection(&crit_sect);
379 if ((lpMidiHdr = MidiInDev[wDevID].lpQueueHdr) != NULL) {
380 if (lpMidiHdr->dwBytesRecorded + len <= lpMidiHdr->dwBufferLength) {
381 memcpy(lpMidiHdr->lpData + lpMidiHdr->dwBytesRecorded, ptr, len);
382 lpMidiHdr->dwBytesRecorded += len;
383 if (*(ptr + (len-1)) == 0xF7) {
384 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
385 lpMidiHdr->dwFlags |= MHDR_DONE;
386 MidiInDev[wDevID].lpQueueHdr = (LPMIDIHDR)lpMidiHdr->lpNext;
387 if (MIDI_NotifyClient(wDevID, MIM_LONGDATA, (DWORD)lpMidiHdr, dwTime) != MMSYSERR_NOERROR)
388 WARN("Couldn't notify client\n");
391 FIXME("No enough space in the buffer to store sysex!\n");
393 FIXME("Sysex received but no buffer to store it!\n");
394 LeaveCriticalSection(&crit_sect);
397 case SND_SEQ_EVENT_SENSING:
401 FIXME("Unhandled event received, type = %x\n", ev->type);
405 TRACE("Sending event %08x (from %d %d)\n", toSend, ev->source.client, ev->source.port);
406 if (MIDI_NotifyClient(wDevID, MIM_DATA, toSend, dwTime) != MMSYSERR_NOERROR) {
407 WARN("Couldn't notify client\n");
411 snd_seq_free_event(ev);
412 } while(snd_seq_event_input_pending(midiSeq, 0) > 0);
414 HeapFree(GetProcessHeap(), 0, pfd);
419 /**************************************************************************
420 * midGetDevCaps [internal]
422 static DWORD midGetDevCaps(WORD wDevID, LPMIDIINCAPSW lpCaps, DWORD dwSize)
424 TRACE("(%04X, %p, %08X);\n", wDevID, lpCaps, dwSize);
426 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
427 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
429 memcpy(lpCaps, &MidiInDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
431 return MMSYSERR_NOERROR;
435 /**************************************************************************
438 static DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
440 TRACE("(%04X, %p, %08X);\n", wDevID, lpDesc, dwFlags);
442 if (lpDesc == NULL) {
443 WARN("Invalid Parameter !\n");
444 return MMSYSERR_INVALPARAM;
448 * how to check that content of lpDesc is correct ?
450 if (wDevID >= MIDM_NumDevs) {
451 WARN("wDevID too large (%u) !\n", wDevID);
452 return MMSYSERR_BADDEVICEID;
454 if (MidiInDev[wDevID].state == -1) {
455 WARN("device disabled\n");
456 return MIDIERR_NODEVICE;
458 if (MidiInDev[wDevID].midiDesc.hMidi != 0) {
459 WARN("device already open !\n");
460 return MMSYSERR_ALLOCATED;
462 if ((dwFlags & MIDI_IO_STATUS) != 0) {
463 WARN("No support for MIDI_IO_STATUS in dwFlags yet, ignoring it\n");
464 dwFlags &= ~MIDI_IO_STATUS;
466 if ((dwFlags & ~CALLBACK_TYPEMASK) != 0) {
467 FIXME("Bad dwFlags\n");
468 return MMSYSERR_INVALFLAG;
471 if (midiOpenSeq(1) < 0) {
472 return MMSYSERR_ERROR;
475 /* Connect our app port to the device port */
476 if (snd_seq_connect_from(midiSeq, port_in, MidiInDev[wDevID].addr.client, MidiInDev[wDevID].addr.port) < 0)
477 return MMSYSERR_NOTENABLED;
479 TRACE("input port connected %d %d %d\n",port_in,MidiInDev[wDevID].addr.client,MidiInDev[wDevID].addr.port);
481 if (numStartedMidiIn++ == 0) {
483 hThread = CreateThread(NULL, 0, midRecThread, NULL, 0, NULL);
485 numStartedMidiIn = 0;
486 WARN("Couldn't create thread for midi-in\n");
488 return MMSYSERR_ERROR;
490 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
491 TRACE("Created thread for midi-in\n");
494 MidiInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
496 MidiInDev[wDevID].lpQueueHdr = NULL;
497 MidiInDev[wDevID].dwTotalPlayed = 0;
498 MidiInDev[wDevID].bufsize = 0x3FFF;
499 MidiInDev[wDevID].midiDesc = *lpDesc;
500 MidiInDev[wDevID].state = 0;
501 MidiInDev[wDevID].incLen = 0;
502 MidiInDev[wDevID].startTime = 0;
504 if (MIDI_NotifyClient(wDevID, MIM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
505 WARN("can't notify client !\n");
506 return MMSYSERR_INVALPARAM;
508 return MMSYSERR_NOERROR;
511 /**************************************************************************
512 * midClose [internal]
514 static DWORD midClose(WORD wDevID)
516 int ret = MMSYSERR_NOERROR;
518 TRACE("(%04X);\n", wDevID);
520 if (wDevID >= MIDM_NumDevs) {
521 WARN("wDevID too big (%u) !\n", wDevID);
522 return MMSYSERR_BADDEVICEID;
524 if (MidiInDev[wDevID].midiDesc.hMidi == 0) {
525 WARN("device not opened !\n");
526 return MMSYSERR_ERROR;
528 if (MidiInDev[wDevID].lpQueueHdr != 0) {
529 return MIDIERR_STILLPLAYING;
532 if (midiSeq == NULL) {
534 return MMSYSERR_ERROR;
536 if (--numStartedMidiIn == 0) {
537 TRACE("Stopping thread for midi-in\n");
539 if (WaitForSingleObject(hThread, 5000) != WAIT_OBJECT_0) {
540 WARN("Thread end not signaled, force termination\n");
541 TerminateThread(hThread, 0);
543 TRACE("Stopped thread for midi-in\n");
546 snd_seq_disconnect_from(midiSeq, port_in, MidiInDev[wDevID].addr.client, MidiInDev[wDevID].addr.port);
549 MidiInDev[wDevID].bufsize = 0;
550 if (MIDI_NotifyClient(wDevID, MIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
551 WARN("can't notify client !\n");
552 ret = MMSYSERR_INVALPARAM;
554 MidiInDev[wDevID].midiDesc.hMidi = 0;
560 /**************************************************************************
561 * midAddBuffer [internal]
563 static DWORD midAddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
565 TRACE("(%04X, %p, %08X);\n", wDevID, lpMidiHdr, dwSize);
567 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
568 if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
570 if (lpMidiHdr == NULL) return MMSYSERR_INVALPARAM;
571 if (sizeof(MIDIHDR) > dwSize) return MMSYSERR_INVALPARAM;
572 if (lpMidiHdr->dwBufferLength == 0) return MMSYSERR_INVALPARAM;
573 if (lpMidiHdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING;
574 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED)) return MIDIERR_UNPREPARED;
576 EnterCriticalSection(&crit_sect);
577 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
578 if (MidiInDev[wDevID].lpQueueHdr == 0) {
579 MidiInDev[wDevID].lpQueueHdr = lpMidiHdr;
583 for (ptr = MidiInDev[wDevID].lpQueueHdr;
585 ptr = (LPMIDIHDR)ptr->lpNext);
586 ptr->lpNext = (struct midihdr_tag*)lpMidiHdr;
588 LeaveCriticalSection(&crit_sect);
590 return MMSYSERR_NOERROR;
593 /**************************************************************************
594 * midPrepare [internal]
596 static DWORD midPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
598 TRACE("(%04X, %p, %08X);\n", wDevID, lpMidiHdr, dwSize);
600 if (dwSize < sizeof(MIDIHDR) || lpMidiHdr == 0 ||
601 lpMidiHdr->lpData == 0 || (lpMidiHdr->dwFlags & MHDR_INQUEUE) != 0 ||
602 lpMidiHdr->dwBufferLength >= 0x10000ul)
603 return MMSYSERR_INVALPARAM;
605 lpMidiHdr->lpNext = 0;
606 lpMidiHdr->dwFlags |= MHDR_PREPARED;
607 lpMidiHdr->dwBytesRecorded = 0;
609 return MMSYSERR_NOERROR;
612 /**************************************************************************
613 * midUnprepare [internal]
615 static DWORD midUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
617 TRACE("(%04X, %p, %08X);\n", wDevID, lpMidiHdr, dwSize);
619 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
620 if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
622 if (dwSize < sizeof(MIDIHDR) || lpMidiHdr == 0 ||
623 lpMidiHdr->lpData == 0 || lpMidiHdr->dwBufferLength >= 0x10000ul)
624 return MMSYSERR_INVALPARAM;
626 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED)) return MIDIERR_UNPREPARED;
627 if (lpMidiHdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING;
629 lpMidiHdr->dwFlags &= ~MHDR_PREPARED;
631 return MMSYSERR_NOERROR;
634 /**************************************************************************
635 * midReset [internal]
637 static DWORD midReset(WORD wDevID)
639 DWORD dwTime = GetTickCount();
641 TRACE("(%04X);\n", wDevID);
643 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
644 if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
646 EnterCriticalSection(&crit_sect);
647 while (MidiInDev[wDevID].lpQueueHdr) {
648 MidiInDev[wDevID].lpQueueHdr->dwFlags &= ~MHDR_INQUEUE;
649 MidiInDev[wDevID].lpQueueHdr->dwFlags |= MHDR_DONE;
650 /* FIXME: when called from 16 bit, lpQueueHdr needs to be a segmented ptr */
651 if (MIDI_NotifyClient(wDevID, MIM_LONGDATA,
652 (DWORD)MidiInDev[wDevID].lpQueueHdr, dwTime) != MMSYSERR_NOERROR) {
653 WARN("Couldn't notify client\n");
655 MidiInDev[wDevID].lpQueueHdr = (LPMIDIHDR)MidiInDev[wDevID].lpQueueHdr->lpNext;
657 LeaveCriticalSection(&crit_sect);
659 return MMSYSERR_NOERROR;
662 /**************************************************************************
663 * midStart [internal]
665 static DWORD midStart(WORD wDevID)
667 TRACE("(%04X);\n", wDevID);
669 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
670 if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
672 MidiInDev[wDevID].state = 1;
673 MidiInDev[wDevID].startTime = GetTickCount();
674 return MMSYSERR_NOERROR;
677 /**************************************************************************
680 static DWORD midStop(WORD wDevID)
682 TRACE("(%04X);\n", wDevID);
684 if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID;
685 if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
687 MidiInDev[wDevID].state = 0;
688 return MMSYSERR_NOERROR;
691 /**************************************************************************
692 * modGetDevCaps [internal]
694 static DWORD modGetDevCaps(WORD wDevID, LPMIDIOUTCAPSW lpCaps, DWORD dwSize)
696 TRACE("(%04X, %p, %08X);\n", wDevID, lpCaps, dwSize);
698 if (wDevID >= MODM_NumDevs) return MMSYSERR_BADDEVICEID;
699 if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
701 memcpy(lpCaps, &MidiOutDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
703 return MMSYSERR_NOERROR;
706 /**************************************************************************
709 static DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
711 TRACE("(%04X, %p, %08X);\n", wDevID, lpDesc, dwFlags);
712 if (lpDesc == NULL) {
713 WARN("Invalid Parameter !\n");
714 return MMSYSERR_INVALPARAM;
716 if (wDevID >= MODM_NumDevs) {
717 TRACE("MAX_MIDIOUTDRV reached !\n");
718 return MMSYSERR_BADDEVICEID;
720 if (MidiOutDev[wDevID].midiDesc.hMidi != 0) {
721 WARN("device already open !\n");
722 return MMSYSERR_ALLOCATED;
724 if (!MidiOutDev[wDevID].bEnabled) {
725 WARN("device disabled !\n");
726 return MIDIERR_NODEVICE;
728 if ((dwFlags & ~CALLBACK_TYPEMASK) != 0) {
729 WARN("bad dwFlags\n");
730 return MMSYSERR_INVALFLAG;
732 if (!MidiOutDev[wDevID].bEnabled) {
733 TRACE("disabled wDevID\n");
734 return MMSYSERR_NOTENABLED;
737 MidiOutDev[wDevID].lpExtra = 0;
739 switch (MidiOutDev[wDevID].caps.wTechnology) {
743 if (midiOpenSeq(1) < 0) {
744 return MMSYSERR_ALLOCATED;
748 WARN("Technology not supported (yet) %d !\n",
749 MidiOutDev[wDevID].caps.wTechnology);
750 return MMSYSERR_NOTENABLED;
753 MidiOutDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
755 MidiOutDev[wDevID].lpQueueHdr = NULL;
756 MidiOutDev[wDevID].dwTotalPlayed = 0;
757 MidiOutDev[wDevID].bufsize = 0x3FFF;
758 MidiOutDev[wDevID].midiDesc = *lpDesc;
760 /* Connect our app port to the device port */
761 if (snd_seq_connect_to(midiSeq, port_out, MidiOutDev[wDevID].addr.client, MidiOutDev[wDevID].addr.port) < 0)
762 return MMSYSERR_NOTENABLED;
764 if (MIDI_NotifyClient(wDevID, MOM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
765 WARN("can't notify client !\n");
766 return MMSYSERR_INVALPARAM;
768 TRACE("Successful !\n");
769 return MMSYSERR_NOERROR;
773 /**************************************************************************
774 * modClose [internal]
776 static DWORD modClose(WORD wDevID)
778 int ret = MMSYSERR_NOERROR;
780 TRACE("(%04X);\n", wDevID);
782 if (MidiOutDev[wDevID].midiDesc.hMidi == 0) {
783 WARN("device not opened !\n");
784 return MMSYSERR_ERROR;
786 /* FIXME: should test that no pending buffer is still in the queue for
789 if (midiSeq == NULL) {
790 WARN("can't close !\n");
791 return MMSYSERR_ERROR;
794 switch (MidiOutDev[wDevID].caps.wTechnology) {
798 snd_seq_disconnect_to(midiSeq, port_out, MidiOutDev[wDevID].addr.client, MidiOutDev[wDevID].addr.port);
802 WARN("Technology not supported (yet) %d !\n",
803 MidiOutDev[wDevID].caps.wTechnology);
804 return MMSYSERR_NOTENABLED;
807 HeapFree(GetProcessHeap(), 0, MidiOutDev[wDevID].lpExtra);
808 MidiOutDev[wDevID].lpExtra = 0;
810 MidiOutDev[wDevID].bufsize = 0;
811 if (MIDI_NotifyClient(wDevID, MOM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
812 WARN("can't notify client !\n");
813 ret = MMSYSERR_INVALPARAM;
815 MidiOutDev[wDevID].midiDesc.hMidi = 0;
819 /**************************************************************************
822 static DWORD modData(WORD wDevID, DWORD dwParam)
824 BYTE evt = LOBYTE(LOWORD(dwParam));
825 BYTE d1 = HIBYTE(LOWORD(dwParam));
826 BYTE d2 = LOBYTE(HIWORD(dwParam));
828 TRACE("(%04X, %08X);\n", wDevID, dwParam);
830 if (wDevID >= MODM_NumDevs) return MMSYSERR_BADDEVICEID;
831 if (!MidiOutDev[wDevID].bEnabled) return MIDIERR_NODEVICE;
833 if (midiSeq == NULL) {
834 WARN("can't play !\n");
835 return MIDIERR_NODEVICE;
837 switch (MidiOutDev[wDevID].caps.wTechnology) {
841 int handled = 1; /* Assume event is handled */
842 snd_seq_event_t event;
843 snd_seq_ev_clear(&event);
844 snd_seq_ev_set_direct(&event);
845 snd_seq_ev_set_source(&event, port_out);
846 snd_seq_ev_set_dest(&event, MidiOutDev[wDevID].addr.client, MidiOutDev[wDevID].addr.port);
848 switch (evt & 0xF0) {
849 case MIDI_CMD_NOTE_OFF:
850 snd_seq_ev_set_noteoff(&event, evt&0x0F, d1, d2);
852 case MIDI_CMD_NOTE_ON:
853 snd_seq_ev_set_noteon(&event, evt&0x0F, d1, d2);
855 case MIDI_CMD_NOTE_PRESSURE:
856 snd_seq_ev_set_keypress(&event, evt&0x0F, d1, d2);
858 case MIDI_CMD_CONTROL:
859 snd_seq_ev_set_controller(&event, evt&0x0F, d1, d2);
861 case MIDI_CMD_BENDER:
862 snd_seq_ev_set_pitchbend(&event, evt&0x0F, ((WORD)d2 << 7 | (WORD)d1) - 0x2000);
864 case MIDI_CMD_PGM_CHANGE:
865 snd_seq_ev_set_pgmchange(&event, evt&0x0F, d1);
867 case MIDI_CMD_CHANNEL_PRESSURE:
868 snd_seq_ev_set_chanpress(&event, evt&0x0F, d1);
870 case MIDI_CMD_COMMON_SYSEX:
871 switch (evt & 0x0F) {
872 case 0x00: /* System Exclusive, don't do it on modData,
873 * should require modLongData*/
874 case 0x01: /* Undefined */
875 case 0x04: /* Undefined. */
876 case 0x05: /* Undefined. */
877 case 0x07: /* End of Exclusive. */
878 case 0x09: /* Undefined. */
879 case 0x0D: /* Undefined. */
882 case 0x06: /* Tune Request */
883 case 0x08: /* Timing Clock. */
884 case 0x0A: /* Start. */
885 case 0x0B: /* Continue */
886 case 0x0C: /* Stop */
887 case 0x0E: /* Active Sensing. */
888 /* FIXME: Is this function suitable for these purposes
889 (and also Song Select and Song Position Pointer) */
890 snd_seq_ev_set_sysex(&event, 1, &evt);
892 case 0x0F: /* Reset */
893 /* snd_seq_ev_set_sysex(&event, 1, &evt);
894 this other way may be better */
896 BYTE reset_sysex_seq[] = {MIDI_CMD_COMMON_SYSEX, 0x7e, 0x7f, 0x09, 0x01, 0xf7};
897 snd_seq_ev_set_sysex(&event, sizeof(reset_sysex_seq), reset_sysex_seq);
900 case 0x03: /* Song Select. */
905 snd_seq_ev_set_sysex(&event, sizeof(buf), buf);
908 case 0x02: /* Song Position Pointer. */
914 snd_seq_ev_set_sysex(&event, sizeof(buf), buf);
921 snd_seq_event_output_direct(midiSeq, &event);
925 WARN("Technology not supported (yet) %d !\n",
926 MidiOutDev[wDevID].caps.wTechnology);
927 return MMSYSERR_NOTENABLED;
930 return MMSYSERR_NOERROR;
933 /**************************************************************************
934 * modLongData [internal]
936 static DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
939 LPBYTE lpData, lpNewData = NULL;
940 snd_seq_event_t event;
942 TRACE("(%04X, %p, %08X);\n", wDevID, lpMidiHdr, dwSize);
944 /* Note: MS doc does not say much about the dwBytesRecorded member of the MIDIHDR structure
945 * but it seems to be used only for midi input.
946 * Taking a look at the WAVEHDR structure (which is quite similar) confirms this assumption.
949 if (wDevID >= MODM_NumDevs) return MMSYSERR_BADDEVICEID;
950 if (!MidiOutDev[wDevID].bEnabled) return MIDIERR_NODEVICE;
952 if (midiSeq == NULL) {
953 WARN("can't play !\n");
954 return MIDIERR_NODEVICE;
957 lpData = (LPBYTE) lpMidiHdr->lpData;
960 return MIDIERR_UNPREPARED;
961 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED))
962 return MIDIERR_UNPREPARED;
963 if (lpMidiHdr->dwFlags & MHDR_INQUEUE)
964 return MIDIERR_STILLPLAYING;
965 lpMidiHdr->dwFlags &= ~MHDR_DONE;
966 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
968 /* FIXME: MS doc is not 100% clear. Will lpData only contain system exclusive
969 * data, or can it also contain raw MIDI data, to be split up and sent to
971 * If the latest is true, then the following WARNing will fire up
973 if (lpData[0] != 0xF0 || lpData[lpMidiHdr->dwBufferLength - 1] != 0xF7) {
974 WARN("Alleged system exclusive buffer is not correct\n\tPlease report with MIDI file\n");
975 lpNewData = HeapAlloc(GetProcessHeap(), 0, lpMidiHdr->dwBufferLength + 2);
978 TRACE("dwBufferLength=%u !\n", lpMidiHdr->dwBufferLength);
979 TRACE(" %02X %02X %02X ... %02X %02X %02X\n",
980 lpData[0], lpData[1], lpData[2], lpData[lpMidiHdr->dwBufferLength-3],
981 lpData[lpMidiHdr->dwBufferLength-2], lpData[lpMidiHdr->dwBufferLength-1]);
983 switch (MidiOutDev[wDevID].caps.wTechnology) {
985 /* FIXME: I don't think there is much to do here */
988 if (lpData[0] != 0xF0) {
989 /* Send start of System Exclusive */
992 memcpy(lpNewData, lpData, lpMidiHdr->dwBufferLength);
993 WARN("Adding missing 0xF0 marker at the beginning of "
994 "system exclusive byte stream\n");
996 if (lpData[lpMidiHdr->dwBufferLength-1] != 0xF7) {
997 /* Send end of System Exclusive */
998 memcpy(lpData + len_add, lpData, lpMidiHdr->dwBufferLength);
999 lpNewData[lpMidiHdr->dwBufferLength + len_add - 1] = 0xF0;
1001 WARN("Adding missing 0xF7 marker at the end of "
1002 "system exclusive byte stream\n");
1004 snd_seq_ev_clear(&event);
1005 snd_seq_ev_set_direct(&event);
1006 snd_seq_ev_set_source(&event, port_out);
1007 snd_seq_ev_set_dest(&event, MidiOutDev[wDevID].addr.client, MidiOutDev[wDevID].addr.port);
1008 TRACE("client = %d port = %d\n", MidiOutDev[wDevID].addr.client, MidiOutDev[wDevID].addr.port);
1009 snd_seq_ev_set_sysex(&event, lpMidiHdr->dwBufferLength + len_add, lpNewData ? lpNewData : lpData);
1010 snd_seq_event_output_direct(midiSeq, &event);
1012 HeapFree(GetProcessHeap(), 0, lpData);
1015 WARN("Technology not supported (yet) %d !\n",
1016 MidiOutDev[wDevID].caps.wTechnology);
1017 return MMSYSERR_NOTENABLED;
1020 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1021 lpMidiHdr->dwFlags |= MHDR_DONE;
1022 if (MIDI_NotifyClient(wDevID, MOM_DONE, (DWORD)lpMidiHdr, 0L) != MMSYSERR_NOERROR) {
1023 WARN("can't notify client !\n");
1024 return MMSYSERR_INVALPARAM;
1026 return MMSYSERR_NOERROR;
1029 /**************************************************************************
1030 * modPrepare [internal]
1032 static DWORD modPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1034 TRACE("(%04X, %p, %08X);\n", wDevID, lpMidiHdr, dwSize);
1036 if (midiSeq == NULL) {
1037 WARN("can't prepare !\n");
1038 return MMSYSERR_NOTENABLED;
1041 /* MS doc says that dwFlags must be set to zero, but (kinda funny) MS mciseq drivers
1042 * asks to prepare MIDIHDR which dwFlags != 0.
1043 * So at least check for the inqueue flag
1045 if (dwSize < sizeof(MIDIHDR) || lpMidiHdr == 0 ||
1046 lpMidiHdr->lpData == 0 || (lpMidiHdr->dwFlags & MHDR_INQUEUE) != 0 ||
1047 lpMidiHdr->dwBufferLength >= 0x10000ul) {
1048 WARN("%p %p %08x %d/%d\n", lpMidiHdr, lpMidiHdr->lpData,
1049 lpMidiHdr->dwFlags, sizeof(MIDIHDR), dwSize);
1050 return MMSYSERR_INVALPARAM;
1053 lpMidiHdr->lpNext = 0;
1054 lpMidiHdr->dwFlags |= MHDR_PREPARED;
1055 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1056 return MMSYSERR_NOERROR;
1059 /**************************************************************************
1060 * modUnprepare [internal]
1062 static DWORD modUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1064 TRACE("(%04X, %p, %08X);\n", wDevID, lpMidiHdr, dwSize);
1066 if (midiSeq == NULL) {
1067 WARN("can't unprepare !\n");
1068 return MMSYSERR_NOTENABLED;
1071 if (dwSize < sizeof(MIDIHDR) || lpMidiHdr == 0)
1072 return MMSYSERR_INVALPARAM;
1073 if (lpMidiHdr->dwFlags & MHDR_INQUEUE)
1074 return MIDIERR_STILLPLAYING;
1075 lpMidiHdr->dwFlags &= ~MHDR_PREPARED;
1076 return MMSYSERR_NOERROR;
1079 /**************************************************************************
1080 * modReset [internal]
1082 static DWORD modReset(WORD wDevID)
1086 TRACE("(%04X);\n", wDevID);
1088 if (wDevID >= MODM_NumDevs) return MMSYSERR_BADDEVICEID;
1089 if (!MidiOutDev[wDevID].bEnabled) return MIDIERR_NODEVICE;
1091 /* stop all notes */
1092 /* FIXME: check if 0x78B0 is channel dependent or not. I coded it so that
1093 * it's channel dependent...
1095 for (chn = 0; chn < 16; chn++) {
1096 /* turn off every note */
1097 modData(wDevID, 0x7800 | MIDI_CMD_CONTROL | chn);
1098 /* remove sustain on all channels */
1099 modData(wDevID, (MIDI_CTL_SUSTAIN << 8) | MIDI_CMD_CONTROL | chn);
1101 /* FIXME: the LongData buffers must also be returned to the app */
1102 return MMSYSERR_NOERROR;
1106 /**************************************************************************
1107 * ALSA_AddMidiPort [internal]
1109 * Helper for ALSA_MidiInit
1111 static void ALSA_AddMidiPort(snd_seq_client_info_t* cinfo, snd_seq_port_info_t* pinfo, int cap, int type)
1113 if (cap & SND_SEQ_PORT_CAP_WRITE) {
1114 TRACE("OUT (%d:%s:%s:%d:%s:%x)\n",snd_seq_client_info_get_client(cinfo),
1115 snd_seq_client_info_get_name(cinfo),
1116 snd_seq_client_info_get_type(cinfo) == SND_SEQ_USER_CLIENT ? "user" : "kernel",
1117 snd_seq_port_info_get_port(pinfo),
1118 snd_seq_port_info_get_name(pinfo),
1121 if (MODM_NumDevs >= MAX_MIDIOUTDRV)
1126 memcpy(&MidiOutDev[MODM_NumDevs].addr, snd_seq_port_info_get_addr(pinfo), sizeof(snd_seq_addr_t));
1128 /* Manufac ID. We do not have access to this with soundcard.h
1129 * Does not seem to be a problem, because in mmsystem.h only
1130 * Microsoft's ID is listed.
1132 MidiOutDev[MODM_NumDevs].caps.wMid = 0x00FF;
1133 MidiOutDev[MODM_NumDevs].caps.wPid = 0x0001; /* FIXME Product ID */
1134 /* Product Version. We simply say "1" */
1135 MidiOutDev[MODM_NumDevs].caps.vDriverVersion = 0x001;
1136 MidiOutDev[MODM_NumDevs].caps.wChannelMask = 0xFFFF;
1138 /* FIXME Do we have this information?
1139 * Assuming the soundcards can handle
1140 * MIDICAPS_VOLUME and MIDICAPS_LRVOLUME but
1141 * not MIDICAPS_CACHE.
1143 MidiOutDev[MODM_NumDevs].caps.dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
1144 MultiByteToWideChar(CP_ACP, 0, snd_seq_client_info_get_name(cinfo), -1,
1145 MidiOutDev[MODM_NumDevs].caps.szPname,
1146 sizeof(MidiOutDev[MODM_NumDevs].caps.szPname) / sizeof(WCHAR));
1148 MidiOutDev[MODM_NumDevs].caps.wTechnology = MIDI_AlsaToWindowsDeviceType(type);
1149 MidiOutDev[MODM_NumDevs].caps.wVoices = 16;
1151 /* FIXME Is it possible to know the maximum
1152 * number of simultaneous notes of a soundcard ?
1153 * I believe we don't have this information, but
1154 * it's probably equal or more than wVoices
1156 MidiOutDev[MODM_NumDevs].caps.wNotes = 16;
1157 MidiOutDev[MODM_NumDevs].bEnabled = TRUE;
1159 TRACE("MidiOut[%d]\tname='%s' techn=%d voices=%d notes=%d chnMsk=%04x support=%d\n"
1160 "\tALSA info: midi dev-type=%lx, capa=%lx\n",
1161 MODM_NumDevs, wine_dbgstr_w(MidiOutDev[MODM_NumDevs].caps.szPname),
1162 MidiOutDev[MODM_NumDevs].caps.wTechnology,
1163 MidiOutDev[MODM_NumDevs].caps.wVoices, MidiOutDev[MODM_NumDevs].caps.wNotes,
1164 MidiOutDev[MODM_NumDevs].caps.wChannelMask, MidiOutDev[MODM_NumDevs].caps.dwSupport,
1165 (long)type, (long)0);
1169 if (cap & SND_SEQ_PORT_CAP_READ) {
1170 TRACE("IN (%d:%s:%s:%d:%s:%x)\n",snd_seq_client_info_get_client(cinfo),
1171 snd_seq_client_info_get_name(cinfo),
1172 snd_seq_client_info_get_type(cinfo) == SND_SEQ_USER_CLIENT ? "user" : "kernel",
1173 snd_seq_port_info_get_port(pinfo),
1174 snd_seq_port_info_get_name(pinfo),
1177 if (MIDM_NumDevs >= MAX_MIDIINDRV)
1182 memcpy(&MidiInDev[MIDM_NumDevs].addr, snd_seq_port_info_get_addr(pinfo), sizeof(snd_seq_addr_t));
1184 /* Manufac ID. We do not have access to this with soundcard.h
1185 * Does not seem to be a problem, because in mmsystem.h only
1186 * Microsoft's ID is listed.
1188 MidiInDev[MIDM_NumDevs].caps.wMid = 0x00FF;
1189 MidiInDev[MIDM_NumDevs].caps.wPid = 0x0001; /* FIXME Product ID */
1190 /* Product Version. We simply say "1" */
1191 MidiInDev[MIDM_NumDevs].caps.vDriverVersion = 0x001;
1193 /* FIXME Do we have this information?
1194 * Assuming the soundcards can handle
1195 * MIDICAPS_VOLUME and MIDICAPS_LRVOLUME but
1196 * not MIDICAPS_CACHE.
1198 MidiInDev[MIDM_NumDevs].caps.dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
1199 MultiByteToWideChar(CP_ACP, 0, snd_seq_client_info_get_name(cinfo), -1,
1200 MidiInDev[MIDM_NumDevs].caps.szPname,
1201 sizeof(MidiInDev[MIDM_NumDevs].caps.szPname) / sizeof(WCHAR));
1202 MidiInDev[MIDM_NumDevs].state = 0;
1204 TRACE("MidiIn [%d]\tname='%s' support=%d\n"
1205 "\tALSA info: midi dev-type=%lx, capa=%lx\n",
1206 MIDM_NumDevs, wine_dbgstr_w(MidiInDev[MIDM_NumDevs].caps.szPname),
1207 MidiInDev[MIDM_NumDevs].caps.dwSupport,
1208 (long)type, (long)0);
1214 #endif /* HAVE_ALSA */
1217 /*======================================================================*
1218 * MIDI entry points *
1219 *======================================================================*/
1221 /**************************************************************************
1222 * ALSA_MidiInit [internal]
1224 * Initializes the MIDI devices information variables
1226 LONG ALSA_MidiInit(void)
1229 static BOOL bInitDone = FALSE;
1230 snd_seq_client_info_t *cinfo;
1231 snd_seq_port_info_t *pinfo;
1236 TRACE("Initializing the MIDI variables.\n");
1239 /* try to open device */
1240 if (midiOpenSeq(0) == -1) {
1244 #if 0 /* Debug purpose */
1245 snd_lib_error_set_handler(error_handler);
1248 snd_seq_client_info_alloca(&cinfo);
1249 snd_seq_port_info_alloca(&pinfo);
1251 /* First, search for all internal midi devices */
1252 snd_seq_client_info_set_client(cinfo, -1);
1253 while(snd_seq_query_next_client(midiSeq, cinfo) >= 0) {
1254 snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
1255 snd_seq_port_info_set_port(pinfo, -1);
1256 while (snd_seq_query_next_port(midiSeq, pinfo) >= 0) {
1257 int cap = snd_seq_port_info_get_capability(pinfo);
1258 int type = snd_seq_port_info_get_type(pinfo);
1259 if (!(type & SND_SEQ_PORT_TYPE_PORT))
1260 ALSA_AddMidiPort(cinfo, pinfo, cap, type);
1264 /* Second, search for all external ports */
1265 snd_seq_client_info_set_client(cinfo, -1);
1266 while(snd_seq_query_next_client(midiSeq, cinfo) >= 0) {
1267 snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
1268 snd_seq_port_info_set_port(pinfo, -1);
1269 while (snd_seq_query_next_port(midiSeq, pinfo) >= 0) {
1270 int cap = snd_seq_port_info_get_capability(pinfo);
1271 int type = snd_seq_port_info_get_type(pinfo);
1272 if (type & SND_SEQ_PORT_TYPE_PORT)
1273 ALSA_AddMidiPort(cinfo, pinfo, cap, type);
1277 /* close file and exit */
1285 /**************************************************************************
1286 * midMessage (WINEOSS.4)
1288 DWORD WINAPI ALSA_midMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
1289 DWORD dwParam1, DWORD dwParam2)
1291 TRACE("(%04X, %04X, %08X, %08X, %08X);\n",
1292 wDevID, wMsg, dwUser, dwParam1, dwParam2);
1299 /* FIXME: Pretend this is supported */
1302 return midOpen(wDevID, (LPMIDIOPENDESC)dwParam1, dwParam2);
1304 return midClose(wDevID);
1305 case MIDM_ADDBUFFER:
1306 return midAddBuffer(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1308 return midPrepare(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1309 case MIDM_UNPREPARE:
1310 return midUnprepare(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1311 case MIDM_GETDEVCAPS:
1312 return midGetDevCaps(wDevID, (LPMIDIINCAPSW)dwParam1,dwParam2);
1313 case MIDM_GETNUMDEVS:
1314 return MIDM_NumDevs;
1316 return midReset(wDevID);
1318 return midStart(wDevID);
1320 return midStop(wDevID);
1323 TRACE("Unsupported message\n");
1325 return MMSYSERR_NOTSUPPORTED;
1328 /**************************************************************************
1329 * modMessage (WINEOSS.5)
1331 DWORD WINAPI ALSA_modMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
1332 DWORD dwParam1, DWORD dwParam2)
1334 TRACE("(%04X, %04X, %08X, %08X, %08X);\n",
1335 wDevID, wMsg, dwUser, dwParam1, dwParam2);
1343 /* FIXME: Pretend this is supported */
1346 return modOpen(wDevID, (LPMIDIOPENDESC)dwParam1, dwParam2);
1348 return modClose(wDevID);
1350 return modData(wDevID, dwParam1);
1352 return modLongData(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1354 return modPrepare(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1355 case MODM_UNPREPARE:
1356 return modUnprepare(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1357 case MODM_GETDEVCAPS:
1358 return modGetDevCaps(wDevID, (LPMIDIOUTCAPSW)dwParam1, dwParam2);
1359 case MODM_GETNUMDEVS:
1360 return MODM_NumDevs;
1361 case MODM_GETVOLUME:
1363 case MODM_SETVOLUME:
1366 return modReset(wDevID);
1369 TRACE("Unsupported message\n");
1371 return MMSYSERR_NOTSUPPORTED;
1374 /*-----------------------------------------------------------------------*/