Don't return from overlapped ReadFile on EAGAIN and other non-fatal
[wine/gsoc_dplay.git] / dlls / winmm / mciseq / mcimidi.c
blob247c93ced41c96b83057e8529b6c8287171e4c2d
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * Sample MIDI Wine Driver for Linux
6 * Copyright 1994 Martin Ayotte
7 * 1999 Eric Pouech
8 */
10 /*
11 * Eric POUECH :
12 * 98/7 changes for making this MIDI driver work on OSS
13 * current support is limited to MIDI ports of OSS systems
14 * 98/9 rewriting MCI code for MIDI
15 * 98/11 splitted in midi.c and mcimidi.c
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winuser.h"
26 #include "mmddk.h"
27 #include "debugtools.h"
29 DEFAULT_DEBUG_CHANNEL(mcimidi);
31 #define MIDI_NOTEOFF 0x80
32 #define MIDI_NOTEON 0x90
34 typedef struct {
35 DWORD dwFirst; /* offset in file of track */
36 DWORD dwLast; /* number of bytes in file of track */
37 DWORD dwIndex; /* current index in file (dwFirst <= dwIndex < dwLast) */
38 DWORD dwLength; /* number of pulses in this track */
39 DWORD dwEventPulse; /* current pulse # (event) pointed by dwIndex */
40 DWORD dwEventData; /* current data (event) pointed by dwIndex */
41 WORD wEventLength; /* current length (event) pointed by dwIndex */
42 WORD wStatus : 1, /* 1 : playing, 0 : done */
43 wTrackNr : 7,
44 wLastCommand : 8; /* last MIDI command on track */
45 } MCI_MIDITRACK;
47 typedef struct tagWINE_MCIMIDI {
48 UINT wDevID; /* the MCI one */
49 HMIDI hMidi;
50 int nUseCount; /* Incremented for each shared open */
51 WORD wNotifyDeviceID; /* MCI device ID with a pending notification */
52 HANDLE hCallback; /* Callback handle for pending notification */
53 HMMIO hFile; /* mmio file handle open as Element */
54 LPSTR lpstrElementName; /* Name of file */
55 LPSTR lpstrCopyright;
56 LPSTR lpstrName;
57 WORD dwStatus; /* one from MCI_MODE_xxxx */
58 DWORD dwMciTimeFormat; /* One of the supported MCI_FORMAT_xxxx */
59 WORD wFormat; /* Format of MIDI hFile (0, 1 or 2) */
60 WORD nTracks; /* Number of tracks in hFile */
61 WORD nDivision; /* Number of division in hFile PPQN or SMPTE */
62 WORD wStartedPlaying;
63 DWORD dwTempo; /* Tempo (# of 1/4 note per second */
64 MCI_MIDITRACK* tracks; /* Content of each track */
65 DWORD dwPulse;
66 DWORD dwPositionMS;
67 DWORD dwStartTicks;
68 } WINE_MCIMIDI;
70 /* ===================================================================
71 * ===================================================================
72 * FIXME: should be using the new mmThreadXXXX functions from WINMM
73 * instead of those
74 * it would require to add a wine internal flag to mmThreadCreate
75 * in order to pass a 32 bit function instead of a 16 bit
76 * ===================================================================
77 * =================================================================== */
79 struct SCA {
80 UINT wDevID;
81 UINT wMsg;
82 DWORD dwParam1;
83 DWORD dwParam2;
86 /* EPP DWORD WINAPI mciSendCommandA(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2); */
88 /**************************************************************************
89 * MCI_SCAStarter [internal]
91 static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
93 struct SCA* sca = (struct SCA*)arg;
94 DWORD ret;
96 TRACE("In thread before async command (%08x,%u,%08lx,%08lx)\n",
97 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
98 ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2);
99 TRACE("In thread after async command (%08x,%u,%08lx,%08lx)\n",
100 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
101 HeapFree(GetProcessHeap(), 0, sca);
102 ExitThread(ret);
103 WARN("Should not happen ? what's wrong \n");
104 /* should not go after this point */
105 return ret;
108 /**************************************************************************
109 * MCI_SendCommandAsync [internal]
111 static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1,
112 DWORD dwParam2, UINT size)
114 struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA) + size);
116 if (sca == 0)
117 return MCIERR_OUT_OF_MEMORY;
119 sca->wDevID = wDevID;
120 sca->wMsg = wMsg;
121 sca->dwParam1 = dwParam1;
123 if (size && dwParam2) {
124 sca->dwParam2 = (DWORD)sca + sizeof(struct SCA);
125 /* copy structure passed by program in dwParam2 to be sure
126 * we can still use it whatever the program does
128 memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size);
129 } else {
130 sca->dwParam2 = dwParam2;
133 if (CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL) == 0) {
134 WARN("Couldn't allocate thread for async command handling, sending synchonously\n");
135 return MCI_SCAStarter(&sca);
137 return 0;
140 /*======================================================================*
141 * MCI MIDI implemantation *
142 *======================================================================*/
144 static DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
146 /**************************************************************************
147 * MIDI_drvOpen [internal]
149 static DWORD MIDI_drvOpen(LPSTR str, LPMCI_OPEN_DRIVER_PARMSA modp)
151 WINE_MCIMIDI* wmm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIMIDI));
153 if (!wmm)
154 return 0;
156 wmm->wDevID = modp->wDeviceID;
157 mciSetDriverData(wmm->wDevID, (DWORD)wmm);
158 modp->wCustomCommandTable = MCI_NO_COMMAND_TABLE;
159 modp->wType = MCI_DEVTYPE_SEQUENCER;
160 return modp->wDeviceID;
163 /**************************************************************************
164 * MCIMIDI_drvClose [internal]
166 static DWORD MIDI_drvClose(DWORD dwDevID)
168 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(dwDevID);
170 if (wmm) {
171 HeapFree(GetProcessHeap(), 0, wmm);
172 mciSetDriverData(dwDevID, 0);
173 return 1;
175 return 0;
178 /**************************************************************************
179 * MIDI_mciGetOpenDev [internal]
181 static WINE_MCIMIDI* MIDI_mciGetOpenDev(UINT wDevID)
183 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
185 if (wmm == NULL || wmm->nUseCount == 0) {
186 WARN("Invalid wDevID=%u\n", wDevID);
187 return 0;
189 return wmm;
192 /**************************************************************************
193 * MIDI_mciReadByte [internal]
195 static DWORD MIDI_mciReadByte(WINE_MCIMIDI* wmm, BYTE *lpbyt)
197 DWORD ret = 0;
199 if (lpbyt == NULL ||
200 mmioRead(wmm->hFile, (HPSTR)lpbyt, sizeof(BYTE)) != (long)sizeof(BYTE)) {
201 WARN("Error reading wmm=%p\n", wmm);
202 ret = MCIERR_INVALID_FILE;
205 return ret;
208 /**************************************************************************
209 * MIDI_mciReadWord [internal]
211 static DWORD MIDI_mciReadWord(WINE_MCIMIDI* wmm, LPWORD lpw)
213 BYTE hibyte, lobyte;
214 DWORD ret = MCIERR_INVALID_FILE;
216 if (lpw != NULL &&
217 MIDI_mciReadByte(wmm, &hibyte) == 0 &&
218 MIDI_mciReadByte(wmm, &lobyte) == 0) {
219 *lpw = ((WORD)hibyte << 8) + lobyte;
220 ret = 0;
222 return ret;
225 /**************************************************************************
226 * MIDI_mciReadLong [internal]
228 static DWORD MIDI_mciReadLong(WINE_MCIMIDI* wmm, LPDWORD lpdw)
230 WORD hiword, loword;
231 DWORD ret = MCIERR_INVALID_FILE;
233 if (lpdw != NULL &&
234 MIDI_mciReadWord(wmm, &hiword) == 0 &&
235 MIDI_mciReadWord(wmm, &loword) == 0) {
236 *lpdw = MAKELONG(loword, hiword);
237 ret = 0;
239 return ret;
242 /**************************************************************************
243 * MIDI_mciReadVaryLen [internal]
245 static WORD MIDI_mciReadVaryLen(WINE_MCIMIDI* wmm, LPDWORD lpdw)
247 BYTE byte;
248 DWORD value = 0;
249 WORD ret = 0;
251 if (lpdw == NULL) {
252 ret = MCIERR_INVALID_FILE;
253 } else {
254 do {
255 if (MIDI_mciReadByte(wmm, &byte) != 0) {
256 return 0;
258 value = (value << 7) + (byte & 0x7F);
259 ret++;
260 } while (byte & 0x80);
261 *lpdw = value;
263 TRACE("val=%08lX \n", value);
266 return ret;
269 /**************************************************************************
270 * MIDI_mciReadNextEvent [internal]
272 static DWORD MIDI_mciReadNextEvent(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
274 BYTE b1, b2 = 0, b3;
275 WORD hw = 0;
276 DWORD evtPulse;
277 DWORD evtLength;
278 DWORD tmp;
280 if (mmioSeek(wmm->hFile, mmt->dwIndex, SEEK_SET) != mmt->dwIndex) {
281 WARN("Can't seek at %08lX \n", mmt->dwIndex);
282 return MCIERR_INVALID_FILE;
284 evtLength = MIDI_mciReadVaryLen(wmm, &evtPulse) + 1; /* > 0 */
285 MIDI_mciReadByte(wmm, &b1);
286 switch (b1) {
287 case 0xF0:
288 case 0xF7:
289 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
290 evtLength += tmp;
291 break;
292 case 0xFF:
293 MIDI_mciReadByte(wmm, &b2); evtLength++;
295 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
296 if (evtLength >= 0x10000u) {
297 /* this limitation shouldn't be a problem */
298 WARN("Ouch !! Implementation limitation to 64k bytes for a MIDI event is overflowed\n");
299 hw = 0xFFFF;
300 } else {
301 hw = LOWORD(evtLength);
303 evtLength += tmp;
304 break;
305 default:
306 if (b1 & 0x80) { /* use running status ? */
307 mmt->wLastCommand = b1;
308 MIDI_mciReadByte(wmm, &b2); evtLength++;
309 } else {
310 b2 = b1;
311 b1 = mmt->wLastCommand;
313 switch ((b1 >> 4) & 0x07) {
314 case 0: case 1: case 2: case 3: case 6:
315 MIDI_mciReadByte(wmm, &b3); evtLength++;
316 hw = b3;
317 break;
318 case 4: case 5:
319 break;
320 case 7:
321 WARN("Strange indeed b1=0x%02x\n", b1);
323 break;
325 if (mmt->dwIndex + evtLength > mmt->dwLast)
326 return MCIERR_INTERNAL;
328 mmt->dwEventPulse += evtPulse;
329 mmt->dwEventData = (hw << 16) + (b2 << 8) + b1;
330 mmt->wEventLength = evtLength;
333 TRACE("[%u] => pulse=%08lx(%08lx), data=%08lx, length=%u\n",
334 mmt->wTrackNr, mmt->dwEventPulse, evtPulse,
335 mmt->dwEventData, mmt->wEventLength);
337 return 0;
340 /**************************************************************************
341 * MIDI_mciReadMTrk [internal]
343 static DWORD MIDI_mciReadMTrk(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
345 DWORD toberead;
346 FOURCC fourcc;
348 if (mmioRead(wmm->hFile, (HPSTR)&fourcc, (long)sizeof(FOURCC)) !=
349 (long)sizeof(FOURCC)) {
350 return MCIERR_INVALID_FILE;
353 if (fourcc != mmioFOURCC('M', 'T', 'r', 'k')) {
354 WARN("Can't synchronize on 'MTrk' !\n");
355 return MCIERR_INVALID_FILE;
358 if (MIDI_mciReadLong(wmm, &toberead) != 0) {
359 return MCIERR_INVALID_FILE;
361 mmt->dwFirst = mmioSeek(wmm->hFile, 0, SEEK_CUR); /* >= 0 */
362 mmt->dwLast = mmt->dwFirst + toberead;
364 /* compute # of pulses in this track */
365 mmt->dwIndex = mmt->dwFirst;
366 mmt->dwEventPulse = 0;
368 while (MIDI_mciReadNextEvent(wmm, mmt) == 0 && LOWORD(mmt->dwEventData) != 0x2FFF) {
369 char buf[1024];
370 WORD len;
372 mmt->dwIndex += mmt->wEventLength;
374 switch (LOWORD(mmt->dwEventData)) {
375 case 0x02FF:
376 case 0x03FF:
377 /* position after meta data header */
378 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
379 len = mmt->wEventLength - HIWORD(mmt->dwEventData);
381 if (len >= sizeof(buf)) {
382 WARN("Buffer for text is too small (%d bytes, when %u are needed)\n", sizeof(buf) - 1, len);
383 len = sizeof(buf) - 1;
385 if (mmioRead(wmm->hFile, (HPSTR)buf, len) == len) {
386 buf[len] = 0; /* end string in case */
387 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
388 case 0x02:
389 if (wmm->lpstrCopyright) {
390 WARN("Two copyright notices (%s|%s)\n", wmm->lpstrCopyright, buf);
391 } else {
392 wmm->lpstrCopyright = HeapAlloc( GetProcessHeap(), 0, strlen(buf)+1 );
393 strcpy( wmm->lpstrCopyright, buf );
395 break;
396 case 0x03:
397 if (wmm->lpstrName) {
398 WARN("Two names (%s|%s)\n", wmm->lpstrName, buf);
399 } else {
400 wmm->lpstrName = HeapAlloc( GetProcessHeap(), 0, strlen(buf)+1 );
401 strcpy( wmm->lpstrName, buf );
403 break;
406 break;
409 mmt->dwLength = mmt->dwEventPulse;
411 TRACE("Track %u has %lu bytes and %lu pulses\n", mmt->wTrackNr, toberead, mmt->dwLength);
413 /* reset track data */
414 mmt->wStatus = 1; /* ok, playing */
415 mmt->dwIndex = mmt->dwFirst;
416 mmt->dwEventPulse = 0;
418 if (mmioSeek(wmm->hFile, 0, SEEK_CUR) != mmt->dwLast) {
419 WARN("Ouch, out of sync seek=%lu track=%lu\n",
420 mmioSeek(wmm->hFile, 0, SEEK_CUR), mmt->dwLast);
421 /* position at end of this track, to be ready to read next track */
422 mmioSeek(wmm->hFile, mmt->dwLast, SEEK_SET);
425 return 0;
428 /**************************************************************************
429 * MIDI_mciReadMThd [internal]
431 static DWORD MIDI_mciReadMThd(WINE_MCIMIDI* wmm, DWORD dwOffset)
433 DWORD toberead;
434 FOURCC fourcc;
435 WORD nt;
437 TRACE("(%p, %08lX);\n", wmm, dwOffset);
439 if (mmioSeek(wmm->hFile, dwOffset, SEEK_SET) != dwOffset) {
440 WARN("Can't seek at %08lX begin of 'MThd' \n", dwOffset);
441 return MCIERR_INVALID_FILE;
443 if (mmioRead(wmm->hFile, (HPSTR)&fourcc,
444 (long) sizeof(FOURCC)) != (long) sizeof(FOURCC))
445 return MCIERR_INVALID_FILE;
447 if (fourcc != mmioFOURCC('M', 'T', 'h', 'd')) {
448 WARN("Can't synchronize on 'MThd' !\n");
449 return MCIERR_INVALID_FILE;
452 if (MIDI_mciReadLong(wmm, &toberead) != 0 || toberead < 3 * sizeof(WORD))
453 return MCIERR_INVALID_FILE;
455 if (MIDI_mciReadWord(wmm, &wmm->wFormat) != 0 ||
456 MIDI_mciReadWord(wmm, &wmm->nTracks) != 0 ||
457 MIDI_mciReadWord(wmm, &wmm->nDivision) != 0) {
458 return MCIERR_INVALID_FILE;
461 TRACE("toberead=0x%08lX, wFormat=0x%04X nTracks=0x%04X nDivision=0x%04X\n",
462 toberead, wmm->wFormat, wmm->nTracks, wmm->nDivision);
464 /* MS doc says that the MIDI MCI time format must be put by default to the format
465 * stored in the MIDI file...
467 if (wmm->nDivision > 0x8000) {
468 /* eric.pouech@lemel.fr 98/11
469 * In did not check this very code (pulses are expressed as SMPTE sub-frames).
470 * In about 40 MB of MIDI files I have, none was SMPTE based...
471 * I'm just wondering if this is widely used :-). So, if someone has one of
472 * these files, I'd like to know about.
474 FIXME("Handling SMPTE time in MIDI files has not been tested\n"
475 "Please report to comp.emulators.ms-windows.wine with MIDI file !\n");
477 switch (HIBYTE(wmm->nDivision)) {
478 case 0xE8: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24; break; /* -24 */
479 case 0xE7: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25; break; /* -25 */
480 case 0xE3: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
481 case 0xE2: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30; break; /* -30 */
482 default:
483 WARN("Unsupported number of frames %d\n", -(char)HIBYTE(wmm->nDivision));
484 return MCIERR_INVALID_FILE;
486 switch (LOBYTE(wmm->nDivision)) {
487 case 4: /* MIDI Time Code */
488 case 8:
489 case 10:
490 case 80: /* SMPTE bit resolution */
491 case 100:
492 default:
493 WARN("Unsupported number of sub-frames %d\n", LOBYTE(wmm->nDivision));
494 return MCIERR_INVALID_FILE;
496 } else if (wmm->nDivision == 0) {
497 WARN("Number of division is 0, can't support that !!\n");
498 return MCIERR_INVALID_FILE;
499 } else {
500 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
503 switch (wmm->wFormat) {
504 case 0:
505 if (wmm->nTracks != 1) {
506 WARN("Got type 0 file whose number of track is not 1. Setting it to 1\n");
507 wmm->nTracks = 1;
509 break;
510 case 1:
511 case 2:
512 break;
513 default:
514 WARN("Handling MIDI files which format = %d is not (yet) supported\n"
515 "Please report with MIDI file !\n", wmm->wFormat);
516 return MCIERR_INVALID_FILE;
519 if (wmm->nTracks & 0x8000) {
520 /* this shouldn't be a problem... */
521 WARN("Ouch !! Implementation limitation to 32k tracks per MIDI file is overflowed\n");
522 wmm->nTracks = 0x7FFF;
525 if ((wmm->tracks = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_MIDITRACK) * wmm->nTracks)) == NULL) {
526 return MCIERR_OUT_OF_MEMORY;
529 toberead -= 3 * sizeof(WORD);
530 if (toberead > 0) {
531 TRACE("Size of MThd > 6, skipping %ld extra bytes\n", toberead);
532 mmioSeek(wmm->hFile, toberead, SEEK_CUR);
535 for (nt = 0; nt < wmm->nTracks; nt++) {
536 wmm->tracks[nt].wTrackNr = nt;
537 if (MIDI_mciReadMTrk(wmm, &wmm->tracks[nt]) != 0) {
538 WARN("Can't read 'MTrk' header \n");
539 return MCIERR_INVALID_FILE;
543 wmm->dwTempo = 500000;
545 return 0;
548 /**************************************************************************
549 * MIDI_ConvertPulseToMS [internal]
551 static DWORD MIDI_ConvertPulseToMS(WINE_MCIMIDI* wmm, DWORD pulse)
553 DWORD ret = 0;
555 /* FIXME: this function may return false values since the tempo (wmm->dwTempo)
556 * may change during file playing
558 if (wmm->nDivision == 0) {
559 FIXME("Shouldn't happen. wmm->nDivision = 0\n");
560 } else if (wmm->nDivision > 0x8000) { /* SMPTE, unchecked FIXME? */
561 int nf = -(char)HIBYTE(wmm->nDivision); /* number of frames */
562 int nsf = LOBYTE(wmm->nDivision); /* number of sub-frames */
563 ret = (pulse * 1000) / (nf * nsf);
564 } else {
565 ret = (DWORD)((double)pulse * ((double)wmm->dwTempo / 1000) /
566 (double)wmm->nDivision);
570 TRACE("pulse=%lu tempo=%lu division=%u=0x%04x => ms=%lu\n",
571 pulse, wmm->dwTempo, wmm->nDivision, wmm->nDivision, ret);
574 return ret;
577 #define TIME_MS_IN_ONE_HOUR (60*60*1000)
578 #define TIME_MS_IN_ONE_MINUTE (60*1000)
579 #define TIME_MS_IN_ONE_SECOND (1000)
581 /**************************************************************************
582 * MIDI_ConvertTimeFormatToMS [internal]
584 static DWORD MIDI_ConvertTimeFormatToMS(WINE_MCIMIDI* wmm, DWORD val)
586 DWORD ret = 0;
588 switch (wmm->dwMciTimeFormat) {
589 case MCI_FORMAT_MILLISECONDS:
590 ret = val;
591 break;
592 case MCI_FORMAT_SMPTE_24:
593 ret =
594 (HIBYTE(HIWORD(val)) * 125) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
595 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
596 break;
597 case MCI_FORMAT_SMPTE_25:
598 ret =
599 HIBYTE(HIWORD(val)) * 40 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
600 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
601 break;
602 case MCI_FORMAT_SMPTE_30:
603 ret =
604 (HIBYTE(HIWORD(val)) * 100) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
605 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
606 break;
607 default:
608 WARN("Bad time format %lu!\n", wmm->dwMciTimeFormat);
611 TRACE("val=%lu=0x%08lx [tf=%lu] => ret=%lu\n", val, val, wmm->dwMciTimeFormat, ret);
613 return ret;
616 /**************************************************************************
617 * MIDI_ConvertMSToTimeFormat [internal]
619 static DWORD MIDI_ConvertMSToTimeFormat(WINE_MCIMIDI* wmm, DWORD _val)
621 DWORD ret = 0, val = _val;
622 DWORD h, m, s, f;
624 switch (wmm->dwMciTimeFormat) {
625 case MCI_FORMAT_MILLISECONDS:
626 ret = val;
627 break;
628 case MCI_FORMAT_SMPTE_24:
629 case MCI_FORMAT_SMPTE_25:
630 case MCI_FORMAT_SMPTE_30:
631 h = val / TIME_MS_IN_ONE_HOUR;
632 m = (val -= h * TIME_MS_IN_ONE_HOUR) / TIME_MS_IN_ONE_MINUTE;
633 s = (val -= m * TIME_MS_IN_ONE_MINUTE) / TIME_MS_IN_ONE_SECOND;
634 switch (wmm->dwMciTimeFormat) {
635 case MCI_FORMAT_SMPTE_24:
636 /* one frame is 1000/24 val long, 1000/24 == 125/3 */
637 f = (val * 3) / 125; val -= (f * 125) / 3;
638 break;
639 case MCI_FORMAT_SMPTE_25:
640 /* one frame is 1000/25 ms long, 1000/25 == 40 */
641 f = val / 40; val -= f * 40;
642 break;
643 case MCI_FORMAT_SMPTE_30:
644 /* one frame is 1000/30 ms long, 1000/30 == 100/3 */
645 f = (val * 3) / 100; val -= (f * 100) / 3;
646 break;
647 default:
648 FIXME("There must be some bad bad programmer\n");
649 f = 0;
651 /* val contains the number of ms which cannot make a complete frame */
652 /* FIXME: is this correct ? programs seem to be happy with that */
653 ret = (f << 24) | (s << 16) | (m << 8) | (h << 0);
654 break;
655 default:
656 WARN("Bad time format %lu!\n", wmm->dwMciTimeFormat);
659 TRACE("val=%lu [tf=%lu] => ret=%lu=0x%08lx\n", _val, wmm->dwMciTimeFormat, ret, ret);
661 return ret;
664 /**************************************************************************
665 * MIDI_GetMThdLengthMS [internal]
667 static DWORD MIDI_GetMThdLengthMS(WINE_MCIMIDI* wmm)
669 WORD nt;
670 DWORD ret = 0;
672 for (nt = 0; nt < wmm->nTracks; nt++) {
673 if (wmm->wFormat == 2) {
674 ret += wmm->tracks[nt].dwLength;
675 } else if (wmm->tracks[nt].dwLength > ret) {
676 ret = wmm->tracks[nt].dwLength;
679 /* FIXME: this is wrong if there is a tempo change inside the file */
680 return MIDI_ConvertPulseToMS(wmm, ret);
683 /**************************************************************************
684 * MIDI_mciOpen [internal]
686 static DWORD MIDI_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMSA lpParms)
688 DWORD dwRet = 0;
689 DWORD dwDeviceID;
690 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
692 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
694 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
695 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
696 if (dwFlags & MCI_OPEN_SHAREABLE)
697 return MCIERR_HARDWARE;
699 if (wmm->nUseCount > 0) {
700 /* The driver is already opened on this channel
701 * MIDI sequencer cannot be shared
703 return MCIERR_DEVICE_OPEN;
705 wmm->nUseCount++;
707 wmm->hFile = 0;
708 wmm->hMidi = 0;
709 dwDeviceID = lpParms->wDeviceID;
711 TRACE("wDevID=%04X (lpParams->wDeviceID=%08lX)\n", wDevID, dwDeviceID);
712 /* lpParms->wDeviceID = wDevID;*/
714 if (dwFlags & MCI_OPEN_ELEMENT) {
715 TRACE("MCI_OPEN_ELEMENT '%s' !\n", lpParms->lpstrElementName);
716 if (lpParms->lpstrElementName && strlen(lpParms->lpstrElementName) > 0) {
717 wmm->hFile = mmioOpenA(lpParms->lpstrElementName, NULL,
718 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
719 if (wmm->hFile == 0) {
720 WARN("Can't find file '%s' !\n", lpParms->lpstrElementName);
721 wmm->nUseCount--;
722 return MCIERR_FILE_NOT_FOUND;
724 } else {
725 wmm->hFile = 0;
728 TRACE("hFile=%u\n", wmm->hFile);
730 /* FIXME: should I get a strdup() of it instead? */
731 wmm->lpstrElementName = HeapAlloc( GetProcessHeap(), 0, strlen(lpParms->lpstrElementName)+1 );
732 strcpy( wmm->lpstrElementName, lpParms->lpstrElementName );
733 wmm->lpstrCopyright = NULL;
734 wmm->lpstrName = NULL;
736 wmm->wNotifyDeviceID = dwDeviceID;
737 wmm->dwStatus = MCI_MODE_NOT_READY; /* while loading file contents */
738 /* spec says it should be the default format from the MIDI file... */
739 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
741 if (wmm->hFile != 0) {
742 MMCKINFO ckMainRIFF;
743 MMCKINFO mmckInfo;
744 DWORD dwOffset = 0;
746 if (mmioDescend(wmm->hFile, &ckMainRIFF, NULL, 0) != 0) {
747 dwRet = MCIERR_INVALID_FILE;
748 } else {
749 TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n",
750 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
752 if (ckMainRIFF.ckid == FOURCC_RIFF && ckMainRIFF.fccType == mmioFOURCC('R', 'M', 'I', 'D')) {
753 mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
754 mmioSeek(wmm->hFile, ckMainRIFF.dwDataOffset + ((ckMainRIFF.cksize + 1) & ~1), SEEK_SET);
755 if (mmioDescend(wmm->hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) {
756 TRACE("... is a 'RMID' file \n");
757 dwOffset = mmckInfo.dwDataOffset;
758 } else {
759 dwRet = MCIERR_INVALID_FILE;
762 if (dwRet == 0 && MIDI_mciReadMThd(wmm, dwOffset) != 0) {
763 WARN("Can't read 'MThd' header \n");
764 dwRet = MCIERR_INVALID_FILE;
767 } else {
768 TRACE("hFile==0, setting #tracks to 0; is this correct ?\n");
769 wmm->nTracks = 0;
770 wmm->wFormat = 0;
771 wmm->nDivision = 1;
773 if (dwRet != 0) {
774 wmm->nUseCount--;
775 if (wmm->hFile != 0)
776 mmioClose(wmm->hFile, 0);
777 wmm->hFile = 0;
778 } else {
779 wmm->dwPositionMS = 0;
780 wmm->dwStatus = MCI_MODE_STOP;
782 return dwRet;
785 /**************************************************************************
786 * MIDI_mciStop [internal]
788 static DWORD MIDI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
790 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
791 DWORD dwRet = 0;
793 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
795 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
797 if (wmm->dwStatus != MCI_MODE_STOP) {
798 int oldstat = wmm->dwStatus;
800 wmm->dwStatus = MCI_MODE_NOT_READY;
801 if (oldstat == MCI_MODE_PAUSE)
802 dwRet = midiOutReset(wmm->hMidi);
804 while (wmm->dwStatus != MCI_MODE_STOP)
805 Sleep(10);
808 /* sanitiy reset */
809 wmm->dwStatus = MCI_MODE_STOP;
811 TRACE("wmm->dwStatus=%d\n", wmm->dwStatus);
813 if (lpParms && (dwFlags & MCI_NOTIFY)) {
814 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
815 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
816 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
818 return 0;
821 /**************************************************************************
822 * MIDI_mciClose [internal]
824 static DWORD MIDI_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
826 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
828 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
830 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
832 if (wmm->dwStatus != MCI_MODE_STOP) {
833 MIDI_mciStop(wDevID, MCI_WAIT, lpParms);
836 wmm->nUseCount--;
837 if (wmm->nUseCount == 0) {
838 if (wmm->hFile != 0) {
839 mmioClose(wmm->hFile, 0);
840 wmm->hFile = 0;
841 TRACE("hFile closed !\n");
843 HeapFree(GetProcessHeap(), 0, wmm->tracks);
844 HeapFree(GetProcessHeap(), 0, (LPSTR)wmm->lpstrElementName);
845 HeapFree(GetProcessHeap(), 0, (LPSTR)wmm->lpstrCopyright);
846 HeapFree(GetProcessHeap(), 0, (LPSTR)wmm->lpstrName);
847 } else {
848 TRACE("Shouldn't happen... nUseCount=%d\n", wmm->nUseCount);
849 return MCIERR_INTERNAL;
852 if (lpParms && (dwFlags & MCI_NOTIFY)) {
853 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
854 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
855 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
857 return 0;
860 /**************************************************************************
861 * MIDI_mciFindNextEvent [internal]
863 static MCI_MIDITRACK* MIDI_mciFindNextEvent(WINE_MCIMIDI* wmm, LPDWORD hiPulse)
865 WORD cnt, nt;
866 MCI_MIDITRACK* mmt;
868 *hiPulse = 0xFFFFFFFFul;
869 cnt = 0xFFFFu;
870 for (nt = 0; nt < wmm->nTracks; nt++) {
871 mmt = &wmm->tracks[nt];
873 if (mmt->wStatus == 0)
874 continue;
875 if (mmt->dwEventPulse < *hiPulse) {
876 *hiPulse = mmt->dwEventPulse;
877 cnt = nt;
880 return (cnt == 0xFFFFu) ? 0 /* no more event on all tracks */
881 : &wmm->tracks[cnt];
884 /**************************************************************************
885 * MIDI_mciPlay [internal]
887 static DWORD MIDI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
889 DWORD dwStartMS, dwEndMS;
890 DWORD dwRet = 0;
891 WORD doPlay, nt;
892 MCI_MIDITRACK* mmt;
893 DWORD hiPulse;
894 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
896 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
898 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
900 if (wmm->hFile == 0) {
901 WARN("Can't play: no file '%s' !\n", wmm->lpstrElementName);
902 return MCIERR_FILE_NOT_FOUND;
905 if (wmm->dwStatus != MCI_MODE_STOP) {
906 if (wmm->dwStatus == MCI_MODE_PAUSE) {
907 /* FIXME: parameters (start/end) in lpParams may not be used */
908 return MIDI_mciResume(wDevID, dwFlags, (LPMCI_GENERIC_PARMS)lpParms);
910 WARN("Can't play: device is not stopped !\n");
911 return MCIERR_INTERNAL;
914 if (!(dwFlags & MCI_WAIT)) {
915 /** FIXME: I'm not 100% sure that wNotifyDeviceID is the right value in all cases ??? */
916 return MCI_SendCommandAsync(wmm->wNotifyDeviceID, MCI_PLAY, dwFlags, (DWORD)lpParms, sizeof(LPMCI_PLAY_PARMS));
919 if (lpParms && (dwFlags & MCI_FROM)) {
920 dwStartMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwFrom);
921 } else {
922 dwStartMS = wmm->dwPositionMS;
925 if (lpParms && (dwFlags & MCI_TO)) {
926 dwEndMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
927 } else {
928 dwEndMS = 0xFFFFFFFFul;
931 TRACE("Playing from %lu to %lu\n", dwStartMS, dwEndMS);
933 /* init tracks */
934 for (nt = 0; nt < wmm->nTracks; nt++) {
935 mmt = &wmm->tracks[nt];
937 mmt->wStatus = 1; /* ok, playing */
938 mmt->dwIndex = mmt->dwFirst;
939 if (wmm->wFormat == 2 && nt > 0) {
940 mmt->dwEventPulse = wmm->tracks[nt - 1].dwLength;
941 } else {
942 mmt->dwEventPulse = 0;
944 MIDI_mciReadNextEvent(wmm, mmt); /* FIXME == 0 */
947 wmm->dwPulse = 0;
948 wmm->dwTempo = 500000;
949 wmm->dwStatus = MCI_MODE_PLAY;
950 wmm->dwPositionMS = 0;
951 wmm->wStartedPlaying = FALSE;
953 dwRet = midiOutOpen(&wmm->hMidi, MIDIMAPPER, 0L, 0L, CALLBACK_NULL);
954 /* dwRet = midiInOpen(&wmm->hMidi, MIDIMAPPER, 0L, 0L, CALLBACK_NULL);*/
956 while (wmm->dwStatus != MCI_MODE_STOP && wmm->dwStatus != MCI_MODE_NOT_READY) {
957 /* it seems that in case of multi-threading, gcc is optimizing just a little bit
958 * too much. Tell gcc not to optimize status value using volatile.
960 while (((volatile WINE_MCIMIDI*)wmm)->dwStatus == MCI_MODE_PAUSE);
962 doPlay = (wmm->dwPositionMS >= dwStartMS && wmm->dwPositionMS <= dwEndMS);
964 TRACE("wmm->dwStatus=%d, doPlay=%c\n", wmm->dwStatus, doPlay ? 'T' : 'F');
966 if ((mmt = MIDI_mciFindNextEvent(wmm, &hiPulse)) == NULL)
967 break; /* no more event on tracks */
969 /* if starting playing, then set StartTicks to the value it would have had
970 * if play had started at position 0
972 if (doPlay && !wmm->wStartedPlaying) {
973 wmm->dwStartTicks = GetTickCount() - MIDI_ConvertPulseToMS(wmm, wmm->dwPulse);
974 wmm->wStartedPlaying = TRUE;
975 TRACE("Setting dwStartTicks to %lu\n", wmm->dwStartTicks);
978 if (hiPulse > wmm->dwPulse) {
979 wmm->dwPositionMS += MIDI_ConvertPulseToMS(wmm, hiPulse - wmm->dwPulse);
980 if (doPlay) {
981 DWORD togo = wmm->dwStartTicks + wmm->dwPositionMS;
982 DWORD tc = GetTickCount();
984 TRACE("Pulses hi=0x%08lx <> cur=0x%08lx\n", hiPulse, wmm->dwPulse);
985 TRACE("Wait until %lu => %lu ms\n",
986 tc - wmm->dwStartTicks, togo - wmm->dwStartTicks);
987 if (tc < togo)
988 Sleep(togo - tc);
990 wmm->dwPulse = hiPulse;
993 switch (LOBYTE(LOWORD(mmt->dwEventData))) {
994 case 0xF0:
995 case 0xF7: /* sysex events */
997 FIXME("Not handling SysEx events (yet)\n");
999 break;
1000 case 0xFF:
1001 /* position after meta data header */
1002 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
1003 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
1004 case 0x00: /* 16-bit sequence number */
1005 if (TRACE_ON(mcimidi)) {
1006 WORD twd;
1008 MIDI_mciReadWord(wmm, &twd); /* == 0 */
1009 TRACE("Got sequence number %u\n", twd);
1011 break;
1012 case 0x01: /* any text */
1013 case 0x02: /* Copyright Message text */
1014 case 0x03: /* Sequence/Track Name text */
1015 case 0x04: /* Instrument Name text */
1016 case 0x05: /* Lyric text */
1017 case 0x06: /* Marker text */
1018 case 0x07: /* Cue-point text */
1019 if (TRACE_ON(mcimidi)) {
1020 char buf[1024];
1021 WORD len = mmt->wEventLength - HIWORD(mmt->dwEventData);
1022 static char* info[8] = {"", "Text", "Copyright", "Seq/Trk name",
1023 "Instrument", "Lyric", "Marker", "Cue-point"};
1024 WORD idx = HIBYTE(LOWORD(mmt->dwEventData));
1026 if (len >= sizeof(buf)) {
1027 WARN("Buffer for text is too small (%d bytes, when %u are needed)\n", sizeof(buf) - 1, len);
1028 len = sizeof(buf) - 1;
1030 if (mmioRead(wmm->hFile, (HPSTR)buf, len) == len) {
1031 buf[len] = 0; /* end string in case */
1032 TRACE("%s => \"%s\"\n", (idx < 8 ) ? info[idx] : "", buf);
1033 } else {
1034 WARN("Couldn't read data for %s\n", (idx < 8) ? info[idx] : "");
1037 break;
1038 case 0x20:
1039 /* MIDI channel (cc) */
1040 if (FIXME_ON(mcimidi)) {
1041 BYTE bt;
1043 MIDI_mciReadByte(wmm, &bt); /* == 0 */
1044 FIXME("NIY: MIDI channel=%u, track=%u\n", bt, mmt->wTrackNr);
1046 break;
1047 case 0x21:
1048 /* MIDI port (pp) */
1049 if (FIXME_ON(mcimidi)) {
1050 BYTE bt;
1052 MIDI_mciReadByte(wmm, &bt); /* == 0 */
1053 FIXME("NIY: MIDI port=%u, track=%u\n", bt, mmt->wTrackNr);
1055 break;
1056 case 0x2F: /* end of track */
1057 mmt->wStatus = 0;
1058 break;
1059 case 0x51:/* set tempo */
1060 /* Tempo is expressed in µ-seconds per midi quarter note
1061 * for format 1 MIDI files, this can only be present on track #0
1063 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1064 WARN("For format #1 MIDI files, tempo can only be changed on track #0 (%u)\n", mmt->wTrackNr);
1065 } else {
1066 BYTE tbt;
1067 DWORD value = 0;
1069 MIDI_mciReadByte(wmm, &tbt); value = ((DWORD)tbt) << 16;
1070 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 8;
1071 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 0;
1072 TRACE("Setting tempo to %ld (BPM=%ld)\n", wmm->dwTempo, (value) ? (60000000l / value) : 0);
1073 wmm->dwTempo = value;
1075 break;
1076 case 0x54: /* (hour) (min) (second) (frame) (fractional-frame) - SMPTE track start */
1077 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1078 WARN("For format #1 MIDI files, SMPTE track start can only be expressed on track #0 (%u)\n", mmt->wTrackNr);
1079 } if (mmt->dwEventPulse != 0) {
1080 WARN("SMPTE track start can only be expressed at start of track (%lu)\n", mmt->dwEventPulse);
1081 } else {
1082 BYTE h, m, s, f, ff;
1084 MIDI_mciReadByte(wmm, &h);
1085 MIDI_mciReadByte(wmm, &m);
1086 MIDI_mciReadByte(wmm, &s);
1087 MIDI_mciReadByte(wmm, &f);
1088 MIDI_mciReadByte(wmm, &ff);
1089 FIXME("NIY: SMPTE track start %u:%u:%u %u.%u\n", h, m, s, f, ff);
1091 break;
1092 case 0x58: /* file rythm */
1093 if (TRACE_ON(mcimidi)) {
1094 BYTE num, den, cpmc, _32npqn;
1096 MIDI_mciReadByte(wmm, &num);
1097 MIDI_mciReadByte(wmm, &den); /* to notate e.g. 6/8 */
1098 MIDI_mciReadByte(wmm, &cpmc); /* number of MIDI clocks per metronome click */
1099 MIDI_mciReadByte(wmm, &_32npqn); /* number of notated 32nd notes per MIDI quarter note */
1101 TRACE("%u/%u, clock per metronome click=%u, 32nd notes by 1/4 note=%u\n", num, 1 << den, cpmc, _32npqn);
1103 break;
1104 case 0x59: /* key signature */
1105 if (TRACE_ON(mcimidi)) {
1106 BYTE sf, mm;
1108 MIDI_mciReadByte(wmm, &sf);
1109 MIDI_mciReadByte(wmm, &mm);
1111 if (sf >= 0x80) TRACE("%d flats\n", -(char)sf);
1112 else if (sf > 0) TRACE("%d sharps\n", (char)sf);
1113 else TRACE("Key of C\n");
1114 TRACE("Mode: %s\n", (mm = 0) ? "major" : "minor");
1116 break;
1117 default:
1118 WARN("Unknown MIDI meta event %02x. Skipping...\n", HIBYTE(LOWORD(mmt->dwEventData)));
1119 break;
1121 break;
1122 default:
1123 if (doPlay) {
1124 dwRet = midiOutShortMsg(wmm->hMidi, mmt->dwEventData);
1125 } else {
1126 switch (LOBYTE(LOWORD(mmt->dwEventData)) & 0xF0) {
1127 case MIDI_NOTEON:
1128 case MIDI_NOTEOFF:
1129 dwRet = 0;
1130 break;
1131 default:
1132 dwRet = midiOutShortMsg(wmm->hMidi, mmt->dwEventData);
1136 mmt->dwIndex += mmt->wEventLength;
1137 if (mmt->dwIndex < mmt->dwFirst || mmt->dwIndex >= mmt->dwLast) {
1138 mmt->wStatus = 0;
1140 if (mmt->wStatus) {
1141 MIDI_mciReadNextEvent(wmm, mmt);
1145 midiOutReset(wmm->hMidi);
1147 dwRet = midiOutClose(wmm->hMidi);
1148 /* to restart playing at beginning when it's over */
1149 wmm->dwPositionMS = 0;
1151 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1152 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1153 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
1154 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1157 wmm->dwStatus = MCI_MODE_STOP;
1158 return dwRet;
1161 /**************************************************************************
1162 * MIDI_mciRecord [internal]
1164 static DWORD MIDI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
1166 int start, end;
1167 MIDIHDR midiHdr;
1168 DWORD dwRet;
1169 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1171 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1173 if (wmm == 0) return MCIERR_INVALID_DEVICE_ID;
1175 if (wmm->hFile == 0) {
1176 WARN("Can't find file='%s' !\n", wmm->lpstrElementName);
1177 return MCIERR_FILE_NOT_FOUND;
1179 start = 1; end = 99999;
1180 if (lpParms && (dwFlags & MCI_FROM)) {
1181 start = lpParms->dwFrom;
1182 TRACE("MCI_FROM=%d \n", start);
1184 if (lpParms && (dwFlags & MCI_TO)) {
1185 end = lpParms->dwTo;
1186 TRACE("MCI_TO=%d \n", end);
1188 midiHdr.lpData = (LPSTR) HeapAlloc(GetProcessHeap(), 0, 1200);
1189 if (!midiHdr.lpData)
1190 return MCIERR_OUT_OF_MEMORY;
1191 midiHdr.dwBufferLength = 1024;
1192 midiHdr.dwUser = 0L;
1193 midiHdr.dwFlags = 0L;
1194 dwRet = midiInPrepareHeader(wmm->hMidi, &midiHdr, sizeof(MIDIHDR));
1195 TRACE("After MIDM_PREPARE \n");
1196 wmm->dwStatus = MCI_MODE_RECORD;
1197 /* FIXME: there is no buffer added */
1198 while (wmm->dwStatus != MCI_MODE_STOP) {
1199 TRACE("wmm->dwStatus=%p %d\n",
1200 &wmm->dwStatus, wmm->dwStatus);
1201 midiHdr.dwBytesRecorded = 0;
1202 dwRet = midiInStart(wmm->hMidi);
1203 TRACE("midiInStart => dwBytesRecorded=%lu\n", midiHdr.dwBytesRecorded);
1204 if (midiHdr.dwBytesRecorded == 0) break;
1206 TRACE("Before MIDM_UNPREPARE \n");
1207 dwRet = midiInUnprepareHeader(wmm->hMidi, &midiHdr, sizeof(MIDIHDR));
1208 TRACE("After MIDM_UNPREPARE \n");
1209 if (midiHdr.lpData != NULL) {
1210 HeapFree(GetProcessHeap(), 0, midiHdr.lpData);
1211 midiHdr.lpData = NULL;
1213 wmm->dwStatus = MCI_MODE_STOP;
1214 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1215 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1216 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
1217 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1219 return 0;
1222 /**************************************************************************
1223 * MIDI_mciPause [internal]
1225 static DWORD MIDI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1227 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1229 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1231 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1233 if (wmm->dwStatus == MCI_MODE_PLAY) {
1234 /* stop all notes */
1235 unsigned chn;
1236 for (chn = 0; chn < 16; chn++)
1237 midiOutShortMsg(wmm->hMidi, 0x78B0 | chn);
1238 wmm->dwStatus = MCI_MODE_PAUSE;
1240 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1241 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1242 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
1243 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1246 return 0;
1249 /**************************************************************************
1250 * MIDI_mciResume [internal]
1252 static DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1254 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1256 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1258 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1260 if (wmm->dwStatus == MCI_MODE_PAUSE) {
1261 wmm->wStartedPlaying = FALSE;
1262 wmm->dwStatus = MCI_MODE_PLAY;
1264 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1265 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1266 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
1267 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1269 return 0;
1272 /**************************************************************************
1273 * MIDI_mciSet [internal]
1275 static DWORD MIDI_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
1277 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1279 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1281 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1282 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1284 if (dwFlags & MCI_SET_TIME_FORMAT) {
1285 switch (lpParms->dwTimeFormat) {
1286 case MCI_FORMAT_MILLISECONDS:
1287 TRACE("MCI_FORMAT_MILLISECONDS !\n");
1288 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
1289 break;
1290 case MCI_FORMAT_SMPTE_24:
1291 TRACE("MCI_FORMAT_SMPTE_24 !\n");
1292 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24;
1293 break;
1294 case MCI_FORMAT_SMPTE_25:
1295 TRACE("MCI_FORMAT_SMPTE_25 !\n");
1296 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25;
1297 break;
1298 case MCI_FORMAT_SMPTE_30:
1299 TRACE("MCI_FORMAT_SMPTE_30 !\n");
1300 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30;
1301 break;
1302 default:
1303 WARN("Bad time format %lu!\n", lpParms->dwTimeFormat);
1304 return MCIERR_BAD_TIME_FORMAT;
1307 if (dwFlags & MCI_SET_VIDEO) {
1308 TRACE("No support for video !\n");
1309 return MCIERR_UNSUPPORTED_FUNCTION;
1311 if (dwFlags & MCI_SET_DOOR_OPEN) {
1312 TRACE("No support for door open !\n");
1313 return MCIERR_UNSUPPORTED_FUNCTION;
1315 if (dwFlags & MCI_SET_DOOR_CLOSED) {
1316 TRACE("No support for door close !\n");
1317 return MCIERR_UNSUPPORTED_FUNCTION;
1319 if (dwFlags & MCI_SET_AUDIO) {
1320 if (dwFlags & MCI_SET_ON) {
1321 TRACE("MCI_SET_ON audio !\n");
1322 } else if (dwFlags & MCI_SET_OFF) {
1323 TRACE("MCI_SET_OFF audio !\n");
1324 } else {
1325 WARN("MCI_SET_AUDIO without SET_ON or SET_OFF\n");
1326 return MCIERR_BAD_INTEGER;
1329 if (lpParms->dwAudio & MCI_SET_AUDIO_ALL)
1330 TRACE("MCI_SET_AUDIO_ALL !\n");
1331 if (lpParms->dwAudio & MCI_SET_AUDIO_LEFT)
1332 TRACE("MCI_SET_AUDIO_LEFT !\n");
1333 if (lpParms->dwAudio & MCI_SET_AUDIO_RIGHT)
1334 TRACE("MCI_SET_AUDIO_RIGHT !\n");
1337 if (dwFlags & MCI_SEQ_SET_MASTER)
1338 TRACE("MCI_SEQ_SET_MASTER !\n");
1339 if (dwFlags & MCI_SEQ_SET_SLAVE)
1340 TRACE("MCI_SEQ_SET_SLAVE !\n");
1341 if (dwFlags & MCI_SEQ_SET_OFFSET)
1342 TRACE("MCI_SEQ_SET_OFFSET !\n");
1343 if (dwFlags & MCI_SEQ_SET_PORT)
1344 TRACE("MCI_SEQ_SET_PORT !\n");
1345 if (dwFlags & MCI_SEQ_SET_TEMPO)
1346 TRACE("MCI_SEQ_SET_TEMPO !\n");
1347 return 0;
1350 /**************************************************************************
1351 * MIDI_mciStatus [internal]
1353 static DWORD MIDI_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
1355 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1356 DWORD ret = 0;
1358 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1360 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1361 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1363 if (dwFlags & MCI_STATUS_ITEM) {
1364 switch (lpParms->dwItem) {
1365 case MCI_STATUS_CURRENT_TRACK:
1366 /* FIXME in Format 2 */
1367 lpParms->dwReturn = 1;
1368 TRACE("MCI_STATUS_CURRENT_TRACK => %lu\n", lpParms->dwReturn);
1369 break;
1370 case MCI_STATUS_LENGTH:
1371 if ((dwFlags & MCI_TRACK) && wmm->wFormat == 2) {
1372 if (lpParms->dwTrack >= wmm->nTracks)
1373 return MCIERR_BAD_INTEGER;
1374 /* FIXME: this is wrong if there is a tempo change inside the file */
1375 lpParms->dwReturn = MIDI_ConvertPulseToMS(wmm, wmm->tracks[lpParms->dwTrack].dwLength);
1376 } else {
1377 lpParms->dwReturn = MIDI_GetMThdLengthMS(wmm);
1379 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm, lpParms->dwReturn);
1380 TRACE("MCI_STATUS_LENGTH => %lu\n", lpParms->dwReturn);
1381 break;
1382 case MCI_STATUS_MODE:
1383 TRACE("MCI_STATUS_MODE => %u\n", wmm->dwStatus);
1384 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwStatus, wmm->dwStatus);
1385 ret = MCI_RESOURCE_RETURNED;
1386 break;
1387 case MCI_STATUS_MEDIA_PRESENT:
1388 TRACE("MCI_STATUS_MEDIA_PRESENT => TRUE\n");
1389 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1390 ret = MCI_RESOURCE_RETURNED;
1391 break;
1392 case MCI_STATUS_NUMBER_OF_TRACKS:
1393 lpParms->dwReturn = (wmm->wFormat == 2) ? wmm->nTracks : 1;
1394 TRACE("MCI_STATUS_NUMBER_OF_TRACKS => %lu\n", lpParms->dwReturn);
1395 break;
1396 case MCI_STATUS_POSITION:
1397 /* FIXME: do I need to use MCI_TRACK ? */
1398 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm,
1399 (dwFlags & MCI_STATUS_START) ? 0 : wmm->dwPositionMS);
1400 TRACE("MCI_STATUS_POSITION %s => %lu\n",
1401 (dwFlags & MCI_STATUS_START) ? "start" : "current", lpParms->dwReturn);
1402 break;
1403 case MCI_STATUS_READY:
1404 lpParms->dwReturn = (wmm->dwStatus == MCI_MODE_NOT_READY) ?
1405 MAKEMCIRESOURCE(FALSE, MCI_FALSE) : MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1406 ret = MCI_RESOURCE_RETURNED;
1407 TRACE("MCI_STATUS_READY = %u\n", LOWORD(lpParms->dwReturn));
1408 break;
1409 case MCI_STATUS_TIME_FORMAT:
1410 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwMciTimeFormat, wmm->dwMciTimeFormat);
1411 TRACE("MCI_STATUS_TIME_FORMAT => %u\n", LOWORD(lpParms->dwReturn));
1412 ret = MCI_RESOURCE_RETURNED;
1413 break;
1414 case MCI_SEQ_STATUS_DIVTYPE:
1415 TRACE("MCI_SEQ_STATUS_DIVTYPE !\n");
1416 if (wmm->nDivision > 0x8000) {
1417 switch (wmm->nDivision) {
1418 case 0xE8: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_24; break; /* -24 */
1419 case 0xE7: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_25; break; /* -25 */
1420 case 0xE3: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
1421 case 0xE2: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30; break; /* -30 */
1422 default: FIXME("There is a bad bad programmer\n");
1424 } else {
1425 lpParms->dwReturn = MCI_SEQ_DIV_PPQN;
1427 lpParms->dwReturn = MAKEMCIRESOURCE(lpParms->dwReturn,lpParms->dwReturn);
1428 ret = MCI_RESOURCE_RETURNED;
1429 break;
1430 case MCI_SEQ_STATUS_MASTER:
1431 TRACE("MCI_SEQ_STATUS_MASTER !\n");
1432 lpParms->dwReturn = 0;
1433 break;
1434 case MCI_SEQ_STATUS_SLAVE:
1435 TRACE("MCI_SEQ_STATUS_SLAVE !\n");
1436 lpParms->dwReturn = 0;
1437 break;
1438 case MCI_SEQ_STATUS_OFFSET:
1439 TRACE("MCI_SEQ_STATUS_OFFSET !\n");
1440 lpParms->dwReturn = 0;
1441 break;
1442 case MCI_SEQ_STATUS_PORT:
1443 TRACE("MCI_SEQ_STATUS_PORT (%u)!\n", wmm->wDevID);
1444 lpParms->dwReturn = MIDI_MAPPER;
1445 break;
1446 case MCI_SEQ_STATUS_TEMPO:
1447 TRACE("MCI_SEQ_STATUS_TEMPO !\n");
1448 lpParms->dwReturn = wmm->dwTempo;
1449 break;
1450 default:
1451 FIXME("Unknowm command %08lX !\n", lpParms->dwItem);
1452 return MCIERR_UNRECOGNIZED_COMMAND;
1454 } else {
1455 WARN("No Status-Item!\n");
1456 return MCIERR_UNRECOGNIZED_COMMAND;
1458 if (dwFlags & MCI_NOTIFY) {
1459 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1460 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
1461 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1463 return ret;
1466 /**************************************************************************
1467 * MIDI_mciGetDevCaps [internal]
1469 static DWORD MIDI_mciGetDevCaps(UINT wDevID, DWORD dwFlags,
1470 LPMCI_GETDEVCAPS_PARMS lpParms)
1472 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1473 DWORD ret;
1475 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1477 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1478 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1480 if (dwFlags & MCI_GETDEVCAPS_ITEM) {
1481 switch (lpParms->dwItem) {
1482 case MCI_GETDEVCAPS_DEVICE_TYPE:
1483 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE !\n");
1484 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_SEQUENCER, MCI_DEVTYPE_SEQUENCER);
1485 ret = MCI_RESOURCE_RETURNED;
1486 break;
1487 case MCI_GETDEVCAPS_HAS_AUDIO:
1488 TRACE("MCI_GETDEVCAPS_HAS_AUDIO !\n");
1489 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1490 ret = MCI_RESOURCE_RETURNED;
1491 break;
1492 case MCI_GETDEVCAPS_HAS_VIDEO:
1493 TRACE("MCI_GETDEVCAPS_HAS_VIDEO !\n");
1494 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1495 ret = MCI_RESOURCE_RETURNED;
1496 break;
1497 case MCI_GETDEVCAPS_USES_FILES:
1498 TRACE("MCI_GETDEVCAPS_USES_FILES !\n");
1499 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1500 ret = MCI_RESOURCE_RETURNED;
1501 break;
1502 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
1503 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE !\n");
1504 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1505 ret = MCI_RESOURCE_RETURNED;
1506 break;
1507 case MCI_GETDEVCAPS_CAN_EJECT:
1508 TRACE("MCI_GETDEVCAPS_CAN_EJECT !\n");
1509 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1510 ret = MCI_RESOURCE_RETURNED;
1511 break;
1512 case MCI_GETDEVCAPS_CAN_PLAY:
1513 TRACE("MCI_GETDEVCAPS_CAN_PLAY !\n");
1514 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1515 ret = MCI_RESOURCE_RETURNED;
1516 break;
1517 case MCI_GETDEVCAPS_CAN_RECORD:
1518 TRACE("MCI_GETDEVCAPS_CAN_RECORD !\n");
1519 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1520 ret = MCI_RESOURCE_RETURNED;
1521 break;
1522 case MCI_GETDEVCAPS_CAN_SAVE:
1523 TRACE("MCI_GETDEVCAPS_CAN_SAVE !\n");
1524 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1525 ret = MCI_RESOURCE_RETURNED;
1526 break;
1527 default:
1528 FIXME("Unknown capability (%08lx) !\n", lpParms->dwItem);
1529 return MCIERR_UNRECOGNIZED_COMMAND;
1531 } else {
1532 WARN("No GetDevCaps-Item !\n");
1533 return MCIERR_UNRECOGNIZED_COMMAND;
1535 return ret;
1538 /**************************************************************************
1539 * MIDI_mciInfo [internal]
1541 static DWORD MIDI_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMSA lpParms)
1543 LPCSTR str = 0;
1544 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1545 DWORD ret = 0;
1547 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1549 if (lpParms == NULL || lpParms->lpstrReturn == NULL)
1550 return MCIERR_NULL_PARAMETER_BLOCK;
1551 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1553 TRACE("buf=%p, len=%lu\n", lpParms->lpstrReturn, lpParms->dwRetSize);
1555 switch (dwFlags & ~(MCI_WAIT|MCI_NOTIFY)) {
1556 case MCI_INFO_PRODUCT:
1557 str = "Wine's MIDI sequencer";
1558 break;
1559 case MCI_INFO_FILE:
1560 str = wmm->lpstrElementName;
1561 break;
1562 case MCI_INFO_COPYRIGHT:
1563 str = wmm->lpstrCopyright;
1564 break;
1565 case MCI_INFO_NAME:
1566 str = wmm->lpstrName;
1567 break;
1568 default:
1569 WARN("Don't know this info command (%lu)\n", dwFlags);
1570 return MCIERR_UNRECOGNIZED_COMMAND;
1572 if (str) {
1573 if (lpParms->dwRetSize <= strlen(str)) {
1574 lstrcpynA(lpParms->lpstrReturn, str, lpParms->dwRetSize - 1);
1575 ret = MCIERR_PARAM_OVERFLOW;
1576 } else {
1577 strcpy(lpParms->lpstrReturn, str);
1579 } else {
1580 *lpParms->lpstrReturn = 0;
1582 return ret;
1585 /**************************************************************************
1586 * MIDI_mciSeek [internal]
1588 static DWORD MIDI_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
1590 DWORD ret = 0;
1591 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1593 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1595 if (lpParms == NULL) {
1596 ret = MCIERR_NULL_PARAMETER_BLOCK;
1597 } else if (wmm == NULL) {
1598 ret = MCIERR_INVALID_DEVICE_ID;
1599 } else {
1600 MIDI_mciStop(wDevID, MCI_WAIT, 0);
1602 if (dwFlags & MCI_SEEK_TO_START) {
1603 wmm->dwPositionMS = 0;
1604 } else if (dwFlags & MCI_SEEK_TO_END) {
1605 wmm->dwPositionMS = 0xFFFFFFFF; /* fixme */
1606 } else if (dwFlags & MCI_TO) {
1607 wmm->dwPositionMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
1608 } else {
1609 WARN("dwFlag doesn't tell where to seek to...\n");
1610 return MCIERR_MISSING_PARAMETER;
1613 TRACE("Seeking to position=%lu ms\n", wmm->dwPositionMS);
1615 if (dwFlags & MCI_NOTIFY) {
1616 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1617 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
1618 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1621 return ret;
1624 /*======================================================================*
1625 * MIDI entry points *
1626 *======================================================================*/
1628 /**************************************************************************
1629 * DriverProc (MCISEQ.@)
1631 LONG CALLBACK MCIMIDI_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg,
1632 DWORD dwParam1, DWORD dwParam2)
1634 switch (wMsg) {
1635 case DRV_LOAD: return 1;
1636 case DRV_FREE: return 1;
1637 case DRV_ENABLE: return 1;
1638 case DRV_DISABLE: return 1;
1639 case DRV_QUERYCONFIGURE: return 1;
1640 case DRV_CONFIGURE: MessageBoxA(0, "Sample Midi Driver !", "OSS Driver", MB_OK); return 1;
1641 case DRV_INSTALL: return DRVCNF_RESTART;
1642 case DRV_REMOVE: return DRVCNF_RESTART;
1643 case DRV_OPEN: return MIDI_drvOpen((LPSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSA)dwParam2);
1644 case DRV_CLOSE: return MIDI_drvClose(dwDevID);
1645 case MCI_OPEN_DRIVER: return MIDI_mciOpen (dwDevID, dwParam1, (LPMCI_OPEN_PARMSA) dwParam2);
1646 case MCI_CLOSE_DRIVER: return MIDI_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1647 case MCI_PLAY: return MIDI_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
1648 case MCI_RECORD: return MIDI_mciRecord (dwDevID, dwParam1, (LPMCI_RECORD_PARMS) dwParam2);
1649 case MCI_STOP: return MIDI_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1650 case MCI_SET: return MIDI_mciSet (dwDevID, dwParam1, (LPMCI_SET_PARMS) dwParam2);
1651 case MCI_PAUSE: return MIDI_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1652 case MCI_RESUME: return MIDI_mciResume (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1653 case MCI_STATUS: return MIDI_mciStatus (dwDevID, dwParam1, (LPMCI_STATUS_PARMS) dwParam2);
1654 case MCI_GETDEVCAPS: return MIDI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2);
1655 case MCI_INFO: return MIDI_mciInfo (dwDevID, dwParam1, (LPMCI_INFO_PARMSA) dwParam2);
1656 case MCI_SEEK: return MIDI_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
1657 /* commands that should be supported */
1658 case MCI_LOAD:
1659 case MCI_SAVE:
1660 case MCI_FREEZE:
1661 case MCI_PUT:
1662 case MCI_REALIZE:
1663 case MCI_UNFREEZE:
1664 case MCI_UPDATE:
1665 case MCI_WHERE:
1666 case MCI_STEP:
1667 case MCI_SPIN:
1668 case MCI_ESCAPE:
1669 case MCI_COPY:
1670 case MCI_CUT:
1671 case MCI_DELETE:
1672 case MCI_PASTE:
1673 WARN("Unsupported command [%lu]\n", wMsg);
1674 break;
1675 /* commands that should report an error */
1676 case MCI_WINDOW:
1677 TRACE("Unsupported command [%lu]\n", wMsg);
1678 break;
1679 case MCI_OPEN:
1680 case MCI_CLOSE:
1681 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1682 break;
1683 default:
1684 TRACE("Sending msg [%lu] to default driver proc\n", wMsg);
1685 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1687 return MCIERR_UNRECOGNIZED_COMMAND;