1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * Sample MIDI Wine Driver for Linux
6 * Copyright 1994 Martin Ayotte
11 * 98/7 changes for making this MIDI driver work on OSS
12 * current support is limited to MIDI ports of OSS systems
13 * 98/9 rewriting MCI code for MIDI
14 * 98/11 splitted in midi.c and mcimidi.c
23 #include <sys/ioctl.h>
26 #include "multimedia.h"
42 LPMIDIOPENDESC midiDesc;
47 unsigned char incoming[3];
48 unsigned char incPrev;
60 LPMIDIOPENDESC midiDesc;
65 void* lpExtra; /* according to port type (MIDI, FM...), extra data when needed */
69 static WINE_MIDIIN MidiInDev [MAX_MIDIINDRV ];
70 static WINE_MIDIOUT MidiOutDev[MAX_MIDIOUTDRV];
72 /* this is the total number of MIDI out devices found */
74 /* this is the number of FM synthetizers (index from 0 to
75 NUMFMSYNTHDEVS - 1) */
76 int MODM_NUMFMSYNTHDEVS = 0;
77 /* this is the number of Midi ports (index from NUMFMSYNTHDEVS to
78 NUMFMSYNTHDEVS + NUMMIDIDEVS - 1) */
79 int MODM_NUMMIDIDEVS = 0;
81 /* this is the total number of MIDI out devices found */
85 static int midiSeqFD = -1;
86 static int numOpenMidiSeq = 0;
87 static UINT32 midiInTimerID = 0;
88 static int numStartedMidiIn = 0;
91 /* this structure holds pointers with information for each MIDI
94 LPMIDIOUTCAPS16 midiOutDevices[MAX_MIDIOUTDRV];
96 /* this structure holds pointers with information for each MIDI
99 LPMIDIINCAPS16 midiInDevices [MAX_MIDIINDRV];
102 * FIXME : all tests on device ID for midXXX and modYYY are made against
103 * MAX_MIDIxxDRV (when they are made) but should be done against the actual
104 * number of midi devices found...
105 * check also when HAVE_OSS is defined that midiDesc is not NULL
108 /*======================================================================*
109 * Low level MIDI implemantation *
110 *======================================================================*/
112 /**************************************************************************
113 * MIDI_NotifyClient [internal]
115 static DWORD MIDI_NotifyClient(UINT16 wDevID, WORD wMsg,
116 DWORD dwParam1, DWORD dwParam2)
123 TRACE(midi,"wDevID = %04X wMsg = %d dwParm1 = %04lX dwParam2 = %04lX\n",
124 wDevID, wMsg, dwParam1, dwParam2);
130 if (wDevID > MAX_MIDIOUTDRV)
131 return MCIERR_INTERNAL;
133 dwCallBack = MidiOutDev[wDevID].midiDesc->dwCallback;
134 uFlags = MidiOutDev[wDevID].wFlags;
135 hDev = MidiOutDev[wDevID].midiDesc->hMidi;
136 dwInstance = MidiOutDev[wDevID].midiDesc->dwInstance;
143 if (wDevID > MAX_MIDIINDRV)
144 return MCIERR_INTERNAL;
146 dwCallBack = MidiInDev[wDevID].midiDesc->dwCallback;
147 uFlags = MidiInDev[wDevID].wFlags;
148 hDev = MidiInDev[wDevID].midiDesc->hMidi;
149 dwInstance = MidiInDev[wDevID].midiDesc->dwInstance;
152 WARN(midi, "Unsupported MSW-MIDI message %u\n", wMsg);
153 return MCIERR_INTERNAL;
156 return DriverCallback(dwCallBack, uFlags, hDev, wMsg, dwInstance, dwParam1, dwParam2) ?
161 /**************************************************************************
162 * midiOpenSeq [internal]
164 static int midiOpenSeq(void)
166 if (numOpenMidiSeq == 0) {
167 midiSeqFD = open(MIDI_SEQ, O_RDWR, 0);
168 if (midiSeqFD == -1) {
169 ERR(midi, "can't open '%s' ! (%d)\n", MIDI_SEQ, errno);
172 if (fcntl(midiSeqFD, F_SETFL, O_NONBLOCK) < 0) {
173 WARN(midi, "can't set sequencer fd to non blocking (%d)\n", errno);
178 ioctl(midiSeqFD, SNDCTL_SEQ_RESET);
184 /**************************************************************************
185 * midiCloseSeq [internal]
187 static int midiCloseSeq(void)
189 if (--numOpenMidiSeq == 0) {
196 /* FIXME: this is a bad idea, it's even not static... */
199 /* FIXME: this is not reentrant, not static - because of global variable
201 /**************************************************************************
202 * seqbuf_dump [internal]
204 void seqbuf_dump(void)
207 if (write(midiSeqFD, _seqbuf, _seqbufptr) == -1) {
208 WARN(midi, "Can't write data to sequencer (%d/%d)!\n",
212 * in any case buffer is lost so that if many errors occur the buffer
218 #endif /* HAVE_OSS */
222 static void midReceiveChar(WORD wDevID, unsigned char value, DWORD dwTime)
226 TRACE(midi, "Adding %02xh to %d[%d]\n", value, wDevID, MidiInDev[wDevID].incLen);
228 if (wDevID >= MAX_MIDIINDRV) {
229 WARN(midi, "bad devID\n");
232 if (MidiInDev[wDevID].state == 0) {
233 TRACE(midi, "input not started, thrown away\n");
237 if (MidiInDev[wDevID].state & 2) { /* system exclusive */
238 LPMIDIHDR ptr = MidiInDev[wDevID].lpQueueHdr;
242 ((LPSTR)(ptr->reserved))[ptr->dwBytesRecorded++] = value;
243 if (ptr->dwBytesRecorded == ptr->dwBufferLength) {
247 if (value == 0xF7) { /* then end */
248 MidiInDev[wDevID].state &= ~2;
251 if (sbfb && ptr != NULL) {
252 ptr = MidiInDev[wDevID].lpQueueHdr;
253 ptr->dwFlags &= ~MHDR_INQUEUE;
254 ptr->dwFlags |= MHDR_DONE;
255 MidiInDev[wDevID].lpQueueHdr = (LPMIDIHDR)ptr->lpNext;
256 if (MIDI_NotifyClient(wDevID, MIM_LONGDATA, (DWORD)ptr, dwTime) != MMSYSERR_NOERROR) {
257 WARN(midi, "Couldn't notify client\n");
263 #define IS_CMD(_x) (((_x) & 0x80) == 0x80)
264 #define IS_SYS_CMD(_x) (((_x) & 0xF0) == 0xF0)
266 if (!IS_CMD(value) && MidiInDev[wDevID].incLen == 0) { /* try to reuse old cmd */
267 if (IS_CMD(MidiInDev[wDevID].incPrev) && !IS_SYS_CMD(MidiInDev[wDevID].incPrev)) {
268 MidiInDev[wDevID].incoming[0] = MidiInDev[wDevID].incPrev;
269 MidiInDev[wDevID].incLen = 1;
270 TRACE(midi, "Reusing old command %02xh\n", MidiInDev[wDevID].incPrev);
272 FIXME(midi, "error for midi-in, should generate MIM_ERROR notification:"
273 " prev=%02Xh, incLen=%02Xh\n",
274 MidiInDev[wDevID].incPrev, MidiInDev[wDevID].incLen);
278 MidiInDev[wDevID].incoming[(int)(MidiInDev[wDevID].incLen++)] = value;
279 if (MidiInDev[wDevID].incLen == 1 && !IS_SYS_CMD(MidiInDev[wDevID].incoming[0])) {
280 /* store new cmd, just in case */
281 MidiInDev[wDevID].incPrev = MidiInDev[wDevID].incoming[0];
285 #undef IS_SYS_CMD(_x)
287 switch (MidiInDev[wDevID].incoming[0] & 0xF0) {
290 case MIDI_KEY_PRESSURE:
291 case MIDI_CTL_CHANGE:
292 case MIDI_PITCH_BEND:
293 if (MidiInDev[wDevID].incLen == 3) {
294 toSend = (MidiInDev[wDevID].incoming[2] << 16) |
295 (MidiInDev[wDevID].incoming[1] << 8) |
296 (MidiInDev[wDevID].incoming[0] << 0);
299 case MIDI_PGM_CHANGE:
300 case MIDI_CHN_PRESSURE:
301 if (MidiInDev[wDevID].incLen == 2) {
302 toSend = (MidiInDev[wDevID].incoming[1] << 8) |
303 (MidiInDev[wDevID].incoming[0] << 0);
306 case MIDI_SYSTEM_PREFIX:
307 if (MidiInDev[wDevID].incoming[0] == 0xF0) {
308 MidiInDev[wDevID].state |= 2;
309 MidiInDev[wDevID].incLen = 0;
311 if (MidiInDev[wDevID].incLen == 1) {
312 toSend = (MidiInDev[wDevID].incoming[0] << 0);
317 WARN(midi, "This shouldn't happen (%02X)\n", MidiInDev[wDevID].incoming[0]);
320 TRACE(midi, "Sending event %08lx\n", toSend);
321 MidiInDev[wDevID].incLen = 0;
322 dwTime -= MidiInDev[wDevID].startTime;
323 if (MIDI_NotifyClient(wDevID, MIM_DATA, toSend, dwTime) != MMSYSERR_NOERROR) {
324 WARN(midi, "Couldn't notify client\n");
329 static VOID WINAPI midTimeCallback(HWND32 hwnd, UINT32 msg, UINT32 id, DWORD dwTime)
331 unsigned char buffer[256];
334 TRACE(midi, "(%04X, %d, %d, %lu)\n", hwnd, msg, id, dwTime);
336 len = read(midiSeqFD, buffer, sizeof(buffer));
338 if ((len % 4) != 0) {
339 WARN(midi, "bad length %d (%d)\n", len, errno);
343 for (idx = 0; idx < len; ) {
344 if (buffer[idx] & 0x80) {
346 "reading<8> %02x %02x %02x %02x %02x %02x %02x %02x\n",
347 buffer[idx + 0], buffer[idx + 1],
348 buffer[idx + 2], buffer[idx + 3],
349 buffer[idx + 4], buffer[idx + 5],
350 buffer[idx + 6], buffer[idx + 7]);
353 switch (buffer[idx + 0]) {
358 midReceiveChar(buffer[idx + 2], buffer[idx + 1], dwTime);
361 TRACE(midi, "Unsupported event %d\n", buffer[idx + 0]);
368 #endif /* HAVE_OSS */
370 /**************************************************************************
371 * midGetDevCaps [internal]
373 static DWORD midGetDevCaps(WORD wDevID, LPMIDIINCAPS16 lpCaps, DWORD dwSize)
375 LPMIDIINCAPS16 tmplpCaps;
377 TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpCaps, dwSize);
379 if (wDevID >= MIDM_NUMDEVS) {
380 return MMSYSERR_BADDEVICEID;
382 if (lpCaps == NULL) {
383 return MMSYSERR_INVALPARAM;
386 tmplpCaps = midiInDevices[wDevID];
387 lpCaps->wMid = tmplpCaps->wMid;
388 lpCaps->wPid = tmplpCaps->wPid;
389 lpCaps->vDriverVersion = tmplpCaps->vDriverVersion;
390 strcpy(lpCaps->szPname, tmplpCaps->szPname);
391 if (dwSize == sizeof(MIDIINCAPS16)) {
392 /* we should run win 95, so make use of dwSupport */
393 lpCaps->dwSupport = tmplpCaps->dwSupport;
394 } else if (dwSize != sizeof(MIDIINCAPS16) - sizeof(DWORD)) {
395 TRACE(midi, "bad size for lpCaps\n");
396 return MMSYSERR_INVALPARAM;
399 return MMSYSERR_NOERROR;
402 /**************************************************************************
405 static DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
407 TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
409 if (lpDesc == NULL) {
410 WARN(midi, "Invalid Parameter !\n");
411 return MMSYSERR_INVALPARAM;
414 * how to check that content of lpDesc is correct ?
416 if (wDevID >= MAX_MIDIINDRV) {
417 WARN(midi,"wDevID too large (%u) !\n", wDevID);
418 return MMSYSERR_BADDEVICEID;
420 if (MidiInDev[wDevID].midiDesc != 0) {
421 WARN(midi, "device already open !\n");
422 return MMSYSERR_ALLOCATED;
424 if ((dwFlags & ~CALLBACK_TYPEMASK) != 0) {
425 FIXME(midi, "No support for MIDI_IO_STATUS in dwFlags\n");
426 return MMSYSERR_INVALFLAG;
430 if (midiOpenSeq() < 0) {
431 return MMSYSERR_ERROR;
434 if (numStartedMidiIn++ == 0) {
435 midiInTimerID = SetTimer32(0, 0, 250, midTimeCallback);
436 if (!midiInTimerID) {
437 numStartedMidiIn = 0;
438 WARN(midi, "Couldn't start timer for midi-in\n");
440 return MMSYSERR_ERROR;
442 TRACE(midi, "Starting timer (%u) for midi-in\n", midiInTimerID);
446 int midi = open(MIDI_DEV, O_WRONLY, 0);
448 MidiInDev[wDevID].unixdev = 0;
450 WARN(midi,"can't open '%s' (%d)!\n", MIDI_DEV, errno);
451 return MMSYSERR_ALLOCATED;
453 MidiInDev[wDevID].unixdev = midi;
455 #endif /* HAVE_OSS */
457 MidiInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
458 switch (MidiInDev[wDevID].wFlags) {
460 TRACE(midi,"CALLBACK_NULL !\n");
463 TRACE(midi, "CALLBACK_WINDOW !\n");
466 TRACE(midi, "CALLBACK_TASK !\n");
469 TRACE(midi, "CALLBACK_FUNCTION (%08lX)!\n", lpDesc->dwCallback);
472 MidiInDev[wDevID].lpQueueHdr = NULL;
473 MidiInDev[wDevID].dwTotalPlayed = 0;
474 MidiInDev[wDevID].bufsize = 0x3FFF;
475 MidiInDev[wDevID].midiDesc = lpDesc;
476 MidiInDev[wDevID].state = 0;
478 MidiInDev[wDevID].incLen = 0;
479 MidiInDev[wDevID].startTime = 0;
480 #endif /* HAVE_OSS */
481 if (MIDI_NotifyClient(wDevID, MIM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
482 WARN(midi,"can't notify client !\n");
483 return MMSYSERR_INVALPARAM;
485 return MMSYSERR_NOERROR;
488 /**************************************************************************
489 * midClose [internal]
491 static DWORD midClose(WORD wDevID)
493 int ret = MMSYSERR_NOERROR;
495 TRACE(midi, "(%04X);\n", wDevID);
497 if (wDevID >= MAX_MIDIINDRV) {
498 WARN(midi,"wDevID too bif (%u) !\n", wDevID);
499 return MMSYSERR_BADDEVICEID;
501 if (MidiInDev[wDevID].midiDesc == 0) {
502 WARN(midi, "device not opened !\n");
503 return MMSYSERR_ERROR;
505 if (MidiInDev[wDevID].lpQueueHdr != 0) {
506 return MIDIERR_STILLPLAYING;
510 if (midiSeqFD == -1) {
511 WARN(midi,"ooops !\n");
512 return MMSYSERR_ERROR;
514 if (--numStartedMidiIn == 0) {
515 TRACE(midi, "Stopping timer for midi-in\n");
516 if (!KillTimer32(0, midiInTimerID)) {
517 WARN(midi, "Couldn't stop timer for midi-in\n");
523 if (MidiInDev[wDevID].unixdev == 0) {
524 WARN(midi,"ooops !\n");
525 return MMSYSERR_ERROR;
527 close(MidiInDev[wDevID].unixdev);
528 MidiInDev[wDevID].unixdev = 0;
529 #endif /* HAVE_OSS */
530 MidiInDev[wDevID].bufsize = 0;
531 if (MIDI_NotifyClient(wDevID, MIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
532 WARN(midi,"can't notify client !\n");
533 ret = MMSYSERR_INVALPARAM;
535 MidiInDev[wDevID].midiDesc = 0;
539 /**************************************************************************
540 * midAddBuffer [internal]
542 static DWORD midAddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
544 TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
546 if (lpMidiHdr == NULL) return MMSYSERR_INVALPARAM;
547 if (sizeof(MIDIHDR) != dwSize) return MMSYSERR_INVALPARAM;
548 if (lpMidiHdr->dwBufferLength == 0) return MMSYSERR_INVALPARAM;
549 if (lpMidiHdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING;
550 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED)) return MIDIERR_UNPREPARED;
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 return MMSYSERR_NOERROR;
565 /**************************************************************************
566 * midPrepare [internal]
568 static DWORD midPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
570 TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
572 if (dwSize != sizeof(MIDIHDR) || lpMidiHdr == 0 ||
573 lpMidiHdr->lpData == 0 || lpMidiHdr->dwFlags != 0 ||
574 lpMidiHdr->dwBufferLength >= 0x10000ul)
575 return MMSYSERR_INVALPARAM;
577 lpMidiHdr->lpNext = 0;
578 lpMidiHdr->dwFlags |= MHDR_PREPARED;
579 lpMidiHdr->dwBytesRecorded = 0;
581 return MMSYSERR_NOERROR;
584 /**************************************************************************
585 * midUnprepare [internal]
587 static DWORD midUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
589 TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
591 if (dwSize != sizeof(MIDIHDR) || lpMidiHdr == 0 ||
592 lpMidiHdr->lpData == 0 || lpMidiHdr->dwBufferLength >= 0x10000ul)
593 return MMSYSERR_INVALPARAM;
595 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED)) return MIDIERR_UNPREPARED;
596 if (lpMidiHdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING;
598 lpMidiHdr->dwFlags &= ~MHDR_PREPARED;
600 return MMSYSERR_NOERROR;
603 /**************************************************************************
604 * midReset [internal]
606 static DWORD midReset(WORD wDevID)
608 DWORD dwTime = GetTickCount();
610 TRACE(midi, "(%04X);\n", wDevID);
612 while (MidiInDev[wDevID].lpQueueHdr) {
613 MidiInDev[wDevID].lpQueueHdr->dwFlags &= ~MHDR_INQUEUE;
614 MidiInDev[wDevID].lpQueueHdr->dwFlags |= MHDR_DONE;
615 if (MIDI_NotifyClient(wDevID, MIM_LONGDATA,
616 (DWORD)MidiInDev[wDevID].lpQueueHdr, dwTime) != MMSYSERR_NOERROR) {
617 WARN(midi, "Couldn't notify client\n");
619 MidiInDev[wDevID].lpQueueHdr = (LPMIDIHDR)MidiInDev[wDevID].lpQueueHdr->lpNext;
622 return MMSYSERR_NOERROR;
626 /**************************************************************************
627 * midStart [internal]
629 static DWORD midStart(WORD wDevID)
631 TRACE(midi, "(%04X);\n", wDevID);
633 /* FIXME : should test value of wDevID */
636 MidiInDev[wDevID].state = 1;
637 MidiInDev[wDevID].startTime = GetTickCount();
638 return MMSYSERR_NOERROR;
640 return MMSYSERR_NOTENABLED;
641 #endif /* HAVE_OSS */
644 /**************************************************************************
647 static DWORD midStop(WORD wDevID)
649 TRACE(midi, "(%04X);\n", wDevID);
651 /* FIXME : should test value of wDevID */
654 MidiInDev[wDevID].state = 0;
655 return MMSYSERR_NOERROR;
657 return MMSYSERR_NOTENABLED;
658 #endif /* HAVE_OSS */
661 /**************************************************************************
662 * midMessage [sample driver]
664 DWORD WINAPI midMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
665 DWORD dwParam1, DWORD dwParam2)
667 TRACE(midi, "(%04X, %04X, %08lX, %08lX, %08lX);\n",
668 wDevID, wMsg, dwUser, dwParam1, dwParam2);
671 return midOpen(wDevID,(LPMIDIOPENDESC)dwParam1, dwParam2);
673 return midClose(wDevID);
675 return midAddBuffer(wDevID,(LPMIDIHDR)dwParam1, dwParam2);
677 return midPrepare(wDevID,(LPMIDIHDR)dwParam1, dwParam2);
679 return midUnprepare(wDevID,(LPMIDIHDR)dwParam1, dwParam2);
680 case MIDM_GETDEVCAPS:
681 return midGetDevCaps(wDevID,(LPMIDIINCAPS16)dwParam1,dwParam2);
682 case MIDM_GETNUMDEVS:
685 return midReset(wDevID);
687 return midStart(wDevID);
689 return midStop(wDevID);
691 TRACE(midi, "Unsupported message\n");
693 return MMSYSERR_NOTSUPPORTED;
696 /*-----------------------------------------------------------------------*/
700 typedef struct sVoice {
701 int note; /* 0 means not used */
703 unsigned cntMark : 30,
706 #define sVS_PLAYING 1
707 #define sVS_SUSTAINED 2
710 typedef struct sChannel {
716 int bank; /* CTL_BANK_SELECT */
717 int volume; /* CTL_MAIN_VOLUME */
718 int balance; /* CTL_BALANCE */
719 int expression; /* CTL_EXPRESSION */
720 int sustain; /* CTL_SUSTAIN */
722 unsigned char nrgPmtMSB; /* Non register Parameters */
723 unsigned char nrgPmtLSB;
724 unsigned char regPmtMSB; /* Non register Parameters */
725 unsigned char regPmtLSB;
728 typedef struct sFMextra {
731 sChannel channel[16]; /* MIDI has only 16 channels */
732 sVoice voice[1]; /* dyn allocated according to sound card */
733 /* do not append fields below voice[1] since the size of this structure
734 * depends on the number of available voices on the FM synth...
738 extern unsigned char midiFMInstrumentPatches[16 * 128];
739 extern unsigned char midiFMDrumsPatches [16 * 128];
741 /**************************************************************************
742 * modFMLoad [internal]
744 static int modFMLoad(int dev)
747 struct sbi_instrument sbi;
752 memset(sbi.operators + 16, 0, 16);
753 for (i = 0; i < 128; i++) {
755 memcpy(sbi.operators, midiFMInstrumentPatches + i * 16, 16);
757 if (write(midiSeqFD, (char*)&sbi, sizeof(sbi)) == -1) {
758 WARN(midi, "Couldn't write patch for instrument %d (%d)!\n", sbi.channel, errno);
762 for (i = 0; i < 128; i++) {
763 sbi.channel = 128 + i;
764 memcpy(sbi.operators, midiFMDrumsPatches + i * 16, 16);
766 if (write(midiSeqFD, (char*)&sbi, sizeof(sbi)) == -1) {
767 WARN(midi, "Couldn't write patch for drum %d (%d)!\n", sbi.channel, errno);
774 /**************************************************************************
775 * modFMReset [internal]
777 static void modFMReset(WORD wDevID)
779 sFMextra* extra = (sFMextra*)MidiOutDev[wDevID].lpExtra;
780 sVoice* voice = extra->voice;
781 sChannel* channel = extra->channel;
784 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
785 if (voice[i].status != sVS_UNUSED) {
786 SEQ_STOP_NOTE(wDevID, i, voice[i].note, 64);
788 SEQ_KEY_PRESSURE(wDevID, i, 127, 0);
789 SEQ_CONTROL(wDevID, i, SEQ_VOLMODE, VOL_METHOD_LINEAR);
791 voice[i].channel = -1;
792 voice[i].cntMark = 0;
793 voice[i].status = sVS_UNUSED;
795 for (i = 0; i < 16; i++) {
796 channel[i].program = 0;
797 channel[i].bender = 8192;
798 channel[i].benderRange = 2;
800 channel[i].volume = 127;
801 channel[i].balance = 64;
802 channel[i].expression = 0;
803 channel[i].sustain = 0;
806 extra->drumSetMask = 1 << 9; /* channel 10 is normally drums, sometimes 16 also */
810 #define IS_DRUM_CHANNEL(_xtra, _chn) ((_xtra)->drumSetMask & (1 << (_chn)))
812 #endif /* HAVE_OSS */
814 /**************************************************************************
815 * modGetDevCaps [internal]
817 static DWORD modGetDevCaps(WORD wDevID, LPMIDIOUTCAPS16 lpCaps,
820 TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpCaps, dwSize);
821 if (wDevID == (WORD) MIDI_MAPPER) {
822 lpCaps->wMid = 0x00FF; /* Manufac ID */
823 lpCaps->wPid = 0x0001; /* Product ID */
824 lpCaps->vDriverVersion = 0x001; /* Product Version */
825 strcpy(lpCaps->szPname, "MIDI Mapper (not functional yet)");
826 /* FIXME Does it make any difference ? */
827 lpCaps->wTechnology = MOD_FMSYNTH;
828 lpCaps->wVoices = 14; /* FIXME */
829 lpCaps->wNotes = 14; /* FIXME */
830 /* FIXME Does it make any difference ? */
831 lpCaps->dwSupport = MIDICAPS_VOLUME|MIDICAPS_LRVOLUME;
833 LPMIDIOUTCAPS16 tmplpCaps;
835 if (wDevID >= MODM_NUMDEVS) {
836 TRACE(midi, "MAX_MIDIOUTDRV reached !\n");
837 return MMSYSERR_BADDEVICEID;
839 /* FIXME There is a way to do it so easily, but I'm too
840 * sleepy to think and I want to test
843 tmplpCaps = midiOutDevices[wDevID];
844 lpCaps->wMid = tmplpCaps->wMid;
845 lpCaps->wPid = tmplpCaps->wPid;
846 lpCaps->vDriverVersion = tmplpCaps->vDriverVersion;
847 strcpy(lpCaps->szPname, tmplpCaps->szPname);
848 lpCaps->wTechnology = tmplpCaps->wTechnology;
849 lpCaps->wVoices = tmplpCaps->wVoices;
850 lpCaps->wNotes = tmplpCaps->wNotes;
851 lpCaps->dwSupport = tmplpCaps->dwSupport;
853 return MMSYSERR_NOERROR;
856 /**************************************************************************
859 static DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
861 TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
862 if (lpDesc == NULL) {
863 WARN(midi, "Invalid Parameter !\n");
864 return MMSYSERR_INVALPARAM;
866 if (wDevID >= MAX_MIDIOUTDRV) {
867 TRACE(midi,"MAX_MIDIOUTDRV reached !\n");
868 return MMSYSERR_BADDEVICEID;
870 if (MidiOutDev[wDevID].midiDesc != 0) {
871 WARN(midi, "device already open !\n");
872 return MMSYSERR_ALLOCATED;
874 if ((dwFlags & ~CALLBACK_TYPEMASK) != 0) {
875 WARN(midi, "bad dwFlags\n");
876 return MMSYSERR_INVALFLAG;
878 if (midiOutDevices[wDevID] == NULL) {
879 TRACE(midi, "un-allocated wDevID\n");
880 return MMSYSERR_BADDEVICEID;
884 MidiOutDev[wDevID].lpExtra = 0;
886 switch (midiOutDevices[wDevID]->wTechnology) {
889 void* extra = xmalloc(sizeof(struct sFMextra) +
890 sizeof(struct sVoice) *
891 (midiOutDevices[wDevID]->wVoices - 1));
894 WARN(midi, "can't alloc extra data !\n");
895 return MMSYSERR_NOMEM;
897 MidiOutDev[wDevID].lpExtra = extra;
898 if (midiOpenSeq() < 0) {
899 MidiOutDev[wDevID].lpExtra = 0;
901 return MMSYSERR_ERROR;
903 if (modFMLoad(wDevID) < 0) {
905 MidiOutDev[wDevID].lpExtra = 0;
907 return MMSYSERR_ERROR;
913 if (midiOpenSeq() < 0) {
914 return MMSYSERR_ALLOCATED;
918 WARN(midi,"Technology not supported (yet) %d !\n",
919 midiOutDevices[wDevID]->wTechnology);
920 return MMSYSERR_NOTENABLED;
924 int midi = open (MIDI_DEV, O_WRONLY, 0);
925 MidiOutDev[wDevID].unixdev = 0;
927 WARN(midi, "can't open !\n");
928 return MMSYSERR_ALLOCATED;
930 MidiOutDev[wDevID].unixdev = midi;
932 #endif /* HAVE_OSS */
934 MidiOutDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
935 switch (MidiOutDev[wDevID].wFlags) {
937 TRACE(midi,"CALLBACK_NULL !\n");
940 TRACE(midi, "CALLBACK_WINDOW !\n");
943 TRACE(midi, "CALLBACK_TASK !\n");
946 TRACE(midi, "CALLBACK_FUNCTION !\n");
949 MidiOutDev[wDevID].lpQueueHdr = NULL;
950 MidiOutDev[wDevID].dwTotalPlayed = 0;
951 MidiOutDev[wDevID].bufsize = 0x3FFF;
952 MidiOutDev[wDevID].midiDesc = lpDesc;
954 if (MIDI_NotifyClient(wDevID, MOM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
955 WARN(midi,"can't notify client !\n");
956 return MMSYSERR_INVALPARAM;
958 TRACE(midi, "Succesful !\n");
959 return MMSYSERR_NOERROR;
963 /**************************************************************************
964 * modClose [internal]
966 static DWORD modClose(WORD wDevID)
968 int ret = MMSYSERR_NOERROR;
970 TRACE(midi, "(%04X);\n", wDevID);
972 if (MidiOutDev[wDevID].midiDesc == 0) {
973 WARN(midi, "device not opened !\n");
974 return MMSYSERR_ERROR;
976 /* FIXME: should test that no pending buffer is still in the queue for
980 if (midiSeqFD == -1) {
981 WARN(midi,"can't close !\n");
982 return MMSYSERR_ERROR;
985 switch (midiOutDevices[wDevID]->wTechnology) {
991 WARN(midi,"Technology not supported (yet) %d !\n",
992 midiOutDevices[wDevID]->wTechnology);
993 return MMSYSERR_NOTENABLED;
996 if (MidiOutDev[wDevID].lpExtra != 0) {
997 free(MidiOutDev[wDevID].lpExtra);
998 MidiOutDev[wDevID].lpExtra = 0;
1001 if (MidiOutDev[wDevID].unixdev == 0) {
1002 WARN(midi,"can't close !\n");
1003 return MMSYSERR_NOTENABLED;
1005 close(MidiOutDev[wDevID].unixdev);
1006 MidiOutDev[wDevID].unixdev = 0;
1007 #endif /* HAVE_OSS */
1009 MidiOutDev[wDevID].bufsize = 0;
1010 if (MIDI_NotifyClient(wDevID, MOM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
1011 WARN(midi,"can't notify client !\n");
1012 ret = MMSYSERR_INVALPARAM;
1014 MidiOutDev[wDevID].midiDesc = 0;
1018 /**************************************************************************
1019 * modData [internal]
1021 static DWORD modData(WORD wDevID, DWORD dwParam)
1023 WORD evt = LOBYTE(LOWORD(dwParam));
1024 WORD d1 = HIBYTE(LOWORD(dwParam));
1025 WORD d2 = LOBYTE(HIWORD(dwParam));
1027 TRACE(midi, "(%04X, %08lX);\n", wDevID, dwParam);
1030 if (midiSeqFD == -1) {
1031 WARN(midi,"can't play !\n");
1032 return MIDIERR_NODEVICE;
1034 switch (midiOutDevices[wDevID]->wTechnology) {
1037 * - chorus depth controller is not used
1040 sFMextra* extra = (sFMextra*)MidiOutDev[wDevID].lpExtra;
1041 sVoice* voice = extra->voice;
1042 sChannel* channel = extra->channel;
1043 int chn = (evt & 0x0F);
1046 switch (evt & 0xF0) {
1048 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1049 /* don't stop sustained notes */
1050 if (voice[i].status == sVS_PLAYING && voice[i].channel == chn && voice[i].note == d1) {
1051 voice[i].status = sVS_UNUSED;
1052 SEQ_STOP_NOTE(wDevID, i, d1, d2);
1057 if (d2 == 0) { /* note off if velocity == 0 */
1058 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1059 /* don't stop sustained notes */
1060 if (voice[i].status == sVS_PLAYING && voice[i].channel == chn && voice[i].note == d1) {
1061 voice[i].status = sVS_UNUSED;
1062 SEQ_STOP_NOTE(wDevID, i, d1, 64);
1067 /* finding out in this order :
1069 * - if replaying the same note on the same channel
1070 * - the older voice (LRU)
1072 for (i = nv = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1073 if (voice[i].status == sVS_UNUSED ||
1074 (voice[i].note == d1 && voice[i].channel == chn)) {
1078 if (voice[i].cntMark < voice[0].cntMark) {
1083 "playing on voice=%d, pgm=%d, pan=0x%02X, vol=0x%02X, "
1084 "bender=0x%02X, note=0x%02X, vel=0x%02X\n",
1085 nv, channel[chn].program,
1086 channel[chn].balance,
1087 channel[chn].volume,
1088 channel[chn].bender, d1, d2);
1090 SEQ_SET_PATCH(wDevID, nv, IS_DRUM_CHANNEL(extra, chn) ?
1091 (128 + d1) : channel[chn].program);
1092 SEQ_BENDER_RANGE(wDevID, nv, channel[chn].benderRange * 100);
1093 SEQ_BENDER(wDevID, nv, channel[chn].bender);
1094 SEQ_CONTROL(wDevID, nv, CTL_PAN, channel[chn].balance);
1095 SEQ_CONTROL(wDevID, nv, CTL_EXPRESSION, channel[chn].expression);
1097 /* FIXME: does not really seem to work on my SB card and
1098 * screws everything up... so lay it down
1100 SEQ_CONTROL(wDevID, nv, CTL_MAIN_VOLUME, channel[chn].volume);
1102 SEQ_START_NOTE(wDevID, nv, d1, d2);
1103 voice[nv].status = channel[chn].sustain ? sVS_SUSTAINED : sVS_PLAYING;
1104 voice[nv].note = d1;
1105 voice[nv].channel = chn;
1106 voice[nv].cntMark = extra->counter++;
1108 case MIDI_KEY_PRESSURE:
1109 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1110 if (voice[i].status != sVS_UNUSED && voice[i].channel == chn && voice[i].note == d1) {
1111 SEQ_KEY_PRESSURE(wDevID, i, d1, d2);
1115 case MIDI_CTL_CHANGE:
1117 case CTL_BANK_SELECT: channel[chn].bank = d2; break;
1118 case CTL_MAIN_VOLUME: channel[chn].volume = d2; break;
1119 case CTL_PAN: channel[chn].balance = d2; break;
1120 case CTL_EXPRESSION: channel[chn].expression = d2; break;
1121 case CTL_SUSTAIN: channel[chn].sustain = d2;
1123 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1124 if (voice[i].status == sVS_PLAYING && voice[i].channel == chn) {
1125 voice[i].status = sVS_SUSTAINED;
1129 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1130 if (voice[i].status == sVS_SUSTAINED && voice[i].channel == chn) {
1131 voice[i].status = sVS_UNUSED;
1132 SEQ_STOP_NOTE(wDevID, i, voice[i].note, 64);
1137 case CTL_NONREG_PARM_NUM_LSB: channel[chn].nrgPmtLSB = d2; break;
1138 case CTL_NONREG_PARM_NUM_MSB: channel[chn].nrgPmtMSB = d2; break;
1139 case CTL_REGIST_PARM_NUM_LSB: channel[chn].regPmtLSB = d2; break;
1140 case CTL_REGIST_PARM_NUM_MSB: channel[chn].regPmtMSB = d2; break;
1142 case CTL_DATA_ENTRY:
1143 switch ((channel[chn].regPmtMSB << 8) | channel[chn].regPmtLSB) {
1145 if (channel[chn].benderRange != d2) {
1146 channel[chn].benderRange = d2;
1147 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1148 if (voice[i].channel == chn) {
1149 SEQ_BENDER_RANGE(wDevID, i, channel[chn].benderRange);
1156 channel[chn].benderRange = 2;
1157 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1158 if (voice[i].channel == chn) {
1159 SEQ_BENDER_RANGE(wDevID, i, channel[chn].benderRange);
1164 TRACE(midi, "Data entry: regPmt=0x%02x%02x, nrgPmt=0x%02x%02x with %x\n",
1165 channel[chn].regPmtMSB, channel[chn].regPmtLSB,
1166 channel[chn].nrgPmtMSB, channel[chn].nrgPmtLSB,
1172 case 0x78: /* all sounds off */
1173 /* FIXME: I don't know if I have to take care of the channel
1174 * for this control ?
1176 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1177 if (voice[i].status != sVS_UNUSED && voice[i].channel == chn) {
1178 voice[i].status = sVS_UNUSED;
1179 SEQ_STOP_NOTE(wDevID, i, voice[i].note, 0);
1183 case 0x7B: /* all notes off */
1184 /* FIXME: I don't know if I have to take care of the channel
1185 * for this control ?
1187 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1188 if (voice[i].status == sVS_PLAYING && voice[i].channel == chn) {
1189 voice[i].status = sVS_UNUSED;
1190 SEQ_STOP_NOTE(wDevID, i, voice[i].note, 0);
1195 TRACE(midi, "Dropping MIDI control event 0x%02x(%02x) on channel %d\n",
1200 case MIDI_PGM_CHANGE:
1201 channel[chn].program = d1;
1203 case MIDI_CHN_PRESSURE:
1204 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1205 if (voice[i].status != sVS_UNUSED && voice[i].channel == chn) {
1206 SEQ_KEY_PRESSURE(wDevID, i, voice[i].note, d1);
1210 case MIDI_PITCH_BEND:
1211 channel[chn].bender = (d2 << 7) + d1;
1212 for (i = 0; i < midiOutDevices[wDevID]->wVoices; i++) {
1213 if (voice[i].channel == chn) {
1214 SEQ_BENDER(wDevID, i, channel[chn].bender);
1218 case MIDI_SYSTEM_PREFIX:
1219 switch (evt & 0x0F) {
1220 case 0x0F: /* Reset */
1224 WARN(midi, "Unsupported (yet) system event %02x\n", evt & 0x0F);
1228 WARN(midi, "Internal error, shouldn't happen (event=%08x)\n", evt & 0xF0);
1229 return MMSYSERR_NOTENABLED;
1235 int dev = wDevID - MODM_NUMFMSYNTHDEVS;
1237 WARN(midi, "Internal error on devID (%u) !\n", wDevID);
1238 return MIDIERR_NODEVICE;
1241 switch (evt & 0xF0) {
1244 case MIDI_KEY_PRESSURE:
1245 case MIDI_CTL_CHANGE:
1246 case MIDI_PITCH_BEND:
1247 SEQ_MIDIOUT(dev, evt);
1248 SEQ_MIDIOUT(dev, d1);
1249 SEQ_MIDIOUT(dev, d2);
1251 case MIDI_PGM_CHANGE:
1252 case MIDI_CHN_PRESSURE:
1253 SEQ_MIDIOUT(dev, evt);
1254 SEQ_MIDIOUT(dev, d1);
1256 case MIDI_SYSTEM_PREFIX:
1257 switch (evt & 0x0F) {
1258 case 0x00: /* System Exclusive, don't do it on modData,
1259 * should require modLongData*/
1260 case 0x01: /* Undefined */
1261 case 0x04: /* Undefined. */
1262 case 0x05: /* Undefined. */
1263 case 0x07: /* End of Exclusive. */
1264 case 0x09: /* Undefined. */
1265 case 0x0D: /* Undefined. */
1267 case 0x06: /* Tune Request */
1268 case 0x08: /* Timing Clock. */
1269 case 0x0A: /* Start. */
1270 case 0x0B: /* Continue */
1271 case 0x0C: /* Stop */
1272 case 0x0E: /* Active Sensing. */
1273 SEQ_MIDIOUT(dev, evt);
1275 case 0x0F: /* Reset */
1276 /* SEQ_MIDIOUT(dev, evt);
1277 this other way may be better */
1278 SEQ_MIDIOUT(dev, MIDI_SYSTEM_PREFIX);
1279 SEQ_MIDIOUT(dev, 0x7e);
1280 SEQ_MIDIOUT(dev, 0x7f);
1281 SEQ_MIDIOUT(dev, 0x09);
1282 SEQ_MIDIOUT(dev, 0x01);
1283 SEQ_MIDIOUT(dev, 0xf7);
1285 case 0x03: /* Song Select. */
1286 SEQ_MIDIOUT(dev, evt);
1287 SEQ_MIDIOUT(dev, d1);
1288 case 0x02: /* Song Position Pointer. */
1289 SEQ_MIDIOUT(dev, evt);
1290 SEQ_MIDIOUT(dev, d1);
1291 SEQ_MIDIOUT(dev, d2);
1298 WARN(midi, "Technology not supported (yet) %d !\n",
1299 midiOutDevices[wDevID]->wTechnology);
1300 return MMSYSERR_NOTENABLED;
1305 if (MidiOutDev[wDevID].unixdev == 0) {
1306 WARN(midi,"can't play !\n");
1307 return MIDIERR_NODEVICE;
1310 WORD event = LOWORD(dwParam);
1311 if (write (MidiOutDev[wDevID].unixdev,
1312 &event, sizeof(event)) != sizeof(WORD)) {
1313 WARN(midi, "error writting unixdev !\n");
1316 #endif /* HAVE_OSS */
1317 return MMSYSERR_NOERROR;
1320 /**************************************************************************
1321 * modLongData [internal]
1323 static DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1327 TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
1330 if (midiSeqFD == -1) {
1331 WARN(midi,"can't play !\n");
1332 return MIDIERR_NODEVICE;
1334 #else /* HAVE_OSS */
1335 if (MidiOutDev[wDevID].unixdev == 0) {
1336 WARN(midi,"can't play !\n");
1337 return MIDIERR_NODEVICE;
1339 #endif /* HAVE_OSS */
1341 if (lpMidiHdr->lpData == NULL)
1342 return MIDIERR_UNPREPARED;
1343 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED))
1344 return MIDIERR_UNPREPARED;
1345 if (lpMidiHdr->dwFlags & MHDR_INQUEUE)
1346 return MIDIERR_STILLPLAYING;
1347 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1348 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
1350 TRACE(midi, "dwBytesRecorded %lu !\n", lpMidiHdr->dwBytesRecorded);
1351 TRACE(midi, " %02X %02X %02X %02X\n",
1352 ((LPBYTE)(lpMidiHdr->reserved))[0],
1353 ((LPBYTE)(lpMidiHdr->reserved))[1],
1354 ((LPBYTE)(lpMidiHdr->reserved))[2],
1355 ((LPBYTE)(lpMidiHdr->reserved))[3]);
1357 switch (midiOutDevices[wDevID]->wTechnology) {
1359 /* FIXME: I don't think there is much to do here */
1362 if (((LPBYTE)lpMidiHdr->reserved)[0] != 0xF0) {
1363 /* Send end of System Exclusive */
1364 SEQ_MIDIOUT(wDevID - MODM_NUMFMSYNTHDEVS, 0xF0);
1365 TRACE(midi, "Adding missing 0xF0 marker at the begining of "
1366 "system exclusive byte stream\n");
1368 for (count = 0; count < lpMidiHdr->dwBytesRecorded; count++) {
1369 SEQ_MIDIOUT(wDevID - MODM_NUMFMSYNTHDEVS,
1370 ((LPBYTE)lpMidiHdr->reserved)[count]);
1372 if (((LPBYTE)lpMidiHdr->reserved)[count - 1] != 0xF7) {
1373 /* Send end of System Exclusive */
1374 SEQ_MIDIOUT(wDevID - MODM_NUMFMSYNTHDEVS, 0xF7);
1375 TRACE(midi, "Adding missing 0xF7 marker at the end of "
1376 "system exclusive byte stream\n");
1381 WARN(midi, "Technology not supported (yet) %d !\n",
1382 midiOutDevices[wDevID]->wTechnology);
1383 return MMSYSERR_NOTENABLED;
1385 #else /* HAVE_OSS */
1387 LPWORD ptr = (LPWORD)lpMidiHdr->reserved;
1390 for (count = 0; count < lpMidiHdr->dwBytesRecorded; count++) {
1391 if (write(MidiOutDev[wDevID].unixdev,
1392 ptr, sizeof(WORD)) != sizeof(WORD))
1398 TRACE(midi, "after write count = %d\n",count);
1399 if (count != lpMidiHdr->dwBytesRecorded) {
1400 WARN(midi, "error writting unixdev #%d ! (%d != %ld)\n",
1401 MidiOutDev[wDevID].unixdev, count,
1402 lpMidiHdr->dwBytesRecorded);
1403 TRACE(midi, "\terrno = %d error = %s\n",en,strerror(en));
1404 return MMSYSERR_NOTENABLED;
1407 #endif /* HAVE_OSS */
1409 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1410 lpMidiHdr->dwFlags |= MHDR_DONE;
1411 if (MIDI_NotifyClient(wDevID, MOM_DONE, (DWORD)lpMidiHdr, 0L) != MMSYSERR_NOERROR) {
1412 WARN(midi,"can't notify client !\n");
1413 return MMSYSERR_INVALPARAM;
1415 return MMSYSERR_NOERROR;
1418 /**************************************************************************
1419 * modPrepare [internal]
1421 static DWORD modPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1423 TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
1426 if (midiSeqFD == -1) {
1427 WARN(midi,"can't prepare !\n");
1428 return MMSYSERR_NOTENABLED;
1430 #else /* HAVE_OSS */
1431 if (MidiOutDev[wDevID].unixdev == 0) {
1432 WARN(midi,"can't prepare !\n");
1433 return MMSYSERR_NOTENABLED;
1435 #endif /* HAVE_OSS */
1436 if (dwSize != sizeof(MIDIHDR) || lpMidiHdr == 0 ||
1437 lpMidiHdr->lpData == 0 || lpMidiHdr->dwFlags != 0 ||
1438 lpMidiHdr->dwBufferLength >= 0x10000ul)
1439 return MMSYSERR_INVALPARAM;
1441 lpMidiHdr->lpNext = 0;
1442 lpMidiHdr->dwFlags |= MHDR_PREPARED;
1443 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1444 return MMSYSERR_NOERROR;
1447 /**************************************************************************
1448 * modUnprepare [internal]
1450 static DWORD modUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1452 TRACE(midi, "(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
1455 if (midiSeqFD == -1) {
1456 WARN(midi,"can't unprepare !\n");
1457 return MMSYSERR_NOTENABLED;
1459 #else /* HAVE_OSS */
1460 if (MidiOutDev[wDevID].unixdev == 0) {
1461 WARN(midi,"can't unprepare !\n");
1462 return MMSYSERR_NOTENABLED;
1464 #endif /* HAVE_OSS */
1465 if (dwSize != sizeof(MIDIHDR) || lpMidiHdr == 0)
1466 return MMSYSERR_INVALPARAM;
1467 if (lpMidiHdr->dwFlags & MHDR_INQUEUE)
1468 return MIDIERR_STILLPLAYING;
1469 lpMidiHdr->dwFlags &= ~MHDR_PREPARED;
1470 return MMSYSERR_NOERROR;
1473 /**************************************************************************
1474 * modReset [internal]
1476 static DWORD modReset(WORD wDevID)
1478 TRACE(midi, "(%04X);\n", wDevID);
1479 /* FIXME: this function should :
1480 * turn off every note, remove sustain on all channels
1481 * remove any pending buffers
1483 return MMSYSERR_NOTENABLED;
1486 /*======================================================================*
1487 * MIDI entry points *
1488 *======================================================================*/
1490 /**************************************************************************
1491 * modMessage [sample driver]
1493 DWORD WINAPI modMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
1494 DWORD dwParam1, DWORD dwParam2)
1496 TRACE(midi, "(%04X, %04X, %08lX, %08lX, %08lX);\n",
1497 wDevID, wMsg, dwUser, dwParam1, dwParam2);
1501 return modOpen(wDevID, (LPMIDIOPENDESC)dwParam1, dwParam2);
1503 return modClose(wDevID);
1505 return modData(wDevID, dwParam1);
1507 return modLongData(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1509 return modPrepare(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1510 case MODM_UNPREPARE:
1511 return modUnprepare(wDevID, (LPMIDIHDR)dwParam1, dwParam2);
1512 case MODM_GETDEVCAPS:
1513 return modGetDevCaps(wDevID,(LPMIDIOUTCAPS16)dwParam1,dwParam2);
1514 case MODM_GETNUMDEVS:
1515 return MODM_NUMDEVS;
1516 case MODM_GETVOLUME:
1518 case MODM_SETVOLUME:
1521 return modReset(wDevID);
1523 TRACE(midi, "Unsupported message\n");
1525 return MMSYSERR_NOTSUPPORTED;
1528 /**************************************************************************
1529 * MIDI_DriverProc32 [sample driver]
1531 LONG MIDI_DriverProc32(DWORD dwDevID, HDRVR16 hDriv, DWORD wMsg,
1532 DWORD dwParam1, DWORD dwParam2)
1535 case DRV_LOAD: return 1;
1536 case DRV_FREE: return 1;
1537 case DRV_OPEN: return 1;
1538 case DRV_CLOSE: return 1;
1539 case DRV_ENABLE: return 1;
1540 case DRV_DISABLE: return 1;
1541 case DRV_QUERYCONFIGURE: return 1;
1542 case DRV_CONFIGURE: MessageBox16(0, "Sample Midi Linux Driver !", "MMLinux Driver", MB_OK); return 1;
1543 case DRV_INSTALL: return DRVCNF_RESTART;
1544 case DRV_REMOVE: return DRVCNF_RESTART;
1546 TRACE(midi, "Sending msg=%lu to default driver proc\n", wMsg);
1547 return DefDriverProc32(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1551 /**************************************************************************
1552 * MIDI_DriverProc16 [sample driver]
1554 LONG MIDI_DriverProc16(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg,
1555 DWORD dwParam1, DWORD dwParam2)
1558 case DRV_LOAD: return 1;
1559 case DRV_FREE: return 1;
1560 case DRV_OPEN: return 1;
1561 case DRV_CLOSE: return 1;
1562 case DRV_ENABLE: return 1;
1563 case DRV_DISABLE: return 1;
1564 case DRV_QUERYCONFIGURE: return 1;
1565 case DRV_CONFIGURE: MessageBox16(0, "Sample Midi Linux Driver !", "MMLinux Driver", MB_OK); return 1;
1566 case DRV_INSTALL: return DRVCNF_RESTART;
1567 case DRV_REMOVE: return DRVCNF_RESTART;
1569 TRACE(midi, "Sending msg=%u to default driver proc\n", wMsg);
1570 return DefDriverProc32(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1574 /*-----------------------------------------------------------------------*/