2 * Sample MIDI Wine Driver for Linux
4 * Copyright 1994 Martin Ayotte
11 #include <sys/ioctl.h>
23 #include <linux/soundcard.h>
25 #include <machine/soundcard.h>
28 #if defined(linux) || defined(__FreeBSD__)
29 #define MIDI_DEV "/dev/sequencer"
32 #define IOCTL(a,b,c) ioctl(a,b,&c)
34 #define IOCTL(a,b,c) (c = ioctl(a,b,c) )
37 #define MAX_MIDIINDRV (1)
38 #define MAX_MIDIOUTDRV (1)
39 #define MAX_MCIMIDIDRV (1)
45 MIDIOPENDESC midiDesc;
55 MIDIOPENDESC midiDesc;
62 int nUseCount; /* Incremented for each shared open */
63 BOOL16 fShareable; /* TRUE if first open was shareable */
64 WORD wNotifyDeviceID; /* MCI device ID with a pending notification */
65 HANDLE16 hCallback; /* Callback handle for pending notification */
66 HMMIO16 hFile; /* mmio file handle open as Element */
72 MCI_OPEN_PARMS openParms;
73 /* MIDIHDR MidiHdr; */
78 static LINUX_MIDIIN MidiInDev[MAX_MIDIINDRV];
79 static LINUX_MIDIOUT MidiOutDev[MAX_MIDIOUTDRV];
80 static LINUX_MCIMIDI MCIMidiDev[MAX_MCIMIDIDRV];
84 /**************************************************************************
85 * MIDI_NotifyClient [internal]
87 static DWORD MIDI_NotifyClient(UINT16 wDevID, WORD wMsg,
88 DWORD dwParam1, DWORD dwParam2)
90 #if defined(linux) || defined(__FreeBSD__)
91 if (MidiInDev[wDevID].wFlags != DCB_NULL && !DriverCallback(
92 MidiInDev[wDevID].midiDesc.dwCallback, MidiInDev[wDevID].wFlags,
93 MidiInDev[wDevID].midiDesc.hMidi, wMsg,
94 MidiInDev[wDevID].midiDesc.dwInstance, dwParam1, dwParam2)) {
95 dprintf_midi(stddeb, "MIDI_NotifyClient // can't notify client !\n");
96 return MMSYSERR_NOERROR;
100 return MMSYSERR_NOTENABLED;
105 /**************************************************************************
106 * MIDI_ReadByte [internal]
108 static DWORD MIDI_ReadByte(UINT16 wDevID, BYTE *lpbyt)
110 #if defined(linux) || defined(__FreeBSD__)
112 if (mmioRead(MCIMidiDev[wDevID].hFile, (HPSTR)lpbyt,
113 (long) sizeof(BYTE)) == (long) sizeof(BYTE)) {
117 dprintf_midi(stddeb, "MIDI_ReadByte // error reading wDevID=%04X\n", wDevID);
118 return MCIERR_INTERNAL;
121 return MMSYSERR_NOTENABLED;
126 /**************************************************************************
127 * MIDI_ReadWord [internal]
129 static DWORD MIDI_ReadWord(UINT16 wDevID, LPWORD lpw)
133 if (MIDI_ReadByte(wDevID, &hibyte) == 0) {
134 if (MIDI_ReadByte(wDevID, &lobyte) == 0) {
135 *lpw = ((WORD)hibyte << 8) + lobyte;
140 dprintf_midi(stddeb, "MIDI_ReadWord // error reading wDevID=%04X\n", wDevID);
141 return MCIERR_INTERNAL;
145 /**************************************************************************
146 * MIDI_ReadLong [internal]
148 static DWORD MIDI_ReadLong(UINT16 wDevID, LPDWORD lpdw)
152 if (MIDI_ReadWord(wDevID, &hiword) == 0) {
153 if (MIDI_ReadWord(wDevID, &loword) == 0) {
154 *lpdw = MAKELONG(loword, hiword);
159 dprintf_midi(stddeb, "MIDI_ReadLong // error reading wDevID=%04X\n", wDevID);
160 return MCIERR_INTERNAL;
164 /**************************************************************************
165 * MIDI_ReadVaryLen [internal]
167 static DWORD MIDI_ReadVaryLen(UINT16 wDevID, LPDWORD lpdw)
171 if (lpdw == NULL) return MCIERR_INTERNAL;
172 if (MIDI_ReadByte(wDevID, &byte) != 0) {
173 dprintf_midi(stddeb, "MIDI_ReadVaryLen // error reading wDevID=%04X\n", wDevID);
174 return MCIERR_INTERNAL;
176 value = (DWORD)(byte & 0x7F);
177 while (byte & 0x80) {
178 if (MIDI_ReadByte(wDevID, &byte) != 0) {
179 dprintf_midi(stddeb, "MIDI_ReadVaryLen // error reading wDevID=%04X\n", wDevID);
180 return MCIERR_INTERNAL;
182 value = (value << 7) + (byte & 0x7F);
186 dprintf_midi(stddeb, "MIDI_ReadVaryLen // val=%08lX \n", value);
192 /**************************************************************************
193 * MIDI_ReadMThd [internal]
195 static DWORD MIDI_ReadMThd(UINT16 wDevID, DWORD dwOffset)
197 #if defined(linux) || defined(__FreeBSD__)
200 dprintf_midi(stddeb, "MIDI_ReadMThd(%04X, %08lX);\n", wDevID, dwOffset);
201 if (mmioSeek(MCIMidiDev[wDevID].hFile, dwOffset, SEEK_SET) != dwOffset) {
202 dprintf_midi(stddeb, "MIDI_ReadMThd // can't seek at %08lX begin of 'MThd' \n", dwOffset);
203 return MCIERR_INTERNAL;
205 if (mmioRead(MCIMidiDev[wDevID].hFile, (HPSTR)&fourcc,
206 (long) sizeof(FOURCC)) != (long) sizeof(FOURCC)) {
207 return MCIERR_INTERNAL;
209 if (MIDI_ReadLong(wDevID, &toberead) != 0) {
210 return MCIERR_INTERNAL;
212 if (MIDI_ReadWord(wDevID, &MCIMidiDev[wDevID].wFormat) != 0) {
213 return MCIERR_INTERNAL;
215 if (MIDI_ReadWord(wDevID, &MCIMidiDev[wDevID].nTracks) != 0) {
216 return MCIERR_INTERNAL;
218 if (MIDI_ReadWord(wDevID, &MCIMidiDev[wDevID].nTempo) != 0) {
219 return MCIERR_INTERNAL;
221 dprintf_midi(stddeb, "MIDI_ReadMThd // toberead=%08lX, wFormat=%04X nTracks=%04X nTempo=%04X\n",
222 toberead, MCIMidiDev[wDevID].wFormat,
223 MCIMidiDev[wDevID].nTracks,
224 MCIMidiDev[wDevID].nTempo);
225 toberead -= 3 * sizeof(WORD);
227 ntrks = read16bit ();
228 Mf_division = division = read16bit ();
233 return MMSYSERR_NOTENABLED;
238 static DWORD MIDI_ReadMTrk(UINT16 wDevID, DWORD dwOffset)
240 #if defined(linux) || defined(__FreeBSD__)
243 if (mmioSeek(MCIMidiDev[wDevID].hFile, dwOffset, SEEK_SET) != dwOffset) {
244 dprintf_midi(stddeb, "MIDI_ReadMTrk // can't seek at %08lX begin of 'MThd' \n", dwOffset);
246 if (mmioRead(MCIMidiDev[wDevID].hFile, (HPSTR)&fourcc,
247 (long) sizeof(FOURCC)) != (long) sizeof(FOURCC)) {
248 return MCIERR_INTERNAL;
250 if (MIDI_ReadLong(wDevID, &toberead) != 0) {
251 return MCIERR_INTERNAL;
253 dprintf_midi(stddeb, "MIDI_ReadMTrk // toberead=%08lX\n", toberead);
254 toberead -= 3 * sizeof(WORD);
255 MCIMidiDev[wDevID].dwTotalLen = toberead;
258 return MMSYSERR_NOTENABLED;
263 /**************************************************************************
264 * MIDI_mciOpen [internal]
266 static DWORD MIDI_mciOpen(UINT16 wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
268 #if defined(linux) || defined(__FreeBSD__)
269 MIDIOPENDESC MidiDesc;
272 LPSTR lpstrElementName;
275 dprintf_midi(stddeb, "MIDI_mciOpen(%08lX, %p)\n", dwFlags, lpParms);
276 if (lpParms == NULL) return MCIERR_INTERNAL;
278 if (MCIMidiDev[wDevID].nUseCount > 0) {
279 /* The driver already open on this channel */
280 /* If the driver was opened shareable before and this open specifies */
281 /* shareable then increment the use count */
282 if (MCIMidiDev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE))
283 ++MCIMidiDev[wDevID].nUseCount;
285 return MCIERR_MUST_USE_SHAREABLE;
288 MCIMidiDev[wDevID].nUseCount = 1;
289 MCIMidiDev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE;
290 MCIMidiDev[wDevID].hMidiHdr = USER_HEAP_ALLOC(sizeof(MIDIHDR));
292 dprintf_midi(stddeb, "MIDI_mciOpen // wDevID=%04X\n", wDevID);
293 /* lpParms->wDeviceID = wDevID;*/
294 dprintf_midi(stddeb, "MIDI_mciOpen // lpParms->wDevID=%04X\n", lpParms->wDeviceID);
295 dprintf_midi(stddeb, "MIDI_mciOpen // before OPEN_ELEMENT\n");
296 if (dwFlags & MCI_OPEN_ELEMENT) {
297 lpstrElementName = (LPSTR)PTR_SEG_TO_LIN(lpParms->lpstrElementName);
298 dprintf_midi(stddeb, "MIDI_mciOpen // MCI_OPEN_ELEMENT '%s' !\n", lpstrElementName);
299 if (strlen(lpstrElementName) > 0) {
300 strcpy(str, lpstrElementName);
302 MCIMidiDev[wDevID].hFile = mmioOpen(str, NULL,
303 MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_EXCLUSIVE);
304 if (MCIMidiDev[wDevID].hFile == 0) {
305 dprintf_midi(stddeb, "MIDI_mciOpen // can't find file='%s' !\n", str);
306 return MCIERR_FILE_NOT_FOUND;
310 MCIMidiDev[wDevID].hFile = 0;
312 dprintf_midi(stddeb, "MIDI_mciOpen // hFile=%u\n", MCIMidiDev[wDevID].hFile);
313 memcpy(&MCIMidiDev[wDevID].openParms, lpParms, sizeof(MCI_OPEN_PARMS));
314 MCIMidiDev[wDevID].wNotifyDeviceID = lpParms->wDeviceID;
315 MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
316 MCIMidiDev[wDevID].dwBeginData = 0;
317 MCIMidiDev[wDevID].dwTotalLen = 0;
319 if (MCIMidiDev[wDevID].hFile != 0) {
321 if (mmioDescend(MCIMidiDev[wDevID].hFile, &ckMainRIFF, NULL, 0) != 0) {
322 return MCIERR_INTERNAL;
324 dprintf_midi(stddeb,"MIDI_mciOpen // ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n",
325 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType,
328 if (ckMainRIFF.ckid == mmioFOURCC('R', 'M', 'I', 'D')) {
329 dprintf_midi(stddeb, "MIDI_mciOpen // is a 'RMID' file \n");
330 dwOffset = ckMainRIFF.dwDataOffset;
332 if (ckMainRIFF.ckid != mmioFOURCC('M', 'T', 'h', 'd')) {
333 dprintf_midi(stddeb, "MIDI_mciOpen // unknown format !\n");
334 return MCIERR_INTERNAL;
336 if (MIDI_ReadMThd(wDevID, dwOffset) != 0) {
337 dprintf_midi(stddeb, "MIDI_mciOpen // can't read 'MThd' header \n");
338 return MCIERR_INTERNAL;
340 dwOffset = mmioSeek(MCIMidiDev[wDevID].hFile, 0, SEEK_CUR);
341 if (MIDI_ReadMTrk(wDevID, dwOffset) != 0) {
342 dprintf_midi(stddeb, "MIDI_mciOpen // can't read 'MTrk' header \n");
343 return MCIERR_INTERNAL;
345 dwOffset = mmioSeek(MCIMidiDev[wDevID].hFile, 0, SEEK_CUR);
346 MCIMidiDev[wDevID].dwBeginData = dwOffset;
347 dprintf_midi(stddeb, "MIDI_mciOpen // Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
348 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType,
351 dwRet = modMessage(wDevID, MODM_OPEN, 0, (DWORD)&MidiDesc, CALLBACK_NULL);
352 /* dwRet = midMessage(wDevID, MIDM_OPEN, 0, (DWORD)&MidiDesc, CALLBACK_NULL); */
355 return MMSYSERR_NOTENABLED;
360 /**************************************************************************
361 * MIDI_mciStop [internal]
363 static DWORD MIDI_mciStop(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
365 #if defined(linux) || defined(__FreeBSD__)
366 dprintf_midi(stddeb, "MIDI_mciStop(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
367 if (lpParms == NULL) return MCIERR_INTERNAL;
368 MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
369 dprintf_midi(stddeb, "MIDI_mciStop // MCIMidiDev[wDevID].dwStatus=%p %d\n",
370 &MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus);
373 return MCIERR_INTERNAL;
378 /**************************************************************************
379 * MIDI_mciClose [internal]
381 static DWORD MIDI_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
383 #if defined(linux) || defined(__FreeBSD__)
386 dprintf_midi(stddeb, "MIDI_mciClose(%04X, %08lX, %p);\n", wDevID, dwParam, lpParms);
387 if (MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) {
388 MIDI_mciStop(wDevID, MCI_WAIT, lpParms);
390 MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
391 MCIMidiDev[wDevID].nUseCount--;
392 if (MCIMidiDev[wDevID].nUseCount == 0) {
393 if (MCIMidiDev[wDevID].hFile != 0) {
394 mmioClose(MCIMidiDev[wDevID].hFile, 0);
395 MCIMidiDev[wDevID].hFile = 0;
396 dprintf_midi(stddeb, "MIDI_mciClose // hFile closed !\n");
398 USER_HEAP_FREE(MCIMidiDev[wDevID].hMidiHdr);
399 dwRet = modMessage(wDevID, MODM_CLOSE, 0, 0L, 0L);
400 if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL;
402 dwRet = midMessage(wDevID, MIDM_CLOSE, 0, 0L, 0L);
403 if (dwRet != MMSYSERR_NOERROR) return MCIERR_INTERNAL;
413 /**************************************************************************
414 * MIDI_mciPlay [internal]
416 static DWORD MIDI_mciPlay(UINT16 wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
418 #if defined(linux) || defined(__FreeBSD__)
427 dprintf_midi(stddeb, "MIDI_mciPlay(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
428 if (MCIMidiDev[wDevID].hFile == 0) {
429 dprintf_midi(stddeb, "MIDI_mciPlay // can't find file='%08lx' !\n",
430 MCIMidiDev[wDevID].openParms.lpstrElementName);
431 return MCIERR_FILE_NOT_FOUND;
433 start = 1; end = 99999;
434 if (dwFlags & MCI_FROM) {
435 start = lpParms->dwFrom;
436 dprintf_midi(stddeb, "MIDI_mciPlay // MCI_FROM=%d \n", start);
438 if (dwFlags & MCI_TO) {
440 dprintf_midi(stddeb, "MIDI_mciPlay // MCI_TO=%d \n", end);
443 if (dwFlags & MCI_NOTIFY) {
444 dprintf_midi(stddeb, "MIDI_mciPlay // MCI_NOTIFY %08lX !\n", lpParms->dwCallback);
447 dprintf_midi(stddeb, "MIDI_mciPlay // Can't 'fork' process !\n");
450 dprintf_midi(stddeb, "MIDI_mciPlay // process started ! play in background ...\n");
453 dprintf_midi(stddeb, "MIDI_mciPlay // process started ! return to caller...\n");
459 lpMidiHdr = USER_HEAP_LIN_ADDR(MCIMidiDev[wDevID].hMidiHdr);
460 lp16MidiHdr = USER_HEAP_SEG_ADDR(MCIMidiDev[wDevID].hMidiHdr);
462 lpMidiHdr->lpData = (LPSTR) malloc(1200);
463 if (lpMidiHdr->lpData == NULL) return MCIERR_INTERNAL;
464 lpMidiHdr->dwBufferLength = 1024;
465 lpMidiHdr->dwUser = 0L;
466 lpMidiHdr->dwFlags = 0L;
467 dwRet = modMessage(wDevID, MODM_PREPARE, 0, (DWORD)lp16MidiHdr, sizeof(MIDIHDR));
469 /* dprintf_midi(stddeb, "MIDI_mciPlay // after MODM_PREPARE \n"); */
471 MCIMidiDev[wDevID].dwStatus = MCI_MODE_PLAY;
472 while(MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) {
473 dprintf_midi(stddeb, "MIDI_mciPlay // MCIMidiDev[wDevID].dwStatus=%p %d\n",
474 &MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus);
476 ptr = (LPWORD)lpMidiHdr->lpData;
477 for (count = 0; count < lpMidiHdr->dwBufferLength; count++) {
478 if (MIDI_ReadVaryLen(wDevID, &dwData) != 0) break;
479 *ptr = LOWORD(dwData);
482 count = mmioRead(MCIMidiDev[wDevID].hFile, lpMidiHdr->lpData, lpMidiHdr->dwBufferLength);
484 dprintf_midi(stddeb, "MIDI_mciPlay // after read count = %d\n",count);
486 if (count < 1) break;
487 lpMidiHdr->dwBytesRecorded = count;
488 dprintf_midi(stddeb, "MIDI_mciPlay // before MODM_LONGDATA lpMidiHdr=%p dwBytesRecorded=%lu\n",
489 lpMidiHdr, lpMidiHdr->dwBytesRecorded);
490 dwRet = modMessage(wDevID, MODM_LONGDATA, 0, (DWORD)lp16MidiHdr, sizeof(MIDIHDR));
491 if (dwRet != MMSYSERR_NOERROR) {
493 case MMSYSERR_NOTENABLED:
494 return MCIERR_DEVICE_NOT_READY;
496 case MIDIERR_NODEVICE:
497 return MCIERR_INVALID_DEVICE_ID;
499 case MIDIERR_UNPREPARED:
500 return MCIERR_DRIVER_INTERNAL;
502 case MIDIERR_STILLPLAYING:
503 return MCIERR_SEQ_PORT_INUSE;
505 case MMSYSERR_INVALPARAM:
506 return MCIERR_CANNOT_LOAD_DRIVER;
509 return MCIERR_DRIVER;
513 dwRet = modMessage(wDevID, MODM_UNPREPARE, 0, (DWORD)lp16MidiHdr, sizeof(MIDIHDR));
514 if (lpMidiHdr->lpData != NULL) {
515 free(lpMidiHdr->lpData);
516 lpMidiHdr->lpData = NULL;
518 MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
519 if (dwFlags & MCI_NOTIFY) {
520 dprintf_midi(stddeb, "MIDI_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
521 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
522 MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
529 return MMSYSERR_NOTENABLED;
534 /**************************************************************************
535 * MIDI_mciRecord [internal]
537 static DWORD MIDI_mciRecord(UINT16 wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
539 #if defined(linux) || defined(__FreeBSD__)
544 dprintf_midi(stddeb, "MIDI_mciRecord(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
545 if (MCIMidiDev[wDevID].hFile == 0) {
546 dprintf_midi(stddeb, "MIDI_mciRecord // can't find file='%08lx' !\n",
547 MCIMidiDev[wDevID].openParms.lpstrElementName);
548 return MCIERR_FILE_NOT_FOUND;
550 start = 1; end = 99999;
551 if (dwFlags & MCI_FROM) {
552 start = lpParms->dwFrom;
553 dprintf_midi(stddeb, "MIDI_mciRecord // MCI_FROM=%d \n", start);
555 if (dwFlags & MCI_TO) {
557 dprintf_midi(stddeb, "MIDI_mciRecord // MCI_TO=%d \n", end);
559 lpMidiHdr = USER_HEAP_LIN_ADDR(MCIMidiDev[wDevID].hMidiHdr);
560 lpMidiHdr->lpData = (LPSTR) xmalloc(1200);
561 lpMidiHdr->dwBufferLength = 1024;
562 lpMidiHdr->dwUser = 0L;
563 lpMidiHdr->dwFlags = 0L;
564 dwRet = midMessage(wDevID, MIDM_PREPARE, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR));
565 dprintf_midi(stddeb, "MIDI_mciRecord // after MIDM_PREPARE \n");
566 MCIMidiDev[wDevID].dwStatus = MCI_MODE_RECORD;
567 while(MCIMidiDev[wDevID].dwStatus != MCI_MODE_STOP) {
568 dprintf_midi(stddeb, "MIDI_mciRecord // MCIMidiDev[wDevID].dwStatus=%p %d\n",
569 &MCIMidiDev[wDevID].dwStatus, MCIMidiDev[wDevID].dwStatus);
570 lpMidiHdr->dwBytesRecorded = 0;
571 dwRet = midMessage(wDevID, MIDM_START, 0, 0L, 0L);
572 dprintf_midi(stddeb, "MIDI_mciRecord // after MIDM_START lpMidiHdr=%p dwBytesRecorded=%lu\n",
573 lpMidiHdr, lpMidiHdr->dwBytesRecorded);
574 if (lpMidiHdr->dwBytesRecorded == 0) break;
576 dprintf_midi(stddeb, "MIDI_mciRecord // before MIDM_UNPREPARE \n");
577 dwRet = midMessage(wDevID, MIDM_UNPREPARE, 0, (DWORD)lpMidiHdr, sizeof(MIDIHDR));
578 dprintf_midi(stddeb, "MIDI_mciRecord // after MIDM_UNPREPARE \n");
579 if (lpMidiHdr->lpData != NULL) {
580 free(lpMidiHdr->lpData);
581 lpMidiHdr->lpData = NULL;
583 MCIMidiDev[wDevID].dwStatus = MCI_MODE_STOP;
584 if (dwFlags & MCI_NOTIFY) {
585 dprintf_midi(stddeb, "MIDI_mciRecord // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
586 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
587 MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
591 return MMSYSERR_NOTENABLED;
596 /**************************************************************************
597 * MIDI_mciPause [internal]
599 static DWORD MIDI_mciPause(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
601 #if defined(linux) || defined(__FreeBSD__)
602 dprintf_midi(stddeb, "MIDI_mciPause(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
603 if (lpParms == NULL) return MCIERR_INTERNAL;
606 return MCIERR_INTERNAL;
611 /**************************************************************************
612 * MIDI_mciResume [internal]
614 static DWORD MIDI_mciResume(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
616 #if defined(linux) || defined(__FreeBSD__)
617 dprintf_midi(stddeb, "MIDI_mciResume(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
618 if (lpParms == NULL) return MCIERR_INTERNAL;
621 return MCIERR_INTERNAL;
626 /**************************************************************************
627 * MIDI_mciSet [internal]
629 static DWORD MIDI_mciSet(UINT16 wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
631 #if defined(linux) || defined(__FreeBSD__)
632 dprintf_midi(stddeb, "MIDI_mciSet(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
633 if (lpParms == NULL) return MCIERR_INTERNAL;
634 dprintf_midi(stddeb, "MIDI_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
635 dprintf_midi(stddeb, "MIDI_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
636 if (dwFlags & MCI_SET_TIME_FORMAT) {
637 switch (lpParms->dwTimeFormat) {
638 case MCI_FORMAT_MILLISECONDS:
639 dprintf_midi(stddeb, "MIDI_mciSet // MCI_FORMAT_MILLISECONDS !\n");
641 case MCI_FORMAT_BYTES:
642 dprintf_midi(stddeb, "MIDI_mciSet // MCI_FORMAT_BYTES !\n");
644 case MCI_FORMAT_SAMPLES:
645 dprintf_midi(stddeb, "MIDI_mciSet // MCI_FORMAT_SAMPLES !\n");
648 dprintf_midi(stddeb, "MIDI_mciSet // bad time format !\n");
649 return MCIERR_BAD_TIME_FORMAT;
652 if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION;
653 if (dwFlags & MCI_SET_DOOR_OPEN) return MCIERR_UNSUPPORTED_FUNCTION;
654 if (dwFlags & MCI_SET_DOOR_CLOSED) return MCIERR_UNSUPPORTED_FUNCTION;
655 if (dwFlags & MCI_SET_AUDIO) {
656 dprintf_midi(stddeb, "MIDI_mciSet // MCI_SET_AUDIO !\n");
658 if (dwFlags && MCI_SET_ON) {
659 dprintf_midi(stddeb, "MIDI_mciSet // MCI_SET_ON !\n");
660 if (dwFlags && MCI_SET_AUDIO_LEFT) {
661 dprintf_midi(stddeb, "MIDI_mciSet // MCI_SET_AUDIO_LEFT !\n");
663 if (dwFlags && MCI_SET_AUDIO_RIGHT) {
664 dprintf_midi(stddeb, "MIDI_mciSet // MCI_SET_AUDIO_RIGHT !\n");
667 if (dwFlags & MCI_SET_OFF) {
668 dprintf_midi(stddeb, "MIDI_mciSet // MCI_SET_OFF !\n");
670 if (dwFlags & MCI_SEQ_SET_MASTER) {
671 dprintf_midi(stddeb, "MIDI_mciSet // MCI_SEQ_SET_MASTER !\n");
673 if (dwFlags & MCI_SEQ_SET_SLAVE) {
674 dprintf_midi(stddeb, "MIDI_mciSet // MCI_SEQ_SET_SLAVE !\n");
676 if (dwFlags & MCI_SEQ_SET_OFFSET) {
677 dprintf_midi(stddeb, "MIDI_mciSet // MCI_SEQ_SET_OFFSET !\n");
679 if (dwFlags & MCI_SEQ_SET_PORT) {
680 dprintf_midi(stddeb, "MIDI_mciSet // MCI_SEQ_SET_PORT !\n");
682 if (dwFlags & MCI_SEQ_SET_TEMPO) {
683 dprintf_midi(stddeb, "MIDI_mciSet // MCI_SEQ_SET_TEMPO !\n");
687 return MCIERR_INTERNAL;
692 /**************************************************************************
693 * MIDI_mciStatus [internal]
695 static DWORD MIDI_mciStatus(UINT16 wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
697 #if defined(linux) || defined(__FreeBSD__)
698 dprintf_midi(stddeb, "MIDI_mciStatus(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
699 if (lpParms == NULL) return MCIERR_INTERNAL;
700 if (dwFlags & MCI_STATUS_ITEM) {
701 switch(lpParms->dwItem) {
702 case MCI_STATUS_CURRENT_TRACK:
703 lpParms->dwReturn = 1;
705 case MCI_STATUS_LENGTH:
706 lpParms->dwReturn = 5555;
707 if (dwFlags & MCI_TRACK) {
708 lpParms->dwTrack = 1;
709 lpParms->dwReturn = 2222;
712 case MCI_STATUS_MODE:
713 lpParms->dwReturn = MCI_MODE_STOP;
715 case MCI_STATUS_MEDIA_PRESENT:
716 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
717 lpParms->dwReturn = TRUE;
719 case MCI_STATUS_NUMBER_OF_TRACKS:
720 lpParms->dwReturn = 1;
722 case MCI_STATUS_POSITION:
723 lpParms->dwReturn = 3333;
724 if (dwFlags & MCI_STATUS_START) {
727 if (dwFlags & MCI_TRACK) {
728 lpParms->dwTrack = 1;
729 lpParms->dwReturn = 777;
732 case MCI_STATUS_READY:
733 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_STATUS_READY !\n");
734 lpParms->dwReturn = TRUE;
736 case MCI_STATUS_TIME_FORMAT:
737 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
738 lpParms->dwReturn = MCI_FORMAT_MILLISECONDS;
740 case MCI_SEQ_STATUS_DIVTYPE:
741 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_DIVTYPE !\n");
742 lpParms->dwReturn = 0;
744 case MCI_SEQ_STATUS_MASTER:
745 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_MASTER !\n");
746 lpParms->dwReturn = 0;
748 case MCI_SEQ_STATUS_SLAVE:
749 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_SLAVE !\n");
750 lpParms->dwReturn = 0;
752 case MCI_SEQ_STATUS_OFFSET:
753 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_OFFSET !\n");
754 lpParms->dwReturn = 0;
756 case MCI_SEQ_STATUS_PORT:
757 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_PORT !\n");
758 lpParms->dwReturn = 0;
760 case MCI_SEQ_STATUS_TEMPO:
761 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_TEMPO !\n");
762 lpParms->dwReturn = 0;
765 dprintf_midi(stddeb, "MIDI_mciStatus // unknowm command %08lX !\n", lpParms->dwItem);
766 return MCIERR_UNRECOGNIZED_COMMAND;
769 if (dwFlags & MCI_NOTIFY) {
770 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
771 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
772 MCIMidiDev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
776 return MCIERR_INTERNAL;
780 /**************************************************************************
781 * MIDI_mciGetDevCaps [internal]
783 static DWORD MIDI_mciGetDevCaps(UINT16 wDevID, DWORD dwFlags,
784 LPMCI_GETDEVCAPS_PARMS lpParms)
786 #if defined(linux) || defined(__FreeBSD__)
787 dprintf_midi(stddeb, "MIDI_mciGetDevCaps(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
788 if (lpParms == NULL) return MCIERR_INTERNAL;
789 if (dwFlags & MCI_GETDEVCAPS_ITEM) {
790 switch(lpParms->dwItem) {
791 case MCI_GETDEVCAPS_CAN_RECORD:
792 lpParms->dwReturn = TRUE;
794 case MCI_GETDEVCAPS_HAS_AUDIO:
795 lpParms->dwReturn = TRUE;
797 case MCI_GETDEVCAPS_HAS_VIDEO:
798 lpParms->dwReturn = FALSE;
800 case MCI_GETDEVCAPS_DEVICE_TYPE:
801 lpParms->dwReturn = MCI_DEVTYPE_SEQUENCER;
803 case MCI_GETDEVCAPS_USES_FILES:
804 lpParms->dwReturn = TRUE;
806 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
807 lpParms->dwReturn = TRUE;
809 case MCI_GETDEVCAPS_CAN_EJECT:
810 lpParms->dwReturn = FALSE;
812 case MCI_GETDEVCAPS_CAN_PLAY:
813 lpParms->dwReturn = TRUE;
815 case MCI_GETDEVCAPS_CAN_SAVE:
816 lpParms->dwReturn = FALSE;
819 return MCIERR_UNRECOGNIZED_COMMAND;
824 return MCIERR_INTERNAL;
828 /**************************************************************************
829 * MIDI_mciInfo [internal]
831 static DWORD MIDI_mciInfo(UINT16 wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
833 #if defined(linux) || defined(__FreeBSD__)
834 dprintf_midi(stddeb, "MIDI_mciInfo(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
835 if (lpParms == NULL) return MCIERR_INTERNAL;
836 lpParms->lpstrReturn = NULL;
838 case MCI_INFO_PRODUCT:
839 lpParms->lpstrReturn = "Linux Sound System 0.5";
842 lpParms->lpstrReturn = "FileName";
845 return MCIERR_UNRECOGNIZED_COMMAND;
847 if (lpParms->lpstrReturn != NULL)
848 lpParms->dwRetSize = strlen(lpParms->lpstrReturn);
850 lpParms->dwRetSize = 0;
853 return MCIERR_INTERNAL;
858 /*-----------------------------------------------------------------------*/
861 /**************************************************************************
862 * midGetDevCaps [internal]
864 static DWORD midGetDevCaps(WORD wDevID, LPMIDIINCAPS lpCaps, DWORD dwSize)
866 dprintf_midi(stddeb, "midGetDevCaps(%04X, %p, %08lX);\n", wDevID, lpCaps, dwSize);
867 return MMSYSERR_NOTENABLED;
870 /**************************************************************************
873 static DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
875 #if defined(linux) || defined(__FreeBSD__)
878 "midOpen(%04X, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
879 if (lpDesc == NULL) {
880 dprintf_midi(stddeb,"Linux 'midOpen' // Invalid Parameter !\n");
881 return MMSYSERR_INVALPARAM;
883 if (wDevID >= MAX_MIDIINDRV) {
884 dprintf_midi(stddeb,"Linux 'midOpen' // MAX_MIDIINDRV reached !\n");
885 return MMSYSERR_ALLOCATED;
887 MidiInDev[wDevID].unixdev = 0;
888 midi = open (MIDI_DEV, O_RDONLY, 0);
890 dprintf_midi(stddeb,"Linux 'midOpen' // can't open !\n");
891 return MMSYSERR_NOTENABLED;
893 MidiInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
894 switch(MidiInDev[wDevID].wFlags) {
896 dprintf_midi(stddeb,"Linux 'midOpen' // CALLBACK_NULL !\n");
900 "Linux 'midOpen' // CALLBACK_WINDOW !\n");
904 "Linux 'midOpen' // CALLBACK_TASK !\n");
908 "Linux 'midOpen' // CALLBACK_FUNCTION !\n");
911 MidiInDev[wDevID].lpQueueHdr = NULL;
912 MidiInDev[wDevID].unixdev = midi;
913 MidiInDev[wDevID].dwTotalPlayed = 0;
914 MidiInDev[wDevID].bufsize = 0x3FFF;
915 if (MIDI_NotifyClient(wDevID, MIM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
916 dprintf_midi(stddeb,"Linux 'midOpen' // can't notify client !\n");
917 return MMSYSERR_INVALPARAM;
919 return MMSYSERR_NOERROR;
921 return MMSYSERR_NOTENABLED;
925 /**************************************************************************
926 * midClose [internal]
928 static DWORD midClose(WORD wDevID)
930 #if defined(linux) || defined(__FreeBSD__)
931 dprintf_midi(stddeb, "midClose(%04X);\n", wDevID);
932 if (MidiInDev[wDevID].unixdev == 0) {
933 dprintf_midi(stddeb,"Linux 'midClose' // can't close !\n");
934 return MMSYSERR_NOTENABLED;
936 close(MidiInDev[wDevID].unixdev);
937 MidiInDev[wDevID].unixdev = 0;
938 MidiInDev[wDevID].bufsize = 0;
939 if (MIDI_NotifyClient(wDevID, MIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
940 dprintf_midi(stddeb,"Linux 'midClose' // can't notify client !\n");
941 return MMSYSERR_INVALPARAM;
943 return MMSYSERR_NOERROR;
945 return MMSYSERR_NOTENABLED;
949 /**************************************************************************
950 * midAddBuffer [internal]
952 static DWORD midAddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
954 dprintf_midi(stddeb, "midAddBuffer(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
955 return MMSYSERR_NOTENABLED;
958 /**************************************************************************
959 * midPrepare [internal]
961 static DWORD midPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
963 dprintf_midi(stddeb, "midPrepare(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
964 return MMSYSERR_NOTENABLED;
967 /**************************************************************************
968 * midUnprepare [internal]
970 static DWORD midUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
972 dprintf_midi(stddeb, "midUnprepare(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
973 return MMSYSERR_NOTENABLED;
976 /**************************************************************************
977 * midReset [internal]
979 static DWORD midReset(WORD wDevID)
981 dprintf_midi(stddeb, "midReset(%04X);\n", wDevID);
982 return MMSYSERR_NOTENABLED;
986 /**************************************************************************
987 * midStart [internal]
989 static DWORD midStart(WORD wDevID)
991 dprintf_midi(stddeb, "midStart(%04X);\n", wDevID);
992 return MMSYSERR_NOTENABLED;
996 /**************************************************************************
999 static DWORD midStop(WORD wDevID)
1001 dprintf_midi(stddeb, "midStop(%04X);\n", wDevID);
1002 return MMSYSERR_NOTENABLED;
1006 /**************************************************************************
1007 * midMessage [sample driver]
1009 DWORD midMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
1010 DWORD dwParam1, DWORD dwParam2)
1012 dprintf_midi(stddeb, "midMessage(%04X, %04X, %08lX, %08lX, %08lX);\n",
1013 wDevID, wMsg, dwUser, dwParam1, dwParam2);
1016 return midOpen(wDevID, (LPMIDIOPENDESC)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1018 return midClose(wDevID);
1019 case MIDM_ADDBUFFER:
1020 return midAddBuffer(wDevID, (LPMIDIHDR)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1022 return midPrepare(wDevID, (LPMIDIHDR)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1023 case MIDM_UNPREPARE:
1024 return midUnprepare(wDevID, (LPMIDIHDR)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1025 case MIDM_GETDEVCAPS:
1026 return midGetDevCaps(wDevID, (LPMIDIINCAPS)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1027 case MIDM_GETNUMDEVS:
1030 return midReset(wDevID);
1032 return midStart(wDevID);
1034 return midStop(wDevID);
1036 return MMSYSERR_NOTSUPPORTED;
1041 /*-----------------------------------------------------------------------*/
1044 /**************************************************************************
1045 * modGetDevCaps [internal]
1047 static DWORD modGetDevCaps(WORD wDevID, LPMIDIOUTCAPS lpCaps, DWORD dwSize)
1049 dprintf_midi(stddeb, "modGetDevCaps(%04X, %p, %08lX);\n", wDevID, lpCaps, dwSize);
1050 return MMSYSERR_NOTENABLED;
1054 /**************************************************************************
1055 * modOpen [internal]
1057 static DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
1059 #if defined(linux) || defined(__FreeBSD__)
1062 dprintf_midi(stddeb,
1063 "modOpen(%04X, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
1064 if (lpDesc == NULL) {
1065 dprintf_midi(stddeb,"Linux 'modOpen' // Invalid Parameter !\n");
1066 return MMSYSERR_INVALPARAM;
1068 if (wDevID>= MAX_MIDIOUTDRV) {
1069 dprintf_midi(stddeb,"Linux 'modOpen' // MAX_MIDIOUTDRV reached !\n");
1070 return MMSYSERR_ALLOCATED;
1072 MidiOutDev[wDevID].unixdev = 0;
1073 midi = open (MIDI_DEV, O_WRONLY, 0);
1075 dprintf_midi(stddeb,"Linux 'modOpen' // can't open !\n");
1076 return MMSYSERR_NOTENABLED;
1078 MidiOutDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
1079 switch(MidiOutDev[wDevID].wFlags) {
1081 dprintf_midi(stddeb,"Linux 'modOpen' // CALLBACK_NULL !\n");
1084 dprintf_midi(stddeb,
1085 "Linux 'modOpen' // CALLBACK_WINDOW !\n");
1088 dprintf_midi(stddeb,
1089 "Linux 'modOpen' // CALLBACK_TASK !\n");
1092 dprintf_midi(stddeb,
1093 "Linux 'modOpen' // CALLBACK_FUNCTION !\n");
1096 MidiOutDev[wDevID].lpQueueHdr = NULL;
1097 MidiOutDev[wDevID].unixdev = midi;
1098 MidiOutDev[wDevID].dwTotalPlayed = 0;
1099 MidiOutDev[wDevID].bufsize = 0x3FFF;
1100 if (MIDI_NotifyClient(wDevID, MOM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
1101 dprintf_midi(stddeb,"Linux 'modOpen' // can't notify client !\n");
1102 return MMSYSERR_INVALPARAM;
1104 dprintf_midi(stddeb,
1105 "Linux 'modOpen' // Succesful unixdev=%d !\n", midi);
1106 return MMSYSERR_NOERROR;
1108 return MMSYSERR_NOTENABLED;
1113 /**************************************************************************
1114 * modClose [internal]
1116 static DWORD modClose(WORD wDevID)
1118 #if defined(linux) || defined(__FreeBSD__)
1119 dprintf_midi(stddeb, "modClose(%04X);\n", wDevID);
1120 if (MidiOutDev[wDevID].unixdev == 0) {
1121 dprintf_midi(stddeb,"Linux 'modClose' // can't close !\n");
1122 return MMSYSERR_NOTENABLED;
1124 close(MidiOutDev[wDevID].unixdev);
1125 MidiOutDev[wDevID].unixdev = 0;
1126 MidiOutDev[wDevID].bufsize = 0;
1127 if (MIDI_NotifyClient(wDevID, MOM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
1128 dprintf_midi(stddeb,"Linux 'modClose' // can't notify client !\n");
1129 return MMSYSERR_INVALPARAM;
1131 return MMSYSERR_NOERROR;
1133 return MMSYSERR_NOTENABLED;
1137 /**************************************************************************
1138 * modData [internal]
1140 static DWORD modData(WORD wDevID, DWORD dwParam)
1142 #if defined(linux) || defined(__FreeBSD__)
1145 dprintf_midi(stddeb,
1146 "modData(%04X, %08lX);\n", wDevID, dwParam);
1147 if (MidiOutDev[wDevID].unixdev == 0) {
1148 dprintf_midi(stddeb,"Linux 'modData' // can't play !\n");
1149 return MIDIERR_NODEVICE;
1151 event = LOWORD(dwParam);
1152 if (write (MidiOutDev[wDevID].unixdev,
1153 &event, sizeof(WORD)) != sizeof(WORD)) {
1154 dprintf_midi(stddeb,
1155 "modData() // error writting unixdev !\n");
1157 return MMSYSERR_NOTENABLED;
1159 return MMSYSERR_NOTENABLED;
1163 /**************************************************************************
1164 * modLongData [internal]
1166 static DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1168 #if defined(linux) || defined(__FreeBSD__)
1173 dprintf_midi(stddeb,
1174 "modLongData(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
1175 if (MidiOutDev[wDevID].unixdev == 0) {
1176 dprintf_midi(stddeb,"Linux 'modLongData' // can't play !\n");
1177 return MIDIERR_NODEVICE;
1179 if (lpMidiHdr->lpData == NULL) return MIDIERR_UNPREPARED;
1180 if (!(lpMidiHdr->dwFlags & MHDR_PREPARED)) return MIDIERR_UNPREPARED;
1181 if (lpMidiHdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING;
1182 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1183 lpMidiHdr->dwFlags |= MHDR_INQUEUE;
1184 dprintf_midi(stddeb,
1185 "modLongData() // dwBytesRecorded %lu !\n", lpMidiHdr->dwBytesRecorded);
1186 dprintf_midi(stddeb,
1187 " %02X %02X %02X %02X\n",lpMidiHdr->lpData[0],
1188 lpMidiHdr->lpData[1],
1189 lpMidiHdr->lpData[2],
1190 lpMidiHdr->lpData[3]);
1192 count = write (MidiOutDev[wDevID].unixdev,
1193 lpMidiHdr->lpData, lpMidiHdr->dwBytesRecorded);
1195 ptr = (LPWORD)lpMidiHdr->lpData;
1196 for (count = 0; count < lpMidiHdr->dwBytesRecorded; count++) {
1197 if (write (MidiOutDev[wDevID].unixdev, ptr,
1198 sizeof(WORD)) != sizeof(WORD)) break;
1203 dprintf_midi(stddeb, "Linux 'modLongData' // after write count = %d\n",count);
1204 if (count != lpMidiHdr->dwBytesRecorded) {
1205 dprintf_midi(stddeb,
1206 "modLongData() // error writting unixdev #%d ! (%d != %ld)\n",
1207 MidiOutDev[wDevID].unixdev, count, lpMidiHdr->dwBytesRecorded);
1208 dprintf_midi(stddeb,
1209 " errno = %d error = %s\n",en,strerror(en));
1210 return MMSYSERR_NOTENABLED;
1212 lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
1213 lpMidiHdr->dwFlags |= MHDR_DONE;
1214 if (MIDI_NotifyClient(wDevID, MOM_DONE, 0L, 0L) != MMSYSERR_NOERROR) {
1215 dprintf_midi(stddeb,"Linux 'modLongData' // can't notify client !\n");
1216 return MMSYSERR_INVALPARAM;
1218 return MMSYSERR_NOERROR;
1220 return MMSYSERR_NOTENABLED;
1224 /**************************************************************************
1225 * modPrepare [internal]
1227 static DWORD modPrepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1229 #if defined(linux) || defined(__FreeBSD__)
1230 dprintf_midi(stddeb,
1231 "modPrepare(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
1232 if (MidiOutDev[wDevID].unixdev == 0) {
1233 dprintf_midi(stddeb,"Linux 'modPrepare' // can't prepare !\n");
1234 return MMSYSERR_NOTENABLED;
1236 if (MidiOutDev[wDevID].lpQueueHdr != NULL) {
1237 dprintf_midi(stddeb,"Linux 'modPrepare' // already prepare !\n");
1238 return MMSYSERR_NOTENABLED;
1240 MidiOutDev[wDevID].dwTotalPlayed = 0;
1241 MidiOutDev[wDevID].lpQueueHdr = PTR_SEG_TO_LIN(lpMidiHdr);
1242 if (lpMidiHdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING;
1243 lpMidiHdr->dwFlags |= MHDR_PREPARED;
1244 lpMidiHdr->dwFlags &= ~MHDR_DONE;
1245 return MMSYSERR_NOERROR;
1247 return MMSYSERR_NOTENABLED;
1251 /**************************************************************************
1252 * modUnprepare [internal]
1254 static DWORD modUnprepare(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1256 #if defined(linux) || defined(__FreeBSD__)
1257 dprintf_midi(stddeb,
1258 "modUnprepare(%04X, %p, %08lX);\n", wDevID, lpMidiHdr, dwSize);
1259 if (MidiOutDev[wDevID].unixdev == 0) {
1260 dprintf_midi(stddeb,"Linux 'modUnprepare' // can't unprepare !\n");
1261 return MMSYSERR_NOTENABLED;
1263 return MMSYSERR_NOERROR;
1265 return MMSYSERR_NOTENABLED;
1269 /**************************************************************************
1270 * modReset [internal]
1272 static DWORD modReset(WORD wDevID)
1274 dprintf_midi(stddeb, "modReset(%04X);\n", wDevID);
1275 return MMSYSERR_NOTENABLED;
1279 /**************************************************************************
1280 * modMessage [sample driver]
1282 DWORD modMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
1283 DWORD dwParam1, DWORD dwParam2)
1285 dprintf_midi(stddeb, "modMessage(%04X, %04X, %08lX, %08lX, %08lX);\n",
1286 wDevID, wMsg, dwUser, dwParam1, dwParam2);
1289 return modOpen(wDevID, (LPMIDIOPENDESC)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1291 return modClose(wDevID);
1293 return modData(wDevID, dwParam1);
1295 return modLongData(wDevID, (LPMIDIHDR)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1297 return modPrepare(wDevID, (LPMIDIHDR)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1298 case MODM_UNPREPARE:
1299 return modUnprepare(wDevID, (LPMIDIHDR)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1300 case MODM_GETDEVCAPS:
1301 return modGetDevCaps(wDevID, (LPMIDIOUTCAPS)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1302 case MODM_GETNUMDEVS:
1304 case MODM_GETVOLUME:
1306 case MODM_SETVOLUME:
1309 return modReset(wDevID);
1311 return MMSYSERR_NOTSUPPORTED;
1315 /**************************************************************************
1316 * MIDI_DriverProc [sample driver]
1318 LONG MIDI_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg,
1319 DWORD dwParam1, DWORD dwParam2)
1321 #if defined(linux) || defined(__FreeBSD__)
1335 case DRV_QUERYCONFIGURE:
1338 MessageBox16(0, "Sample Midi Linux Driver !",
1339 "MMLinux Driver", MB_OK);
1342 return DRVCNF_RESTART;
1344 return DRVCNF_RESTART;
1345 case MCI_OPEN_DRIVER:
1347 return MIDI_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS)PTR_SEG_TO_LIN(dwParam2));
1348 case MCI_CLOSE_DRIVER:
1350 return MIDI_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1352 return MIDI_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2));
1354 return MIDI_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)PTR_SEG_TO_LIN(dwParam2));
1356 return MIDI_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1358 return MIDI_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2));
1360 return MIDI_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1362 return MIDI_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1364 return MIDI_mciStatus(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2));
1365 case MCI_GETDEVCAPS:
1366 return MIDI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
1368 return MIDI_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS)PTR_SEG_TO_LIN(dwParam2));
1370 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1373 return MMSYSERR_NOTENABLED;
1378 /*-----------------------------------------------------------------------*/