Release 970202
[wine/multimedia.git] / multimedia / midi.c
blobaddbf169ba37e8ee3f04e77594bd1617decdf54d
1 /*
2 * Sample MIDI Wine Driver for Linux
4 * Copyright 1994 Martin Ayotte
5 */
7 #ifndef WINELIB
8 #define BUILTIN_MMSYSTEM
9 #endif
11 #ifdef BUILTIN_MMSYSTEM
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17 #include <sys/ioctl.h>
18 #include "windows.h"
19 #include "ldt.h"
20 #include "driver.h"
21 #include "mmsystem.h"
22 #include "xmalloc.h"
24 #include "stddebug.h"
25 #include "debug.h"
27 #ifdef linux
28 #include <linux/soundcard.h>
29 #elif __FreeBSD__
30 #include <machine/soundcard.h>
31 #endif
33 #if defined(linux) || defined(__FreeBSD__)
34 #define MIDI_DEV "/dev/sequencer"
36 #ifdef SOUND_VERSION
37 #define IOCTL(a,b,c) ioctl(a,b,&c)
38 #else
39 #define IOCTL(a,b,c) (c = ioctl(a,b,c) )
40 #endif
42 #define MAX_MIDIINDRV 2
43 #define MAX_MIDIOUTDRV 2
44 #define MAX_MCIMIDIDRV 2
46 typedef struct {
47 int unixdev;
48 int state;
49 DWORD bufsize;
50 MIDIOPENDESC midiDesc;
51 WORD wFlags;
52 LPMIDIHDR lpQueueHdr;
53 DWORD dwTotalPlayed;
54 } LINUX_MIDIIN;
56 typedef struct {
57 int unixdev;
58 int state;
59 DWORD bufsize;
60 MIDIOPENDESC midiDesc;
61 WORD wFlags;
62 LPMIDIHDR lpQueueHdr;
63 DWORD dwTotalPlayed;
64 } LINUX_MIDIOUT;
66 typedef struct {
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 */
72 DWORD dwBeginData;
73 DWORD dwTotalLen;
74 WORD wFormat;
75 WORD nTracks;
76 WORD nTempo;
77 MCI_OPEN_PARMS openParms;
78 MIDIHDR MidiHdr;
79 WORD dwStatus;
80 } LINUX_MCIMIDI;
82 static LINUX_MIDIIN MidiInDev[MAX_MIDIINDRV];
83 static LINUX_MIDIOUT MidiOutDev[MAX_MIDIOUTDRV];
84 static LINUX_MCIMIDI MCIMidiDev[MAX_MCIMIDIDRV];
85 #endif
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;
102 return 0;
103 #else
104 return MMSYSERR_NOTENABLED;
105 #endif
109 /**************************************************************************
110 * MIDI_ReadByte [internal]
112 static DWORD MIDI_ReadByte(UINT wDevID, BYTE *lpbyt)
114 #if defined(linux) || defined(__FreeBSD__)
115 if (lpbyt != NULL) {
116 if (mmioRead(MCIMidiDev[wDevID].hFile, (HPSTR)lpbyt,
117 (long) sizeof(BYTE)) == (long) sizeof(BYTE)) {
118 return 0;
121 dprintf_midi(stddeb, "MIDI_ReadByte // error reading wDevID=%d \n", wDevID);
122 return MCIERR_INTERNAL;
124 #else
125 return MMSYSERR_NOTENABLED;
126 #endif
130 /**************************************************************************
131 * MIDI_ReadWord [internal]
133 static DWORD MIDI_ReadWord(UINT wDevID, LPWORD lpw)
135 BYTE hibyte, lobyte;
136 if (lpw != NULL) {
137 if (MIDI_ReadByte(wDevID, &hibyte) == 0) {
138 if (MIDI_ReadByte(wDevID, &lobyte) == 0) {
139 *lpw = ((WORD)hibyte << 8) + lobyte;
140 return 0;
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)
154 WORD hiword, loword;
155 if (lpdw != NULL) {
156 if (MIDI_ReadWord(wDevID, &hiword) == 0) {
157 if (MIDI_ReadWord(wDevID, &loword) == 0) {
158 *lpdw = MAKELONG(loword, hiword);
159 return 0;
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)
173 BYTE byte;
174 DWORD value;
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);
188 *lpdw = value;
190 dprintf_midi(stddeb, "MIDI_ReadVaryLen // val=%08lX \n", value);
192 return 0;
196 /**************************************************************************
197 * MIDI_ReadMThd [internal]
199 static DWORD MIDI_ReadMThd(UINT wDevID, DWORD dwOffset)
201 #if defined(linux) || defined(__FreeBSD__)
202 DWORD toberead;
203 FOURCC fourcc;
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 ();
234 return 0;
236 #else
237 return MMSYSERR_NOTENABLED;
238 #endif
242 static DWORD MIDI_ReadMTrk(UINT wDevID, DWORD dwOffset)
244 #if defined(linux) || defined(__FreeBSD__)
245 DWORD toberead;
246 FOURCC fourcc;
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;
260 return 0;
261 #else
262 return MMSYSERR_NOTENABLED;
263 #endif
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;
274 DWORD dwRet;
275 DWORD dwOffset;
276 LPSTR lpstrElementName;
277 char str[128];
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;
287 else
288 return MCIERR_MUST_USE_SHAREABLE;
290 else {
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);
303 CharUpper32A(str);
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;
311 else
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;
320 MidiDesc.hMidi = 0;
321 if (MCIMidiDev[wDevID].hFile != 0) {
322 MMCKINFO ckMainRIFF;
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,
328 ckMainRIFF.cksize);
329 dwOffset = 0;
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,
351 ckMainRIFF.cksize);
353 dwRet = modMessage(0, MODM_OPEN, 0, (DWORD)&MidiDesc, CALLBACK_NULL);
354 dwRet = midMessage(0, MIDM_OPEN, 0, (DWORD)&MidiDesc, CALLBACK_NULL);
355 return 0;
356 #else
357 return MMSYSERR_NOTENABLED;
358 #endif
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);
373 return 0;
374 #else
375 return MCIERR_INTERNAL;
376 #endif
380 /**************************************************************************
381 * MIDI_mciClose [internal]
383 static DWORD MIDI_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
385 #if defined(linux) || defined(__FreeBSD__)
386 DWORD dwRet;
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;
404 return 0;
405 #else
406 return 0;
407 #endif
411 /**************************************************************************
412 * MIDI_mciPlay [internal]
414 static DWORD MIDI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
416 #if defined(linux) || defined(__FreeBSD__)
417 int count;
418 int start, end;
419 LPMIDIHDR lpMidiHdr;
420 DWORD dwData;
421 LPWORD ptr;
422 DWORD dwRet;
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) {
435 end = lpParms->dwTo;
436 dprintf_midi(stddeb, "MIDI_mciPlay // MCI_TO=%d \n", end);
438 #if 0
439 if (dwFlags & MCI_NOTIFY) {
440 dprintf_midi(stddeb, "MIDI_mciPlay // MCI_NOTIFY %08lX !\n", lpParms->dwCallback);
441 switch(fork()) {
442 case -1:
443 dprintf_midi(stddeb, "MIDI_mciPlay // Can't 'fork' process !\n");
444 break;
445 case 0:
446 dprintf_midi(stddeb, "MIDI_mciPlay // process started ! play in background ...\n");
447 break;
448 default:
449 dprintf_midi(stddeb, "MIDI_mciPlay // process started ! return to caller...\n");
450 return 0;
453 #endif
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);
490 #if 0
491 exit(1);
492 #endif
494 return 0;
495 #else
496 return MMSYSERR_NOTENABLED;
497 #endif
501 /**************************************************************************
502 * MIDI_mciRecord [internal]
504 static DWORD MIDI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
506 #if defined(linux) || defined(__FreeBSD__)
507 int start, end;
508 LPMIDIHDR lpMidiHdr;
509 DWORD dwRet;
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) {
523 end = lpParms->dwTo;
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);
556 return 0;
557 #else
558 return MMSYSERR_NOTENABLED;
559 #endif
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;
571 return 0;
572 #else
573 return MCIERR_INTERNAL;
574 #endif
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;
586 return 0;
587 #else
588 return MCIERR_INTERNAL;
589 #endif
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");
607 break;
608 case MCI_FORMAT_BYTES:
609 dprintf_midi(stddeb, "MIDI_mciSet // MCI_FORMAT_BYTES !\n");
610 break;
611 case MCI_FORMAT_SAMPLES:
612 dprintf_midi(stddeb, "MIDI_mciSet // MCI_FORMAT_SAMPLES !\n");
613 break;
614 default:
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");
652 return 0;
653 #else
654 return MCIERR_INTERNAL;
655 #endif
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;
671 break;
672 case MCI_STATUS_LENGTH:
673 lpParms->dwReturn = 5555;
674 if (dwFlags & MCI_TRACK) {
675 lpParms->dwTrack = 1;
676 lpParms->dwReturn = 2222;
678 break;
679 case MCI_STATUS_MODE:
680 lpParms->dwReturn = MCI_MODE_STOP;
681 break;
682 case MCI_STATUS_MEDIA_PRESENT:
683 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
684 lpParms->dwReturn = TRUE;
685 break;
686 case MCI_STATUS_NUMBER_OF_TRACKS:
687 lpParms->dwReturn = 1;
688 break;
689 case MCI_STATUS_POSITION:
690 lpParms->dwReturn = 3333;
691 if (dwFlags & MCI_STATUS_START) {
692 lpParms->dwItem = 1;
694 if (dwFlags & MCI_TRACK) {
695 lpParms->dwTrack = 1;
696 lpParms->dwReturn = 777;
698 break;
699 case MCI_STATUS_READY:
700 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_STATUS_READY !\n");
701 lpParms->dwReturn = TRUE;
702 break;
703 case MCI_STATUS_TIME_FORMAT:
704 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
705 lpParms->dwReturn = MCI_FORMAT_MILLISECONDS;
706 break;
707 case MCI_SEQ_STATUS_DIVTYPE:
708 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_DIVTYPE !\n");
709 lpParms->dwReturn = 0;
710 break;
711 case MCI_SEQ_STATUS_MASTER:
712 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_MASTER !\n");
713 lpParms->dwReturn = 0;
714 break;
715 case MCI_SEQ_STATUS_SLAVE:
716 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_SLAVE !\n");
717 lpParms->dwReturn = 0;
718 break;
719 case MCI_SEQ_STATUS_OFFSET:
720 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_OFFSET !\n");
721 lpParms->dwReturn = 0;
722 break;
723 case MCI_SEQ_STATUS_PORT:
724 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_PORT !\n");
725 lpParms->dwReturn = 0;
726 break;
727 case MCI_SEQ_STATUS_TEMPO:
728 dprintf_midi(stddeb, "MIDI_mciStatus // MCI_SEQ_STATUS_TEMPO !\n");
729 lpParms->dwReturn = 0;
730 break;
731 default:
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);
741 return 0;
742 #else
743 return MCIERR_INTERNAL;
744 #endif
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;
760 break;
761 case MCI_GETDEVCAPS_HAS_AUDIO:
762 lpParms->dwReturn = TRUE;
763 break;
764 case MCI_GETDEVCAPS_HAS_VIDEO:
765 lpParms->dwReturn = FALSE;
766 break;
767 case MCI_GETDEVCAPS_DEVICE_TYPE:
768 lpParms->dwReturn = MCI_DEVTYPE_SEQUENCER;
769 break;
770 case MCI_GETDEVCAPS_USES_FILES:
771 lpParms->dwReturn = TRUE;
772 break;
773 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
774 lpParms->dwReturn = TRUE;
775 break;
776 case MCI_GETDEVCAPS_CAN_EJECT:
777 lpParms->dwReturn = FALSE;
778 break;
779 case MCI_GETDEVCAPS_CAN_PLAY:
780 lpParms->dwReturn = TRUE;
781 break;
782 case MCI_GETDEVCAPS_CAN_SAVE:
783 lpParms->dwReturn = FALSE;
784 break;
785 default:
786 return MCIERR_UNRECOGNIZED_COMMAND;
789 return 0;
790 #else
791 return MCIERR_INTERNAL;
792 #endif
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;
804 switch(dwFlags) {
805 case MCI_INFO_PRODUCT:
806 lpParms->lpstrReturn = "Linux Sound System 0.5";
807 break;
808 case MCI_INFO_FILE:
809 lpParms->lpstrReturn = "FileName";
810 break;
811 default:
812 return MCIERR_UNRECOGNIZED_COMMAND;
814 if (lpParms->lpstrReturn != NULL)
815 lpParms->dwRetSize = strlen(lpParms->lpstrReturn);
816 else
817 lpParms->dwRetSize = 0;
818 return 0;
819 #else
820 return MCIERR_INTERNAL;
821 #endif
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 /**************************************************************************
838 * midOpen [internal]
840 static DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
842 #if defined(linux) || defined(__FreeBSD__)
843 int midi;
844 dprintf_midi(stddeb,
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);
856 if (midi == -1) {
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) {
862 case DCB_NULL:
863 dprintf_midi(stddeb,"Linux 'midOpen' // CALLBACK_NULL !\n");
864 break;
865 case DCB_WINDOW:
866 dprintf_midi(stddeb,
867 "Linux 'midOpen' // CALLBACK_WINDOW !\n");
868 break;
869 case DCB_TASK:
870 dprintf_midi(stddeb,
871 "Linux 'midOpen' // CALLBACK_TASK !\n");
872 break;
873 case DCB_FUNCTION:
874 dprintf_midi(stddeb,
875 "Linux 'midOpen' // CALLBACK_FUNCTION !\n");
876 break;
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;
887 #else
888 return MMSYSERR_NOTENABLED;
889 #endif
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;
911 #else
912 return MMSYSERR_NOTENABLED;
913 #endif
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 /**************************************************************************
964 * midStop [internal]
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);
981 switch(wMsg) {
982 case MIDM_OPEN:
983 return midOpen(wDevID, (LPMIDIOPENDESC)PTR_SEG_TO_LIN(dwParam1), dwParam2);
984 case MIDM_CLOSE:
985 return midClose(wDevID);
986 case MIDM_ADDBUFFER:
987 return midAddBuffer(wDevID, (LPMIDIHDR)PTR_SEG_TO_LIN(dwParam1), dwParam2);
988 case MIDM_PREPARE:
989 return midPrepare(wDevID, (LPMIDIHDR)PTR_SEG_TO_LIN(dwParam1), dwParam2);
990 case MIDM_UNPREPARE:
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:
995 return 0;
996 case MIDM_RESET:
997 return midReset(wDevID);
998 case MIDM_START:
999 return midStart(wDevID);
1000 case MIDM_STOP:
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__)
1027 int midi;
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);
1040 if (midi == -1) {
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) {
1046 case DCB_NULL:
1047 dprintf_midi(stddeb,"Linux 'modOpen' // CALLBACK_NULL !\n");
1048 break;
1049 case DCB_WINDOW:
1050 dprintf_midi(stddeb,
1051 "Linux 'modOpen' // CALLBACK_WINDOW !\n");
1052 break;
1053 case DCB_TASK:
1054 dprintf_midi(stddeb,
1055 "Linux 'modOpen' // CALLBACK_TASK !\n");
1056 break;
1057 case DCB_FUNCTION:
1058 dprintf_midi(stddeb,
1059 "Linux 'modOpen' // CALLBACK_FUNCTION !\n");
1060 break;
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;
1073 #else
1074 return MMSYSERR_NOTENABLED;
1075 #endif
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;
1098 #else
1099 return MMSYSERR_NOTENABLED;
1100 #endif
1103 /**************************************************************************
1104 * modData [internal]
1106 static DWORD modData(WORD wDevID, DWORD dwParam)
1108 #if defined(linux) || defined(__FreeBSD__)
1109 WORD event;
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;
1123 #else
1124 return MMSYSERR_NOTENABLED;
1125 #endif
1128 /**************************************************************************
1129 * modLongData [internal]
1131 static DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
1133 #if defined(linux) || defined(__FreeBSD__)
1134 int count;
1135 LPWORD ptr;
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;
1158 ptr++;
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;
1173 #else
1174 return MMSYSERR_NOTENABLED;
1175 #endif
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;
1200 #else
1201 return MMSYSERR_NOTENABLED;
1202 #endif
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;
1218 #else
1219 return MMSYSERR_NOTENABLED;
1220 #endif
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);
1241 switch(wMsg) {
1242 case MODM_OPEN:
1243 return modOpen(wDevID, (LPMIDIOPENDESC)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1244 case MODM_CLOSE:
1245 return modClose(wDevID);
1246 case MODM_DATA:
1247 return modData(wDevID, dwParam1);
1248 case MODM_LONGDATA:
1249 return modLongData(wDevID, (LPMIDIHDR)PTR_SEG_TO_LIN(dwParam1), dwParam2);
1250 case MODM_PREPARE:
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:
1257 return 1;
1258 case MODM_GETVOLUME:
1259 return 0;
1260 case MODM_SETVOLUME:
1261 return 0;
1262 case MODM_RESET:
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__)
1276 switch(wMsg) {
1277 case DRV_LOAD:
1278 return 1;
1279 case DRV_FREE:
1280 return 1;
1281 case DRV_OPEN:
1282 return 1;
1283 case DRV_CLOSE:
1284 return 1;
1285 case DRV_ENABLE:
1286 return 1;
1287 case DRV_DISABLE:
1288 return 1;
1289 case DRV_QUERYCONFIGURE:
1290 return 1;
1291 case DRV_CONFIGURE:
1292 MessageBox16(0, "Sample Midi Linux Driver !",
1293 "MMLinux Driver", MB_OK);
1294 return 1;
1295 case DRV_INSTALL:
1296 return DRVCNF_RESTART;
1297 case DRV_REMOVE:
1298 return DRVCNF_RESTART;
1299 case MCI_OPEN_DRIVER:
1300 case MCI_OPEN:
1301 return MIDI_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS)PTR_SEG_TO_LIN(dwParam2));
1302 case MCI_CLOSE_DRIVER:
1303 case MCI_CLOSE:
1304 return MIDI_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1305 case MCI_PLAY:
1306 return MIDI_mciPlay(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2));
1307 case MCI_RECORD:
1308 return MIDI_mciRecord(dwDevID, dwParam1, (LPMCI_RECORD_PARMS)PTR_SEG_TO_LIN(dwParam2));
1309 case MCI_STOP:
1310 return MIDI_mciStop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1311 case MCI_SET:
1312 return MIDI_mciSet(dwDevID, dwParam1, (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2));
1313 case MCI_PAUSE:
1314 return MIDI_mciPause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1315 case MCI_RESUME:
1316 return MIDI_mciResume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1317 case MCI_STATUS:
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));
1321 case MCI_INFO:
1322 return MIDI_mciInfo(dwDevID, dwParam1, (LPMCI_INFO_PARMS)PTR_SEG_TO_LIN(dwParam2));
1323 default:
1324 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1326 #else
1327 return MMSYSERR_NOTENABLED;
1328 #endif
1332 /*-----------------------------------------------------------------------*/
1334 #endif /* #ifdef BUILTIN_MMSYSTEM */