Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / mciseq / mcimidi.c
blob2783c079a860bbcb5015853e5d014fe465474817
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 HANDLE hCallback; /* Callback handle for pending notification */
65 HMMIO hFile; /* mmio file handle open as Element */
66 LPWSTR lpstrElementName; /* Name of file (if any) */
67 LPWSTR lpstrCopyright;
68 LPWSTR lpstrName;
69 WORD wPort; /* the WINMM device unit */
70 WORD dwStatus; /* one from MCI_MODE_xxxx */
71 DWORD dwMciTimeFormat; /* One of the supported MCI_FORMAT_xxxx */
72 WORD wFormat; /* Format of MIDI hFile (0, 1 or 2) */
73 WORD nTracks; /* Number of tracks in hFile */
74 WORD nDivision; /* Number of division in hFile PPQN or SMPTE */
75 WORD wStartedPlaying;
76 DWORD dwTempo; /* Tempo (# of 1/4 note per second */
77 MCI_MIDITRACK* tracks; /* Content of each track */
78 DWORD dwPulse;
79 DWORD dwPositionMS;
80 DWORD dwStartTicks;
81 } WINE_MCIMIDI;
83 /* ===================================================================
84 * ===================================================================
85 * FIXME: should be using the new mmThreadXXXX functions from WINMM
86 * instead of those
87 * it would require to add a wine internal flag to mmThreadCreate
88 * in order to pass a 32 bit function instead of a 16 bit
89 * ===================================================================
90 * =================================================================== */
92 struct SCA {
93 UINT wDevID;
94 UINT wMsg;
95 DWORD_PTR dwParam1;
96 DWORD_PTR dwParam2;
99 /* EPP DWORD WINAPI mciSendCommandA(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2); */
101 /**************************************************************************
102 * MCI_SCAStarter [internal]
104 static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
106 struct SCA* sca = arg;
107 DWORD ret;
109 TRACE("In thread before async command (%08x,%u,%08lx,%08lx)\n",
110 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
111 ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2);
112 TRACE("In thread after async command (%08x,%u,%08lx,%08lx)\n",
113 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
114 HeapFree(GetProcessHeap(), 0, sca);
115 return ret;
118 /**************************************************************************
119 * MCI_SendCommandAsync [internal]
121 static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD_PTR dwParam1,
122 DWORD_PTR dwParam2, UINT size)
124 HANDLE handle;
125 struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA) + size);
127 if (sca == 0)
128 return MCIERR_OUT_OF_MEMORY;
130 sca->wDevID = wDevID;
131 sca->wMsg = wMsg;
132 sca->dwParam1 = dwParam1;
134 if (size && dwParam2) {
135 sca->dwParam2 = (DWORD_PTR)sca + sizeof(struct SCA);
136 /* copy structure passed by program in dwParam2 to be sure
137 * we can still use it whatever the program does
139 memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size);
140 } else {
141 sca->dwParam2 = dwParam2;
144 if ((handle = CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL)) == 0) {
145 WARN("Couldn't allocate thread for async command handling, sending synchronously\n");
146 return MCI_SCAStarter(sca);
148 SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
149 CloseHandle(handle);
150 return 0;
153 /*======================================================================*
154 * MCI MIDI implementation *
155 *======================================================================*/
157 static DWORD MIDI_mciResume(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
159 /**************************************************************************
160 * MIDI_drvOpen [internal]
162 static DWORD MIDI_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
164 WINE_MCIMIDI* wmm;
166 if (!modp) return 0xFFFFFFFF;
168 wmm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIMIDI));
170 if (!wmm)
171 return 0;
173 wmm->wDevID = modp->wDeviceID;
174 mciSetDriverData(wmm->wDevID, (DWORD_PTR)wmm);
175 modp->wCustomCommandTable = MCI_NO_COMMAND_TABLE;
176 modp->wType = MCI_DEVTYPE_SEQUENCER;
177 return modp->wDeviceID;
180 /**************************************************************************
181 * MCIMIDI_drvClose [internal]
183 static DWORD MIDI_drvClose(DWORD dwDevID)
185 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(dwDevID);
187 if (wmm) {
188 HeapFree(GetProcessHeap(), 0, wmm);
189 mciSetDriverData(dwDevID, 0);
190 return 1;
192 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
195 /**************************************************************************
196 * MIDI_mciGetOpenDev [internal]
198 static WINE_MCIMIDI* MIDI_mciGetOpenDev(MCIDEVICEID wDevID, UINT wMsg)
200 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
202 if (wmm == NULL || ((wmm->nUseCount == 0) ^ (wMsg == MCI_OPEN_DRIVER))) {
203 WARN("Invalid wDevID=%u\n", wDevID);
204 return 0;
206 return wmm;
209 /**************************************************************************
210 * MIDI_mciNotify [internal]
212 * Notifications in MCI work like a 1-element queue.
213 * Each new notification request supersedes the previous one.
214 * This affects Play and Record; other commands are immediate.
216 static void MIDI_mciNotify(DWORD_PTR hWndCallBack, WINE_MCIMIDI* wmm, UINT wStatus)
218 /* We simply save one parameter by not passing the wDevID local
219 * to the command. They are the same (via mciGetDriverData).
221 MCIDEVICEID wDevID = wmm->wDevID;
222 HANDLE old = InterlockedExchangePointer(&wmm->hCallback, NULL);
223 if (old) mciDriverNotify(old, wDevID, MCI_NOTIFY_SUPERSEDED);
224 mciDriverNotify(HWND_32(LOWORD(hWndCallBack)), wDevID, wStatus);
227 /**************************************************************************
228 * MIDI_mciReadByte [internal]
230 static DWORD MIDI_mciReadByte(WINE_MCIMIDI* wmm, BYTE *lpbyt)
232 DWORD ret = 0;
234 if (lpbyt == NULL ||
235 mmioRead(wmm->hFile, (HPSTR)lpbyt, sizeof(BYTE)) != (long)sizeof(BYTE)) {
236 WARN("Error reading wmm=%p\n", wmm);
237 ret = MCIERR_INVALID_FILE;
240 return ret;
243 /**************************************************************************
244 * MIDI_mciReadWord [internal]
246 static DWORD MIDI_mciReadWord(WINE_MCIMIDI* wmm, LPWORD lpw)
248 BYTE hibyte, lobyte;
249 DWORD ret = MCIERR_INVALID_FILE;
251 if (lpw != NULL &&
252 MIDI_mciReadByte(wmm, &hibyte) == 0 &&
253 MIDI_mciReadByte(wmm, &lobyte) == 0) {
254 *lpw = ((WORD)hibyte << 8) + lobyte;
255 ret = 0;
257 return ret;
260 /**************************************************************************
261 * MIDI_mciReadLong [internal]
263 static DWORD MIDI_mciReadLong(WINE_MCIMIDI* wmm, LPDWORD lpdw)
265 WORD hiword, loword;
266 DWORD ret = MCIERR_INVALID_FILE;
268 if (lpdw != NULL &&
269 MIDI_mciReadWord(wmm, &hiword) == 0 &&
270 MIDI_mciReadWord(wmm, &loword) == 0) {
271 *lpdw = MAKELONG(loword, hiword);
272 ret = 0;
274 return ret;
277 /**************************************************************************
278 * MIDI_mciReadVaryLen [internal]
280 static WORD MIDI_mciReadVaryLen(WINE_MCIMIDI* wmm, LPDWORD lpdw)
282 BYTE byte;
283 DWORD value = 0;
284 WORD ret = 0;
286 if (lpdw == NULL) {
287 ret = MCIERR_INVALID_FILE;
288 } else {
289 do {
290 if (MIDI_mciReadByte(wmm, &byte) != 0) {
291 return 0;
293 value = (value << 7) + (byte & 0x7F);
294 ret++;
295 } while (byte & 0x80);
296 *lpdw = value;
298 TRACE("val=%08X\n", value);
301 return ret;
304 /**************************************************************************
305 * MIDI_mciReadNextEvent [internal]
307 static DWORD MIDI_mciReadNextEvent(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
309 BYTE b1, b2 = 0, b3;
310 WORD hw = 0;
311 DWORD evtPulse;
312 DWORD evtLength;
313 DWORD tmp;
315 if (mmioSeek(wmm->hFile, mmt->dwIndex, SEEK_SET) != mmt->dwIndex) {
316 WARN("Can't seek at %08X\n", mmt->dwIndex);
317 return MCIERR_INVALID_FILE;
319 evtLength = MIDI_mciReadVaryLen(wmm, &evtPulse) + 1; /* > 0 */
320 MIDI_mciReadByte(wmm, &b1);
321 switch (b1) {
322 case 0xF0:
323 case 0xF7:
324 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
325 evtLength += tmp;
326 break;
327 case 0xFF:
328 MIDI_mciReadByte(wmm, &b2); evtLength++;
330 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
331 if (evtLength >= 0x10000u) {
332 /* this limitation shouldn't be a problem */
333 WARN("Ouch !! Implementation limitation to 64k bytes for a MIDI event is overflowed\n");
334 hw = 0xFFFF;
335 } else {
336 hw = LOWORD(evtLength);
338 evtLength += tmp;
339 break;
340 default:
341 if (b1 & 0x80) { /* use running status ? */
342 mmt->wLastCommand = b1;
343 MIDI_mciReadByte(wmm, &b2); evtLength++;
344 } else {
345 b2 = b1;
346 b1 = mmt->wLastCommand;
348 switch ((b1 >> 4) & 0x07) {
349 case 0: case 1: case 2: case 3: case 6:
350 MIDI_mciReadByte(wmm, &b3); evtLength++;
351 hw = b3;
352 break;
353 case 4: case 5:
354 break;
355 case 7:
356 WARN("Strange indeed b1=0x%02x\n", b1);
358 break;
360 if (mmt->dwIndex + evtLength > mmt->dwLast)
361 return MCIERR_INTERNAL;
363 mmt->dwEventPulse += evtPulse;
364 mmt->dwEventData = (hw << 16) + (b2 << 8) + b1;
365 mmt->wEventLength = evtLength;
368 TRACE("[%u] => pulse=%08x(%08x), data=%08x, length=%u\n",
369 mmt->wTrackNr, mmt->dwEventPulse, evtPulse,
370 mmt->dwEventData, mmt->wEventLength);
372 return 0;
375 /**************************************************************************
376 * MIDI_mciReadMTrk [internal]
378 static DWORD MIDI_mciReadMTrk(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
380 DWORD toberead;
381 FOURCC fourcc;
383 if (mmioRead(wmm->hFile, (HPSTR)&fourcc, (long)sizeof(FOURCC)) !=
384 (long)sizeof(FOURCC)) {
385 return MCIERR_INVALID_FILE;
388 if (fourcc != mmioFOURCC('M', 'T', 'r', 'k')) {
389 WARN("Can't synchronize on 'MTrk' !\n");
390 return MCIERR_INVALID_FILE;
393 if (MIDI_mciReadLong(wmm, &toberead) != 0) {
394 return MCIERR_INVALID_FILE;
396 mmt->dwFirst = mmioSeek(wmm->hFile, 0, SEEK_CUR); /* >= 0 */
397 mmt->dwLast = mmt->dwFirst + toberead;
399 /* compute # of pulses in this track */
400 mmt->dwIndex = mmt->dwFirst;
401 mmt->dwEventPulse = 0;
403 while (MIDI_mciReadNextEvent(wmm, mmt) == 0 && LOWORD(mmt->dwEventData) != 0x2FFF) {
404 char buf[1024];
405 WORD len;
407 mmt->dwIndex += mmt->wEventLength;
409 switch (LOWORD(mmt->dwEventData)) {
410 case 0x02FF:
411 case 0x03FF:
412 /* position after meta data header */
413 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
414 len = mmt->wEventLength - HIWORD(mmt->dwEventData);
416 if (len >= sizeof(buf)) {
417 WARN("Buffer for text is too small (%u are needed)\n", len);
418 len = sizeof(buf) - 1;
420 if (mmioRead(wmm->hFile, buf, len) == len) {
421 buf[len] = 0; /* end string in case */
422 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
423 case 0x02:
424 if (wmm->lpstrCopyright) {
425 WARN("Two copyright notices (%s|%s)\n", debugstr_w(wmm->lpstrCopyright), buf);
426 } else {
427 len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
428 wmm->lpstrCopyright = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
429 MultiByteToWideChar( CP_ACP, 0, buf, -1, wmm->lpstrCopyright, len );
431 break;
432 case 0x03:
433 if (wmm->lpstrName) {
434 WARN("Two names (%s|%s)\n", debugstr_w(wmm->lpstrName), buf);
435 } else {
436 len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
437 wmm->lpstrName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
438 MultiByteToWideChar( CP_ACP, 0, buf, -1, wmm->lpstrName, len );
440 break;
443 break;
446 mmt->dwLength = mmt->dwEventPulse;
448 TRACE("Track %u has %u bytes and %u pulses\n", mmt->wTrackNr, toberead, mmt->dwLength);
450 /* reset track data */
451 mmt->wStatus = 1; /* ok, playing */
452 mmt->dwIndex = mmt->dwFirst;
453 mmt->dwEventPulse = 0;
455 if (mmioSeek(wmm->hFile, 0, SEEK_CUR) != mmt->dwLast) {
456 WARN("Ouch, out of sync seek=%u track=%u\n",
457 mmioSeek(wmm->hFile, 0, SEEK_CUR), mmt->dwLast);
458 /* position at end of this track, to be ready to read next track */
459 mmioSeek(wmm->hFile, mmt->dwLast, SEEK_SET);
462 return 0;
465 /**************************************************************************
466 * MIDI_mciReadMThd [internal]
468 static DWORD MIDI_mciReadMThd(WINE_MCIMIDI* wmm, DWORD dwOffset)
470 DWORD toberead;
471 FOURCC fourcc;
472 WORD nt;
474 TRACE("(%p, %08X);\n", wmm, dwOffset);
476 if (mmioSeek(wmm->hFile, dwOffset, SEEK_SET) != dwOffset) {
477 WARN("Can't seek at %08X begin of 'MThd'\n", dwOffset);
478 return MCIERR_INVALID_FILE;
480 if (mmioRead(wmm->hFile, (HPSTR)&fourcc,
481 (long) sizeof(FOURCC)) != (long) sizeof(FOURCC))
482 return MCIERR_INVALID_FILE;
484 if (fourcc != mmioFOURCC('M', 'T', 'h', 'd')) {
485 WARN("Can't synchronize on 'MThd' !\n");
486 return MCIERR_INVALID_FILE;
489 if (MIDI_mciReadLong(wmm, &toberead) != 0 || toberead < 3 * sizeof(WORD))
490 return MCIERR_INVALID_FILE;
492 if (MIDI_mciReadWord(wmm, &wmm->wFormat) != 0 ||
493 MIDI_mciReadWord(wmm, &wmm->nTracks) != 0 ||
494 MIDI_mciReadWord(wmm, &wmm->nDivision) != 0) {
495 return MCIERR_INVALID_FILE;
498 TRACE("toberead=0x%08X, wFormat=0x%04X nTracks=0x%04X nDivision=0x%04X\n",
499 toberead, wmm->wFormat, wmm->nTracks, wmm->nDivision);
501 /* MS doc says that the MIDI MCI time format must be put by default to the format
502 * stored in the MIDI file...
504 if (wmm->nDivision > 0x8000) {
505 /* eric.pouech@lemel.fr 98/11
506 * I did not check this very code (pulses are expressed as SMPTE sub-frames).
507 * In about 40 MB of MIDI files I have, none was SMPTE based...
508 * I'm just wondering if this is widely used :-). So, if someone has one of
509 * these files, I'd like to know about it.
511 FIXME("Handling SMPTE time in MIDI files has not been tested\n"
512 "Please report to comp.emulators.ms-windows.wine with MIDI file !\n");
514 switch (HIBYTE(wmm->nDivision)) {
515 case 0xE8: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24; break; /* -24 */
516 case 0xE7: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25; break; /* -25 */
517 case 0xE3: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
518 case 0xE2: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30; break; /* -30 */
519 default:
520 WARN("Unsupported number of frames %d\n", -(char)HIBYTE(wmm->nDivision));
521 return MCIERR_INVALID_FILE;
523 switch (LOBYTE(wmm->nDivision)) {
524 case 4: /* MIDI Time Code */
525 case 8:
526 case 10:
527 case 80: /* SMPTE bit resolution */
528 case 100:
529 default:
530 WARN("Unsupported number of sub-frames %d\n", LOBYTE(wmm->nDivision));
531 return MCIERR_INVALID_FILE;
533 } else if (wmm->nDivision == 0) {
534 WARN("Number of division is 0, can't support that !!\n");
535 return MCIERR_INVALID_FILE;
536 } else {
537 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
540 switch (wmm->wFormat) {
541 case 0:
542 if (wmm->nTracks != 1) {
543 WARN("Got type 0 file whose number of track is not 1. Setting it to 1\n");
544 wmm->nTracks = 1;
546 break;
547 case 1:
548 case 2:
549 break;
550 default:
551 WARN("Handling MIDI files which format = %d is not (yet) supported\n"
552 "Please report with MIDI file !\n", wmm->wFormat);
553 return MCIERR_INVALID_FILE;
556 if (wmm->nTracks & 0x8000) {
557 /* this shouldn't be a problem... */
558 WARN("Ouch !! Implementation limitation to 32k tracks per MIDI file is overflowed\n");
559 wmm->nTracks = 0x7FFF;
562 if ((wmm->tracks = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_MIDITRACK) * wmm->nTracks)) == NULL) {
563 return MCIERR_OUT_OF_MEMORY;
566 toberead -= 3 * sizeof(WORD);
567 if (toberead > 0) {
568 TRACE("Size of MThd > 6, skipping %d extra bytes\n", toberead);
569 mmioSeek(wmm->hFile, toberead, SEEK_CUR);
572 for (nt = 0; nt < wmm->nTracks; nt++) {
573 wmm->tracks[nt].wTrackNr = nt;
574 if (MIDI_mciReadMTrk(wmm, &wmm->tracks[nt]) != 0) {
575 WARN("Can't read 'MTrk' header\n");
576 return MCIERR_INVALID_FILE;
580 wmm->dwTempo = 500000;
582 return 0;
585 /**************************************************************************
586 * MIDI_ConvertPulseToMS [internal]
588 static DWORD MIDI_ConvertPulseToMS(WINE_MCIMIDI* wmm, DWORD pulse)
590 DWORD ret = 0;
592 /* FIXME: this function may return false values since the tempo (wmm->dwTempo)
593 * may change during file playing
595 if (wmm->nDivision == 0) {
596 FIXME("Shouldn't happen. wmm->nDivision = 0\n");
597 } else if (wmm->nDivision > 0x8000) { /* SMPTE, unchecked FIXME? */
598 int nf = -(char)HIBYTE(wmm->nDivision); /* number of frames */
599 int nsf = LOBYTE(wmm->nDivision); /* number of sub-frames */
600 ret = (pulse * 1000) / (nf * nsf);
601 } else {
602 ret = (DWORD)((double)pulse * ((double)wmm->dwTempo / 1000) /
603 (double)wmm->nDivision);
607 TRACE("pulse=%u tempo=%u division=%u=0x%04x => ms=%u\n",
608 pulse, wmm->dwTempo, wmm->nDivision, wmm->nDivision, ret);
611 return ret;
614 #define TIME_MS_IN_ONE_HOUR (60*60*1000)
615 #define TIME_MS_IN_ONE_MINUTE (60*1000)
616 #define TIME_MS_IN_ONE_SECOND (1000)
618 /**************************************************************************
619 * MIDI_ConvertTimeFormatToMS [internal]
621 static DWORD MIDI_ConvertTimeFormatToMS(WINE_MCIMIDI* wmm, DWORD val)
623 DWORD ret = 0;
625 switch (wmm->dwMciTimeFormat) {
626 case MCI_FORMAT_MILLISECONDS:
627 ret = val;
628 break;
629 case MCI_FORMAT_SMPTE_24:
630 ret =
631 (HIBYTE(HIWORD(val)) * 125) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
632 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
633 break;
634 case MCI_FORMAT_SMPTE_25:
635 ret =
636 HIBYTE(HIWORD(val)) * 40 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
637 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
638 break;
639 case MCI_FORMAT_SMPTE_30:
640 ret =
641 (HIBYTE(HIWORD(val)) * 100) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
642 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
643 break;
644 default:
645 WARN("Bad time format %u!\n", wmm->dwMciTimeFormat);
648 TRACE("val=%u=0x%08x [tf=%u] => ret=%u\n", val, val, wmm->dwMciTimeFormat, ret);
650 return ret;
653 /**************************************************************************
654 * MIDI_ConvertMSToTimeFormat [internal]
656 static DWORD MIDI_ConvertMSToTimeFormat(WINE_MCIMIDI* wmm, DWORD _val)
658 DWORD ret = 0, val = _val;
659 DWORD h, m, s, f;
661 switch (wmm->dwMciTimeFormat) {
662 case MCI_FORMAT_MILLISECONDS:
663 ret = val;
664 break;
665 case MCI_FORMAT_SMPTE_24:
666 case MCI_FORMAT_SMPTE_25:
667 case MCI_FORMAT_SMPTE_30:
668 h = val / TIME_MS_IN_ONE_HOUR;
669 m = (val -= h * TIME_MS_IN_ONE_HOUR) / TIME_MS_IN_ONE_MINUTE;
670 s = (val -= m * TIME_MS_IN_ONE_MINUTE) / TIME_MS_IN_ONE_SECOND;
671 switch (wmm->dwMciTimeFormat) {
672 case MCI_FORMAT_SMPTE_24:
673 /* one frame is 1000/24 val long, 1000/24 == 125/3 */
674 f = (val * 3) / 125; val -= (f * 125) / 3;
675 break;
676 case MCI_FORMAT_SMPTE_25:
677 /* one frame is 1000/25 ms long, 1000/25 == 40 */
678 f = val / 40; val -= f * 40;
679 break;
680 case MCI_FORMAT_SMPTE_30:
681 /* one frame is 1000/30 ms long, 1000/30 == 100/3 */
682 f = (val * 3) / 100; val -= (f * 100) / 3;
683 break;
684 default:
685 FIXME("There must be some bad bad programmer\n");
686 f = 0;
688 /* val contains the number of ms which cannot make a complete frame */
689 /* FIXME: is this correct ? programs seem to be happy with that */
690 ret = (f << 24) | (s << 16) | (m << 8) | (h << 0);
691 break;
692 default:
693 WARN("Bad time format %u!\n", wmm->dwMciTimeFormat);
696 TRACE("val=%u [tf=%u] => ret=%u=0x%08x\n", _val, wmm->dwMciTimeFormat, ret, ret);
698 return ret;
701 /**************************************************************************
702 * MIDI_GetMThdLengthMS [internal]
704 static DWORD MIDI_GetMThdLengthMS(WINE_MCIMIDI* wmm)
706 WORD nt;
707 DWORD ret = 0;
709 for (nt = 0; nt < wmm->nTracks; nt++) {
710 if (wmm->wFormat == 2) {
711 ret += wmm->tracks[nt].dwLength;
712 } else if (wmm->tracks[nt].dwLength > ret) {
713 ret = wmm->tracks[nt].dwLength;
716 /* FIXME: this is wrong if there is a tempo change inside the file */
717 return MIDI_ConvertPulseToMS(wmm, ret);
720 /**************************************************************************
721 * MIDI_mciOpen [internal]
723 static DWORD MIDI_mciOpen(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_OPEN_PARMSW lpParms)
725 DWORD dwRet = 0;
727 TRACE("(%d, %08X, %p)\n", wmm->wDevID, dwFlags, lpParms);
729 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
730 if (dwFlags & MCI_OPEN_SHAREABLE)
731 return MCIERR_HARDWARE;
733 if (wmm->nUseCount > 0) {
734 /* The driver is already opened on this channel
735 * MIDI sequencer cannot be shared
737 return MCIERR_DEVICE_OPEN;
739 wmm->nUseCount++;
741 wmm->hFile = 0;
742 wmm->hMidi = 0;
743 wmm->wPort = MIDI_MAPPER;
744 wmm->lpstrElementName = NULL;
746 TRACE("wDevID=%d (lpParams->wDeviceID=%d)\n", wmm->wDevID, lpParms->wDeviceID);
747 /* lpParms->wDeviceID = wDevID;*/
749 if (dwFlags & MCI_OPEN_ELEMENT) {
750 TRACE("MCI_OPEN_ELEMENT %s!\n", debugstr_w(lpParms->lpstrElementName));
751 if (lpParms->lpstrElementName && strlenW(lpParms->lpstrElementName) > 0) {
752 wmm->hFile = mmioOpenW((LPWSTR)lpParms->lpstrElementName, NULL,
753 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
754 if (wmm->hFile == 0) {
755 WARN("Can't find file %s!\n", debugstr_w(lpParms->lpstrElementName));
756 wmm->nUseCount--;
757 return MCIERR_FILE_NOT_FOUND;
759 wmm->lpstrElementName = HeapAlloc(GetProcessHeap(), 0,
760 (strlenW(lpParms->lpstrElementName) + 1) * sizeof(WCHAR));
761 strcpyW(wmm->lpstrElementName, lpParms->lpstrElementName);
764 TRACE("hFile=%p\n", wmm->hFile);
766 wmm->lpstrCopyright = NULL;
767 wmm->lpstrName = NULL;
769 wmm->dwStatus = MCI_MODE_NOT_READY; /* while loading file contents */
770 /* spec says it should be the default format from the MIDI file... */
771 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
773 if (wmm->hFile != 0) {
774 MMCKINFO ckMainRIFF;
775 MMCKINFO mmckInfo;
776 DWORD dwOffset = 0;
778 if (mmioDescend(wmm->hFile, &ckMainRIFF, NULL, 0) != 0) {
779 dwRet = MCIERR_INVALID_FILE;
780 } else {
781 TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08X\n",
782 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
784 if (ckMainRIFF.ckid == FOURCC_RIFF && ckMainRIFF.fccType == mmioFOURCC('R', 'M', 'I', 'D')) {
785 mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
786 mmioSeek(wmm->hFile, ckMainRIFF.dwDataOffset + ((ckMainRIFF.cksize + 1) & ~1), SEEK_SET);
787 if (mmioDescend(wmm->hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) {
788 TRACE("... is a 'RMID' file\n");
789 dwOffset = mmckInfo.dwDataOffset;
790 } else {
791 dwRet = MCIERR_INVALID_FILE;
794 if (dwRet == 0 && MIDI_mciReadMThd(wmm, dwOffset) != 0) {
795 WARN("Can't read 'MThd' header\n");
796 dwRet = MCIERR_INVALID_FILE;
799 } else {
800 TRACE("hFile==0, setting #tracks to 0; is this correct ?\n");
801 wmm->nTracks = 0;
802 wmm->wFormat = 0;
803 wmm->nDivision = 1;
805 if (dwRet != 0) {
806 wmm->nUseCount--;
807 if (wmm->hFile != 0)
808 mmioClose(wmm->hFile, 0);
809 wmm->hFile = 0;
810 } else {
811 wmm->dwPositionMS = 0;
812 wmm->dwStatus = MCI_MODE_STOP;
813 if (dwFlags & MCI_NOTIFY)
814 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
816 return dwRet;
819 /**************************************************************************
820 * MIDI_mciStop [internal]
822 static DWORD MIDI_mciStop(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
824 DWORD dwRet = 0;
826 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
828 if (wmm->dwStatus != MCI_MODE_STOP) {
829 HANDLE old = InterlockedExchangePointer(&wmm->hCallback, NULL);
830 if (old) mciDriverNotify(old, wmm->wDevID, MCI_NOTIFY_ABORTED);
833 if (wmm->dwStatus != MCI_MODE_STOP) {
834 int oldstat = wmm->dwStatus;
836 wmm->dwStatus = MCI_MODE_NOT_READY;
837 if (oldstat == MCI_MODE_PAUSE)
838 dwRet = midiOutReset((HMIDIOUT)wmm->hMidi);
840 while (wmm->dwStatus != MCI_MODE_STOP)
841 Sleep(10);
844 /* sanity reset */
845 wmm->dwStatus = MCI_MODE_STOP;
847 if ((dwFlags & MCI_NOTIFY) && lpParms && MMSYSERR_NOERROR==dwRet)
848 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
849 return dwRet;
852 /**************************************************************************
853 * MIDI_mciClose [internal]
855 static DWORD MIDI_mciClose(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
858 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
860 if (wmm->dwStatus != MCI_MODE_STOP) {
861 /* mciStop handles MCI_NOTIFY_ABORTED */
862 MIDI_mciStop(wmm, MCI_WAIT, lpParms);
865 wmm->nUseCount--;
866 if (wmm->nUseCount == 0) {
867 if (wmm->hFile != 0) {
868 mmioClose(wmm->hFile, 0);
869 wmm->hFile = 0;
870 TRACE("hFile closed !\n");
872 HeapFree(GetProcessHeap(), 0, wmm->tracks);
873 HeapFree(GetProcessHeap(), 0, wmm->lpstrElementName);
874 HeapFree(GetProcessHeap(), 0, wmm->lpstrCopyright);
875 HeapFree(GetProcessHeap(), 0, wmm->lpstrName);
876 } else {
877 TRACE("Shouldn't happen... nUseCount=%d\n", wmm->nUseCount);
878 return MCIERR_INTERNAL;
881 if ((dwFlags & MCI_NOTIFY) && lpParms) {
882 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
884 return 0;
887 /**************************************************************************
888 * MIDI_mciFindNextEvent [internal]
890 static MCI_MIDITRACK* MIDI_mciFindNextEvent(WINE_MCIMIDI* wmm, LPDWORD hiPulse)
892 WORD cnt, nt;
893 MCI_MIDITRACK* mmt;
895 *hiPulse = 0xFFFFFFFFul;
896 cnt = 0xFFFFu;
897 for (nt = 0; nt < wmm->nTracks; nt++) {
898 mmt = &wmm->tracks[nt];
900 if (mmt->wStatus == 0)
901 continue;
902 if (mmt->dwEventPulse < *hiPulse) {
903 *hiPulse = mmt->dwEventPulse;
904 cnt = nt;
907 return (cnt == 0xFFFFu) ? 0 /* no more event on all tracks */
908 : &wmm->tracks[cnt];
911 /**************************************************************************
912 * MIDI_mciPlay [internal]
914 static DWORD MIDI_mciPlay(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
916 DWORD dwStartMS, dwEndMS;
917 DWORD dwRet = 0;
918 WORD doPlay, nt;
919 MCI_MIDITRACK* mmt;
920 DWORD hiPulse;
921 HANDLE oldcb;
923 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
925 if (wmm->hFile == 0) {
926 WARN("Can't play: no file %s!\n", debugstr_w(wmm->lpstrElementName));
927 return MCIERR_FILE_NOT_FOUND;
930 if (wmm->dwStatus != MCI_MODE_STOP) {
931 if (wmm->dwStatus == MCI_MODE_PAUSE) {
932 /* FIXME: parameters (start/end) in lpParams may not be used */
933 return MIDI_mciResume(wmm, dwFlags, (LPMCI_GENERIC_PARMS)lpParms);
935 WARN("Can't play: device is not stopped !\n");
936 return MCIERR_INTERNAL;
939 if (!(dwFlags & MCI_WAIT)) {
940 return MCI_SendCommandAsync(wmm->wDevID, MCI_PLAY, dwFlags, (DWORD_PTR)lpParms, sizeof(MCI_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 oldcb = InterlockedExchangePointer(&wmm->hCallback,
958 (dwFlags & MCI_NOTIFY) ? HWND_32(LOWORD(lpParms->dwCallback)) : NULL);
959 if (oldcb) mciDriverNotify(oldcb, wmm->wDevID, MCI_NOTIFY_ABORTED);
960 oldcb = NULL;
962 /* init tracks */
963 for (nt = 0; nt < wmm->nTracks; nt++) {
964 mmt = &wmm->tracks[nt];
966 mmt->wStatus = 1; /* ok, playing */
967 mmt->dwIndex = mmt->dwFirst;
968 if (wmm->wFormat == 2 && nt > 0) {
969 mmt->dwEventPulse = wmm->tracks[nt - 1].dwLength;
970 } else {
971 mmt->dwEventPulse = 0;
973 MIDI_mciReadNextEvent(wmm, mmt); /* FIXME == 0 */
976 dwRet = midiOutOpen((LPHMIDIOUT)&wmm->hMidi, wmm->wPort, 0L, 0L, CALLBACK_NULL);
977 if (dwRet != MMSYSERR_NOERROR) {
978 return dwRet;
981 wmm->dwPulse = 0;
982 wmm->dwTempo = 500000;
983 wmm->dwStatus = MCI_MODE_PLAY;
984 wmm->dwPositionMS = 0;
985 wmm->wStartedPlaying = FALSE;
987 while (wmm->dwStatus != MCI_MODE_STOP && wmm->dwStatus != MCI_MODE_NOT_READY) {
988 /* it seems that in case of multi-threading, gcc is optimizing just a little bit
989 * too much. Tell gcc not to optimize status value using volatile.
991 while (((volatile WINE_MCIMIDI*)wmm)->dwStatus == MCI_MODE_PAUSE);
993 doPlay = (wmm->dwPositionMS >= dwStartMS && wmm->dwPositionMS <= dwEndMS);
995 TRACE("wmm->dwStatus=%d, doPlay=%c\n", wmm->dwStatus, doPlay ? 'T' : 'F');
997 if ((mmt = MIDI_mciFindNextEvent(wmm, &hiPulse)) == NULL)
998 break; /* no more event on tracks */
1000 /* if starting playing, then set StartTicks to the value it would have had
1001 * if play had started at position 0
1003 if (doPlay && !wmm->wStartedPlaying) {
1004 wmm->dwStartTicks = GetTickCount() - MIDI_ConvertPulseToMS(wmm, wmm->dwPulse);
1005 wmm->wStartedPlaying = TRUE;
1006 TRACE("Setting dwStartTicks to %u\n", wmm->dwStartTicks);
1009 if (hiPulse > wmm->dwPulse) {
1010 wmm->dwPositionMS += MIDI_ConvertPulseToMS(wmm, hiPulse - wmm->dwPulse);
1011 if (doPlay) {
1012 DWORD togo = wmm->dwStartTicks + wmm->dwPositionMS;
1013 DWORD tc = GetTickCount();
1015 TRACE("Pulses hi=0x%08x <> cur=0x%08x\n", hiPulse, wmm->dwPulse);
1016 TRACE("Wait until %u => %u ms\n",
1017 tc - wmm->dwStartTicks, togo - wmm->dwStartTicks);
1018 if (tc < togo)
1019 Sleep(togo - tc);
1021 wmm->dwPulse = hiPulse;
1024 switch (LOBYTE(LOWORD(mmt->dwEventData))) {
1025 case 0xF0:
1026 case 0xF7: /* sysex events */
1028 FIXME("Not handling SysEx events (yet)\n");
1030 break;
1031 case 0xFF:
1032 /* position after meta data header */
1033 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
1034 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
1035 case 0x00: /* 16-bit sequence number */
1036 if (TRACE_ON(mcimidi)) {
1037 WORD twd;
1039 MIDI_mciReadWord(wmm, &twd); /* == 0 */
1040 TRACE("Got sequence number %u\n", twd);
1042 break;
1043 case 0x01: /* any text */
1044 case 0x02: /* Copyright Message text */
1045 case 0x03: /* Sequence/Track Name text */
1046 case 0x04: /* Instrument Name text */
1047 case 0x05: /* Lyric text */
1048 case 0x06: /* Marker text */
1049 case 0x07: /* Cue-point text */
1050 if (TRACE_ON(mcimidi)) {
1051 char buf[1024];
1052 WORD len = mmt->wEventLength - HIWORD(mmt->dwEventData);
1053 static const char* const info[8] = {"", "Text", "Copyright", "Seq/Trk name",
1054 "Instrument", "Lyric", "Marker", "Cue-point"};
1055 WORD idx = HIBYTE(LOWORD(mmt->dwEventData));
1057 if (len >= sizeof(buf)) {
1058 WARN("Buffer for text is too small (%u are needed)\n", len);
1059 len = sizeof(buf) - 1;
1061 if (mmioRead(wmm->hFile, buf, len) == len) {
1062 buf[len] = 0; /* end string in case */
1063 TRACE("%s => \"%s\"\n", (idx < 8 ) ? info[idx] : "", buf);
1064 } else {
1065 WARN("Couldn't read data for %s\n", (idx < 8) ? info[idx] : "");
1068 break;
1069 case 0x20:
1070 /* MIDI channel (cc) */
1071 if (FIXME_ON(mcimidi)) {
1072 BYTE bt;
1074 MIDI_mciReadByte(wmm, &bt); /* == 0 */
1075 FIXME("NIY: MIDI channel=%u, track=%u\n", bt, mmt->wTrackNr);
1077 break;
1078 case 0x21:
1079 /* MIDI port (pp) */
1080 if (FIXME_ON(mcimidi)) {
1081 BYTE bt;
1083 MIDI_mciReadByte(wmm, &bt); /* == 0 */
1084 FIXME("NIY: MIDI port=%u, track=%u\n", bt, mmt->wTrackNr);
1086 break;
1087 case 0x2F: /* end of track */
1088 mmt->wStatus = 0;
1089 break;
1090 case 0x51:/* set tempo */
1091 /* Tempo is expressed in -seconds per midi quarter note
1092 * for format 1 MIDI files, this can only be present on track #0
1094 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1095 WARN("For format #1 MIDI files, tempo can only be changed on track #0 (%u)\n", mmt->wTrackNr);
1096 } else {
1097 BYTE tbt;
1098 DWORD value = 0;
1100 MIDI_mciReadByte(wmm, &tbt); value = ((DWORD)tbt) << 16;
1101 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 8;
1102 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 0;
1103 TRACE("Setting tempo to %d (BPM=%d)\n", wmm->dwTempo, (value) ? (60000000 / value) : 0);
1104 wmm->dwTempo = value;
1106 break;
1107 case 0x54: /* (hour) (min) (second) (frame) (fractional-frame) - SMPTE track start */
1108 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1109 WARN("For format #1 MIDI files, SMPTE track start can only be expressed on track #0 (%u)\n", mmt->wTrackNr);
1110 } if (mmt->dwEventPulse != 0) {
1111 WARN("SMPTE track start can only be expressed at start of track (%u)\n", mmt->dwEventPulse);
1112 } else {
1113 BYTE h, m, s, f, ff;
1115 MIDI_mciReadByte(wmm, &h);
1116 MIDI_mciReadByte(wmm, &m);
1117 MIDI_mciReadByte(wmm, &s);
1118 MIDI_mciReadByte(wmm, &f);
1119 MIDI_mciReadByte(wmm, &ff);
1120 FIXME("NIY: SMPTE track start %u:%u:%u %u.%u\n", h, m, s, f, ff);
1122 break;
1123 case 0x58: /* file rhythm */
1124 if (TRACE_ON(mcimidi)) {
1125 BYTE num, den, cpmc, _32npqn;
1127 MIDI_mciReadByte(wmm, &num);
1128 MIDI_mciReadByte(wmm, &den); /* to notate e.g. 6/8 */
1129 MIDI_mciReadByte(wmm, &cpmc); /* number of MIDI clocks per metronome click */
1130 MIDI_mciReadByte(wmm, &_32npqn); /* number of notated 32nd notes per MIDI quarter note */
1132 TRACE("%u/%u, clock per metronome click=%u, 32nd notes by 1/4 note=%u\n", num, 1 << den, cpmc, _32npqn);
1134 break;
1135 case 0x59: /* key signature */
1136 if (TRACE_ON(mcimidi)) {
1137 BYTE sf, mm;
1139 MIDI_mciReadByte(wmm, &sf);
1140 MIDI_mciReadByte(wmm, &mm);
1142 if (sf >= 0x80) TRACE("%d flats\n", -(char)sf);
1143 else if (sf > 0) TRACE("%d sharps\n", (char)sf);
1144 else TRACE("Key of C\n");
1145 TRACE("Mode: %s\n", (mm == 0) ? "major" : "minor");
1147 break;
1148 default:
1149 WARN("Unknown MIDI meta event %02x. Skipping...\n", HIBYTE(LOWORD(mmt->dwEventData)));
1150 break;
1152 break;
1153 default:
1154 if (doPlay) {
1155 dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
1156 } else {
1157 switch (LOBYTE(LOWORD(mmt->dwEventData)) & 0xF0) {
1158 case MIDI_NOTEON:
1159 case MIDI_NOTEOFF:
1160 dwRet = 0;
1161 break;
1162 default:
1163 dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
1167 mmt->dwIndex += mmt->wEventLength;
1168 if (mmt->dwIndex < mmt->dwFirst || mmt->dwIndex >= mmt->dwLast) {
1169 mmt->wStatus = 0;
1171 if (mmt->wStatus) {
1172 MIDI_mciReadNextEvent(wmm, mmt);
1176 midiOutReset((HMIDIOUT)wmm->hMidi);
1178 dwRet = midiOutClose((HMIDIOUT)wmm->hMidi);
1180 if (dwFlags & MCI_NOTIFY)
1181 oldcb = InterlockedExchangePointer(&wmm->hCallback, NULL);
1183 wmm->dwStatus = MCI_MODE_STOP;
1185 /* Let the potentially asynchronous commands support FAILURE notification. */
1186 if (oldcb) mciDriverNotify(oldcb, wmm->wDevID,
1187 dwRet ? MCI_NOTIFY_FAILURE : MCI_NOTIFY_SUCCESSFUL);
1188 return dwRet;
1191 /**************************************************************************
1192 * MIDI_mciPause [internal]
1194 static DWORD MIDI_mciPause(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1196 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
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 ((dwFlags & MCI_NOTIFY) && lpParms)
1206 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1207 return 0;
1210 /**************************************************************************
1211 * MIDI_mciResume [internal]
1213 static DWORD MIDI_mciResume(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1215 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1217 if (wmm->dwStatus == MCI_MODE_PAUSE) {
1218 wmm->wStartedPlaying = FALSE;
1219 wmm->dwStatus = MCI_MODE_PLAY;
1221 if ((dwFlags & MCI_NOTIFY) && lpParms)
1222 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1223 return 0;
1226 /**************************************************************************
1227 * MIDI_mciSet [internal]
1229 static DWORD MIDI_mciSet(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_SEQ_SET_PARMS lpParms)
1231 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1233 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1235 if (dwFlags & MCI_SET_TIME_FORMAT) {
1236 switch (lpParms->dwTimeFormat) {
1237 case MCI_FORMAT_MILLISECONDS:
1238 TRACE("MCI_FORMAT_MILLISECONDS !\n");
1239 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
1240 break;
1241 case MCI_FORMAT_SMPTE_24:
1242 TRACE("MCI_FORMAT_SMPTE_24 !\n");
1243 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24;
1244 break;
1245 case MCI_FORMAT_SMPTE_25:
1246 TRACE("MCI_FORMAT_SMPTE_25 !\n");
1247 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25;
1248 break;
1249 case MCI_FORMAT_SMPTE_30:
1250 TRACE("MCI_FORMAT_SMPTE_30 !\n");
1251 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30;
1252 break;
1253 default:
1254 WARN("Bad time format %u!\n", lpParms->dwTimeFormat);
1255 return MCIERR_BAD_TIME_FORMAT;
1258 if (dwFlags & MCI_SET_VIDEO) {
1259 TRACE("No support for video !\n");
1260 return MCIERR_UNSUPPORTED_FUNCTION;
1262 if (dwFlags & MCI_SET_DOOR_OPEN) {
1263 TRACE("No support for door open !\n");
1264 return MCIERR_UNSUPPORTED_FUNCTION;
1266 if (dwFlags & MCI_SET_DOOR_CLOSED) {
1267 TRACE("No support for door close !\n");
1268 return MCIERR_UNSUPPORTED_FUNCTION;
1270 if (dwFlags & MCI_SET_AUDIO) {
1271 if (dwFlags & MCI_SET_ON) {
1272 TRACE("MCI_SET_ON audio !\n");
1273 } else if (dwFlags & MCI_SET_OFF) {
1274 TRACE("MCI_SET_OFF audio !\n");
1275 } else {
1276 WARN("MCI_SET_AUDIO without SET_ON or SET_OFF\n");
1277 return MCIERR_BAD_INTEGER;
1280 switch (lpParms->dwAudio)
1282 case MCI_SET_AUDIO_ALL: TRACE("MCI_SET_AUDIO_ALL !\n"); break;
1283 case MCI_SET_AUDIO_LEFT: TRACE("MCI_SET_AUDIO_LEFT !\n"); break;
1284 case MCI_SET_AUDIO_RIGHT: TRACE("MCI_SET_AUDIO_RIGHT !\n"); break;
1285 default: WARN("Unknown audio channel %u\n", lpParms->dwAudio); break;
1289 if (dwFlags & MCI_SEQ_SET_MASTER)
1290 TRACE("MCI_SEQ_SET_MASTER !\n");
1291 if (dwFlags & MCI_SEQ_SET_SLAVE)
1292 TRACE("MCI_SEQ_SET_SLAVE !\n");
1293 if (dwFlags & MCI_SEQ_SET_OFFSET)
1294 TRACE("MCI_SEQ_SET_OFFSET !\n");
1295 if (dwFlags & MCI_SEQ_SET_PORT) {
1296 TRACE("MCI_SEQ_SET_PORT = %d\n", lpParms->dwPort);
1297 if ((UINT16)lpParms->dwPort != (UINT16)MIDI_MAPPER &&
1298 (UINT16)lpParms->dwPort >= midiOutGetNumDevs())
1299 /* FIXME: input/output port distinction? */
1300 return MCIERR_SEQ_PORT_NONEXISTENT;
1301 /* FIXME: Native manages to swap the device while playing! */
1302 wmm->wPort = lpParms->dwPort;
1304 if (dwFlags & MCI_SEQ_SET_TEMPO)
1305 TRACE("MCI_SEQ_SET_TEMPO !\n");
1306 if (dwFlags & MCI_NOTIFY)
1307 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1308 return 0;
1311 /**************************************************************************
1312 * MIDI_mciStatus [internal]
1314 static DWORD MIDI_mciStatus(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
1316 DWORD ret = 0;
1318 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1320 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1322 if (dwFlags & MCI_STATUS_ITEM) {
1323 switch (lpParms->dwItem) {
1324 case MCI_STATUS_CURRENT_TRACK:
1325 /* FIXME in Format 2 */
1326 lpParms->dwReturn = 1;
1327 TRACE("MCI_STATUS_CURRENT_TRACK => %lu\n", lpParms->dwReturn);
1328 break;
1329 case MCI_STATUS_LENGTH:
1330 if ((dwFlags & MCI_TRACK) && wmm->wFormat == 2) {
1331 if (lpParms->dwTrack >= wmm->nTracks)
1332 return MCIERR_BAD_INTEGER;
1333 /* FIXME: this is wrong if there is a tempo change inside the file */
1334 lpParms->dwReturn = MIDI_ConvertPulseToMS(wmm, wmm->tracks[lpParms->dwTrack].dwLength);
1335 } else {
1336 lpParms->dwReturn = MIDI_GetMThdLengthMS(wmm);
1338 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm, lpParms->dwReturn);
1339 TRACE("MCI_STATUS_LENGTH => %lu\n", lpParms->dwReturn);
1340 break;
1341 case MCI_STATUS_MODE:
1342 TRACE("MCI_STATUS_MODE => %u\n", wmm->dwStatus);
1343 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwStatus, wmm->dwStatus);
1344 ret = MCI_RESOURCE_RETURNED;
1345 break;
1346 case MCI_STATUS_MEDIA_PRESENT:
1347 TRACE("MCI_STATUS_MEDIA_PRESENT => TRUE\n");
1348 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1349 ret = MCI_RESOURCE_RETURNED;
1350 break;
1351 case MCI_STATUS_NUMBER_OF_TRACKS:
1352 lpParms->dwReturn = (wmm->wFormat == 2) ? wmm->nTracks : 1;
1353 TRACE("MCI_STATUS_NUMBER_OF_TRACKS => %lu\n", lpParms->dwReturn);
1354 break;
1355 case MCI_STATUS_POSITION:
1356 /* FIXME: do I need to use MCI_TRACK ? */
1357 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm,
1358 (dwFlags & MCI_STATUS_START) ? 0 : wmm->dwPositionMS);
1359 TRACE("MCI_STATUS_POSITION %s => %lu\n",
1360 (dwFlags & MCI_STATUS_START) ? "start" : "current", lpParms->dwReturn);
1361 break;
1362 case MCI_STATUS_READY:
1363 lpParms->dwReturn = (wmm->dwStatus == MCI_MODE_NOT_READY) ?
1364 MAKEMCIRESOURCE(FALSE, MCI_FALSE) : MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1365 ret = MCI_RESOURCE_RETURNED;
1366 TRACE("MCI_STATUS_READY = %u\n", LOWORD(lpParms->dwReturn));
1367 break;
1368 case MCI_STATUS_TIME_FORMAT:
1369 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwMciTimeFormat, MCI_FORMAT_RETURN_BASE + wmm->dwMciTimeFormat);
1370 TRACE("MCI_STATUS_TIME_FORMAT => %u\n", LOWORD(lpParms->dwReturn));
1371 ret = MCI_RESOURCE_RETURNED;
1372 break;
1373 case MCI_SEQ_STATUS_DIVTYPE:
1374 TRACE("MCI_SEQ_STATUS_DIVTYPE !\n");
1375 if (wmm->nDivision > 0x8000) {
1376 switch (wmm->nDivision) {
1377 case 0xE8: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_24; break; /* -24 */
1378 case 0xE7: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_25; break; /* -25 */
1379 case 0xE3: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
1380 case 0xE2: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30; break; /* -30 */
1381 default: FIXME("There is a bad bad programmer\n");
1383 } else {
1384 lpParms->dwReturn = MCI_SEQ_DIV_PPQN;
1386 lpParms->dwReturn = MAKEMCIRESOURCE(lpParms->dwReturn,lpParms->dwReturn);
1387 ret = MCI_RESOURCE_RETURNED;
1388 break;
1389 case MCI_SEQ_STATUS_MASTER:
1390 TRACE("MCI_SEQ_STATUS_MASTER !\n");
1391 lpParms->dwReturn = 0;
1392 break;
1393 case MCI_SEQ_STATUS_SLAVE:
1394 TRACE("MCI_SEQ_STATUS_SLAVE !\n");
1395 lpParms->dwReturn = 0;
1396 break;
1397 case MCI_SEQ_STATUS_OFFSET:
1398 TRACE("MCI_SEQ_STATUS_OFFSET !\n");
1399 lpParms->dwReturn = 0;
1400 break;
1401 case MCI_SEQ_STATUS_PORT:
1402 if (wmm->wPort != (UINT16)MIDI_MAPPER)
1403 lpParms->dwReturn = wmm->wPort;
1404 else {
1405 lpParms->dwReturn = MAKEMCIRESOURCE(MIDI_MAPPER, MCI_SEQ_MAPPER_S);
1406 ret = MCI_RESOURCE_RETURNED;
1408 TRACE("MCI_SEQ_STATUS_PORT (%u) => %d\n", wmm->wDevID, wmm->wPort);
1409 break;
1410 case MCI_SEQ_STATUS_TEMPO:
1411 TRACE("MCI_SEQ_STATUS_TEMPO !\n");
1412 lpParms->dwReturn = wmm->dwTempo;
1413 break;
1414 default:
1415 FIXME("Unknown command %08X !\n", lpParms->dwItem);
1416 return MCIERR_UNRECOGNIZED_COMMAND;
1418 } else {
1419 WARN("No Status-Item!\n");
1420 return MCIERR_UNRECOGNIZED_COMMAND;
1422 if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
1423 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1424 return ret;
1427 /**************************************************************************
1428 * MIDI_mciGetDevCaps [internal]
1430 static DWORD MIDI_mciGetDevCaps(WINE_MCIMIDI* wmm, DWORD dwFlags,
1431 LPMCI_GETDEVCAPS_PARMS lpParms)
1433 DWORD ret;
1435 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1437 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1439 if (dwFlags & MCI_GETDEVCAPS_ITEM) {
1440 switch (lpParms->dwItem) {
1441 case MCI_GETDEVCAPS_DEVICE_TYPE:
1442 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE !\n");
1443 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_SEQUENCER, MCI_DEVTYPE_SEQUENCER);
1444 ret = MCI_RESOURCE_RETURNED;
1445 break;
1446 case MCI_GETDEVCAPS_HAS_AUDIO:
1447 TRACE("MCI_GETDEVCAPS_HAS_AUDIO !\n");
1448 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1449 ret = MCI_RESOURCE_RETURNED;
1450 break;
1451 case MCI_GETDEVCAPS_HAS_VIDEO:
1452 TRACE("MCI_GETDEVCAPS_HAS_VIDEO !\n");
1453 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1454 ret = MCI_RESOURCE_RETURNED;
1455 break;
1456 case MCI_GETDEVCAPS_USES_FILES:
1457 TRACE("MCI_GETDEVCAPS_USES_FILES !\n");
1458 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1459 ret = MCI_RESOURCE_RETURNED;
1460 break;
1461 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
1462 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE !\n");
1463 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1464 ret = MCI_RESOURCE_RETURNED;
1465 break;
1466 case MCI_GETDEVCAPS_CAN_EJECT:
1467 TRACE("MCI_GETDEVCAPS_CAN_EJECT !\n");
1468 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1469 ret = MCI_RESOURCE_RETURNED;
1470 break;
1471 case MCI_GETDEVCAPS_CAN_PLAY:
1472 TRACE("MCI_GETDEVCAPS_CAN_PLAY !\n");
1473 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1474 ret = MCI_RESOURCE_RETURNED;
1475 break;
1476 case MCI_GETDEVCAPS_CAN_RECORD:
1477 TRACE("MCI_GETDEVCAPS_CAN_RECORD !\n");
1478 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1479 ret = MCI_RESOURCE_RETURNED;
1480 break;
1481 case MCI_GETDEVCAPS_CAN_SAVE:
1482 TRACE("MCI_GETDEVCAPS_CAN_SAVE !\n");
1483 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1484 ret = MCI_RESOURCE_RETURNED;
1485 break;
1486 default:
1487 FIXME("Unknown capability (%08x) !\n", lpParms->dwItem);
1488 return MCIERR_UNRECOGNIZED_COMMAND;
1490 } else {
1491 WARN("No GetDevCaps-Item !\n");
1492 return MCIERR_UNRECOGNIZED_COMMAND;
1494 if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
1495 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1496 return ret;
1499 /**************************************************************************
1500 * MIDI_mciInfo [internal]
1502 static DWORD MIDI_mciInfo(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_INFO_PARMSW lpParms)
1504 LPCWSTR str = 0;
1505 DWORD ret = 0;
1506 static const WCHAR wszMidiSeq[] = {'W','i','n','e','\'','s',' ','M','I','D','I',' ','s','e','q','u','e','n','c','e','r',0};
1508 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1510 if (lpParms == NULL || lpParms->lpstrReturn == NULL)
1511 return MCIERR_NULL_PARAMETER_BLOCK;
1513 TRACE("buf=%p, len=%u\n", lpParms->lpstrReturn, lpParms->dwRetSize);
1515 switch (dwFlags & ~(MCI_WAIT|MCI_NOTIFY)) {
1516 case MCI_INFO_PRODUCT: str = wszMidiSeq; break;
1517 case MCI_INFO_FILE: str = wmm->lpstrElementName; break;
1518 case MCI_INFO_COPYRIGHT: str = wmm->lpstrCopyright; break;
1519 case MCI_INFO_NAME: str = wmm->lpstrName; break;
1520 default:
1521 WARN("Don't know this info command (%u)\n", dwFlags);
1522 return MCIERR_UNRECOGNIZED_COMMAND;
1524 if (!ret) {
1525 if (lpParms->dwRetSize) {
1526 WCHAR zero = 0;
1527 /* FIXME? Since NT, mciwave, mciseq and mcicda set dwRetSize
1528 * to the number of characters written, excluding \0. */
1529 lstrcpynW(lpParms->lpstrReturn, str ? str : &zero, lpParms->dwRetSize);
1530 } else ret = MCIERR_PARAM_OVERFLOW;
1532 if (MMSYSERR_NOERROR==ret && (dwFlags & MCI_NOTIFY))
1533 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1534 return ret;
1537 /**************************************************************************
1538 * MIDI_mciSeek [internal]
1540 static DWORD MIDI_mciSeek(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
1542 DWORD ret = 0;
1544 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1546 if (lpParms == NULL) {
1547 ret = MCIERR_NULL_PARAMETER_BLOCK;
1548 } else {
1549 MIDI_mciStop(wmm, MCI_WAIT, 0);
1551 if (dwFlags & MCI_SEEK_TO_START) {
1552 wmm->dwPositionMS = 0;
1553 } else if (dwFlags & MCI_SEEK_TO_END) {
1554 wmm->dwPositionMS = 0xFFFFFFFF; /* FIXME */
1555 } else if (dwFlags & MCI_TO) {
1556 wmm->dwPositionMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
1557 } else {
1558 WARN("dwFlag doesn't tell where to seek to...\n");
1559 return MCIERR_MISSING_PARAMETER;
1562 TRACE("Seeking to position=%u ms\n", wmm->dwPositionMS);
1564 if (dwFlags & MCI_NOTIFY)
1565 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1567 return ret;
1570 /*======================================================================*
1571 * MIDI entry points *
1572 *======================================================================*/
1574 /**************************************************************************
1575 * DriverProc (MCISEQ.@)
1577 LRESULT CALLBACK MCIMIDI_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
1578 LPARAM dwParam1, LPARAM dwParam2)
1580 WINE_MCIMIDI* wmm;
1581 switch (wMsg) {
1582 case DRV_LOAD: return 1;
1583 case DRV_FREE: return 1;
1584 case DRV_ENABLE: return 1;
1585 case DRV_DISABLE: return 1;
1586 case DRV_QUERYCONFIGURE: return 1;
1587 case DRV_CONFIGURE: MessageBoxA(0, "Sample Midi Driver !", "OSS Driver", MB_OK); return 1;
1588 case DRV_INSTALL: return DRVCNF_RESTART;
1589 case DRV_REMOVE: return DRVCNF_RESTART;
1590 case DRV_OPEN: return MIDI_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
1591 case DRV_CLOSE: return MIDI_drvClose(dwDevID);
1593 if ((wMsg < DRV_MCI_FIRST) || (wMsg > DRV_MCI_LAST)) {
1594 TRACE("Sending msg %04x to default driver proc\n", wMsg);
1595 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1598 wmm = MIDI_mciGetOpenDev(dwDevID, wMsg);
1599 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1601 switch (wMsg) {
1602 case MCI_OPEN_DRIVER: return MIDI_mciOpen (wmm, dwParam1, (LPMCI_OPEN_PARMSW) dwParam2);
1603 case MCI_CLOSE_DRIVER: return MIDI_mciClose (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1604 case MCI_PLAY: return MIDI_mciPlay (wmm, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
1605 case MCI_STOP: return MIDI_mciStop (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1606 case MCI_SET: return MIDI_mciSet (wmm, dwParam1, (LPMCI_SEQ_SET_PARMS) dwParam2);
1607 case MCI_PAUSE: return MIDI_mciPause (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1608 case MCI_RESUME: return MIDI_mciResume (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1609 case MCI_STATUS: return MIDI_mciStatus (wmm, dwParam1, (LPMCI_STATUS_PARMS) dwParam2);
1610 case MCI_GETDEVCAPS: return MIDI_mciGetDevCaps(wmm, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2);
1611 case MCI_INFO: return MIDI_mciInfo (wmm, dwParam1, (LPMCI_INFO_PARMSW) dwParam2);
1612 case MCI_SEEK: return MIDI_mciSeek (wmm, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
1613 case MCI_OPEN:
1614 case MCI_CLOSE:
1615 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1616 /* fall through */
1617 default:
1618 TRACE("Unsupported command [0x%x]\n", wMsg);
1619 return MCIERR_UNSUPPORTED_FUNCTION; /* Win9x: MCIERR_UNRECOGNIZED_COMMAND */