Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / mciseq / mcimidi.c
blob4ff68fe10dfd6471401269a880a8cecbfc928041
1 /*
2 * Sample MIDI Wine Driver for Linux
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1999 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 /* TODO:
23 * + implement it correctly
24 * + finish asynchronous commands
25 * + better implement non waiting command (without the MCI_WAIT flag).
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <string.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "wownt32.h"
38 #include "mmddk.h"
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(mcimidi);
44 #define MIDI_NOTEOFF 0x80
45 #define MIDI_NOTEON 0x90
47 typedef struct {
48 DWORD dwFirst; /* offset in file of track */
49 DWORD dwLast; /* number of bytes in file of track */
50 DWORD dwIndex; /* current index in file (dwFirst <= dwIndex < dwLast) */
51 DWORD dwLength; /* number of pulses in this track */
52 DWORD dwEventPulse; /* current pulse # (event) pointed by dwIndex */
53 DWORD dwEventData; /* current data (event) pointed by dwIndex */
54 WORD wEventLength; /* current length (event) pointed by dwIndex */
55 WORD wStatus : 1, /* 1 : playing, 0 : done */
56 wTrackNr : 7,
57 wLastCommand : 8; /* last MIDI command on track */
58 } MCI_MIDITRACK;
60 typedef struct tagWINE_MCIMIDI {
61 UINT wDevID; /* the MCI one */
62 HMIDI hMidi;
63 int nUseCount; /* Incremented for each shared open */
64 WORD wPort; /* the WINMM device unit */
65 WORD wNotifyDeviceID; /* MCI device ID with a pending notification */
66 HANDLE hCallback; /* Callback handle for pending notification */
67 HMMIO hFile; /* mmio file handle open as Element */
68 LPWSTR lpstrElementName; /* Name of file (if any) */
69 LPWSTR lpstrCopyright;
70 LPWSTR lpstrName;
71 WORD dwStatus; /* one from MCI_MODE_xxxx */
72 DWORD dwMciTimeFormat; /* One of the supported MCI_FORMAT_xxxx */
73 WORD wFormat; /* Format of MIDI hFile (0, 1 or 2) */
74 WORD nTracks; /* Number of tracks in hFile */
75 WORD nDivision; /* Number of division in hFile PPQN or SMPTE */
76 WORD wStartedPlaying;
77 DWORD dwTempo; /* Tempo (# of 1/4 note per second */
78 MCI_MIDITRACK* tracks; /* Content of each track */
79 DWORD dwPulse;
80 DWORD dwPositionMS;
81 DWORD dwStartTicks;
82 } WINE_MCIMIDI;
84 /* ===================================================================
85 * ===================================================================
86 * FIXME: should be using the new mmThreadXXXX functions from WINMM
87 * instead of those
88 * it would require to add a wine internal flag to mmThreadCreate
89 * in order to pass a 32 bit function instead of a 16 bit
90 * ===================================================================
91 * =================================================================== */
93 struct SCA {
94 UINT wDevID;
95 UINT wMsg;
96 DWORD_PTR dwParam1;
97 DWORD_PTR dwParam2;
100 /* EPP DWORD WINAPI mciSendCommandA(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2); */
102 /**************************************************************************
103 * MCI_SCAStarter [internal]
105 static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
107 struct SCA* sca = arg;
108 DWORD ret;
110 TRACE("In thread before async command (%08x,%u,%08lx,%08lx)\n",
111 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
112 ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2);
113 TRACE("In thread after async command (%08x,%u,%08lx,%08lx)\n",
114 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
115 HeapFree(GetProcessHeap(), 0, sca);
116 return ret;
119 /**************************************************************************
120 * MCI_SendCommandAsync [internal]
122 static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD_PTR dwParam1,
123 DWORD_PTR dwParam2, UINT size)
125 HANDLE handle;
126 struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA) + size);
128 if (sca == 0)
129 return MCIERR_OUT_OF_MEMORY;
131 sca->wDevID = wDevID;
132 sca->wMsg = wMsg;
133 sca->dwParam1 = dwParam1;
135 if (size && dwParam2) {
136 sca->dwParam2 = (DWORD_PTR)sca + sizeof(struct SCA);
137 /* copy structure passed by program in dwParam2 to be sure
138 * we can still use it whatever the program does
140 memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size);
141 } else {
142 sca->dwParam2 = dwParam2;
145 if ((handle = CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL)) == 0) {
146 WARN("Couldn't allocate thread for async command handling, sending synchronously\n");
147 return MCI_SCAStarter(sca);
149 SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
150 CloseHandle(handle);
151 return 0;
154 /*======================================================================*
155 * MCI MIDI implementation *
156 *======================================================================*/
158 static DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
160 /**************************************************************************
161 * MIDI_drvOpen [internal]
163 static DWORD MIDI_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
165 WINE_MCIMIDI* wmm;
167 if (!modp) return 0xFFFFFFFF;
169 wmm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIMIDI));
171 if (!wmm)
172 return 0;
174 wmm->wDevID = modp->wDeviceID;
175 mciSetDriverData(wmm->wDevID, (DWORD_PTR)wmm);
176 modp->wCustomCommandTable = MCI_NO_COMMAND_TABLE;
177 modp->wType = MCI_DEVTYPE_SEQUENCER;
178 return modp->wDeviceID;
181 /**************************************************************************
182 * MCIMIDI_drvClose [internal]
184 static DWORD MIDI_drvClose(DWORD dwDevID)
186 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(dwDevID);
188 if (wmm) {
189 HeapFree(GetProcessHeap(), 0, wmm);
190 mciSetDriverData(dwDevID, 0);
191 return 1;
193 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
196 /**************************************************************************
197 * MIDI_mciGetOpenDev [internal]
199 static WINE_MCIMIDI* MIDI_mciGetOpenDev(UINT wDevID)
201 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
203 if (wmm == NULL || wmm->nUseCount == 0) {
204 WARN("Invalid wDevID=%u\n", wDevID);
205 return 0;
207 return wmm;
210 /**************************************************************************
211 * MIDI_mciReadByte [internal]
213 static DWORD MIDI_mciReadByte(WINE_MCIMIDI* wmm, BYTE *lpbyt)
215 DWORD ret = 0;
217 if (lpbyt == NULL ||
218 mmioRead(wmm->hFile, (HPSTR)lpbyt, sizeof(BYTE)) != (long)sizeof(BYTE)) {
219 WARN("Error reading wmm=%p\n", wmm);
220 ret = MCIERR_INVALID_FILE;
223 return ret;
226 /**************************************************************************
227 * MIDI_mciReadWord [internal]
229 static DWORD MIDI_mciReadWord(WINE_MCIMIDI* wmm, LPWORD lpw)
231 BYTE hibyte, lobyte;
232 DWORD ret = MCIERR_INVALID_FILE;
234 if (lpw != NULL &&
235 MIDI_mciReadByte(wmm, &hibyte) == 0 &&
236 MIDI_mciReadByte(wmm, &lobyte) == 0) {
237 *lpw = ((WORD)hibyte << 8) + lobyte;
238 ret = 0;
240 return ret;
243 /**************************************************************************
244 * MIDI_mciReadLong [internal]
246 static DWORD MIDI_mciReadLong(WINE_MCIMIDI* wmm, LPDWORD lpdw)
248 WORD hiword, loword;
249 DWORD ret = MCIERR_INVALID_FILE;
251 if (lpdw != NULL &&
252 MIDI_mciReadWord(wmm, &hiword) == 0 &&
253 MIDI_mciReadWord(wmm, &loword) == 0) {
254 *lpdw = MAKELONG(loword, hiword);
255 ret = 0;
257 return ret;
260 /**************************************************************************
261 * MIDI_mciReadVaryLen [internal]
263 static WORD MIDI_mciReadVaryLen(WINE_MCIMIDI* wmm, LPDWORD lpdw)
265 BYTE byte;
266 DWORD value = 0;
267 WORD ret = 0;
269 if (lpdw == NULL) {
270 ret = MCIERR_INVALID_FILE;
271 } else {
272 do {
273 if (MIDI_mciReadByte(wmm, &byte) != 0) {
274 return 0;
276 value = (value << 7) + (byte & 0x7F);
277 ret++;
278 } while (byte & 0x80);
279 *lpdw = value;
281 TRACE("val=%08X\n", value);
284 return ret;
287 /**************************************************************************
288 * MIDI_mciReadNextEvent [internal]
290 static DWORD MIDI_mciReadNextEvent(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
292 BYTE b1, b2 = 0, b3;
293 WORD hw = 0;
294 DWORD evtPulse;
295 DWORD evtLength;
296 DWORD tmp;
298 if (mmioSeek(wmm->hFile, mmt->dwIndex, SEEK_SET) != mmt->dwIndex) {
299 WARN("Can't seek at %08X\n", mmt->dwIndex);
300 return MCIERR_INVALID_FILE;
302 evtLength = MIDI_mciReadVaryLen(wmm, &evtPulse) + 1; /* > 0 */
303 MIDI_mciReadByte(wmm, &b1);
304 switch (b1) {
305 case 0xF0:
306 case 0xF7:
307 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
308 evtLength += tmp;
309 break;
310 case 0xFF:
311 MIDI_mciReadByte(wmm, &b2); evtLength++;
313 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
314 if (evtLength >= 0x10000u) {
315 /* this limitation shouldn't be a problem */
316 WARN("Ouch !! Implementation limitation to 64k bytes for a MIDI event is overflowed\n");
317 hw = 0xFFFF;
318 } else {
319 hw = LOWORD(evtLength);
321 evtLength += tmp;
322 break;
323 default:
324 if (b1 & 0x80) { /* use running status ? */
325 mmt->wLastCommand = b1;
326 MIDI_mciReadByte(wmm, &b2); evtLength++;
327 } else {
328 b2 = b1;
329 b1 = mmt->wLastCommand;
331 switch ((b1 >> 4) & 0x07) {
332 case 0: case 1: case 2: case 3: case 6:
333 MIDI_mciReadByte(wmm, &b3); evtLength++;
334 hw = b3;
335 break;
336 case 4: case 5:
337 break;
338 case 7:
339 WARN("Strange indeed b1=0x%02x\n", b1);
341 break;
343 if (mmt->dwIndex + evtLength > mmt->dwLast)
344 return MCIERR_INTERNAL;
346 mmt->dwEventPulse += evtPulse;
347 mmt->dwEventData = (hw << 16) + (b2 << 8) + b1;
348 mmt->wEventLength = evtLength;
351 TRACE("[%u] => pulse=%08x(%08x), data=%08x, length=%u\n",
352 mmt->wTrackNr, mmt->dwEventPulse, evtPulse,
353 mmt->dwEventData, mmt->wEventLength);
355 return 0;
358 /**************************************************************************
359 * MIDI_mciReadMTrk [internal]
361 static DWORD MIDI_mciReadMTrk(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
363 DWORD toberead;
364 FOURCC fourcc;
366 if (mmioRead(wmm->hFile, (HPSTR)&fourcc, (long)sizeof(FOURCC)) !=
367 (long)sizeof(FOURCC)) {
368 return MCIERR_INVALID_FILE;
371 if (fourcc != mmioFOURCC('M', 'T', 'r', 'k')) {
372 WARN("Can't synchronize on 'MTrk' !\n");
373 return MCIERR_INVALID_FILE;
376 if (MIDI_mciReadLong(wmm, &toberead) != 0) {
377 return MCIERR_INVALID_FILE;
379 mmt->dwFirst = mmioSeek(wmm->hFile, 0, SEEK_CUR); /* >= 0 */
380 mmt->dwLast = mmt->dwFirst + toberead;
382 /* compute # of pulses in this track */
383 mmt->dwIndex = mmt->dwFirst;
384 mmt->dwEventPulse = 0;
386 while (MIDI_mciReadNextEvent(wmm, mmt) == 0 && LOWORD(mmt->dwEventData) != 0x2FFF) {
387 char buf[1024];
388 WORD len;
390 mmt->dwIndex += mmt->wEventLength;
392 switch (LOWORD(mmt->dwEventData)) {
393 case 0x02FF:
394 case 0x03FF:
395 /* position after meta data header */
396 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
397 len = mmt->wEventLength - HIWORD(mmt->dwEventData);
399 if (len >= sizeof(buf)) {
400 WARN("Buffer for text is too small (%u are needed)\n", len);
401 len = sizeof(buf) - 1;
403 if (mmioRead(wmm->hFile, buf, len) == len) {
404 buf[len] = 0; /* end string in case */
405 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
406 case 0x02:
407 if (wmm->lpstrCopyright) {
408 WARN("Two copyright notices (%s|%s)\n", debugstr_w(wmm->lpstrCopyright), buf);
409 } else {
410 len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
411 wmm->lpstrCopyright = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
412 MultiByteToWideChar( CP_ACP, 0, buf, -1, wmm->lpstrCopyright, len );
414 break;
415 case 0x03:
416 if (wmm->lpstrName) {
417 WARN("Two names (%s|%s)\n", debugstr_w(wmm->lpstrName), buf);
418 } else {
419 len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
420 wmm->lpstrName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
421 MultiByteToWideChar( CP_ACP, 0, buf, -1, wmm->lpstrName, len );
423 break;
426 break;
429 mmt->dwLength = mmt->dwEventPulse;
431 TRACE("Track %u has %u bytes and %u pulses\n", mmt->wTrackNr, toberead, mmt->dwLength);
433 /* reset track data */
434 mmt->wStatus = 1; /* ok, playing */
435 mmt->dwIndex = mmt->dwFirst;
436 mmt->dwEventPulse = 0;
438 if (mmioSeek(wmm->hFile, 0, SEEK_CUR) != mmt->dwLast) {
439 WARN("Ouch, out of sync seek=%u track=%u\n",
440 mmioSeek(wmm->hFile, 0, SEEK_CUR), mmt->dwLast);
441 /* position at end of this track, to be ready to read next track */
442 mmioSeek(wmm->hFile, mmt->dwLast, SEEK_SET);
445 return 0;
448 /**************************************************************************
449 * MIDI_mciReadMThd [internal]
451 static DWORD MIDI_mciReadMThd(WINE_MCIMIDI* wmm, DWORD dwOffset)
453 DWORD toberead;
454 FOURCC fourcc;
455 WORD nt;
457 TRACE("(%p, %08X);\n", wmm, dwOffset);
459 if (mmioSeek(wmm->hFile, dwOffset, SEEK_SET) != dwOffset) {
460 WARN("Can't seek at %08X begin of 'MThd'\n", dwOffset);
461 return MCIERR_INVALID_FILE;
463 if (mmioRead(wmm->hFile, (HPSTR)&fourcc,
464 (long) sizeof(FOURCC)) != (long) sizeof(FOURCC))
465 return MCIERR_INVALID_FILE;
467 if (fourcc != mmioFOURCC('M', 'T', 'h', 'd')) {
468 WARN("Can't synchronize on 'MThd' !\n");
469 return MCIERR_INVALID_FILE;
472 if (MIDI_mciReadLong(wmm, &toberead) != 0 || toberead < 3 * sizeof(WORD))
473 return MCIERR_INVALID_FILE;
475 if (MIDI_mciReadWord(wmm, &wmm->wFormat) != 0 ||
476 MIDI_mciReadWord(wmm, &wmm->nTracks) != 0 ||
477 MIDI_mciReadWord(wmm, &wmm->nDivision) != 0) {
478 return MCIERR_INVALID_FILE;
481 TRACE("toberead=0x%08X, wFormat=0x%04X nTracks=0x%04X nDivision=0x%04X\n",
482 toberead, wmm->wFormat, wmm->nTracks, wmm->nDivision);
484 /* MS doc says that the MIDI MCI time format must be put by default to the format
485 * stored in the MIDI file...
487 if (wmm->nDivision > 0x8000) {
488 /* eric.pouech@lemel.fr 98/11
489 * I did not check this very code (pulses are expressed as SMPTE sub-frames).
490 * In about 40 MB of MIDI files I have, none was SMPTE based...
491 * I'm just wondering if this is widely used :-). So, if someone has one of
492 * these files, I'd like to know about it.
494 FIXME("Handling SMPTE time in MIDI files has not been tested\n"
495 "Please report to comp.emulators.ms-windows.wine with MIDI file !\n");
497 switch (HIBYTE(wmm->nDivision)) {
498 case 0xE8: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24; break; /* -24 */
499 case 0xE7: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25; break; /* -25 */
500 case 0xE3: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
501 case 0xE2: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30; break; /* -30 */
502 default:
503 WARN("Unsupported number of frames %d\n", -(char)HIBYTE(wmm->nDivision));
504 return MCIERR_INVALID_FILE;
506 switch (LOBYTE(wmm->nDivision)) {
507 case 4: /* MIDI Time Code */
508 case 8:
509 case 10:
510 case 80: /* SMPTE bit resolution */
511 case 100:
512 default:
513 WARN("Unsupported number of sub-frames %d\n", LOBYTE(wmm->nDivision));
514 return MCIERR_INVALID_FILE;
516 } else if (wmm->nDivision == 0) {
517 WARN("Number of division is 0, can't support that !!\n");
518 return MCIERR_INVALID_FILE;
519 } else {
520 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
523 switch (wmm->wFormat) {
524 case 0:
525 if (wmm->nTracks != 1) {
526 WARN("Got type 0 file whose number of track is not 1. Setting it to 1\n");
527 wmm->nTracks = 1;
529 break;
530 case 1:
531 case 2:
532 break;
533 default:
534 WARN("Handling MIDI files which format = %d is not (yet) supported\n"
535 "Please report with MIDI file !\n", wmm->wFormat);
536 return MCIERR_INVALID_FILE;
539 if (wmm->nTracks & 0x8000) {
540 /* this shouldn't be a problem... */
541 WARN("Ouch !! Implementation limitation to 32k tracks per MIDI file is overflowed\n");
542 wmm->nTracks = 0x7FFF;
545 if ((wmm->tracks = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_MIDITRACK) * wmm->nTracks)) == NULL) {
546 return MCIERR_OUT_OF_MEMORY;
549 toberead -= 3 * sizeof(WORD);
550 if (toberead > 0) {
551 TRACE("Size of MThd > 6, skipping %d extra bytes\n", toberead);
552 mmioSeek(wmm->hFile, toberead, SEEK_CUR);
555 for (nt = 0; nt < wmm->nTracks; nt++) {
556 wmm->tracks[nt].wTrackNr = nt;
557 if (MIDI_mciReadMTrk(wmm, &wmm->tracks[nt]) != 0) {
558 WARN("Can't read 'MTrk' header\n");
559 return MCIERR_INVALID_FILE;
563 wmm->dwTempo = 500000;
565 return 0;
568 /**************************************************************************
569 * MIDI_ConvertPulseToMS [internal]
571 static DWORD MIDI_ConvertPulseToMS(WINE_MCIMIDI* wmm, DWORD pulse)
573 DWORD ret = 0;
575 /* FIXME: this function may return false values since the tempo (wmm->dwTempo)
576 * may change during file playing
578 if (wmm->nDivision == 0) {
579 FIXME("Shouldn't happen. wmm->nDivision = 0\n");
580 } else if (wmm->nDivision > 0x8000) { /* SMPTE, unchecked FIXME? */
581 int nf = -(char)HIBYTE(wmm->nDivision); /* number of frames */
582 int nsf = LOBYTE(wmm->nDivision); /* number of sub-frames */
583 ret = (pulse * 1000) / (nf * nsf);
584 } else {
585 ret = (DWORD)((double)pulse * ((double)wmm->dwTempo / 1000) /
586 (double)wmm->nDivision);
590 TRACE("pulse=%u tempo=%u division=%u=0x%04x => ms=%u\n",
591 pulse, wmm->dwTempo, wmm->nDivision, wmm->nDivision, ret);
594 return ret;
597 #define TIME_MS_IN_ONE_HOUR (60*60*1000)
598 #define TIME_MS_IN_ONE_MINUTE (60*1000)
599 #define TIME_MS_IN_ONE_SECOND (1000)
601 /**************************************************************************
602 * MIDI_ConvertTimeFormatToMS [internal]
604 static DWORD MIDI_ConvertTimeFormatToMS(WINE_MCIMIDI* wmm, DWORD val)
606 DWORD ret = 0;
608 switch (wmm->dwMciTimeFormat) {
609 case MCI_FORMAT_MILLISECONDS:
610 ret = val;
611 break;
612 case MCI_FORMAT_SMPTE_24:
613 ret =
614 (HIBYTE(HIWORD(val)) * 125) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
615 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
616 break;
617 case MCI_FORMAT_SMPTE_25:
618 ret =
619 HIBYTE(HIWORD(val)) * 40 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
620 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
621 break;
622 case MCI_FORMAT_SMPTE_30:
623 ret =
624 (HIBYTE(HIWORD(val)) * 100) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
625 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
626 break;
627 default:
628 WARN("Bad time format %u!\n", wmm->dwMciTimeFormat);
631 TRACE("val=%u=0x%08x [tf=%u] => ret=%u\n", val, val, wmm->dwMciTimeFormat, ret);
633 return ret;
636 /**************************************************************************
637 * MIDI_ConvertMSToTimeFormat [internal]
639 static DWORD MIDI_ConvertMSToTimeFormat(WINE_MCIMIDI* wmm, DWORD _val)
641 DWORD ret = 0, val = _val;
642 DWORD h, m, s, f;
644 switch (wmm->dwMciTimeFormat) {
645 case MCI_FORMAT_MILLISECONDS:
646 ret = val;
647 break;
648 case MCI_FORMAT_SMPTE_24:
649 case MCI_FORMAT_SMPTE_25:
650 case MCI_FORMAT_SMPTE_30:
651 h = val / TIME_MS_IN_ONE_HOUR;
652 m = (val -= h * TIME_MS_IN_ONE_HOUR) / TIME_MS_IN_ONE_MINUTE;
653 s = (val -= m * TIME_MS_IN_ONE_MINUTE) / TIME_MS_IN_ONE_SECOND;
654 switch (wmm->dwMciTimeFormat) {
655 case MCI_FORMAT_SMPTE_24:
656 /* one frame is 1000/24 val long, 1000/24 == 125/3 */
657 f = (val * 3) / 125; val -= (f * 125) / 3;
658 break;
659 case MCI_FORMAT_SMPTE_25:
660 /* one frame is 1000/25 ms long, 1000/25 == 40 */
661 f = val / 40; val -= f * 40;
662 break;
663 case MCI_FORMAT_SMPTE_30:
664 /* one frame is 1000/30 ms long, 1000/30 == 100/3 */
665 f = (val * 3) / 100; val -= (f * 100) / 3;
666 break;
667 default:
668 FIXME("There must be some bad bad programmer\n");
669 f = 0;
671 /* val contains the number of ms which cannot make a complete frame */
672 /* FIXME: is this correct ? programs seem to be happy with that */
673 ret = (f << 24) | (s << 16) | (m << 8) | (h << 0);
674 break;
675 default:
676 WARN("Bad time format %u!\n", wmm->dwMciTimeFormat);
679 TRACE("val=%u [tf=%u] => ret=%u=0x%08x\n", _val, wmm->dwMciTimeFormat, ret, ret);
681 return ret;
684 /**************************************************************************
685 * MIDI_GetMThdLengthMS [internal]
687 static DWORD MIDI_GetMThdLengthMS(WINE_MCIMIDI* wmm)
689 WORD nt;
690 DWORD ret = 0;
692 for (nt = 0; nt < wmm->nTracks; nt++) {
693 if (wmm->wFormat == 2) {
694 ret += wmm->tracks[nt].dwLength;
695 } else if (wmm->tracks[nt].dwLength > ret) {
696 ret = wmm->tracks[nt].dwLength;
699 /* FIXME: this is wrong if there is a tempo change inside the file */
700 return MIDI_ConvertPulseToMS(wmm, ret);
703 /**************************************************************************
704 * MIDI_mciOpen [internal]
706 static DWORD MIDI_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMSW lpParms)
708 DWORD dwRet = 0;
709 DWORD dwDeviceID;
710 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
712 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
714 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
715 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
716 if (dwFlags & MCI_OPEN_SHAREABLE)
717 return MCIERR_HARDWARE;
719 if (wmm->nUseCount > 0) {
720 /* The driver is already opened on this channel
721 * MIDI sequencer cannot be shared
723 return MCIERR_DEVICE_OPEN;
725 wmm->nUseCount++;
727 wmm->hFile = 0;
728 wmm->hMidi = 0;
729 wmm->wPort = MIDI_MAPPER;
730 wmm->lpstrElementName = NULL;
731 dwDeviceID = lpParms->wDeviceID;
733 TRACE("wDevID=%04X (lpParams->wDeviceID=%08X)\n", wDevID, dwDeviceID);
734 /* lpParms->wDeviceID = wDevID;*/
736 if (dwFlags & MCI_OPEN_ELEMENT) {
737 TRACE("MCI_OPEN_ELEMENT %s!\n", debugstr_w(lpParms->lpstrElementName));
738 if (lpParms->lpstrElementName && strlenW(lpParms->lpstrElementName) > 0) {
739 wmm->hFile = mmioOpenW((LPWSTR)lpParms->lpstrElementName, NULL,
740 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
741 if (wmm->hFile == 0) {
742 WARN("Can't find file %s!\n", debugstr_w(lpParms->lpstrElementName));
743 wmm->nUseCount--;
744 return MCIERR_FILE_NOT_FOUND;
746 wmm->lpstrElementName = HeapAlloc(GetProcessHeap(), 0,
747 (strlenW(lpParms->lpstrElementName) + 1) * sizeof(WCHAR));
748 strcpyW(wmm->lpstrElementName, lpParms->lpstrElementName);
751 TRACE("hFile=%p\n", wmm->hFile);
753 wmm->lpstrCopyright = NULL;
754 wmm->lpstrName = NULL;
756 wmm->wNotifyDeviceID = dwDeviceID;
757 wmm->dwStatus = MCI_MODE_NOT_READY; /* while loading file contents */
758 /* spec says it should be the default format from the MIDI file... */
759 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
761 if (wmm->hFile != 0) {
762 MMCKINFO ckMainRIFF;
763 MMCKINFO mmckInfo;
764 DWORD dwOffset = 0;
766 if (mmioDescend(wmm->hFile, &ckMainRIFF, NULL, 0) != 0) {
767 dwRet = MCIERR_INVALID_FILE;
768 } else {
769 TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08X\n",
770 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
772 if (ckMainRIFF.ckid == FOURCC_RIFF && ckMainRIFF.fccType == mmioFOURCC('R', 'M', 'I', 'D')) {
773 mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
774 mmioSeek(wmm->hFile, ckMainRIFF.dwDataOffset + ((ckMainRIFF.cksize + 1) & ~1), SEEK_SET);
775 if (mmioDescend(wmm->hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) {
776 TRACE("... is a 'RMID' file\n");
777 dwOffset = mmckInfo.dwDataOffset;
778 } else {
779 dwRet = MCIERR_INVALID_FILE;
782 if (dwRet == 0 && MIDI_mciReadMThd(wmm, dwOffset) != 0) {
783 WARN("Can't read 'MThd' header\n");
784 dwRet = MCIERR_INVALID_FILE;
787 } else {
788 TRACE("hFile==0, setting #tracks to 0; is this correct ?\n");
789 wmm->nTracks = 0;
790 wmm->wFormat = 0;
791 wmm->nDivision = 1;
793 if (dwRet != 0) {
794 wmm->nUseCount--;
795 if (wmm->hFile != 0)
796 mmioClose(wmm->hFile, 0);
797 wmm->hFile = 0;
798 } else {
799 wmm->dwPositionMS = 0;
800 wmm->dwStatus = MCI_MODE_STOP;
801 if (dwFlags & MCI_NOTIFY) {
802 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
803 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
804 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
807 return dwRet;
810 /**************************************************************************
811 * MIDI_mciStop [internal]
813 static DWORD MIDI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
815 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
817 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
819 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
821 if (wmm->dwStatus != MCI_MODE_STOP) {
822 int oldstat = wmm->dwStatus;
824 wmm->dwStatus = MCI_MODE_NOT_READY;
825 if (oldstat == MCI_MODE_PAUSE)
826 midiOutReset((HMIDIOUT)wmm->hMidi);
828 while (wmm->dwStatus != MCI_MODE_STOP)
829 Sleep(10);
832 /* sanity reset */
833 wmm->dwStatus = MCI_MODE_STOP;
835 TRACE("wmm->dwStatus=%d\n", wmm->dwStatus);
837 if (lpParms && (dwFlags & MCI_NOTIFY)) {
838 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
839 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
840 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
842 return 0;
845 /**************************************************************************
846 * MIDI_mciClose [internal]
848 static DWORD MIDI_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
850 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
852 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
854 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
856 if (wmm->dwStatus != MCI_MODE_STOP) {
857 MIDI_mciStop(wDevID, MCI_WAIT, lpParms);
860 wmm->nUseCount--;
861 if (wmm->nUseCount == 0) {
862 if (wmm->hFile != 0) {
863 mmioClose(wmm->hFile, 0);
864 wmm->hFile = 0;
865 TRACE("hFile closed !\n");
867 HeapFree(GetProcessHeap(), 0, wmm->tracks);
868 HeapFree(GetProcessHeap(), 0, wmm->lpstrElementName);
869 HeapFree(GetProcessHeap(), 0, wmm->lpstrCopyright);
870 HeapFree(GetProcessHeap(), 0, wmm->lpstrName);
871 } else {
872 TRACE("Shouldn't happen... nUseCount=%d\n", wmm->nUseCount);
873 return MCIERR_INTERNAL;
876 if (lpParms && (dwFlags & MCI_NOTIFY)) {
877 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
878 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
879 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
881 return 0;
884 /**************************************************************************
885 * MIDI_mciFindNextEvent [internal]
887 static MCI_MIDITRACK* MIDI_mciFindNextEvent(WINE_MCIMIDI* wmm, LPDWORD hiPulse)
889 WORD cnt, nt;
890 MCI_MIDITRACK* mmt;
892 *hiPulse = 0xFFFFFFFFul;
893 cnt = 0xFFFFu;
894 for (nt = 0; nt < wmm->nTracks; nt++) {
895 mmt = &wmm->tracks[nt];
897 if (mmt->wStatus == 0)
898 continue;
899 if (mmt->dwEventPulse < *hiPulse) {
900 *hiPulse = mmt->dwEventPulse;
901 cnt = nt;
904 return (cnt == 0xFFFFu) ? 0 /* no more event on all tracks */
905 : &wmm->tracks[cnt];
908 /**************************************************************************
909 * MIDI_mciPlay [internal]
911 static DWORD MIDI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
913 DWORD dwStartMS, dwEndMS;
914 DWORD dwRet = 0;
915 WORD doPlay, nt;
916 MCI_MIDITRACK* mmt;
917 DWORD hiPulse;
918 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
920 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
922 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
924 if (wmm->hFile == 0) {
925 WARN("Can't play: no file %s!\n", debugstr_w(wmm->lpstrElementName));
926 return MCIERR_FILE_NOT_FOUND;
929 if (wmm->dwStatus != MCI_MODE_STOP) {
930 if (wmm->dwStatus == MCI_MODE_PAUSE) {
931 /* FIXME: parameters (start/end) in lpParams may not be used */
932 return MIDI_mciResume(wDevID, dwFlags, (LPMCI_GENERIC_PARMS)lpParms);
934 WARN("Can't play: device is not stopped !\n");
935 return MCIERR_INTERNAL;
938 if (!(dwFlags & MCI_WAIT)) {
939 /** FIXME: I'm not 100% sure that wNotifyDeviceID is the right value in all cases ??? */
940 return MCI_SendCommandAsync(wmm->wNotifyDeviceID, MCI_PLAY, dwFlags, (DWORD_PTR)lpParms, sizeof(LPMCI_PLAY_PARMS));
943 if (lpParms && (dwFlags & MCI_FROM)) {
944 dwStartMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwFrom);
945 } else {
946 dwStartMS = wmm->dwPositionMS;
949 if (lpParms && (dwFlags & MCI_TO)) {
950 dwEndMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
951 } else {
952 dwEndMS = 0xFFFFFFFFul;
955 TRACE("Playing from %u to %u\n", dwStartMS, dwEndMS);
957 /* init tracks */
958 for (nt = 0; nt < wmm->nTracks; nt++) {
959 mmt = &wmm->tracks[nt];
961 mmt->wStatus = 1; /* ok, playing */
962 mmt->dwIndex = mmt->dwFirst;
963 if (wmm->wFormat == 2 && nt > 0) {
964 mmt->dwEventPulse = wmm->tracks[nt - 1].dwLength;
965 } else {
966 mmt->dwEventPulse = 0;
968 MIDI_mciReadNextEvent(wmm, mmt); /* FIXME == 0 */
971 dwRet = midiOutOpen((LPHMIDIOUT)&wmm->hMidi, wmm->wPort, 0L, 0L, CALLBACK_NULL);
972 if (dwRet != MMSYSERR_NOERROR) {
973 return dwRet;
976 wmm->dwPulse = 0;
977 wmm->dwTempo = 500000;
978 wmm->dwStatus = MCI_MODE_PLAY;
979 wmm->dwPositionMS = 0;
980 wmm->wStartedPlaying = FALSE;
982 while (wmm->dwStatus != MCI_MODE_STOP && wmm->dwStatus != MCI_MODE_NOT_READY) {
983 /* it seems that in case of multi-threading, gcc is optimizing just a little bit
984 * too much. Tell gcc not to optimize status value using volatile.
986 while (((volatile WINE_MCIMIDI*)wmm)->dwStatus == MCI_MODE_PAUSE);
988 doPlay = (wmm->dwPositionMS >= dwStartMS && wmm->dwPositionMS <= dwEndMS);
990 TRACE("wmm->dwStatus=%d, doPlay=%c\n", wmm->dwStatus, doPlay ? 'T' : 'F');
992 if ((mmt = MIDI_mciFindNextEvent(wmm, &hiPulse)) == NULL)
993 break; /* no more event on tracks */
995 /* if starting playing, then set StartTicks to the value it would have had
996 * if play had started at position 0
998 if (doPlay && !wmm->wStartedPlaying) {
999 wmm->dwStartTicks = GetTickCount() - MIDI_ConvertPulseToMS(wmm, wmm->dwPulse);
1000 wmm->wStartedPlaying = TRUE;
1001 TRACE("Setting dwStartTicks to %u\n", wmm->dwStartTicks);
1004 if (hiPulse > wmm->dwPulse) {
1005 wmm->dwPositionMS += MIDI_ConvertPulseToMS(wmm, hiPulse - wmm->dwPulse);
1006 if (doPlay) {
1007 DWORD togo = wmm->dwStartTicks + wmm->dwPositionMS;
1008 DWORD tc = GetTickCount();
1010 TRACE("Pulses hi=0x%08x <> cur=0x%08x\n", hiPulse, wmm->dwPulse);
1011 TRACE("Wait until %u => %u ms\n",
1012 tc - wmm->dwStartTicks, togo - wmm->dwStartTicks);
1013 if (tc < togo)
1014 Sleep(togo - tc);
1016 wmm->dwPulse = hiPulse;
1019 switch (LOBYTE(LOWORD(mmt->dwEventData))) {
1020 case 0xF0:
1021 case 0xF7: /* sysex events */
1023 FIXME("Not handling SysEx events (yet)\n");
1025 break;
1026 case 0xFF:
1027 /* position after meta data header */
1028 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
1029 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
1030 case 0x00: /* 16-bit sequence number */
1031 if (TRACE_ON(mcimidi)) {
1032 WORD twd;
1034 MIDI_mciReadWord(wmm, &twd); /* == 0 */
1035 TRACE("Got sequence number %u\n", twd);
1037 break;
1038 case 0x01: /* any text */
1039 case 0x02: /* Copyright Message text */
1040 case 0x03: /* Sequence/Track Name text */
1041 case 0x04: /* Instrument Name text */
1042 case 0x05: /* Lyric text */
1043 case 0x06: /* Marker text */
1044 case 0x07: /* Cue-point text */
1045 if (TRACE_ON(mcimidi)) {
1046 char buf[1024];
1047 WORD len = mmt->wEventLength - HIWORD(mmt->dwEventData);
1048 static const char* const info[8] = {"", "Text", "Copyright", "Seq/Trk name",
1049 "Instrument", "Lyric", "Marker", "Cue-point"};
1050 WORD idx = HIBYTE(LOWORD(mmt->dwEventData));
1052 if (len >= sizeof(buf)) {
1053 WARN("Buffer for text is too small (%u are needed)\n", len);
1054 len = sizeof(buf) - 1;
1056 if (mmioRead(wmm->hFile, buf, len) == len) {
1057 buf[len] = 0; /* end string in case */
1058 TRACE("%s => \"%s\"\n", (idx < 8 ) ? info[idx] : "", buf);
1059 } else {
1060 WARN("Couldn't read data for %s\n", (idx < 8) ? info[idx] : "");
1063 break;
1064 case 0x20:
1065 /* MIDI channel (cc) */
1066 if (FIXME_ON(mcimidi)) {
1067 BYTE bt;
1069 MIDI_mciReadByte(wmm, &bt); /* == 0 */
1070 FIXME("NIY: MIDI channel=%u, track=%u\n", bt, mmt->wTrackNr);
1072 break;
1073 case 0x21:
1074 /* MIDI port (pp) */
1075 if (FIXME_ON(mcimidi)) {
1076 BYTE bt;
1078 MIDI_mciReadByte(wmm, &bt); /* == 0 */
1079 FIXME("NIY: MIDI port=%u, track=%u\n", bt, mmt->wTrackNr);
1081 break;
1082 case 0x2F: /* end of track */
1083 mmt->wStatus = 0;
1084 break;
1085 case 0x51:/* set tempo */
1086 /* Tempo is expressed in -seconds per midi quarter note
1087 * for format 1 MIDI files, this can only be present on track #0
1089 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1090 WARN("For format #1 MIDI files, tempo can only be changed on track #0 (%u)\n", mmt->wTrackNr);
1091 } else {
1092 BYTE tbt;
1093 DWORD value = 0;
1095 MIDI_mciReadByte(wmm, &tbt); value = ((DWORD)tbt) << 16;
1096 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 8;
1097 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 0;
1098 TRACE("Setting tempo to %d (BPM=%d)\n", wmm->dwTempo, (value) ? (60000000 / value) : 0);
1099 wmm->dwTempo = value;
1101 break;
1102 case 0x54: /* (hour) (min) (second) (frame) (fractional-frame) - SMPTE track start */
1103 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1104 WARN("For format #1 MIDI files, SMPTE track start can only be expressed on track #0 (%u)\n", mmt->wTrackNr);
1105 } if (mmt->dwEventPulse != 0) {
1106 WARN("SMPTE track start can only be expressed at start of track (%u)\n", mmt->dwEventPulse);
1107 } else {
1108 BYTE h, m, s, f, ff;
1110 MIDI_mciReadByte(wmm, &h);
1111 MIDI_mciReadByte(wmm, &m);
1112 MIDI_mciReadByte(wmm, &s);
1113 MIDI_mciReadByte(wmm, &f);
1114 MIDI_mciReadByte(wmm, &ff);
1115 FIXME("NIY: SMPTE track start %u:%u:%u %u.%u\n", h, m, s, f, ff);
1117 break;
1118 case 0x58: /* file rhythm */
1119 if (TRACE_ON(mcimidi)) {
1120 BYTE num, den, cpmc, _32npqn;
1122 MIDI_mciReadByte(wmm, &num);
1123 MIDI_mciReadByte(wmm, &den); /* to notate e.g. 6/8 */
1124 MIDI_mciReadByte(wmm, &cpmc); /* number of MIDI clocks per metronome click */
1125 MIDI_mciReadByte(wmm, &_32npqn); /* number of notated 32nd notes per MIDI quarter note */
1127 TRACE("%u/%u, clock per metronome click=%u, 32nd notes by 1/4 note=%u\n", num, 1 << den, cpmc, _32npqn);
1129 break;
1130 case 0x59: /* key signature */
1131 if (TRACE_ON(mcimidi)) {
1132 BYTE sf, mm;
1134 MIDI_mciReadByte(wmm, &sf);
1135 MIDI_mciReadByte(wmm, &mm);
1137 if (sf >= 0x80) TRACE("%d flats\n", -(char)sf);
1138 else if (sf > 0) TRACE("%d sharps\n", (char)sf);
1139 else TRACE("Key of C\n");
1140 TRACE("Mode: %s\n", (mm == 0) ? "major" : "minor");
1142 break;
1143 default:
1144 WARN("Unknown MIDI meta event %02x. Skipping...\n", HIBYTE(LOWORD(mmt->dwEventData)));
1145 break;
1147 break;
1148 default:
1149 if (doPlay) {
1150 dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
1151 } else {
1152 switch (LOBYTE(LOWORD(mmt->dwEventData)) & 0xF0) {
1153 case MIDI_NOTEON:
1154 case MIDI_NOTEOFF:
1155 dwRet = 0;
1156 break;
1157 default:
1158 dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
1162 mmt->dwIndex += mmt->wEventLength;
1163 if (mmt->dwIndex < mmt->dwFirst || mmt->dwIndex >= mmt->dwLast) {
1164 mmt->wStatus = 0;
1166 if (mmt->wStatus) {
1167 MIDI_mciReadNextEvent(wmm, mmt);
1171 midiOutReset((HMIDIOUT)wmm->hMidi);
1173 dwRet = midiOutClose((HMIDIOUT)wmm->hMidi);
1174 /* to restart playing at beginning when it's over */
1175 wmm->dwPositionMS = 0;
1177 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1178 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1179 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1180 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1183 wmm->dwStatus = MCI_MODE_STOP;
1184 return dwRet;
1187 /**************************************************************************
1188 * MIDI_mciPause [internal]
1190 static DWORD MIDI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1192 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1194 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1196 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1198 if (wmm->dwStatus == MCI_MODE_PLAY) {
1199 /* stop all notes */
1200 unsigned chn;
1201 for (chn = 0; chn < 16; chn++)
1202 midiOutShortMsg((HMIDIOUT)(wmm->hMidi), 0x78B0 | chn);
1203 wmm->dwStatus = MCI_MODE_PAUSE;
1205 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1206 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1207 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1208 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1211 return 0;
1214 /**************************************************************************
1215 * MIDI_mciResume [internal]
1217 static DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1219 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1221 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1223 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1225 if (wmm->dwStatus == MCI_MODE_PAUSE) {
1226 wmm->wStartedPlaying = FALSE;
1227 wmm->dwStatus = MCI_MODE_PLAY;
1229 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1230 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1231 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1232 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1234 return 0;
1237 /**************************************************************************
1238 * MIDI_mciSet [internal]
1240 static DWORD MIDI_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SEQ_SET_PARMS lpParms)
1242 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1244 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1246 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1247 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1249 if (dwFlags & MCI_SET_TIME_FORMAT) {
1250 switch (lpParms->dwTimeFormat) {
1251 case MCI_FORMAT_MILLISECONDS:
1252 TRACE("MCI_FORMAT_MILLISECONDS !\n");
1253 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
1254 break;
1255 case MCI_FORMAT_SMPTE_24:
1256 TRACE("MCI_FORMAT_SMPTE_24 !\n");
1257 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24;
1258 break;
1259 case MCI_FORMAT_SMPTE_25:
1260 TRACE("MCI_FORMAT_SMPTE_25 !\n");
1261 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25;
1262 break;
1263 case MCI_FORMAT_SMPTE_30:
1264 TRACE("MCI_FORMAT_SMPTE_30 !\n");
1265 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30;
1266 break;
1267 default:
1268 WARN("Bad time format %u!\n", lpParms->dwTimeFormat);
1269 return MCIERR_BAD_TIME_FORMAT;
1272 if (dwFlags & MCI_SET_VIDEO) {
1273 TRACE("No support for video !\n");
1274 return MCIERR_UNSUPPORTED_FUNCTION;
1276 if (dwFlags & MCI_SET_DOOR_OPEN) {
1277 TRACE("No support for door open !\n");
1278 return MCIERR_UNSUPPORTED_FUNCTION;
1280 if (dwFlags & MCI_SET_DOOR_CLOSED) {
1281 TRACE("No support for door close !\n");
1282 return MCIERR_UNSUPPORTED_FUNCTION;
1284 if (dwFlags & MCI_SET_AUDIO) {
1285 if (dwFlags & MCI_SET_ON) {
1286 TRACE("MCI_SET_ON audio !\n");
1287 } else if (dwFlags & MCI_SET_OFF) {
1288 TRACE("MCI_SET_OFF audio !\n");
1289 } else {
1290 WARN("MCI_SET_AUDIO without SET_ON or SET_OFF\n");
1291 return MCIERR_BAD_INTEGER;
1294 switch (lpParms->dwAudio)
1296 case MCI_SET_AUDIO_ALL: TRACE("MCI_SET_AUDIO_ALL !\n"); break;
1297 case MCI_SET_AUDIO_LEFT: TRACE("MCI_SET_AUDIO_LEFT !\n"); break;
1298 case MCI_SET_AUDIO_RIGHT: TRACE("MCI_SET_AUDIO_RIGHT !\n"); break;
1299 default: WARN("Unknown audio channel %u\n", lpParms->dwAudio); break;
1303 if (dwFlags & MCI_SEQ_SET_MASTER)
1304 TRACE("MCI_SEQ_SET_MASTER !\n");
1305 if (dwFlags & MCI_SEQ_SET_SLAVE)
1306 TRACE("MCI_SEQ_SET_SLAVE !\n");
1307 if (dwFlags & MCI_SEQ_SET_OFFSET)
1308 TRACE("MCI_SEQ_SET_OFFSET !\n");
1309 if (dwFlags & MCI_SEQ_SET_PORT) {
1310 TRACE("MCI_SEQ_SET_PORT = %d\n", lpParms->dwPort);
1311 if ((UINT16)lpParms->dwPort != (UINT16)MIDI_MAPPER &&
1312 (UINT16)lpParms->dwPort >= midiOutGetNumDevs())
1313 /* FIXME: input/output port distinction? */
1314 return MCIERR_SEQ_PORT_NONEXISTENT;
1315 /* FIXME: Native manages to swap the device while playing! */
1316 wmm->wPort = lpParms->dwPort;
1318 if (dwFlags & MCI_SEQ_SET_TEMPO)
1319 TRACE("MCI_SEQ_SET_TEMPO !\n");
1320 return 0;
1323 /**************************************************************************
1324 * MIDI_mciStatus [internal]
1326 static DWORD MIDI_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
1328 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1329 DWORD ret = 0;
1331 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1333 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1334 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1336 if (dwFlags & MCI_STATUS_ITEM) {
1337 switch (lpParms->dwItem) {
1338 case MCI_STATUS_CURRENT_TRACK:
1339 /* FIXME in Format 2 */
1340 lpParms->dwReturn = 1;
1341 TRACE("MCI_STATUS_CURRENT_TRACK => %lu\n", lpParms->dwReturn);
1342 break;
1343 case MCI_STATUS_LENGTH:
1344 if ((dwFlags & MCI_TRACK) && wmm->wFormat == 2) {
1345 if (lpParms->dwTrack >= wmm->nTracks)
1346 return MCIERR_BAD_INTEGER;
1347 /* FIXME: this is wrong if there is a tempo change inside the file */
1348 lpParms->dwReturn = MIDI_ConvertPulseToMS(wmm, wmm->tracks[lpParms->dwTrack].dwLength);
1349 } else {
1350 lpParms->dwReturn = MIDI_GetMThdLengthMS(wmm);
1352 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm, lpParms->dwReturn);
1353 TRACE("MCI_STATUS_LENGTH => %lu\n", lpParms->dwReturn);
1354 break;
1355 case MCI_STATUS_MODE:
1356 TRACE("MCI_STATUS_MODE => %u\n", wmm->dwStatus);
1357 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwStatus, wmm->dwStatus);
1358 ret = MCI_RESOURCE_RETURNED;
1359 break;
1360 case MCI_STATUS_MEDIA_PRESENT:
1361 TRACE("MCI_STATUS_MEDIA_PRESENT => TRUE\n");
1362 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1363 ret = MCI_RESOURCE_RETURNED;
1364 break;
1365 case MCI_STATUS_NUMBER_OF_TRACKS:
1366 lpParms->dwReturn = (wmm->wFormat == 2) ? wmm->nTracks : 1;
1367 TRACE("MCI_STATUS_NUMBER_OF_TRACKS => %lu\n", lpParms->dwReturn);
1368 break;
1369 case MCI_STATUS_POSITION:
1370 /* FIXME: do I need to use MCI_TRACK ? */
1371 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm,
1372 (dwFlags & MCI_STATUS_START) ? 0 : wmm->dwPositionMS);
1373 TRACE("MCI_STATUS_POSITION %s => %lu\n",
1374 (dwFlags & MCI_STATUS_START) ? "start" : "current", lpParms->dwReturn);
1375 break;
1376 case MCI_STATUS_READY:
1377 lpParms->dwReturn = (wmm->dwStatus == MCI_MODE_NOT_READY) ?
1378 MAKEMCIRESOURCE(FALSE, MCI_FALSE) : MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1379 ret = MCI_RESOURCE_RETURNED;
1380 TRACE("MCI_STATUS_READY = %u\n", LOWORD(lpParms->dwReturn));
1381 break;
1382 case MCI_STATUS_TIME_FORMAT:
1383 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwMciTimeFormat, MCI_FORMAT_RETURN_BASE + wmm->dwMciTimeFormat);
1384 TRACE("MCI_STATUS_TIME_FORMAT => %u\n", LOWORD(lpParms->dwReturn));
1385 ret = MCI_RESOURCE_RETURNED;
1386 break;
1387 case MCI_SEQ_STATUS_DIVTYPE:
1388 TRACE("MCI_SEQ_STATUS_DIVTYPE !\n");
1389 if (wmm->nDivision > 0x8000) {
1390 switch (wmm->nDivision) {
1391 case 0xE8: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_24; break; /* -24 */
1392 case 0xE7: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_25; break; /* -25 */
1393 case 0xE3: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
1394 case 0xE2: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30; break; /* -30 */
1395 default: FIXME("There is a bad bad programmer\n");
1397 } else {
1398 lpParms->dwReturn = MCI_SEQ_DIV_PPQN;
1400 lpParms->dwReturn = MAKEMCIRESOURCE(lpParms->dwReturn,lpParms->dwReturn);
1401 ret = MCI_RESOURCE_RETURNED;
1402 break;
1403 case MCI_SEQ_STATUS_MASTER:
1404 TRACE("MCI_SEQ_STATUS_MASTER !\n");
1405 lpParms->dwReturn = 0;
1406 break;
1407 case MCI_SEQ_STATUS_SLAVE:
1408 TRACE("MCI_SEQ_STATUS_SLAVE !\n");
1409 lpParms->dwReturn = 0;
1410 break;
1411 case MCI_SEQ_STATUS_OFFSET:
1412 TRACE("MCI_SEQ_STATUS_OFFSET !\n");
1413 lpParms->dwReturn = 0;
1414 break;
1415 case MCI_SEQ_STATUS_PORT:
1416 if (wmm->wPort != (UINT16)MIDI_MAPPER)
1417 lpParms->dwReturn = wmm->wPort;
1418 else {
1419 lpParms->dwReturn = MAKEMCIRESOURCE(MIDI_MAPPER, MCI_SEQ_MAPPER_S);
1420 ret = MCI_RESOURCE_RETURNED;
1422 TRACE("MCI_SEQ_STATUS_PORT (%u) => %d\n", wmm->wDevID, wmm->wPort);
1423 break;
1424 case MCI_SEQ_STATUS_TEMPO:
1425 TRACE("MCI_SEQ_STATUS_TEMPO !\n");
1426 lpParms->dwReturn = wmm->dwTempo;
1427 break;
1428 default:
1429 FIXME("Unknown command %08X !\n", lpParms->dwItem);
1430 return MCIERR_UNRECOGNIZED_COMMAND;
1432 } else {
1433 WARN("No Status-Item!\n");
1434 return MCIERR_UNRECOGNIZED_COMMAND;
1436 if (dwFlags & MCI_NOTIFY) {
1437 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1438 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1439 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1441 return ret;
1444 /**************************************************************************
1445 * MIDI_mciGetDevCaps [internal]
1447 static DWORD MIDI_mciGetDevCaps(UINT wDevID, DWORD dwFlags,
1448 LPMCI_GETDEVCAPS_PARMS lpParms)
1450 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1451 DWORD ret;
1453 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1455 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1456 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1458 if (dwFlags & MCI_GETDEVCAPS_ITEM) {
1459 switch (lpParms->dwItem) {
1460 case MCI_GETDEVCAPS_DEVICE_TYPE:
1461 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE !\n");
1462 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_SEQUENCER, MCI_DEVTYPE_SEQUENCER);
1463 ret = MCI_RESOURCE_RETURNED;
1464 break;
1465 case MCI_GETDEVCAPS_HAS_AUDIO:
1466 TRACE("MCI_GETDEVCAPS_HAS_AUDIO !\n");
1467 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1468 ret = MCI_RESOURCE_RETURNED;
1469 break;
1470 case MCI_GETDEVCAPS_HAS_VIDEO:
1471 TRACE("MCI_GETDEVCAPS_HAS_VIDEO !\n");
1472 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1473 ret = MCI_RESOURCE_RETURNED;
1474 break;
1475 case MCI_GETDEVCAPS_USES_FILES:
1476 TRACE("MCI_GETDEVCAPS_USES_FILES !\n");
1477 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1478 ret = MCI_RESOURCE_RETURNED;
1479 break;
1480 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
1481 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE !\n");
1482 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1483 ret = MCI_RESOURCE_RETURNED;
1484 break;
1485 case MCI_GETDEVCAPS_CAN_EJECT:
1486 TRACE("MCI_GETDEVCAPS_CAN_EJECT !\n");
1487 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1488 ret = MCI_RESOURCE_RETURNED;
1489 break;
1490 case MCI_GETDEVCAPS_CAN_PLAY:
1491 TRACE("MCI_GETDEVCAPS_CAN_PLAY !\n");
1492 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1493 ret = MCI_RESOURCE_RETURNED;
1494 break;
1495 case MCI_GETDEVCAPS_CAN_RECORD:
1496 TRACE("MCI_GETDEVCAPS_CAN_RECORD !\n");
1497 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1498 ret = MCI_RESOURCE_RETURNED;
1499 break;
1500 case MCI_GETDEVCAPS_CAN_SAVE:
1501 TRACE("MCI_GETDEVCAPS_CAN_SAVE !\n");
1502 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1503 ret = MCI_RESOURCE_RETURNED;
1504 break;
1505 default:
1506 FIXME("Unknown capability (%08x) !\n", lpParms->dwItem);
1507 return MCIERR_UNRECOGNIZED_COMMAND;
1509 } else {
1510 WARN("No GetDevCaps-Item !\n");
1511 return MCIERR_UNRECOGNIZED_COMMAND;
1513 return ret;
1516 /**************************************************************************
1517 * MIDI_mciInfo [internal]
1519 static DWORD MIDI_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMSW lpParms)
1521 LPCWSTR str = 0;
1522 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1523 DWORD ret = 0;
1524 static const WCHAR wszMidiSeq[] = {'W','i','n','e','\'','s',' ','M','I','D','I',' ','s','e','q','u','e','n','c','e','r',0};
1526 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1528 if (lpParms == NULL || lpParms->lpstrReturn == NULL)
1529 return MCIERR_NULL_PARAMETER_BLOCK;
1530 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1532 TRACE("buf=%p, len=%u\n", lpParms->lpstrReturn, lpParms->dwRetSize);
1534 switch (dwFlags & ~(MCI_WAIT|MCI_NOTIFY)) {
1535 case MCI_INFO_PRODUCT: str = wszMidiSeq; break;
1536 case MCI_INFO_FILE: str = wmm->lpstrElementName; break;
1537 case MCI_INFO_COPYRIGHT: str = wmm->lpstrCopyright; break;
1538 case MCI_INFO_NAME: str = wmm->lpstrName; break;
1539 default:
1540 WARN("Don't know this info command (%u)\n", dwFlags);
1541 return MCIERR_UNRECOGNIZED_COMMAND;
1543 if (!ret) {
1544 if (lpParms->dwRetSize) {
1545 WCHAR zero = 0;
1546 /* FIXME? Since NT, mciwave, mciseq and mcicda set dwRetSize
1547 * to the number of characters written, excluding \0. */
1548 lstrcpynW(lpParms->lpstrReturn, str ? str : &zero, lpParms->dwRetSize);
1549 } else ret = MCIERR_PARAM_OVERFLOW;
1551 return ret;
1554 /**************************************************************************
1555 * MIDI_mciSeek [internal]
1557 static DWORD MIDI_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
1559 DWORD ret = 0;
1560 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1562 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1564 if (lpParms == NULL) {
1565 ret = MCIERR_NULL_PARAMETER_BLOCK;
1566 } else if (wmm == NULL) {
1567 ret = MCIERR_INVALID_DEVICE_ID;
1568 } else {
1569 MIDI_mciStop(wDevID, MCI_WAIT, 0);
1571 if (dwFlags & MCI_SEEK_TO_START) {
1572 wmm->dwPositionMS = 0;
1573 } else if (dwFlags & MCI_SEEK_TO_END) {
1574 wmm->dwPositionMS = 0xFFFFFFFF; /* FIXME */
1575 } else if (dwFlags & MCI_TO) {
1576 wmm->dwPositionMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
1577 } else {
1578 WARN("dwFlag doesn't tell where to seek to...\n");
1579 return MCIERR_MISSING_PARAMETER;
1582 TRACE("Seeking to position=%u ms\n", wmm->dwPositionMS);
1584 if (dwFlags & MCI_NOTIFY) {
1585 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1586 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1587 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1590 return ret;
1593 /*======================================================================*
1594 * MIDI entry points *
1595 *======================================================================*/
1597 /**************************************************************************
1598 * DriverProc (MCISEQ.@)
1600 LRESULT CALLBACK MCIMIDI_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
1601 LPARAM dwParam1, LPARAM dwParam2)
1603 switch (wMsg) {
1604 case DRV_LOAD: return 1;
1605 case DRV_FREE: return 1;
1606 case DRV_ENABLE: return 1;
1607 case DRV_DISABLE: return 1;
1608 case DRV_QUERYCONFIGURE: return 1;
1609 case DRV_CONFIGURE: MessageBoxA(0, "Sample Midi Driver !", "OSS Driver", MB_OK); return 1;
1610 case DRV_INSTALL: return DRVCNF_RESTART;
1611 case DRV_REMOVE: return DRVCNF_RESTART;
1612 case DRV_OPEN: return MIDI_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
1613 case DRV_CLOSE: return MIDI_drvClose(dwDevID);
1616 if (dwDevID == 0xFFFFFFFF) return MCIERR_UNSUPPORTED_FUNCTION;
1618 switch (wMsg) {
1619 case MCI_OPEN_DRIVER: return MIDI_mciOpen (dwDevID, dwParam1, (LPMCI_OPEN_PARMSW) dwParam2);
1620 case MCI_CLOSE_DRIVER: return MIDI_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1621 case MCI_PLAY: return MIDI_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
1622 case MCI_STOP: return MIDI_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1623 case MCI_SET: return MIDI_mciSet (dwDevID, dwParam1, (LPMCI_SEQ_SET_PARMS) dwParam2);
1624 case MCI_PAUSE: return MIDI_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1625 case MCI_RESUME: return MIDI_mciResume (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1626 case MCI_STATUS: return MIDI_mciStatus (dwDevID, dwParam1, (LPMCI_STATUS_PARMS) dwParam2);
1627 case MCI_GETDEVCAPS: return MIDI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2);
1628 case MCI_INFO: return MIDI_mciInfo (dwDevID, dwParam1, (LPMCI_INFO_PARMSW) dwParam2);
1629 case MCI_SEEK: return MIDI_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
1630 /* commands that should report an error */
1631 case MCI_RECORD:
1632 case MCI_LOAD:
1633 case MCI_SAVE:
1634 case MCI_FREEZE:
1635 case MCI_PUT:
1636 case MCI_WINDOW:
1637 case MCI_REALIZE:
1638 case MCI_UNFREEZE:
1639 case MCI_UPDATE:
1640 case MCI_WHERE:
1641 case MCI_STEP:
1642 case MCI_SPIN:
1643 case MCI_ESCAPE:
1644 case MCI_COPY:
1645 case MCI_CUT:
1646 case MCI_DELETE:
1647 case MCI_PASTE:
1648 TRACE("Unsupported command [0x%x]\n", wMsg);
1649 break;
1650 case MCI_OPEN:
1651 case MCI_CLOSE:
1652 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1653 break;
1654 default:
1655 TRACE("Sending msg [%u] to default driver proc\n", wMsg);
1656 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1658 return MCIERR_UNSUPPORTED_FUNCTION;