2 * Sample MIDI Wine Driver for Linux
4 * Copyright 1994 Martin Ayotte
8 #define BUILTIN_MMSYSTEM
11 #ifdef BUILTIN_MMSYSTEM
17 #include <sys/ioctl.h>
28 #include <linux/soundcard.h>
30 #include <machine/soundcard.h>
33 #if defined(linux) || defined(__FreeBSD__)
34 #define MIDI_DEV "/dev/sequencer"
37 #define IOCTL(a,b,c) ioctl(a,b,&c)
39 #define IOCTL(a,b,c) (c = ioctl(a,b,c) )
42 #define MAX_MIDIINDRV 2
43 #define MAX_MIDIOUTDRV 2
44 #define MAX_MCIMIDIDRV 2
50 MIDIOPENDESC midiDesc
;
60 MIDIOPENDESC midiDesc
;
67 int nUseCount
; /* Incremented for each shared open */
68 BOOL fShareable
; /* TRUE if first open was shareable */
69 WORD wNotifyDeviceID
; /* MCI device ID with a pending notification */
70 HANDLE16 hCallback
; /* Callback handle for pending notification */
71 HMMIO16 hFile
; /* mmio file handle open as Element */
77 MCI_OPEN_PARMS openParms
;
82 static LINUX_MIDIIN MidiInDev
[MAX_MIDIINDRV
];
83 static LINUX_MIDIOUT MidiOutDev
[MAX_MIDIOUTDRV
];
84 static LINUX_MCIMIDI MCIMidiDev
[MAX_MCIMIDIDRV
];
88 /**************************************************************************
89 * MIDI_NotifyClient [internal]
91 static DWORD
MIDI_NotifyClient(UINT wDevID
, WORD wMsg
,
92 DWORD dwParam1
, DWORD dwParam2
)
94 #if defined(linux) || defined(__FreeBSD__)
95 if (MidiInDev
[wDevID
].wFlags
!= DCB_NULL
&& !DriverCallback(
96 MidiInDev
[wDevID
].midiDesc
.dwCallback
, MidiInDev
[wDevID
].wFlags
,
97 MidiInDev
[wDevID
].midiDesc
.hMidi
, wMsg
,
98 MidiInDev
[wDevID
].midiDesc
.dwInstance
, dwParam1
, dwParam2
)) {
99 dprintf_midi(stddeb
, "MIDI_NotifyClient // can't notify client !\n");
100 return MMSYSERR_NOERROR
;
104 return MMSYSERR_NOTENABLED
;
109 /**************************************************************************
110 * MIDI_ReadByte [internal]
112 static DWORD
MIDI_ReadByte(UINT wDevID
, BYTE
*lpbyt
)
114 #if defined(linux) || defined(__FreeBSD__)
116 if (mmioRead(MCIMidiDev
[wDevID
].hFile
, (HPSTR
)lpbyt
,
117 (long) sizeof(BYTE
)) == (long) sizeof(BYTE
)) {
121 dprintf_midi(stddeb
, "MIDI_ReadByte // error reading wDevID=%d \n", wDevID
);
122 return MCIERR_INTERNAL
;
125 return MMSYSERR_NOTENABLED
;
130 /**************************************************************************
131 * MIDI_ReadWord [internal]
133 static DWORD
MIDI_ReadWord(UINT wDevID
, LPWORD lpw
)
137 if (MIDI_ReadByte(wDevID
, &hibyte
) == 0) {
138 if (MIDI_ReadByte(wDevID
, &lobyte
) == 0) {
139 *lpw
= ((WORD
)hibyte
<< 8) + lobyte
;
144 dprintf_midi(stddeb
, "MIDI_ReadWord // error reading wDevID=%d \n", wDevID
);
145 return MCIERR_INTERNAL
;
149 /**************************************************************************
150 * MIDI_ReadLong [internal]
152 static DWORD
MIDI_ReadLong(UINT wDevID
, LPDWORD lpdw
)
156 if (MIDI_ReadWord(wDevID
, &hiword
) == 0) {
157 if (MIDI_ReadWord(wDevID
, &loword
) == 0) {
158 *lpdw
= MAKELONG(loword
, hiword
);
163 dprintf_midi(stddeb
, "MIDI_ReadLong // error reading wDevID=%d \n", wDevID
);
164 return MCIERR_INTERNAL
;
168 /**************************************************************************
169 * MIDI_ReadVaryLen [internal]
171 static DWORD
MIDI_ReadVaryLen(UINT wDevID
, LPDWORD lpdw
)
175 if (lpdw
== NULL
) return MCIERR_INTERNAL
;
176 if (MIDI_ReadByte(wDevID
, &byte
) != 0) {
177 dprintf_midi(stddeb
, "MIDI_ReadVaryLen // error reading wDevID=%d \n", wDevID
);
178 return MCIERR_INTERNAL
;
180 value
= (DWORD
)(byte
& 0x7F);
181 while (byte
& 0x80) {
182 if (MIDI_ReadByte(wDevID
, &byte
) != 0) {
183 dprintf_midi(stddeb
, "MIDI_ReadVaryLen // error reading wDevID=%d \n", wDevID
);
184 return MCIERR_INTERNAL
;
186 value
= (value
<< 7) + (byte
& 0x7F);
190 dprintf_midi(stddeb, "MIDI_ReadVaryLen // val=%08lX \n", value);
196 /**************************************************************************
197 * MIDI_ReadMThd [internal]
199 static DWORD
MIDI_ReadMThd(UINT wDevID
, DWORD dwOffset
)
201 #if defined(linux) || defined(__FreeBSD__)
204 dprintf_midi(stddeb
, "MIDI_ReadMThd(%04X, %08lX);\n", wDevID
, dwOffset
);
205 if (mmioSeek(MCIMidiDev
[wDevID
].hFile
, dwOffset
, SEEK_SET
) != dwOffset
) {
206 dprintf_midi(stddeb
, "MIDI_ReadMThd // can't seek at %08lX begin of 'MThd' \n", dwOffset
);
207 return MCIERR_INTERNAL
;
209 if (mmioRead(MCIMidiDev
[wDevID
].hFile
, (HPSTR
)&fourcc
,
210 (long) sizeof(FOURCC
)) != (long) sizeof(FOURCC
)) {
211 return MCIERR_INTERNAL
;
213 if (MIDI_ReadLong(wDevID
, &toberead
) != 0) {
214 return MCIERR_INTERNAL
;
216 if (MIDI_ReadWord(wDevID
, &MCIMidiDev
[wDevID
].wFormat
) != 0) {
217 return MCIERR_INTERNAL
;
219 if (MIDI_ReadWord(wDevID
, &MCIMidiDev
[wDevID
].nTracks
) != 0) {
220 return MCIERR_INTERNAL
;
222 if (MIDI_ReadWord(wDevID
, &MCIMidiDev
[wDevID
].nTempo
) != 0) {
223 return MCIERR_INTERNAL
;
225 dprintf_midi(stddeb
, "MIDI_ReadMThd // toberead=%08lX, wFormat=%04X nTracks=%04X nTempo=%04X\n",
226 toberead
, MCIMidiDev
[wDevID
].wFormat
,
227 MCIMidiDev
[wDevID
].nTracks
,
228 MCIMidiDev
[wDevID
].nTempo
);
229 toberead
-= 3 * sizeof(WORD
);
231 ntrks = read16bit ();
232 Mf_division = division = read16bit ();
237 return MMSYSERR_NOTENABLED
;
242 static DWORD
MIDI_ReadMTrk(UINT wDevID
, DWORD dwOffset
)
244 #if defined(linux) || defined(__FreeBSD__)
247 if (mmioSeek(MCIMidiDev
[wDevID
].hFile
, dwOffset
, SEEK_SET
) != dwOffset
) {
248 dprintf_midi(stddeb
, "MIDI_ReadMTrk // can't seek at %08lX begin of 'MThd' \n", dwOffset
);
250 if (mmioRead(MCIMidiDev
[wDevID
].hFile
, (HPSTR
)&fourcc
,
251 (long) sizeof(FOURCC
)) != (long) sizeof(FOURCC
)) {
252 return MCIERR_INTERNAL
;
254 if (MIDI_ReadLong(wDevID
, &toberead
) != 0) {
255 return MCIERR_INTERNAL
;
257 dprintf_midi(stddeb
, "MIDI_ReadMTrk // toberead=%08lX\n", toberead
);
258 toberead
-= 3 * sizeof(WORD
);
259 MCIMidiDev
[wDevID
].dwTotalLen
= toberead
;
262 return MMSYSERR_NOTENABLED
;
267 /**************************************************************************
268 * MIDI_mciOpen [internal]
270 static DWORD
MIDI_mciOpen(UINT wDevID
, DWORD dwFlags
, LPMCI_OPEN_PARMS lpParms
)
272 #if defined(linux) || defined(__FreeBSD__)
273 MIDIOPENDESC MidiDesc
;
276 LPSTR lpstrElementName
;
279 dprintf_midi(stddeb
, "MIDI_mciOpen(%08lX, %p)\n", dwFlags
, lpParms
);
280 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
281 if (MCIMidiDev
[wDevID
].nUseCount
> 0) {
282 /* The driver already open on this channel */
283 /* If the driver was opened shareable before and this open specifies */
284 /* shareable then increment the use count */
285 if (MCIMidiDev
[wDevID
].fShareable
&& (dwFlags
& MCI_OPEN_SHAREABLE
))
286 ++MCIMidiDev
[wDevID
].nUseCount
;
288 return MCIERR_MUST_USE_SHAREABLE
;
291 MCIMidiDev
[wDevID
].nUseCount
= 1;
292 MCIMidiDev
[wDevID
].fShareable
= dwFlags
& MCI_OPEN_SHAREABLE
;
294 dprintf_midi(stddeb
, "MIDI_mciOpen // wDevID=%04X\n", wDevID
);
295 lpParms
->wDeviceID
= wDevID
;
296 dprintf_midi(stddeb
, "MIDI_mciOpen // lpParms->wDevID=%04X\n", lpParms
->wDeviceID
);
297 dprintf_midi(stddeb
, "MIDI_mciOpen // before OPEN_ELEMENT\n");
298 if (dwFlags
& MCI_OPEN_ELEMENT
) {
299 lpstrElementName
= (LPSTR
)PTR_SEG_TO_LIN(lpParms
->lpstrElementName
);
300 dprintf_midi(stddeb
, "MIDI_mciOpen // MCI_OPEN_ELEMENT '%s' !\n", lpstrElementName
);
301 if (strlen(lpstrElementName
) > 0) {
302 strcpy(str
, lpstrElementName
);
304 MCIMidiDev
[wDevID
].hFile
= mmioOpen(str
, NULL
,
305 MMIO_ALLOCBUF
| MMIO_READWRITE
| MMIO_EXCLUSIVE
);
306 if (MCIMidiDev
[wDevID
].hFile
== 0) {
307 dprintf_midi(stddeb
, "MIDI_mciOpen // can't find file='%s' !\n", str
);
308 return MCIERR_FILE_NOT_FOUND
;
312 MCIMidiDev
[wDevID
].hFile
= 0;
314 dprintf_midi(stddeb
, "MIDI_mciOpen // hFile=%u\n", MCIMidiDev
[wDevID
].hFile
);
315 memcpy(&MCIMidiDev
[wDevID
].openParms
, lpParms
, sizeof(MCI_OPEN_PARMS
));
316 MCIMidiDev
[wDevID
].wNotifyDeviceID
= lpParms
->wDeviceID
;
317 MCIMidiDev
[wDevID
].dwStatus
= MCI_MODE_STOP
;
318 MCIMidiDev
[wDevID
].dwBeginData
= 0;
319 MCIMidiDev
[wDevID
].dwTotalLen
= 0;
321 if (MCIMidiDev
[wDevID
].hFile
!= 0) {
323 if (mmioDescend(MCIMidiDev
[wDevID
].hFile
, &ckMainRIFF
, NULL
, 0) != 0) {
324 return MCIERR_INTERNAL
;
326 dprintf_midi(stddeb
,"MIDI_mciOpen // ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n",
327 (LPSTR
)&ckMainRIFF
.ckid
, (LPSTR
)&ckMainRIFF
.fccType
,
330 if (ckMainRIFF
.ckid
== mmioFOURCC('R', 'M', 'I', 'D')) {
331 dprintf_midi(stddeb
, "MIDI_mciOpen // is a 'RMID' file \n");
332 dwOffset
= ckMainRIFF
.dwDataOffset
;
334 if (ckMainRIFF
.ckid
!= mmioFOURCC('M', 'T', 'h', 'd')) {
335 dprintf_midi(stddeb
, "MIDI_mciOpen // unknown format !\n");
336 return MCIERR_INTERNAL
;
338 if (MIDI_ReadMThd(wDevID
, dwOffset
) != 0) {
339 dprintf_midi(stddeb
, "MIDI_mciOpen // can't read 'MThd' header \n");
340 return MCIERR_INTERNAL
;
342 dwOffset
= mmioSeek(MCIMidiDev
[wDevID
].hFile
, 0, SEEK_CUR
);
343 if (MIDI_ReadMTrk(wDevID
, dwOffset
) != 0) {
344 dprintf_midi(stddeb
, "MIDI_mciOpen // can't read 'MTrk' header \n");
345 return MCIERR_INTERNAL
;
347 dwOffset
= mmioSeek(MCIMidiDev
[wDevID
].hFile
, 0, SEEK_CUR
);
348 MCIMidiDev
[wDevID
].dwBeginData
= dwOffset
;
349 dprintf_midi(stddeb
, "MIDI_mciOpen // Chunk Found ckid=%.4s fccType=%.4s cksize=%08lX \n",
350 (LPSTR
)&ckMainRIFF
.ckid
, (LPSTR
)&ckMainRIFF
.fccType
,
353 dwRet
= modMessage(0, MODM_OPEN
, 0, (DWORD
)&MidiDesc
, CALLBACK_NULL
);
354 dwRet
= midMessage(0, MIDM_OPEN
, 0, (DWORD
)&MidiDesc
, CALLBACK_NULL
);
357 return MMSYSERR_NOTENABLED
;
362 /**************************************************************************
363 * MIDI_mciStop [internal]
365 static DWORD
MIDI_mciStop(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
367 #if defined(linux) || defined(__FreeBSD__)
368 dprintf_midi(stddeb
, "MIDI_mciStop(%u, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
369 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
370 MCIMidiDev
[wDevID
].dwStatus
= MCI_MODE_STOP
;
371 dprintf_midi(stddeb
, "MIDI_mciStop // MCIMidiDev[wDevID].dwStatus=%p %d\n",
372 &MCIMidiDev
[wDevID
].dwStatus
, MCIMidiDev
[wDevID
].dwStatus
);
375 return MCIERR_INTERNAL
;
380 /**************************************************************************
381 * MIDI_mciClose [internal]
383 static DWORD
MIDI_mciClose(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
385 #if defined(linux) || defined(__FreeBSD__)
387 dprintf_midi(stddeb
, "MIDI_mciClose(%u, %08lX, %p);\n", wDevID
, dwParam
, lpParms
);
388 if (MCIMidiDev
[wDevID
].dwStatus
!= MCI_MODE_STOP
) {
389 MIDI_mciStop(wDevID
, MCI_WAIT
, lpParms
);
391 MCIMidiDev
[wDevID
].dwStatus
= MCI_MODE_STOP
;
392 MCIMidiDev
[wDevID
].nUseCount
--;
393 if (MCIMidiDev
[wDevID
].nUseCount
== 0) {
394 if (MCIMidiDev
[wDevID
].hFile
!= 0) {
395 mmioClose(MCIMidiDev
[wDevID
].hFile
, 0);
396 MCIMidiDev
[wDevID
].hFile
= 0;
397 dprintf_midi(stddeb
, "MIDI_mciClose // hFile closed !\n");
399 dwRet
= modMessage(0, MODM_CLOSE
, 0, 0L, 0L);
400 if (dwRet
!= MMSYSERR_NOERROR
) return MCIERR_INTERNAL
;
401 dwRet
= midMessage(0, MIDM_CLOSE
, 0, 0L, 0L);
402 if (dwRet
!= MMSYSERR_NOERROR
) return MCIERR_INTERNAL
;
411 /**************************************************************************
412 * MIDI_mciPlay [internal]
414 static DWORD
MIDI_mciPlay(UINT wDevID
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
416 #if defined(linux) || defined(__FreeBSD__)
423 dprintf_midi(stddeb
, "MIDI_mciPlay(%u, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
424 if (MCIMidiDev
[wDevID
].hFile
== 0) {
425 dprintf_midi(stddeb
, "MIDI_mciPlay // can't find file='%s' !\n",
426 MCIMidiDev
[wDevID
].openParms
.lpstrElementName
);
427 return MCIERR_FILE_NOT_FOUND
;
429 start
= 1; end
= 99999;
430 if (dwFlags
& MCI_FROM
) {
431 start
= lpParms
->dwFrom
;
432 dprintf_midi(stddeb
, "MIDI_mciPlay // MCI_FROM=%d \n", start
);
434 if (dwFlags
& MCI_TO
) {
436 dprintf_midi(stddeb
, "MIDI_mciPlay // MCI_TO=%d \n", end
);
439 if (dwFlags
& MCI_NOTIFY
) {
440 dprintf_midi(stddeb
, "MIDI_mciPlay // MCI_NOTIFY %08lX !\n", lpParms
->dwCallback
);
443 dprintf_midi(stddeb
, "MIDI_mciPlay // Can't 'fork' process !\n");
446 dprintf_midi(stddeb
, "MIDI_mciPlay // process started ! play in background ...\n");
449 dprintf_midi(stddeb
, "MIDI_mciPlay // process started ! return to caller...\n");
454 lpMidiHdr
= &MCIMidiDev
[wDevID
].MidiHdr
;
455 lpMidiHdr
->lpData
= (LPSTR
) malloc(1200);
456 if (lpMidiHdr
->lpData
== NULL
) return MCIERR_INTERNAL
;
457 lpMidiHdr
->dwBufferLength
= 1024;
458 lpMidiHdr
->dwUser
= 0L;
459 lpMidiHdr
->dwFlags
= 0L;
460 dwRet
= modMessage(0, MODM_PREPARE
, 0, (DWORD
)lpMidiHdr
, sizeof(MIDIHDR
));
461 /* dprintf_midi(stddeb, "MIDI_mciPlay // after MODM_PREPARE \n"); */
462 MCIMidiDev
[wDevID
].dwStatus
= MCI_MODE_PLAY
;
463 while(MCIMidiDev
[wDevID
].dwStatus
!= MCI_MODE_STOP
) {
464 dprintf_midi(stddeb
, "MIDI_mciPlay // MCIMidiDev[wDevID].dwStatus=%p %d\n",
465 &MCIMidiDev
[wDevID
].dwStatus
, MCIMidiDev
[wDevID
].dwStatus
);
466 ptr
= (LPWORD
)lpMidiHdr
->lpData
;
467 for (count
= 0; count
< lpMidiHdr
->dwBufferLength
; count
++) {
468 if (MIDI_ReadVaryLen(wDevID
, &dwData
) != 0) break;
469 *ptr
= LOWORD(dwData
);
472 count = mmioRead(MCIMidiDev[wDevID].hFile, lpMidiHdr->lpData, lpMidiHdr->dwBufferLength);
474 if (count
< 1) break;
475 lpMidiHdr
->dwBytesRecorded
= count
;
476 dprintf_midi(stddeb
, "MIDI_mciPlay // before MODM_LONGDATA lpMidiHdr=%p dwBytesRecorded=%lu\n",
477 lpMidiHdr
, lpMidiHdr
->dwBytesRecorded
);
478 dwRet
= modMessage(0, MODM_LONGDATA
, 0, (DWORD
)lpMidiHdr
, sizeof(MIDIHDR
));
480 dwRet
= modMessage(0, MODM_UNPREPARE
, 0, (DWORD
)lpMidiHdr
, sizeof(MIDIHDR
));
481 if (lpMidiHdr
->lpData
!= NULL
) {
482 free(lpMidiHdr
->lpData
);
483 lpMidiHdr
->lpData
= NULL
;
485 MCIMidiDev
[wDevID
].dwStatus
= MCI_MODE_STOP
;
486 if (dwFlags
& MCI_NOTIFY
) {
487 dprintf_midi(stddeb
, "MIDI_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
488 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
489 MCIMidiDev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
496 return MMSYSERR_NOTENABLED
;
501 /**************************************************************************
502 * MIDI_mciRecord [internal]
504 static DWORD
MIDI_mciRecord(UINT wDevID
, DWORD dwFlags
, LPMCI_RECORD_PARMS lpParms
)
506 #if defined(linux) || defined(__FreeBSD__)
511 dprintf_midi(stddeb
, "MIDI_mciRecord(%u, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
512 if (MCIMidiDev
[wDevID
].hFile
== 0) {
513 dprintf_midi(stddeb
, "MIDI_mciRecord // can't find file='%s' !\n",
514 MCIMidiDev
[wDevID
].openParms
.lpstrElementName
);
515 return MCIERR_FILE_NOT_FOUND
;
517 start
= 1; end
= 99999;
518 if (dwFlags
& MCI_FROM
) {
519 start
= lpParms
->dwFrom
;
520 dprintf_midi(stddeb
, "MIDI_mciRecord // MCI_FROM=%d \n", start
);
522 if (dwFlags
& MCI_TO
) {
524 dprintf_midi(stddeb
, "MIDI_mciRecord // MCI_TO=%d \n", end
);
526 lpMidiHdr
= &MCIMidiDev
[wDevID
].MidiHdr
;
527 lpMidiHdr
->lpData
= (LPSTR
) xmalloc(1200);
528 lpMidiHdr
->dwBufferLength
= 1024;
529 lpMidiHdr
->dwUser
= 0L;
530 lpMidiHdr
->dwFlags
= 0L;
531 dwRet
= midMessage(0, MIDM_PREPARE
, 0, (DWORD
)lpMidiHdr
, sizeof(MIDIHDR
));
532 dprintf_midi(stddeb
, "MIDI_mciRecord // after MIDM_PREPARE \n");
533 MCIMidiDev
[wDevID
].dwStatus
= MCI_MODE_RECORD
;
534 while(MCIMidiDev
[wDevID
].dwStatus
!= MCI_MODE_STOP
) {
535 dprintf_midi(stddeb
, "MIDI_mciRecord // MCIMidiDev[wDevID].dwStatus=%p %d\n",
536 &MCIMidiDev
[wDevID
].dwStatus
, MCIMidiDev
[wDevID
].dwStatus
);
537 lpMidiHdr
->dwBytesRecorded
= 0;
538 dwRet
= midMessage(0, MIDM_START
, 0, 0L, 0L);
539 dprintf_midi(stddeb
, "MIDI_mciRecord // after MIDM_START lpMidiHdr=%p dwBytesRecorded=%lu\n",
540 lpMidiHdr
, lpMidiHdr
->dwBytesRecorded
);
541 if (lpMidiHdr
->dwBytesRecorded
== 0) break;
543 dprintf_midi(stddeb
, "MIDI_mciRecord // before MIDM_UNPREPARE \n");
544 dwRet
= midMessage(0, MIDM_UNPREPARE
, 0, (DWORD
)lpMidiHdr
, sizeof(MIDIHDR
));
545 dprintf_midi(stddeb
, "MIDI_mciRecord // after MIDM_UNPREPARE \n");
546 if (lpMidiHdr
->lpData
!= NULL
) {
547 free(lpMidiHdr
->lpData
);
548 lpMidiHdr
->lpData
= NULL
;
550 MCIMidiDev
[wDevID
].dwStatus
= MCI_MODE_STOP
;
551 if (dwFlags
& MCI_NOTIFY
) {
552 dprintf_midi(stddeb
, "MIDI_mciRecord // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
553 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
554 MCIMidiDev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
558 return MMSYSERR_NOTENABLED
;
563 /**************************************************************************
564 * MIDI_mciPause [internal]
566 static DWORD
MIDI_mciPause(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
568 #if defined(linux) || defined(__FreeBSD__)
569 dprintf_midi(stddeb
, "MIDI_mciPause(%u, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
570 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
573 return MCIERR_INTERNAL
;
578 /**************************************************************************
579 * MIDI_mciResume [internal]
581 static DWORD
MIDI_mciResume(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
583 #if defined(linux) || defined(__FreeBSD__)
584 dprintf_midi(stddeb
, "MIDI_mciResume(%u, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
585 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
588 return MCIERR_INTERNAL
;
593 /**************************************************************************
594 * MIDI_mciSet [internal]
596 static DWORD
MIDI_mciSet(UINT wDevID
, DWORD dwFlags
, LPMCI_SET_PARMS lpParms
)
598 #if defined(linux) || defined(__FreeBSD__)
599 dprintf_midi(stddeb
, "MIDI_mciSet(%u, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
600 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
601 dprintf_midi(stddeb
, "MIDI_mciSet // dwTimeFormat=%08lX\n", lpParms
->dwTimeFormat
);
602 dprintf_midi(stddeb
, "MIDI_mciSet // dwAudio=%08lX\n", lpParms
->dwAudio
);
603 if (dwFlags
& MCI_SET_TIME_FORMAT
) {
604 switch (lpParms
->dwTimeFormat
) {
605 case MCI_FORMAT_MILLISECONDS
:
606 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_FORMAT_MILLISECONDS !\n");
608 case MCI_FORMAT_BYTES
:
609 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_FORMAT_BYTES !\n");
611 case MCI_FORMAT_SAMPLES
:
612 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_FORMAT_SAMPLES !\n");
615 dprintf_midi(stddeb
, "MIDI_mciSet // bad time format !\n");
616 return MCIERR_BAD_TIME_FORMAT
;
619 if (dwFlags
& MCI_SET_VIDEO
) return MCIERR_UNSUPPORTED_FUNCTION
;
620 if (dwFlags
& MCI_SET_DOOR_OPEN
) return MCIERR_UNSUPPORTED_FUNCTION
;
621 if (dwFlags
& MCI_SET_DOOR_CLOSED
) return MCIERR_UNSUPPORTED_FUNCTION
;
622 if (dwFlags
& MCI_SET_AUDIO
) {
623 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_SET_AUDIO !\n");
625 if (dwFlags
&& MCI_SET_ON
) {
626 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_SET_ON !\n");
627 if (dwFlags
&& MCI_SET_AUDIO_LEFT
) {
628 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_SET_AUDIO_LEFT !\n");
630 if (dwFlags
&& MCI_SET_AUDIO_RIGHT
) {
631 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_SET_AUDIO_RIGHT !\n");
634 if (dwFlags
& MCI_SET_OFF
) {
635 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_SET_OFF !\n");
637 if (dwFlags
& MCI_SEQ_SET_MASTER
) {
638 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_SEQ_SET_MASTER !\n");
640 if (dwFlags
& MCI_SEQ_SET_SLAVE
) {
641 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_SEQ_SET_SLAVE !\n");
643 if (dwFlags
& MCI_SEQ_SET_OFFSET
) {
644 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_SEQ_SET_OFFSET !\n");
646 if (dwFlags
& MCI_SEQ_SET_PORT
) {
647 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_SEQ_SET_PORT !\n");
649 if (dwFlags
& MCI_SEQ_SET_TEMPO
) {
650 dprintf_midi(stddeb
, "MIDI_mciSet // MCI_SEQ_SET_TEMPO !\n");
654 return MCIERR_INTERNAL
;
659 /**************************************************************************
660 * MIDI_mciStatus [internal]
662 static DWORD
MIDI_mciStatus(UINT wDevID
, DWORD dwFlags
, LPMCI_STATUS_PARMS lpParms
)
664 #if defined(linux) || defined(__FreeBSD__)
665 dprintf_midi(stddeb
, "MIDI_mciStatus(%u, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
666 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
667 if (dwFlags
& MCI_STATUS_ITEM
) {
668 switch(lpParms
->dwItem
) {
669 case MCI_STATUS_CURRENT_TRACK
:
670 lpParms
->dwReturn
= 1;
672 case MCI_STATUS_LENGTH
:
673 lpParms
->dwReturn
= 5555;
674 if (dwFlags
& MCI_TRACK
) {
675 lpParms
->dwTrack
= 1;
676 lpParms
->dwReturn
= 2222;
679 case MCI_STATUS_MODE
:
680 lpParms
->dwReturn
= MCI_MODE_STOP
;
682 case MCI_STATUS_MEDIA_PRESENT
:
683 dprintf_midi(stddeb
, "MIDI_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
684 lpParms
->dwReturn
= TRUE
;
686 case MCI_STATUS_NUMBER_OF_TRACKS
:
687 lpParms
->dwReturn
= 1;
689 case MCI_STATUS_POSITION
:
690 lpParms
->dwReturn
= 3333;
691 if (dwFlags
& MCI_STATUS_START
) {
694 if (dwFlags
& MCI_TRACK
) {
695 lpParms
->dwTrack
= 1;
696 lpParms
->dwReturn
= 777;
699 case MCI_STATUS_READY
:
700 dprintf_midi(stddeb
, "MIDI_mciStatus // MCI_STATUS_READY !\n");
701 lpParms
->dwReturn
= TRUE
;
703 case MCI_STATUS_TIME_FORMAT
:
704 dprintf_midi(stddeb
, "MIDI_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
705 lpParms
->dwReturn
= MCI_FORMAT_MILLISECONDS
;
707 case MCI_SEQ_STATUS_DIVTYPE
:
708 dprintf_midi(stddeb
, "MIDI_mciStatus // MCI_SEQ_STATUS_DIVTYPE !\n");
709 lpParms
->dwReturn
= 0;
711 case MCI_SEQ_STATUS_MASTER
:
712 dprintf_midi(stddeb
, "MIDI_mciStatus // MCI_SEQ_STATUS_MASTER !\n");
713 lpParms
->dwReturn
= 0;
715 case MCI_SEQ_STATUS_SLAVE
:
716 dprintf_midi(stddeb
, "MIDI_mciStatus // MCI_SEQ_STATUS_SLAVE !\n");
717 lpParms
->dwReturn
= 0;
719 case MCI_SEQ_STATUS_OFFSET
:
720 dprintf_midi(stddeb
, "MIDI_mciStatus // MCI_SEQ_STATUS_OFFSET !\n");
721 lpParms
->dwReturn
= 0;
723 case MCI_SEQ_STATUS_PORT
:
724 dprintf_midi(stddeb
, "MIDI_mciStatus // MCI_SEQ_STATUS_PORT !\n");
725 lpParms
->dwReturn
= 0;
727 case MCI_SEQ_STATUS_TEMPO
:
728 dprintf_midi(stddeb
, "MIDI_mciStatus // MCI_SEQ_STATUS_TEMPO !\n");
729 lpParms
->dwReturn
= 0;
732 dprintf_midi(stddeb
, "MIDI_mciStatus // unknowm command %08lX !\n", lpParms
->dwItem
);
733 return MCIERR_UNRECOGNIZED_COMMAND
;
736 if (dwFlags
& MCI_NOTIFY
) {
737 dprintf_midi(stddeb
, "MIDI_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
738 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
739 MCIMidiDev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
743 return MCIERR_INTERNAL
;
747 /**************************************************************************
748 * MIDI_mciGetDevCaps [internal]
750 static DWORD
MIDI_mciGetDevCaps(UINT wDevID
, DWORD dwFlags
,
751 LPMCI_GETDEVCAPS_PARMS lpParms
)
753 #if defined(linux) || defined(__FreeBSD__)
754 dprintf_midi(stddeb
, "MIDI_mciGetDevCaps(%u, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
755 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
756 if (dwFlags
& MCI_GETDEVCAPS_ITEM
) {
757 switch(lpParms
->dwItem
) {
758 case MCI_GETDEVCAPS_CAN_RECORD
:
759 lpParms
->dwReturn
= TRUE
;
761 case MCI_GETDEVCAPS_HAS_AUDIO
:
762 lpParms
->dwReturn
= TRUE
;
764 case MCI_GETDEVCAPS_HAS_VIDEO
:
765 lpParms
->dwReturn
= FALSE
;
767 case MCI_GETDEVCAPS_DEVICE_TYPE
:
768 lpParms
->dwReturn
= MCI_DEVTYPE_SEQUENCER
;
770 case MCI_GETDEVCAPS_USES_FILES
:
771 lpParms
->dwReturn
= TRUE
;
773 case MCI_GETDEVCAPS_COMPOUND_DEVICE
:
774 lpParms
->dwReturn
= TRUE
;
776 case MCI_GETDEVCAPS_CAN_EJECT
:
777 lpParms
->dwReturn
= FALSE
;
779 case MCI_GETDEVCAPS_CAN_PLAY
:
780 lpParms
->dwReturn
= TRUE
;
782 case MCI_GETDEVCAPS_CAN_SAVE
:
783 lpParms
->dwReturn
= FALSE
;
786 return MCIERR_UNRECOGNIZED_COMMAND
;
791 return MCIERR_INTERNAL
;
795 /**************************************************************************
796 * MIDI_mciInfo [internal]
798 static DWORD
MIDI_mciInfo(UINT wDevID
, DWORD dwFlags
, LPMCI_INFO_PARMS lpParms
)
800 #if defined(linux) || defined(__FreeBSD__)
801 dprintf_midi(stddeb
, "MIDI_mciInfo(%u, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
802 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
803 lpParms
->lpstrReturn
= NULL
;
805 case MCI_INFO_PRODUCT
:
806 lpParms
->lpstrReturn
= "Linux Sound System 0.5";
809 lpParms
->lpstrReturn
= "FileName";
812 return MCIERR_UNRECOGNIZED_COMMAND
;
814 if (lpParms
->lpstrReturn
!= NULL
)
815 lpParms
->dwRetSize
= strlen(lpParms
->lpstrReturn
);
817 lpParms
->dwRetSize
= 0;
820 return MCIERR_INTERNAL
;
825 /*-----------------------------------------------------------------------*/
828 /**************************************************************************
829 * midGetDevCaps [internal]
831 static DWORD
midGetDevCaps(WORD wDevID
, LPMIDIINCAPS lpCaps
, DWORD dwSize
)
833 dprintf_midi(stddeb
, "midGetDevCaps(%u, %p, %08lX);\n", wDevID
, lpCaps
, dwSize
);
834 return MMSYSERR_NOTENABLED
;
837 /**************************************************************************
840 static DWORD
midOpen(WORD wDevID
, LPMIDIOPENDESC lpDesc
, DWORD dwFlags
)
842 #if defined(linux) || defined(__FreeBSD__)
845 "midOpen(%u, %p, %08lX);\n", wDevID
, lpDesc
, dwFlags
);
846 if (lpDesc
== NULL
) {
847 dprintf_midi(stddeb
,"Linux 'midOpen' // Invalid Parameter !\n");
848 return MMSYSERR_INVALPARAM
;
850 if (wDevID
>= MAX_MIDIINDRV
) {
851 dprintf_midi(stddeb
,"Linux 'midOpen' // MAX_MIDIINDRV reached !\n");
852 return MMSYSERR_ALLOCATED
;
854 MidiInDev
[wDevID
].unixdev
= 0;
855 midi
= open (MIDI_DEV
, O_RDONLY
, 0);
857 dprintf_midi(stddeb
,"Linux 'midOpen' // can't open !\n");
858 return MMSYSERR_NOTENABLED
;
860 MidiInDev
[wDevID
].wFlags
= HIWORD(dwFlags
& CALLBACK_TYPEMASK
);
861 switch(MidiInDev
[wDevID
].wFlags
) {
863 dprintf_midi(stddeb
,"Linux 'midOpen' // CALLBACK_NULL !\n");
867 "Linux 'midOpen' // CALLBACK_WINDOW !\n");
871 "Linux 'midOpen' // CALLBACK_TASK !\n");
875 "Linux 'midOpen' // CALLBACK_FUNCTION !\n");
878 MidiInDev
[wDevID
].lpQueueHdr
= NULL
;
879 MidiInDev
[wDevID
].unixdev
= midi
;
880 MidiInDev
[wDevID
].dwTotalPlayed
= 0;
881 MidiInDev
[wDevID
].bufsize
= 0x3FFF;
882 if (MIDI_NotifyClient(wDevID
, MIM_OPEN
, 0L, 0L) != MMSYSERR_NOERROR
) {
883 dprintf_midi(stddeb
,"Linux 'midOpen' // can't notify client !\n");
884 return MMSYSERR_INVALPARAM
;
886 return MMSYSERR_NOERROR
;
888 return MMSYSERR_NOTENABLED
;
892 /**************************************************************************
893 * midClose [internal]
895 static DWORD
midClose(WORD wDevID
)
897 #if defined(linux) || defined(__FreeBSD__)
898 dprintf_midi(stddeb
, "midClose(%u);\n", wDevID
);
899 if (MidiInDev
[wDevID
].unixdev
== 0) {
900 dprintf_midi(stddeb
,"Linux 'midClose' // can't close !\n");
901 return MMSYSERR_NOTENABLED
;
903 close(MidiInDev
[wDevID
].unixdev
);
904 MidiInDev
[wDevID
].unixdev
= 0;
905 MidiInDev
[wDevID
].bufsize
= 0;
906 if (MIDI_NotifyClient(wDevID
, MIM_CLOSE
, 0L, 0L) != MMSYSERR_NOERROR
) {
907 dprintf_midi(stddeb
,"Linux 'midClose' // can't notify client !\n");
908 return MMSYSERR_INVALPARAM
;
910 return MMSYSERR_NOERROR
;
912 return MMSYSERR_NOTENABLED
;
916 /**************************************************************************
917 * midAddBuffer [internal]
919 static DWORD
midAddBuffer(WORD wDevID
, LPMIDIHDR lpMidiHdr
, DWORD dwSize
)
921 dprintf_midi(stddeb
, "midAddBuffer(%u, %p, %08lX);\n", wDevID
, lpMidiHdr
, dwSize
);
922 return MMSYSERR_NOTENABLED
;
925 /**************************************************************************
926 * midPrepare [internal]
928 static DWORD
midPrepare(WORD wDevID
, LPMIDIHDR lpMidiHdr
, DWORD dwSize
)
930 dprintf_midi(stddeb
, "midPrepare(%u, %p, %08lX);\n", wDevID
, lpMidiHdr
, dwSize
);
931 return MMSYSERR_NOTENABLED
;
934 /**************************************************************************
935 * midUnprepare [internal]
937 static DWORD
midUnprepare(WORD wDevID
, LPMIDIHDR lpMidiHdr
, DWORD dwSize
)
939 dprintf_midi(stddeb
, "midUnprepare(%u, %p, %08lX);\n", wDevID
, lpMidiHdr
, dwSize
);
940 return MMSYSERR_NOTENABLED
;
943 /**************************************************************************
944 * midReset [internal]
946 static DWORD
midReset(WORD wDevID
)
948 dprintf_midi(stddeb
, "midReset(%u);\n", wDevID
);
949 return MMSYSERR_NOTENABLED
;
953 /**************************************************************************
954 * midStart [internal]
956 static DWORD
midStart(WORD wDevID
)
958 dprintf_midi(stddeb
, "midStart(%u);\n", wDevID
);
959 return MMSYSERR_NOTENABLED
;
963 /**************************************************************************
966 static DWORD
midStop(WORD wDevID
)
968 dprintf_midi(stddeb
, "midStop(%u);\n", wDevID
);
969 return MMSYSERR_NOTENABLED
;
973 /**************************************************************************
974 * midMessage [sample driver]
976 DWORD
midMessage(WORD wDevID
, WORD wMsg
, DWORD dwUser
,
977 DWORD dwParam1
, DWORD dwParam2
)
979 dprintf_midi(stddeb
, "midMessage(%u, %04X, %08lX, %08lX, %08lX);\n",
980 wDevID
, wMsg
, dwUser
, dwParam1
, dwParam2
);
983 return midOpen(wDevID
, (LPMIDIOPENDESC
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
985 return midClose(wDevID
);
987 return midAddBuffer(wDevID
, (LPMIDIHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
989 return midPrepare(wDevID
, (LPMIDIHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
991 return midUnprepare(wDevID
, (LPMIDIHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
992 case MIDM_GETDEVCAPS
:
993 return midGetDevCaps(wDevID
, (LPMIDIINCAPS
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
994 case MIDM_GETNUMDEVS
:
997 return midReset(wDevID
);
999 return midStart(wDevID
);
1001 return midStop(wDevID
);
1003 return MMSYSERR_NOTSUPPORTED
;
1008 /*-----------------------------------------------------------------------*/
1011 /**************************************************************************
1012 * modGetDevCaps [internal]
1014 static DWORD
modGetDevCaps(WORD wDevID
, LPMIDIOUTCAPS lpCaps
, DWORD dwSize
)
1016 dprintf_midi(stddeb
, "modGetDevCaps(%u, %p, %08lX);\n", wDevID
, lpCaps
, dwSize
);
1017 return MMSYSERR_NOTENABLED
;
1021 /**************************************************************************
1022 * modOpen [internal]
1024 static DWORD
modOpen(WORD wDevID
, LPMIDIOPENDESC lpDesc
, DWORD dwFlags
)
1026 #if defined(linux) || defined(__FreeBSD__)
1028 dprintf_midi(stddeb
,
1029 "modOpen(%u, %p, %08lX);\n", wDevID
, lpDesc
, dwFlags
);
1030 if (lpDesc
== NULL
) {
1031 dprintf_midi(stddeb
,"Linux 'modOpen' // Invalid Parameter !\n");
1032 return MMSYSERR_INVALPARAM
;
1034 if (wDevID
>= MAX_MIDIOUTDRV
) {
1035 dprintf_midi(stddeb
,"Linux 'modOpen' // MAX_MIDIOUTDRV reached !\n");
1036 return MMSYSERR_ALLOCATED
;
1038 MidiOutDev
[wDevID
].unixdev
= 0;
1039 midi
= open (MIDI_DEV
, O_WRONLY
, 0);
1041 dprintf_midi(stddeb
,"Linux 'modOpen' // can't open !\n");
1042 return MMSYSERR_NOTENABLED
;
1044 MidiOutDev
[wDevID
].wFlags
= HIWORD(dwFlags
& CALLBACK_TYPEMASK
);
1045 switch(MidiOutDev
[wDevID
].wFlags
) {
1047 dprintf_midi(stddeb
,"Linux 'modOpen' // CALLBACK_NULL !\n");
1050 dprintf_midi(stddeb
,
1051 "Linux 'modOpen' // CALLBACK_WINDOW !\n");
1054 dprintf_midi(stddeb
,
1055 "Linux 'modOpen' // CALLBACK_TASK !\n");
1058 dprintf_midi(stddeb
,
1059 "Linux 'modOpen' // CALLBACK_FUNCTION !\n");
1062 MidiOutDev
[wDevID
].lpQueueHdr
= NULL
;
1063 MidiOutDev
[wDevID
].unixdev
= midi
;
1064 MidiOutDev
[wDevID
].dwTotalPlayed
= 0;
1065 MidiOutDev
[wDevID
].bufsize
= 0x3FFF;
1066 if (MIDI_NotifyClient(wDevID
, MOM_OPEN
, 0L, 0L) != MMSYSERR_NOERROR
) {
1067 dprintf_midi(stddeb
,"Linux 'modOpen' // can't notify client !\n");
1068 return MMSYSERR_INVALPARAM
;
1070 dprintf_midi(stddeb
,
1071 "Linux 'modOpen' // Succesful unixdev=%d !\n", midi
);
1072 return MMSYSERR_NOERROR
;
1074 return MMSYSERR_NOTENABLED
;
1079 /**************************************************************************
1080 * modClose [internal]
1082 static DWORD
modClose(WORD wDevID
)
1084 #if defined(linux) || defined(__FreeBSD__)
1085 dprintf_midi(stddeb
, "modClose(%u);\n", wDevID
);
1086 if (MidiOutDev
[wDevID
].unixdev
== 0) {
1087 dprintf_midi(stddeb
,"Linux 'modClose' // can't close !\n");
1088 return MMSYSERR_NOTENABLED
;
1090 close(MidiOutDev
[wDevID
].unixdev
);
1091 MidiOutDev
[wDevID
].unixdev
= 0;
1092 MidiOutDev
[wDevID
].bufsize
= 0;
1093 if (MIDI_NotifyClient(wDevID
, MOM_CLOSE
, 0L, 0L) != MMSYSERR_NOERROR
) {
1094 dprintf_midi(stddeb
,"Linux 'modClose' // can't notify client !\n");
1095 return MMSYSERR_INVALPARAM
;
1097 return MMSYSERR_NOERROR
;
1099 return MMSYSERR_NOTENABLED
;
1103 /**************************************************************************
1104 * modData [internal]
1106 static DWORD
modData(WORD wDevID
, DWORD dwParam
)
1108 #if defined(linux) || defined(__FreeBSD__)
1110 dprintf_midi(stddeb
,
1111 "modData(%u, %08lX);\n", wDevID
, dwParam
);
1112 if (MidiOutDev
[wDevID
].unixdev
== 0) {
1113 dprintf_midi(stddeb
,"Linux 'modData' // can't play !\n");
1114 return MIDIERR_NODEVICE
;
1116 event
= LOWORD(dwParam
);
1117 if (write (MidiOutDev
[wDevID
].unixdev
,
1118 &event
, sizeof(WORD
)) != sizeof(WORD
)) {
1119 dprintf_midi(stddeb
,
1120 "modData() // error writting unixdev !\n");
1122 return MMSYSERR_NOTENABLED
;
1124 return MMSYSERR_NOTENABLED
;
1128 /**************************************************************************
1129 * modLongData [internal]
1131 static DWORD
modLongData(WORD wDevID
, LPMIDIHDR lpMidiHdr
, DWORD dwSize
)
1133 #if defined(linux) || defined(__FreeBSD__)
1136 dprintf_midi(stddeb
,
1137 "modLongData(%u, %p, %08lX);\n", wDevID
, lpMidiHdr
, dwSize
);
1138 dprintf_midi(stddeb
, "modLongData(%u, %p, %08lX);\n", wDevID
, lpMidiHdr
, dwSize
);
1139 if (MidiOutDev
[wDevID
].unixdev
== 0) {
1140 dprintf_midi(stddeb
,"Linux 'modLongData' // can't play !\n");
1141 return MIDIERR_NODEVICE
;
1143 if (lpMidiHdr
->lpData
== NULL
) return MIDIERR_UNPREPARED
;
1144 if (!(lpMidiHdr
->dwFlags
& MHDR_PREPARED
)) return MIDIERR_UNPREPARED
;
1145 if (lpMidiHdr
->dwFlags
& MHDR_INQUEUE
) return MIDIERR_STILLPLAYING
;
1146 lpMidiHdr
->dwFlags
&= ~MHDR_DONE
;
1147 lpMidiHdr
->dwFlags
|= MHDR_INQUEUE
;
1148 dprintf_midi(stddeb
,
1149 "modLongData() // dwBytesRecorded %lu !\n", lpMidiHdr
->dwBytesRecorded
);
1151 count = write (MidiOutDev[wDevID].unixdev,
1152 lpMidiHdr->lpData, lpMidiHdr->dwBytesRecorded);
1154 ptr
= (LPWORD
)lpMidiHdr
->lpData
;
1155 for (count
= 0; count
< lpMidiHdr
->dwBytesRecorded
; count
++) {
1156 if (write (MidiOutDev
[wDevID
].unixdev
, ptr
,
1157 sizeof(WORD
)) != sizeof(WORD
)) break;
1160 if (count
!= lpMidiHdr
->dwBytesRecorded
) {
1161 dprintf_midi(stddeb
,
1162 "modLongData() // error writting unixdev #%d ! (%d != %ld)\n",
1163 MidiOutDev
[wDevID
].unixdev
, count
, lpMidiHdr
->dwBytesRecorded
);
1164 return MMSYSERR_NOTENABLED
;
1166 lpMidiHdr
->dwFlags
&= ~MHDR_INQUEUE
;
1167 lpMidiHdr
->dwFlags
|= MHDR_DONE
;
1168 if (MIDI_NotifyClient(wDevID
, MOM_DONE
, 0L, 0L) != MMSYSERR_NOERROR
) {
1169 dprintf_midi(stddeb
,"Linux 'modLongData' // can't notify client !\n");
1170 return MMSYSERR_INVALPARAM
;
1172 return MMSYSERR_NOERROR
;
1174 return MMSYSERR_NOTENABLED
;
1178 /**************************************************************************
1179 * modPrepare [internal]
1181 static DWORD
modPrepare(WORD wDevID
, LPMIDIHDR lpMidiHdr
, DWORD dwSize
)
1183 #if defined(linux) || defined(__FreeBSD__)
1184 dprintf_midi(stddeb
,
1185 "modPrepare(%u, %p, %08lX);\n", wDevID
, lpMidiHdr
, dwSize
);
1186 if (MidiOutDev
[wDevID
].unixdev
== 0) {
1187 dprintf_midi(stddeb
,"Linux 'modPrepare' // can't prepare !\n");
1188 return MMSYSERR_NOTENABLED
;
1190 if (MidiOutDev
[wDevID
].lpQueueHdr
!= NULL
) {
1191 dprintf_midi(stddeb
,"Linux 'modPrepare' // already prepare !\n");
1192 return MMSYSERR_NOTENABLED
;
1194 MidiOutDev
[wDevID
].dwTotalPlayed
= 0;
1195 MidiOutDev
[wDevID
].lpQueueHdr
= lpMidiHdr
;
1196 if (lpMidiHdr
->dwFlags
& MHDR_INQUEUE
) return MIDIERR_STILLPLAYING
;
1197 lpMidiHdr
->dwFlags
|= MHDR_PREPARED
;
1198 lpMidiHdr
->dwFlags
&= ~MHDR_DONE
;
1199 return MMSYSERR_NOERROR
;
1201 return MMSYSERR_NOTENABLED
;
1205 /**************************************************************************
1206 * modUnprepare [internal]
1208 static DWORD
modUnprepare(WORD wDevID
, LPMIDIHDR lpMidiHdr
, DWORD dwSize
)
1210 #if defined(linux) || defined(__FreeBSD__)
1211 dprintf_midi(stddeb
,
1212 "modUnprepare(%u, %p, %08lX);\n", wDevID
, lpMidiHdr
, dwSize
);
1213 if (MidiOutDev
[wDevID
].unixdev
== 0) {
1214 dprintf_midi(stddeb
,"Linux 'modUnprepare' // can't unprepare !\n");
1215 return MMSYSERR_NOTENABLED
;
1217 return MMSYSERR_NOERROR
;
1219 return MMSYSERR_NOTENABLED
;
1223 /**************************************************************************
1224 * modReset [internal]
1226 static DWORD
modReset(WORD wDevID
)
1228 dprintf_midi(stddeb
, "modReset(%u);\n", wDevID
);
1229 return MMSYSERR_NOTENABLED
;
1233 /**************************************************************************
1234 * modMessage [sample driver]
1236 DWORD
modMessage(WORD wDevID
, WORD wMsg
, DWORD dwUser
,
1237 DWORD dwParam1
, DWORD dwParam2
)
1239 dprintf_midi(stddeb
, "modMessage(%u, %04X, %08lX, %08lX, %08lX);\n",
1240 wDevID
, wMsg
, dwUser
, dwParam1
, dwParam2
);
1243 return modOpen(wDevID
, (LPMIDIOPENDESC
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
1245 return modClose(wDevID
);
1247 return modData(wDevID
, dwParam1
);
1249 return modLongData(wDevID
, (LPMIDIHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
1251 return modPrepare(wDevID
, (LPMIDIHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
1252 case MODM_UNPREPARE
:
1253 return modUnprepare(wDevID
, (LPMIDIHDR
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
1254 case MODM_GETDEVCAPS
:
1255 return modGetDevCaps(wDevID
, (LPMIDIOUTCAPS
)PTR_SEG_TO_LIN(dwParam1
), dwParam2
);
1256 case MODM_GETNUMDEVS
:
1258 case MODM_GETVOLUME
:
1260 case MODM_SETVOLUME
:
1263 return modReset(wDevID
);
1265 return MMSYSERR_NOTSUPPORTED
;
1269 /**************************************************************************
1270 * MIDI_DriverProc [sample driver]
1272 LONG
MIDI_DriverProc(DWORD dwDevID
, HDRVR16 hDriv
, WORD wMsg
,
1273 DWORD dwParam1
, DWORD dwParam2
)
1275 #if defined(linux) || defined(__FreeBSD__)
1289 case DRV_QUERYCONFIGURE
:
1292 MessageBox(0, "Sample Midi Linux Driver !",
1293 "MMLinux Driver", MB_OK
);
1296 return DRVCNF_RESTART
;
1298 return DRVCNF_RESTART
;
1299 case MCI_OPEN_DRIVER
:
1301 return MIDI_mciOpen(dwDevID
, dwParam1
, (LPMCI_OPEN_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1302 case MCI_CLOSE_DRIVER
:
1304 return MIDI_mciClose(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1306 return MIDI_mciPlay(dwDevID
, dwParam1
, (LPMCI_PLAY_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1308 return MIDI_mciRecord(dwDevID
, dwParam1
, (LPMCI_RECORD_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1310 return MIDI_mciStop(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1312 return MIDI_mciSet(dwDevID
, dwParam1
, (LPMCI_SET_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1314 return MIDI_mciPause(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1316 return MIDI_mciResume(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1318 return MIDI_mciStatus(dwDevID
, dwParam1
, (LPMCI_STATUS_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1319 case MCI_GETDEVCAPS
:
1320 return MIDI_mciGetDevCaps(dwDevID
, dwParam1
, (LPMCI_GETDEVCAPS_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1322 return MIDI_mciInfo(dwDevID
, dwParam1
, (LPMCI_INFO_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
1324 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
1327 return MMSYSERR_NOTENABLED
;
1332 /*-----------------------------------------------------------------------*/
1334 #endif /* #ifdef BUILTIN_MMSYSTEM */