wined3d: Introduce wined3d_device_get_immediate_context().
[wine.git] / dlls / mciseq / mcimidi.c
blob33f9fde42c7bcee7bbaa5346dbbbecc807d5c8ae
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 "winnls.h"
36 #include "wingdi.h"
37 #include "winuser.h"
38 #include "wownt32.h"
39 #include "mmddk.h"
40 #include "wine/debug.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 HANDLE hThread; /* Player thread */
66 HMMIO hFile; /* mmio file handle open as Element */
67 LPWSTR lpstrElementName; /* Name of file (if any) */
68 LPWSTR lpstrCopyright;
69 LPWSTR lpstrName;
70 WORD wPort; /* the WINMM device unit */
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 dwEndMS;
82 DWORD dwStartTicks;
83 } WINE_MCIMIDI;
85 /*======================================================================*
86 * MCI MIDI implementation *
87 *======================================================================*/
89 static DWORD mmr2mci(DWORD ret)
91 switch (ret) {
92 case MMSYSERR_ALLOCATED:
93 return MCIERR_SEQ_PORT_INUSE;
94 case MMSYSERR_NOMEM:
95 return MCIERR_OUT_OF_MEMORY;
96 case MMSYSERR_BADDEVICEID: /* wine*.drv disabled */
97 return MCIERR_SEQ_PORT_NONEXISTENT;
98 case MIDIERR_INVALIDSETUP: /* from midimap.dll without snd-seq module */
99 return MCIERR_SEQ_PORT_MAPNODEVICE;
100 default:
101 return ret;
105 static DWORD MIDI_mciResume(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
107 /**************************************************************************
108 * MIDI_drvOpen [internal]
110 static DWORD MIDI_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
112 WINE_MCIMIDI* wmm;
114 if (!modp) return 0xFFFFFFFF;
116 wmm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIMIDI));
118 if (!wmm)
119 return 0;
121 wmm->wDevID = modp->wDeviceID;
122 mciSetDriverData(wmm->wDevID, (DWORD_PTR)wmm);
123 modp->wCustomCommandTable = MCI_NO_COMMAND_TABLE;
124 modp->wType = MCI_DEVTYPE_SEQUENCER;
125 return modp->wDeviceID;
128 /**************************************************************************
129 * MCIMIDI_drvClose [internal]
131 static DWORD MIDI_drvClose(DWORD dwDevID)
133 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(dwDevID);
135 if (wmm) {
136 HeapFree(GetProcessHeap(), 0, wmm);
137 mciSetDriverData(dwDevID, 0);
138 return 1;
140 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
143 /**************************************************************************
144 * MIDI_mciGetOpenDev [internal]
146 static WINE_MCIMIDI* MIDI_mciGetOpenDev(MCIDEVICEID wDevID, UINT wMsg)
148 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
150 if (wmm == NULL || ((wmm->nUseCount == 0) ^ (wMsg == MCI_OPEN_DRIVER))) {
151 WARN("Invalid wDevID=%u\n", wDevID);
152 return 0;
154 return wmm;
157 /**************************************************************************
158 * MIDI_mciNotify [internal]
160 * Notifications in MCI work like a 1-element queue.
161 * Each new notification request supersedes the previous one.
162 * This affects Play and Record; other commands are immediate.
164 static void MIDI_mciNotify(DWORD_PTR hWndCallBack, WINE_MCIMIDI* wmm, UINT wStatus)
166 /* We simply save one parameter by not passing the wDevID local
167 * to the command. They are the same (via mciGetDriverData).
169 MCIDEVICEID wDevID = wmm->wDevID;
170 HANDLE old = InterlockedExchangePointer(&wmm->hCallback, NULL);
171 if (old) mciDriverNotify(old, wDevID, MCI_NOTIFY_SUPERSEDED);
172 mciDriverNotify(HWND_32(LOWORD(hWndCallBack)), wDevID, wStatus);
175 /**************************************************************************
176 * MIDI_mciReadByte [internal]
178 static DWORD MIDI_mciReadByte(WINE_MCIMIDI* wmm, BYTE *lpbyt)
180 DWORD ret = 0;
182 if (mmioRead(wmm->hFile, (HPSTR)lpbyt, sizeof(BYTE)) != (long)sizeof(BYTE)) {
183 WARN("Error reading wmm=%p\n", wmm);
184 ret = MCIERR_INVALID_FILE;
187 return ret;
190 /**************************************************************************
191 * MIDI_mciReadWord [internal]
193 static DWORD MIDI_mciReadWord(WINE_MCIMIDI* wmm, LPWORD lpw)
195 BYTE hibyte, lobyte;
196 DWORD ret = MCIERR_INVALID_FILE;
198 if (MIDI_mciReadByte(wmm, &hibyte) == 0 &&
199 MIDI_mciReadByte(wmm, &lobyte) == 0) {
200 *lpw = ((WORD)hibyte << 8) + lobyte;
201 ret = 0;
203 return ret;
206 /**************************************************************************
207 * MIDI_mciReadLong [internal]
209 static DWORD MIDI_mciReadLong(WINE_MCIMIDI* wmm, LPDWORD lpdw)
211 WORD hiword, loword;
212 DWORD ret = MCIERR_INVALID_FILE;
214 if (MIDI_mciReadWord(wmm, &hiword) == 0 &&
215 MIDI_mciReadWord(wmm, &loword) == 0) {
216 *lpdw = MAKELONG(loword, hiword);
217 ret = 0;
219 return ret;
222 /**************************************************************************
223 * MIDI_mciReadVaryLen [internal]
225 static WORD MIDI_mciReadVaryLen(WINE_MCIMIDI* wmm, LPDWORD lpdw)
227 BYTE byte;
228 DWORD value = 0;
229 WORD len = 0;
231 do {
232 if (MIDI_mciReadByte(wmm, &byte) != 0) {
233 *lpdw = 0;
234 return 0;
236 value = (value << 7) + (byte & 0x7F);
237 len++;
238 } while (byte & 0x80);
239 *lpdw = value;
240 return len;
243 /**************************************************************************
244 * MIDI_mciReadNextEvent [internal]
246 static DWORD MIDI_mciReadNextEvent(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
248 BYTE b1, b2 = 0, b3;
249 WORD hw = 0;
250 DWORD evtPulse;
251 DWORD evtLength;
252 DWORD tmp;
254 if (mmioSeek(wmm->hFile, mmt->dwIndex, SEEK_SET) != mmt->dwIndex) {
255 WARN("Can't seek at %08X\n", mmt->dwIndex);
256 return MCIERR_INVALID_FILE;
258 evtLength = MIDI_mciReadVaryLen(wmm, &evtPulse) + 1; /* > 0 */
259 MIDI_mciReadByte(wmm, &b1);
260 switch (b1) {
261 case 0xF0:
262 case 0xF7:
263 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
264 evtLength += tmp;
265 break;
266 case 0xFF:
267 MIDI_mciReadByte(wmm, &b2); evtLength++;
269 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
270 if (evtLength >= 0x10000u) {
271 /* this limitation shouldn't be a problem */
272 WARN("Ouch !! Implementation limitation to 64k bytes for a MIDI event is overflowed\n");
273 hw = 0xFFFF;
274 } else {
275 hw = LOWORD(evtLength);
277 evtLength += tmp;
278 break;
279 default:
280 if (b1 & 0x80) { /* use running status ? */
281 mmt->wLastCommand = b1;
282 MIDI_mciReadByte(wmm, &b2); evtLength++;
283 } else {
284 b2 = b1;
285 b1 = mmt->wLastCommand;
287 switch ((b1 >> 4) & 0x07) {
288 case 0: case 1: case 2: case 3: case 6:
289 MIDI_mciReadByte(wmm, &b3); evtLength++;
290 hw = b3;
291 break;
292 case 4: case 5:
293 break;
294 case 7:
295 WARN("Strange indeed b1=0x%02x\n", b1);
297 break;
299 if (mmt->dwIndex + evtLength > mmt->dwLast)
300 return MCIERR_INTERNAL;
302 mmt->dwEventPulse += evtPulse;
303 mmt->dwEventData = (hw << 16) + (b2 << 8) + b1;
304 mmt->wEventLength = evtLength;
307 TRACE("[%u] => pulse=%08x(%08x), data=%08x, length=%u\n",
308 mmt->wTrackNr, mmt->dwEventPulse, evtPulse,
309 mmt->dwEventData, mmt->wEventLength);
311 return 0;
314 /**************************************************************************
315 * MIDI_mciReadMTrk [internal]
317 static DWORD MIDI_mciReadMTrk(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
319 DWORD toberead;
320 FOURCC fourcc;
322 if (mmioRead(wmm->hFile, (HPSTR)&fourcc, (long)sizeof(FOURCC)) !=
323 (long)sizeof(FOURCC)) {
324 return MCIERR_INVALID_FILE;
327 if (fourcc != mmioFOURCC('M', 'T', 'r', 'k')) {
328 WARN("Can't synchronize on 'MTrk' !\n");
329 return MCIERR_INVALID_FILE;
332 if (MIDI_mciReadLong(wmm, &toberead) != 0) {
333 return MCIERR_INVALID_FILE;
335 mmt->dwFirst = mmioSeek(wmm->hFile, 0, SEEK_CUR); /* >= 0 */
336 mmt->dwLast = mmt->dwFirst + toberead;
338 /* compute # of pulses in this track */
339 mmt->dwIndex = mmt->dwFirst;
340 mmt->dwEventPulse = 0;
342 while (MIDI_mciReadNextEvent(wmm, mmt) == 0 && LOWORD(mmt->dwEventData) != 0x2FFF) {
343 char buf[1024];
344 WORD len;
346 mmt->dwIndex += mmt->wEventLength;
348 switch (LOWORD(mmt->dwEventData)) {
349 case 0x02FF:
350 case 0x03FF:
351 len = mmt->wEventLength - HIWORD(mmt->dwEventData);
352 if (len >= sizeof(buf)) {
353 WARN("Buffer for text is too small (%u are needed)\n", len);
354 len = sizeof(buf) - 1;
356 if (mmioRead(wmm->hFile, buf, len) == len) {
357 buf[len] = 0; /* end string in case */
358 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
359 case 0x02:
360 if (wmm->lpstrCopyright) {
361 WARN("Two copyright notices (%s|%s)\n", debugstr_w(wmm->lpstrCopyright), buf);
362 HeapFree(GetProcessHeap(), 0, wmm->lpstrCopyright);
364 len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
365 wmm->lpstrCopyright = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
366 MultiByteToWideChar( CP_ACP, 0, buf, -1, wmm->lpstrCopyright, len );
367 break;
368 case 0x03:
369 if (wmm->lpstrName) {
370 WARN("Two names (%s|%s)\n", debugstr_w(wmm->lpstrName), buf);
371 HeapFree(GetProcessHeap(), 0, wmm->lpstrName);
372 } /* last name or name from last track wins */
373 len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
374 wmm->lpstrName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
375 MultiByteToWideChar( CP_ACP, 0, buf, -1, wmm->lpstrName, len );
376 break;
379 break;
382 mmt->dwLength = mmt->dwEventPulse;
384 TRACE("Track %u has %u bytes and %u pulses\n", mmt->wTrackNr, toberead, mmt->dwLength);
386 /* reset track data */
387 mmt->wStatus = 1; /* ok, playing */
388 mmt->dwIndex = mmt->dwFirst;
389 mmt->dwEventPulse = 0;
391 if (mmioSeek(wmm->hFile, 0, SEEK_CUR) != mmt->dwLast) {
392 WARN("Ouch, out of sync seek=%u track=%u\n",
393 mmioSeek(wmm->hFile, 0, SEEK_CUR), mmt->dwLast);
394 /* position at end of this track, to be ready to read next track */
395 mmioSeek(wmm->hFile, mmt->dwLast, SEEK_SET);
398 return 0;
401 /**************************************************************************
402 * MIDI_mciReadMThd [internal]
404 static DWORD MIDI_mciReadMThd(WINE_MCIMIDI* wmm, DWORD dwOffset)
406 DWORD toberead;
407 FOURCC fourcc;
408 WORD nt;
410 TRACE("(%p, %08X);\n", wmm, dwOffset);
412 if (mmioSeek(wmm->hFile, dwOffset, SEEK_SET) != dwOffset) {
413 WARN("Can't seek at %08X begin of 'MThd'\n", dwOffset);
414 return MCIERR_INVALID_FILE;
416 if (mmioRead(wmm->hFile, (HPSTR)&fourcc,
417 (long) sizeof(FOURCC)) != (long) sizeof(FOURCC))
418 return MCIERR_INVALID_FILE;
420 if (fourcc != mmioFOURCC('M', 'T', 'h', 'd')) {
421 WARN("Can't synchronize on 'MThd' !\n");
422 return MCIERR_INVALID_FILE;
425 if (MIDI_mciReadLong(wmm, &toberead) != 0 || toberead < 3 * sizeof(WORD))
426 return MCIERR_INVALID_FILE;
428 if (MIDI_mciReadWord(wmm, &wmm->wFormat) != 0 ||
429 MIDI_mciReadWord(wmm, &wmm->nTracks) != 0 ||
430 MIDI_mciReadWord(wmm, &wmm->nDivision) != 0) {
431 return MCIERR_INVALID_FILE;
434 TRACE("toberead=0x%08X, wFormat=0x%04X nTracks=0x%04X nDivision=0x%04X\n",
435 toberead, wmm->wFormat, wmm->nTracks, wmm->nDivision);
437 /* MS doc says that the MIDI MCI time format must be put by default to the format
438 * stored in the MIDI file...
440 if (wmm->nDivision > 0x8000) {
441 /* eric.pouech@lemel.fr 98/11
442 * I did not check this very code (pulses are expressed as SMPTE sub-frames).
443 * In about 40 MB of MIDI files I have, none was SMPTE based...
444 * I'm just wondering if this is widely used :-). So, if someone has one of
445 * these files, I'd like to know about it.
447 FIXME("Handling SMPTE time in MIDI files has not been tested\n"
448 "Please report to comp.emulators.ms-windows.wine with MIDI file !\n");
450 switch (HIBYTE(wmm->nDivision)) {
451 case 0xE8: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24; break; /* -24 */
452 case 0xE7: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25; break; /* -25 */
453 case 0xE3: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
454 case 0xE2: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30; break; /* -30 */
455 default:
456 WARN("Unsupported number of frames %d\n", -(char)HIBYTE(wmm->nDivision));
457 return MCIERR_INVALID_FILE;
459 switch (LOBYTE(wmm->nDivision)) {
460 case 4: /* MIDI Time Code */
461 case 8:
462 case 10:
463 case 80: /* SMPTE bit resolution */
464 case 100:
465 default:
466 WARN("Unsupported number of sub-frames %d\n", LOBYTE(wmm->nDivision));
467 return MCIERR_INVALID_FILE;
469 } else if (wmm->nDivision == 0) {
470 WARN("Number of division is 0, can't support that !!\n");
471 return MCIERR_INVALID_FILE;
472 } else {
473 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
476 switch (wmm->wFormat) {
477 case 0:
478 if (wmm->nTracks != 1) {
479 WARN("Got type 0 file whose number of track is not 1. Setting it to 1\n");
480 wmm->nTracks = 1;
482 break;
483 case 1:
484 case 2:
485 break;
486 default:
487 WARN("Handling MIDI files which format = %d is not (yet) supported\n"
488 "Please report with MIDI file !\n", wmm->wFormat);
489 return MCIERR_INVALID_FILE;
492 if (wmm->nTracks > 0x80) {
493 /* wTrackNr is 7 bits only */
494 FIXME("Truncating MIDI file with %u tracks\n", wmm->nTracks);
495 wmm->nTracks = 0x80;
498 if ((wmm->tracks = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_MIDITRACK) * wmm->nTracks)) == NULL) {
499 return MCIERR_OUT_OF_MEMORY;
502 toberead -= 3 * sizeof(WORD);
503 if (toberead > 0) {
504 TRACE("Size of MThd > 6, skipping %d extra bytes\n", toberead);
505 mmioSeek(wmm->hFile, toberead, SEEK_CUR);
508 for (nt = 0; nt < wmm->nTracks; nt++) {
509 wmm->tracks[nt].wTrackNr = nt;
510 if (MIDI_mciReadMTrk(wmm, &wmm->tracks[nt]) != 0) {
511 WARN("Can't read 'MTrk' header\n");
512 return MCIERR_INVALID_FILE;
516 wmm->dwTempo = 500000;
518 return 0;
521 /**************************************************************************
522 * MIDI_ConvertPulseToMS [internal]
524 static DWORD MIDI_ConvertPulseToMS(WINE_MCIMIDI* wmm, DWORD pulse)
526 DWORD ret = 0;
528 /* FIXME: this function may return false values since the tempo (wmm->dwTempo)
529 * may change during file playing
531 if (wmm->nDivision == 0) {
532 FIXME("Shouldn't happen. wmm->nDivision = 0\n");
533 } else if (wmm->nDivision > 0x8000) { /* SMPTE, unchecked FIXME? */
534 int nf = -(char)HIBYTE(wmm->nDivision); /* number of frames */
535 int nsf = LOBYTE(wmm->nDivision); /* number of sub-frames */
536 ret = (pulse * 1000) / (nf * nsf);
537 } else {
538 ret = (DWORD)((double)pulse * ((double)wmm->dwTempo / 1000) /
539 (double)wmm->nDivision);
543 TRACE("pulse=%u tempo=%u division=%u=0x%04x => ms=%u\n",
544 pulse, wmm->dwTempo, wmm->nDivision, wmm->nDivision, ret);
547 return ret;
550 #define TIME_MS_IN_ONE_HOUR (60*60*1000)
551 #define TIME_MS_IN_ONE_MINUTE (60*1000)
552 #define TIME_MS_IN_ONE_SECOND (1000)
554 /**************************************************************************
555 * MIDI_ConvertTimeFormatToMS [internal]
557 static DWORD MIDI_ConvertTimeFormatToMS(WINE_MCIMIDI* wmm, DWORD val)
559 DWORD ret = 0;
561 switch (wmm->dwMciTimeFormat) {
562 case MCI_FORMAT_MILLISECONDS:
563 ret = val;
564 break;
565 case MCI_FORMAT_SMPTE_24:
566 ret =
567 (HIBYTE(HIWORD(val)) * 125) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
568 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
569 break;
570 case MCI_FORMAT_SMPTE_25:
571 ret =
572 HIBYTE(HIWORD(val)) * 40 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
573 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
574 break;
575 case MCI_FORMAT_SMPTE_30:
576 ret =
577 (HIBYTE(HIWORD(val)) * 100) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
578 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
579 break;
580 default:
581 WARN("Bad time format %u!\n", wmm->dwMciTimeFormat);
584 TRACE("val=%u=0x%08x [tf=%u] => ret=%u\n", val, val, wmm->dwMciTimeFormat, ret);
586 return ret;
589 /**************************************************************************
590 * MIDI_ConvertMSToTimeFormat [internal]
592 static DWORD MIDI_ConvertMSToTimeFormat(WINE_MCIMIDI* wmm, DWORD _val)
594 DWORD ret = 0, val = _val;
595 DWORD h, m, s, f;
597 switch (wmm->dwMciTimeFormat) {
598 case MCI_FORMAT_MILLISECONDS:
599 ret = val;
600 break;
601 case MCI_FORMAT_SMPTE_24:
602 case MCI_FORMAT_SMPTE_25:
603 case MCI_FORMAT_SMPTE_30:
604 h = val / TIME_MS_IN_ONE_HOUR;
605 m = (val -= h * TIME_MS_IN_ONE_HOUR) / TIME_MS_IN_ONE_MINUTE;
606 s = (val -= m * TIME_MS_IN_ONE_MINUTE) / TIME_MS_IN_ONE_SECOND;
607 switch (wmm->dwMciTimeFormat) {
608 case MCI_FORMAT_SMPTE_24:
609 /* one frame is 1000/24 val long, 1000/24 == 125/3 */
610 f = (val * 3) / 125; val -= (f * 125) / 3;
611 break;
612 case MCI_FORMAT_SMPTE_25:
613 /* one frame is 1000/25 ms long, 1000/25 == 40 */
614 f = val / 40; val -= f * 40;
615 break;
616 case MCI_FORMAT_SMPTE_30:
617 /* one frame is 1000/30 ms long, 1000/30 == 100/3 */
618 f = (val * 3) / 100; val -= (f * 100) / 3;
619 break;
620 default:
621 FIXME("There must be some bad bad programmer\n");
622 f = 0;
624 /* val contains the number of ms which cannot make a complete frame */
625 /* FIXME: is this correct ? programs seem to be happy with that */
626 ret = (f << 24) | (s << 16) | (m << 8) | (h << 0);
627 break;
628 default:
629 WARN("Bad time format %u!\n", wmm->dwMciTimeFormat);
632 TRACE("val=%u [tf=%u] => ret=%u=0x%08x\n", _val, wmm->dwMciTimeFormat, ret, ret);
634 return ret;
637 /**************************************************************************
638 * MIDI_GetMThdLengthMS [internal]
640 static DWORD MIDI_GetMThdLengthMS(WINE_MCIMIDI* wmm)
642 WORD nt;
643 DWORD ret = 0;
645 for (nt = 0; nt < wmm->nTracks; nt++) {
646 if (wmm->wFormat == 2) {
647 ret += wmm->tracks[nt].dwLength;
648 } else if (wmm->tracks[nt].dwLength > ret) {
649 ret = wmm->tracks[nt].dwLength;
652 /* FIXME: this is wrong if there is a tempo change inside the file */
653 return MIDI_ConvertPulseToMS(wmm, ret);
656 /**************************************************************************
657 * MIDI_mciOpen [internal]
659 static DWORD MIDI_mciOpen(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_OPEN_PARMSW lpParms)
661 DWORD dwRet = 0;
663 TRACE("(%d, %08X, %p)\n", wmm->wDevID, dwFlags, lpParms);
665 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
666 if (dwFlags & MCI_OPEN_SHAREABLE)
667 return MCIERR_HARDWARE;
669 if (wmm->nUseCount > 0) {
670 /* The driver is already opened on this channel
671 * MIDI sequencer cannot be shared
673 return MCIERR_DEVICE_OPEN;
675 wmm->nUseCount++;
677 wmm->hFile = 0;
678 wmm->hMidi = 0;
679 wmm->wPort = MIDI_MAPPER;
680 wmm->lpstrElementName = NULL;
682 TRACE("wDevID=%d (lpParams->wDeviceID=%d)\n", wmm->wDevID, lpParms->wDeviceID);
683 /* lpParms->wDeviceID = wDevID;*/
685 if (dwFlags & MCI_OPEN_ELEMENT) {
686 TRACE("MCI_OPEN_ELEMENT %s!\n", debugstr_w(lpParms->lpstrElementName));
687 if (lpParms->lpstrElementName && lpParms->lpstrElementName[0]) {
688 wmm->hFile = mmioOpenW((LPWSTR)lpParms->lpstrElementName, NULL,
689 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
690 if (wmm->hFile == 0) {
691 WARN("Can't find file %s!\n", debugstr_w(lpParms->lpstrElementName));
692 wmm->nUseCount--;
693 return MCIERR_FILE_NOT_FOUND;
695 wmm->lpstrElementName = HeapAlloc(GetProcessHeap(), 0,
696 (lstrlenW(lpParms->lpstrElementName) + 1) * sizeof(WCHAR));
697 lstrcpyW(wmm->lpstrElementName, lpParms->lpstrElementName);
700 TRACE("hFile=%p\n", wmm->hFile);
702 wmm->lpstrCopyright = NULL;
703 wmm->lpstrName = NULL;
705 wmm->dwStatus = MCI_MODE_NOT_READY; /* while loading file contents */
706 /* spec says it should be the default format from the MIDI file... */
707 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
709 if (wmm->hFile != 0) {
710 MMCKINFO ckMainRIFF;
711 MMCKINFO mmckInfo;
712 DWORD dwOffset = 0;
714 if (mmioDescend(wmm->hFile, &ckMainRIFF, NULL, 0) != 0) {
715 dwRet = MCIERR_INVALID_FILE;
716 } else {
717 TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08X\n",
718 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
720 if (ckMainRIFF.ckid == FOURCC_RIFF && ckMainRIFF.fccType == mmioFOURCC('R', 'M', 'I', 'D')) {
721 mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
722 mmioSeek(wmm->hFile, ckMainRIFF.dwDataOffset + ((ckMainRIFF.cksize + 1) & ~1), SEEK_SET);
723 if (mmioDescend(wmm->hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) {
724 TRACE("... is a 'RMID' file\n");
725 dwOffset = mmckInfo.dwDataOffset;
726 } else {
727 dwRet = MCIERR_INVALID_FILE;
730 if (dwRet == 0 && MIDI_mciReadMThd(wmm, dwOffset) != 0) {
731 WARN("Can't read 'MThd' header\n");
732 dwRet = MCIERR_INVALID_FILE;
735 } else {
736 TRACE("hFile==0, setting #tracks to 0; is this correct ?\n");
737 wmm->nTracks = 0;
738 wmm->wFormat = 0;
739 wmm->nDivision = 1;
741 if (dwRet != 0) {
742 wmm->nUseCount--;
743 if (wmm->hFile != 0)
744 mmioClose(wmm->hFile, 0);
745 wmm->hFile = 0;
746 HeapFree(GetProcessHeap(), 0, wmm->tracks);
747 HeapFree(GetProcessHeap(), 0, wmm->lpstrElementName);
748 HeapFree(GetProcessHeap(), 0, wmm->lpstrCopyright);
749 HeapFree(GetProcessHeap(), 0, wmm->lpstrName);
750 } else {
751 wmm->dwPositionMS = 0;
752 wmm->dwStatus = MCI_MODE_STOP;
753 if (dwFlags & MCI_NOTIFY)
754 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
756 return dwRet;
759 /**************************************************************************
760 * MIDI_mciStop [internal]
762 static DWORD MIDI_mciStop(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
764 DWORD dwRet = 0;
766 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
768 if (wmm->dwStatus != MCI_MODE_STOP) {
769 HANDLE old = InterlockedExchangePointer(&wmm->hCallback, NULL);
770 if (old) mciDriverNotify(old, wmm->wDevID, MCI_NOTIFY_ABORTED);
773 if (wmm->dwStatus != MCI_MODE_STOP) {
774 int oldstat = wmm->dwStatus;
776 wmm->dwStatus = MCI_MODE_NOT_READY;
777 if (oldstat == MCI_MODE_PAUSE)
778 dwRet = midiOutReset((HMIDIOUT)wmm->hMidi);
780 if (wmm->hThread)
781 WaitForSingleObject(wmm->hThread, INFINITE);
784 /* sanity reset */
785 wmm->dwStatus = MCI_MODE_STOP;
787 if ((dwFlags & MCI_NOTIFY) && lpParms && MMSYSERR_NOERROR==dwRet)
788 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
789 return dwRet;
792 /**************************************************************************
793 * MIDI_mciClose [internal]
795 static DWORD MIDI_mciClose(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
798 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
800 if (wmm->dwStatus != MCI_MODE_STOP) {
801 /* mciStop handles MCI_NOTIFY_ABORTED */
802 MIDI_mciStop(wmm, MCI_WAIT, lpParms);
805 wmm->nUseCount--;
806 if (wmm->nUseCount == 0) {
807 if (wmm->hFile != 0) {
808 mmioClose(wmm->hFile, 0);
809 wmm->hFile = 0;
810 TRACE("hFile closed !\n");
812 if (wmm->hThread) {
813 CloseHandle(wmm->hThread);
814 wmm->hThread = 0;
816 HeapFree(GetProcessHeap(), 0, wmm->tracks);
817 HeapFree(GetProcessHeap(), 0, wmm->lpstrElementName);
818 HeapFree(GetProcessHeap(), 0, wmm->lpstrCopyright);
819 HeapFree(GetProcessHeap(), 0, wmm->lpstrName);
820 } else {
821 TRACE("Shouldn't happen... nUseCount=%d\n", wmm->nUseCount);
822 return MCIERR_INTERNAL;
825 if ((dwFlags & MCI_NOTIFY) && lpParms) {
826 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
828 return 0;
831 /**************************************************************************
832 * MIDI_mciFindNextEvent [internal]
834 static MCI_MIDITRACK* MIDI_mciFindNextEvent(WINE_MCIMIDI* wmm, LPDWORD hiPulse)
836 WORD cnt, nt;
837 MCI_MIDITRACK* mmt;
839 *hiPulse = 0xFFFFFFFFul;
840 cnt = 0xFFFFu;
841 for (nt = 0; nt < wmm->nTracks; nt++) {
842 mmt = &wmm->tracks[nt];
844 if (mmt->wStatus == 0)
845 continue;
846 if (mmt->dwEventPulse < *hiPulse) {
847 *hiPulse = mmt->dwEventPulse;
848 cnt = nt;
851 return (cnt == 0xFFFFu) ? 0 /* no more event on all tracks */
852 : &wmm->tracks[cnt];
855 /**************************************************************************
856 * MIDI_player [internal]
858 static DWORD MIDI_player(WINE_MCIMIDI* wmm, DWORD dwFlags)
860 DWORD dwRet;
861 WORD doPlay, nt;
862 MCI_MIDITRACK* mmt;
863 DWORD hiPulse, dwStartMS = wmm->dwPositionMS;
864 HANDLE oldcb = NULL;
866 /* init tracks */
867 for (nt = 0; nt < wmm->nTracks; nt++) {
868 mmt = &wmm->tracks[nt];
870 mmt->wStatus = 1; /* ok, playing */
871 mmt->dwIndex = mmt->dwFirst;
872 if (wmm->wFormat == 2 && nt > 0) {
873 mmt->dwEventPulse = wmm->tracks[nt - 1].dwLength;
874 } else {
875 mmt->dwEventPulse = 0;
877 MIDI_mciReadNextEvent(wmm, mmt); /* FIXME == 0 */
880 dwRet = midiOutOpen((LPHMIDIOUT)&wmm->hMidi, wmm->wPort, 0L, 0L, CALLBACK_NULL);
881 if (dwRet != MMSYSERR_NOERROR) {
882 return mmr2mci(dwRet);
885 wmm->dwPulse = 0;
886 wmm->dwTempo = 500000;
887 wmm->dwPositionMS = 0;
888 wmm->wStartedPlaying = FALSE;
890 while (wmm->dwStatus != MCI_MODE_STOP && wmm->dwStatus != MCI_MODE_NOT_READY) {
891 /* it seems that in case of multi-threading, gcc is optimizing just a little bit
892 * too much. Tell gcc not to optimize status value using volatile.
894 while (((volatile WINE_MCIMIDI*)wmm)->dwStatus == MCI_MODE_PAUSE);
896 doPlay = (wmm->dwPositionMS >= dwStartMS && wmm->dwPositionMS <= wmm->dwEndMS);
898 TRACE("wmm->dwStatus=%d, doPlay=%c\n", wmm->dwStatus, doPlay ? 'T' : 'F');
900 if ((mmt = MIDI_mciFindNextEvent(wmm, &hiPulse)) == NULL)
901 break; /* no more event on tracks */
903 /* if starting playing, then set StartTicks to the value it would have had
904 * if play had started at position 0
906 if (doPlay && !wmm->wStartedPlaying) {
907 wmm->dwStartTicks = GetTickCount() - MIDI_ConvertPulseToMS(wmm, wmm->dwPulse);
908 wmm->wStartedPlaying = TRUE;
909 TRACE("Setting dwStartTicks to %u\n", wmm->dwStartTicks);
912 if (hiPulse > wmm->dwPulse) {
913 wmm->dwPositionMS += MIDI_ConvertPulseToMS(wmm, hiPulse - wmm->dwPulse);
914 if (doPlay) {
915 DWORD togo = wmm->dwStartTicks + wmm->dwPositionMS;
916 DWORD tc = GetTickCount();
918 TRACE("Pulses hi=0x%08x <> cur=0x%08x\n", hiPulse, wmm->dwPulse);
919 TRACE("Wait until %u => %u ms\n",
920 tc - wmm->dwStartTicks, togo - wmm->dwStartTicks);
921 if (tc < togo)
922 Sleep(togo - tc);
924 wmm->dwPulse = hiPulse;
927 switch (LOBYTE(LOWORD(mmt->dwEventData))) {
928 case 0xF0:
929 case 0xF7: /* sysex events */
931 FIXME("Not handling SysEx events (yet)\n");
933 break;
934 case 0xFF:
935 /* position after meta data header */
936 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
937 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
938 case 0x00: /* 16-bit sequence number */
939 if (TRACE_ON(mcimidi)) {
940 WORD twd;
942 MIDI_mciReadWord(wmm, &twd); /* == 0 */
943 TRACE("Got sequence number %u\n", twd);
945 break;
946 case 0x01: /* any text */
947 case 0x02: /* Copyright Message text */
948 case 0x03: /* Sequence/Track Name text */
949 case 0x04: /* Instrument Name text */
950 case 0x05: /* Lyric text */
951 case 0x06: /* Marker text */
952 case 0x07: /* Cue-point text */
953 if (TRACE_ON(mcimidi)) {
954 char buf[1024];
955 WORD len = mmt->wEventLength - HIWORD(mmt->dwEventData);
956 static const char* const info[8] = {"", "Text", "Copyright", "Seq/Trk name",
957 "Instrument", "Lyric", "Marker", "Cue-point"};
958 WORD idx = HIBYTE(LOWORD(mmt->dwEventData));
960 if (len >= sizeof(buf)) {
961 WARN("Buffer for text is too small (%u are needed)\n", len);
962 len = sizeof(buf) - 1;
964 if (mmioRead(wmm->hFile, buf, len) == len) {
965 buf[len] = 0; /* end string in case */
966 TRACE("%s => \"%s\"\n", (idx < 8 ) ? info[idx] : "", buf);
967 } else {
968 WARN("Couldn't read data for %s\n", (idx < 8) ? info[idx] : "");
971 break;
972 case 0x20:
973 /* MIDI channel (cc) */
974 if (FIXME_ON(mcimidi)) {
975 BYTE bt;
977 MIDI_mciReadByte(wmm, &bt); /* == 0 */
978 FIXME("NIY: MIDI channel=%u, track=%u\n", bt, mmt->wTrackNr);
980 break;
981 case 0x21:
982 /* MIDI port (pp) */
983 if (FIXME_ON(mcimidi)) {
984 BYTE bt;
986 MIDI_mciReadByte(wmm, &bt); /* == 0 */
987 FIXME("NIY: MIDI port=%u, track=%u\n", bt, mmt->wTrackNr);
989 break;
990 case 0x2F: /* end of track */
991 mmt->wStatus = 0;
992 break;
993 case 0x51:/* set tempo */
994 /* Tempo is expressed in -seconds per midi quarter note
995 * for format 1 MIDI files, this can only be present on track #0
997 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
998 WARN("For format #1 MIDI files, tempo can only be changed on track #0 (%u)\n", mmt->wTrackNr);
999 } else {
1000 BYTE tbt;
1001 DWORD value = 0;
1003 MIDI_mciReadByte(wmm, &tbt); value = ((DWORD)tbt) << 16;
1004 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 8;
1005 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 0;
1006 TRACE("Setting tempo to %d (BPM=%d)\n", wmm->dwTempo, (value) ? (60000000 / value) : 0);
1007 wmm->dwTempo = value;
1009 break;
1010 case 0x54: /* (hour) (min) (second) (frame) (fractional-frame) - SMPTE track start */
1011 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1012 WARN("For format #1 MIDI files, SMPTE track start can only be expressed on track #0 (%u)\n", mmt->wTrackNr);
1013 } if (mmt->dwEventPulse != 0) {
1014 WARN("SMPTE track start can only be expressed at start of track (%u)\n", mmt->dwEventPulse);
1015 } else {
1016 BYTE h, m, s, f, ff;
1018 MIDI_mciReadByte(wmm, &h);
1019 MIDI_mciReadByte(wmm, &m);
1020 MIDI_mciReadByte(wmm, &s);
1021 MIDI_mciReadByte(wmm, &f);
1022 MIDI_mciReadByte(wmm, &ff);
1023 FIXME("NIY: SMPTE track start %u:%u:%u %u.%u\n", h, m, s, f, ff);
1025 break;
1026 case 0x58: /* file rhythm */
1027 if (TRACE_ON(mcimidi)) {
1028 BYTE num, den, cpmc, _32npqn;
1030 MIDI_mciReadByte(wmm, &num);
1031 MIDI_mciReadByte(wmm, &den); /* to notate e.g. 6/8 */
1032 MIDI_mciReadByte(wmm, &cpmc); /* number of MIDI clocks per metronome click */
1033 MIDI_mciReadByte(wmm, &_32npqn); /* number of notated 32nd notes per MIDI quarter note */
1035 TRACE("%u/%u, clock per metronome click=%u, 32nd notes by 1/4 note=%u\n", num, 1 << den, cpmc, _32npqn);
1037 break;
1038 case 0x59: /* key signature */
1039 if (TRACE_ON(mcimidi)) {
1040 BYTE sf, mm;
1042 MIDI_mciReadByte(wmm, &sf);
1043 MIDI_mciReadByte(wmm, &mm);
1045 if (sf >= 0x80) TRACE("%d flats\n", -(char)sf);
1046 else if (sf > 0) TRACE("%d sharps\n", (char)sf);
1047 else TRACE("Key of C\n");
1048 TRACE("Mode: %s\n", (mm == 0) ? "major" : "minor");
1050 break;
1051 default:
1052 WARN("Unknown MIDI meta event %02x. Skipping...\n", HIBYTE(LOWORD(mmt->dwEventData)));
1053 break;
1055 break;
1056 default:
1057 if (doPlay) {
1058 dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
1059 } else {
1060 switch (LOBYTE(LOWORD(mmt->dwEventData)) & 0xF0) {
1061 case MIDI_NOTEON:
1062 case MIDI_NOTEOFF:
1063 dwRet = 0;
1064 break;
1065 default:
1066 dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
1070 mmt->dwIndex += mmt->wEventLength;
1071 if (mmt->dwIndex < mmt->dwFirst || mmt->dwIndex >= mmt->dwLast) {
1072 mmt->wStatus = 0;
1074 if (mmt->wStatus) {
1075 MIDI_mciReadNextEvent(wmm, mmt);
1079 midiOutReset((HMIDIOUT)wmm->hMidi);
1081 dwRet = midiOutClose((HMIDIOUT)wmm->hMidi);
1083 if (dwFlags & MCI_NOTIFY)
1084 oldcb = InterlockedExchangePointer(&wmm->hCallback, NULL);
1086 wmm->dwStatus = MCI_MODE_STOP;
1088 /* Let the potentially asynchronous commands support FAILURE notification. */
1089 if (oldcb) mciDriverNotify(oldcb, wmm->wDevID,
1090 dwRet ? MCI_NOTIFY_FAILURE : MCI_NOTIFY_SUCCESSFUL);
1091 return mmr2mci(dwRet);
1094 static DWORD CALLBACK MIDI_Starter(void *ptr)
1096 WINE_MCIMIDI* wmm = ptr;
1097 return MIDI_player(wmm, MCI_NOTIFY);
1100 static DWORD ensurePlayerThread(WINE_MCIMIDI* wmm)
1102 if (1) {
1103 DWORD dwRet;
1105 switch (wmm->dwStatus) {
1106 default:
1107 return MCIERR_NONAPPLICABLE_FUNCTION;
1108 case MCI_MODE_PAUSE:
1109 return MIDI_mciResume(wmm, 0, NULL);
1110 case MCI_MODE_PLAY:
1111 /* the player was not stopped, use it */
1112 return 0;
1113 case MCI_MODE_STOP:
1114 break;
1116 wmm->dwStatus = MCI_MODE_PLAY;
1117 if (wmm->hThread) {
1118 WaitForSingleObject(wmm->hThread, INFINITE);
1119 CloseHandle(wmm->hThread);
1120 wmm->hThread = 0;
1122 wmm->hThread = CreateThread(NULL, 0, MIDI_Starter, wmm, 0, NULL);
1123 if (!wmm->hThread) {
1124 dwRet = MCIERR_OUT_OF_MEMORY;
1125 } else {
1126 SetThreadPriority(wmm->hThread, THREAD_PRIORITY_TIME_CRITICAL);
1127 dwRet = 0;
1129 if (dwRet)
1130 wmm->dwStatus = MCI_MODE_STOP;
1131 return dwRet;
1135 /**************************************************************************
1136 * MIDI_mciPlay [internal]
1138 static DWORD MIDI_mciPlay(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
1140 DWORD dwStartMS, dwEndMS;
1141 DWORD dwRet;
1142 HANDLE oldcb;
1144 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1146 if (wmm->hFile == 0) {
1147 WARN("Can't play: no file %s!\n", debugstr_w(wmm->lpstrElementName));
1148 return MCIERR_FILE_NOT_FOUND;
1151 if (lpParms && (dwFlags & MCI_TO)) {
1152 dwEndMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
1153 /* FIXME: if (dwEndMS > length) return MCIERR_OUTOFRANGE; */
1154 } else {
1155 dwEndMS = 0xFFFFFFFFul; /* FIXME: dwEndMS = length; */
1157 if (lpParms && (dwFlags & MCI_FROM)) {
1158 dwStartMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwFrom);
1159 } else {
1160 dwStartMS = wmm->dwPositionMS;
1162 if (dwEndMS < dwStartMS)
1163 return MCIERR_OUTOFRANGE;
1165 if (dwFlags & MCI_FROM) {
1166 /* Stop with MCI_NOTIFY_ABORTED and set new position. */
1167 MIDI_mciStop(wmm, MCI_WAIT, NULL);
1168 wmm->dwPositionMS = dwStartMS;
1169 } /* else use existing player. */
1170 if (wmm->dwEndMS != dwEndMS) {
1171 oldcb = InterlockedExchangePointer(&wmm->hCallback, NULL);
1172 if (oldcb) mciDriverNotify(oldcb, wmm->wDevID, MCI_NOTIFY_ABORTED);
1173 wmm->dwEndMS = dwEndMS;
1176 TRACE("Playing from %u to %u\n", dwStartMS, dwEndMS);
1178 if ((dwFlags & MCI_NOTIFY) && lpParms) {
1179 oldcb = InterlockedExchangePointer(&wmm->hCallback, HWND_32(LOWORD(lpParms->dwCallback)));
1180 if (oldcb) mciDriverNotify(oldcb, wmm->wDevID, MCI_NOTIFY_SUPERSEDED);
1183 dwRet = ensurePlayerThread(wmm);
1185 if (!dwRet && (dwFlags & MCI_WAIT)) {
1186 WaitForSingleObject(wmm->hThread, INFINITE);
1187 GetExitCodeThread(wmm->hThread, &dwRet);
1188 /* STATUS_PENDING cannot happen. It folds onto MCIERR_UNRECOGNIZED_KEYWORD */
1190 /* The player thread performs notification at exit. */
1191 return dwRet;
1194 /**************************************************************************
1195 * MIDI_mciPause [internal]
1197 static DWORD MIDI_mciPause(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1199 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1201 if (wmm->dwStatus == MCI_MODE_PLAY) {
1202 /* stop all notes */
1203 unsigned chn;
1204 for (chn = 0; chn < 16; chn++)
1205 midiOutShortMsg((HMIDIOUT)(wmm->hMidi), 0x78B0 | chn);
1206 wmm->dwStatus = MCI_MODE_PAUSE;
1208 if ((dwFlags & MCI_NOTIFY) && lpParms)
1209 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1210 return 0;
1213 /**************************************************************************
1214 * MIDI_mciResume [internal]
1216 static DWORD MIDI_mciResume(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1218 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1220 if (wmm->dwStatus == MCI_MODE_PAUSE) {
1221 wmm->wStartedPlaying = FALSE;
1222 wmm->dwStatus = MCI_MODE_PLAY;
1224 if ((dwFlags & MCI_NOTIFY) && lpParms)
1225 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1226 return 0;
1229 /**************************************************************************
1230 * MIDI_mciSet [internal]
1232 static DWORD MIDI_mciSet(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_SEQ_SET_PARMS lpParms)
1234 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1236 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1238 if (dwFlags & MCI_SET_TIME_FORMAT) {
1239 switch (lpParms->dwTimeFormat) {
1240 case MCI_FORMAT_MILLISECONDS:
1241 TRACE("MCI_FORMAT_MILLISECONDS !\n");
1242 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
1243 break;
1244 case MCI_FORMAT_SMPTE_24:
1245 TRACE("MCI_FORMAT_SMPTE_24 !\n");
1246 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24;
1247 break;
1248 case MCI_FORMAT_SMPTE_25:
1249 TRACE("MCI_FORMAT_SMPTE_25 !\n");
1250 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25;
1251 break;
1252 case MCI_FORMAT_SMPTE_30:
1253 TRACE("MCI_FORMAT_SMPTE_30 !\n");
1254 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30;
1255 break;
1256 default:
1257 WARN("Bad time format %u!\n", lpParms->dwTimeFormat);
1258 return MCIERR_BAD_TIME_FORMAT;
1261 if (dwFlags & MCI_SET_VIDEO) {
1262 TRACE("No support for video !\n");
1263 return MCIERR_UNSUPPORTED_FUNCTION;
1265 if (dwFlags & MCI_SET_DOOR_OPEN) {
1266 TRACE("No support for door open !\n");
1267 return MCIERR_UNSUPPORTED_FUNCTION;
1269 if (dwFlags & MCI_SET_DOOR_CLOSED) {
1270 TRACE("No support for door close !\n");
1271 return MCIERR_UNSUPPORTED_FUNCTION;
1273 if (dwFlags & MCI_SET_AUDIO) {
1274 if (dwFlags & MCI_SET_ON) {
1275 TRACE("MCI_SET_ON audio !\n");
1276 } else if (dwFlags & MCI_SET_OFF) {
1277 TRACE("MCI_SET_OFF audio !\n");
1278 } else {
1279 WARN("MCI_SET_AUDIO without SET_ON or SET_OFF\n");
1280 return MCIERR_BAD_INTEGER;
1283 switch (lpParms->dwAudio)
1285 case MCI_SET_AUDIO_ALL: TRACE("MCI_SET_AUDIO_ALL !\n"); break;
1286 case MCI_SET_AUDIO_LEFT: TRACE("MCI_SET_AUDIO_LEFT !\n"); break;
1287 case MCI_SET_AUDIO_RIGHT: TRACE("MCI_SET_AUDIO_RIGHT !\n"); break;
1288 default: WARN("Unknown audio channel %u\n", lpParms->dwAudio); break;
1292 if (dwFlags & MCI_SEQ_SET_MASTER)
1293 TRACE("MCI_SEQ_SET_MASTER !\n");
1294 if (dwFlags & MCI_SEQ_SET_SLAVE)
1295 TRACE("MCI_SEQ_SET_SLAVE !\n");
1296 if (dwFlags & MCI_SEQ_SET_OFFSET)
1297 TRACE("MCI_SEQ_SET_OFFSET !\n");
1298 if (dwFlags & MCI_SEQ_SET_PORT) {
1299 TRACE("MCI_SEQ_SET_PORT = %d\n", lpParms->dwPort);
1300 if ((UINT16)lpParms->dwPort != (UINT16)MIDI_MAPPER &&
1301 (UINT16)lpParms->dwPort >= midiOutGetNumDevs())
1302 /* FIXME: input/output port distinction? */
1303 return MCIERR_SEQ_PORT_NONEXISTENT;
1304 /* FIXME: Native manages to swap the device while playing! */
1305 wmm->wPort = lpParms->dwPort;
1307 if (dwFlags & MCI_SEQ_SET_TEMPO)
1308 TRACE("MCI_SEQ_SET_TEMPO !\n");
1309 if (dwFlags & MCI_NOTIFY)
1310 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1311 return 0;
1314 /**************************************************************************
1315 * MIDI_mciStatus [internal]
1317 static DWORD MIDI_mciStatus(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
1319 DWORD ret = 0;
1321 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1323 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1325 if (dwFlags & MCI_STATUS_ITEM) {
1326 switch (lpParms->dwItem) {
1327 case MCI_STATUS_CURRENT_TRACK:
1328 /* FIXME in Format 2 */
1329 lpParms->dwReturn = 1;
1330 TRACE("MCI_STATUS_CURRENT_TRACK => %lu\n", lpParms->dwReturn);
1331 break;
1332 case MCI_STATUS_LENGTH:
1333 if ((dwFlags & MCI_TRACK) && wmm->wFormat == 2) {
1334 if (lpParms->dwTrack >= wmm->nTracks)
1335 return MCIERR_OUTOFRANGE;
1336 /* FIXME: this is wrong if there is a tempo change inside the file */
1337 lpParms->dwReturn = MIDI_ConvertPulseToMS(wmm, wmm->tracks[lpParms->dwTrack].dwLength);
1338 } else {
1339 lpParms->dwReturn = MIDI_GetMThdLengthMS(wmm);
1341 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm, lpParms->dwReturn);
1342 /* FIXME: ret = MCI_COLONIZED4_RETURN if SMPTE */
1343 TRACE("MCI_STATUS_LENGTH => %lu\n", lpParms->dwReturn);
1344 break;
1345 case MCI_STATUS_MODE:
1346 TRACE("MCI_STATUS_MODE => %u\n", wmm->dwStatus);
1347 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwStatus, wmm->dwStatus);
1348 ret = MCI_RESOURCE_RETURNED;
1349 break;
1350 case MCI_STATUS_MEDIA_PRESENT:
1351 TRACE("MCI_STATUS_MEDIA_PRESENT => TRUE\n");
1352 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1353 ret = MCI_RESOURCE_RETURNED;
1354 break;
1355 case MCI_STATUS_NUMBER_OF_TRACKS:
1356 lpParms->dwReturn = (wmm->wFormat == 2) ? wmm->nTracks : 1;
1357 TRACE("MCI_STATUS_NUMBER_OF_TRACKS => %lu\n", lpParms->dwReturn);
1358 break;
1359 case MCI_STATUS_POSITION:
1360 /* FIXME: check MCI_TRACK == 1 if set */
1361 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm,
1362 (dwFlags & MCI_STATUS_START) ? 0 : wmm->dwPositionMS);
1363 /* FIXME: ret = MCI_COLONIZED4_RETURN if SMPTE */
1364 TRACE("MCI_STATUS_POSITION %s => %lu\n",
1365 (dwFlags & MCI_STATUS_START) ? "start" : "current", lpParms->dwReturn);
1366 break;
1367 case MCI_STATUS_READY:
1368 lpParms->dwReturn = (wmm->dwStatus == MCI_MODE_NOT_READY) ?
1369 MAKEMCIRESOURCE(FALSE, MCI_FALSE) : MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1370 ret = MCI_RESOURCE_RETURNED;
1371 TRACE("MCI_STATUS_READY = %u\n", LOWORD(lpParms->dwReturn));
1372 break;
1373 case MCI_STATUS_TIME_FORMAT:
1374 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwMciTimeFormat, MCI_FORMAT_RETURN_BASE + wmm->dwMciTimeFormat);
1375 TRACE("MCI_STATUS_TIME_FORMAT => %u\n", LOWORD(lpParms->dwReturn));
1376 ret = MCI_RESOURCE_RETURNED;
1377 break;
1378 case MCI_SEQ_STATUS_DIVTYPE:
1379 TRACE("MCI_SEQ_STATUS_DIVTYPE !\n");
1380 if (wmm->nDivision > 0x8000) {
1381 switch (HIBYTE(wmm->nDivision)) {
1382 case 0xE8: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_24; break; /* -24 */
1383 case 0xE7: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_25; break; /* -25 */
1384 case 0xE3: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
1385 case 0xE2: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30; break; /* -30 */
1386 default: FIXME("There is a bad bad programmer\n");
1388 } else {
1389 lpParms->dwReturn = MCI_SEQ_DIV_PPQN;
1391 lpParms->dwReturn = MAKEMCIRESOURCE(lpParms->dwReturn,lpParms->dwReturn);
1392 ret = MCI_RESOURCE_RETURNED;
1393 break;
1394 case MCI_SEQ_STATUS_MASTER:
1395 TRACE("MCI_SEQ_STATUS_MASTER !\n");
1396 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_SEQ_NONE, MCI_SEQ_NONE_S);
1397 ret = MCI_RESOURCE_RETURNED;
1398 break;
1399 case MCI_SEQ_STATUS_SLAVE:
1400 TRACE("MCI_SEQ_STATUS_SLAVE !\n");
1401 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_SEQ_FILE, MCI_SEQ_FILE_S);
1402 ret = MCI_RESOURCE_RETURNED;
1403 break;
1404 case MCI_SEQ_STATUS_OFFSET:
1405 TRACE("MCI_SEQ_STATUS_OFFSET !\n");
1406 lpParms->dwReturn = 0;
1407 break;
1408 case MCI_SEQ_STATUS_PORT:
1409 if (wmm->wPort != (UINT16)MIDI_MAPPER)
1410 lpParms->dwReturn = wmm->wPort;
1411 else {
1412 lpParms->dwReturn = MAKEMCIRESOURCE(MIDI_MAPPER, MCI_SEQ_MAPPER_S);
1413 ret = MCI_RESOURCE_RETURNED;
1415 TRACE("MCI_SEQ_STATUS_PORT (%u) => %d\n", wmm->wDevID, wmm->wPort);
1416 break;
1417 case MCI_SEQ_STATUS_TEMPO:
1418 TRACE("MCI_SEQ_STATUS_TEMPO !\n");
1419 lpParms->dwReturn = wmm->dwTempo;
1420 break;
1421 default:
1422 FIXME("Unknown command %08X !\n", lpParms->dwItem);
1423 return MCIERR_UNSUPPORTED_FUNCTION;
1425 } else {
1426 return MCIERR_MISSING_PARAMETER;
1428 if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
1429 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1430 return ret;
1433 /**************************************************************************
1434 * MIDI_mciGetDevCaps [internal]
1436 static DWORD MIDI_mciGetDevCaps(WINE_MCIMIDI* wmm, DWORD dwFlags,
1437 LPMCI_GETDEVCAPS_PARMS lpParms)
1439 DWORD ret;
1441 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1443 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1445 if (dwFlags & MCI_GETDEVCAPS_ITEM) {
1446 switch (lpParms->dwItem) {
1447 case MCI_GETDEVCAPS_DEVICE_TYPE:
1448 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE !\n");
1449 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_SEQUENCER, MCI_DEVTYPE_SEQUENCER);
1450 ret = MCI_RESOURCE_RETURNED;
1451 break;
1452 case MCI_GETDEVCAPS_HAS_AUDIO:
1453 TRACE("MCI_GETDEVCAPS_HAS_AUDIO !\n");
1454 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1455 ret = MCI_RESOURCE_RETURNED;
1456 break;
1457 case MCI_GETDEVCAPS_HAS_VIDEO:
1458 TRACE("MCI_GETDEVCAPS_HAS_VIDEO !\n");
1459 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1460 ret = MCI_RESOURCE_RETURNED;
1461 break;
1462 case MCI_GETDEVCAPS_USES_FILES:
1463 TRACE("MCI_GETDEVCAPS_USES_FILES !\n");
1464 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1465 ret = MCI_RESOURCE_RETURNED;
1466 break;
1467 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
1468 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE !\n");
1469 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1470 ret = MCI_RESOURCE_RETURNED;
1471 break;
1472 case MCI_GETDEVCAPS_CAN_EJECT:
1473 TRACE("MCI_GETDEVCAPS_CAN_EJECT !\n");
1474 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1475 ret = MCI_RESOURCE_RETURNED;
1476 break;
1477 case MCI_GETDEVCAPS_CAN_PLAY:
1478 TRACE("MCI_GETDEVCAPS_CAN_PLAY !\n");
1479 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1480 ret = MCI_RESOURCE_RETURNED;
1481 break;
1482 case MCI_GETDEVCAPS_CAN_RECORD:
1483 TRACE("MCI_GETDEVCAPS_CAN_RECORD !\n");
1484 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1485 ret = MCI_RESOURCE_RETURNED;
1486 break;
1487 case MCI_GETDEVCAPS_CAN_SAVE:
1488 TRACE("MCI_GETDEVCAPS_CAN_SAVE !\n");
1489 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1490 ret = MCI_RESOURCE_RETURNED;
1491 break;
1492 default:
1493 FIXME("Unknown capability (%08x) !\n", lpParms->dwItem);
1494 return MCIERR_UNRECOGNIZED_COMMAND;
1496 } else {
1497 WARN("No GetDevCaps-Item !\n");
1498 return MCIERR_UNRECOGNIZED_COMMAND;
1500 if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
1501 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1502 return ret;
1505 /**************************************************************************
1506 * MIDI_mciInfo [internal]
1508 static DWORD MIDI_mciInfo(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_INFO_PARMSW lpParms)
1510 LPCWSTR str = 0;
1511 DWORD ret = 0;
1513 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1515 if (lpParms == NULL || lpParms->lpstrReturn == NULL)
1516 return MCIERR_NULL_PARAMETER_BLOCK;
1518 TRACE("buf=%p, len=%u\n", lpParms->lpstrReturn, lpParms->dwRetSize);
1520 switch (dwFlags & ~(MCI_WAIT|MCI_NOTIFY)) {
1521 case MCI_INFO_PRODUCT: str = L"Wine's MIDI sequencer"; break;
1522 case MCI_INFO_FILE: str = wmm->lpstrElementName; break;
1523 case MCI_INFO_COPYRIGHT: str = wmm->lpstrCopyright; break;
1524 case MCI_INFO_NAME: str = wmm->lpstrName; break;
1525 default:
1526 WARN("Don't know this info command (%u)\n", dwFlags);
1527 return MCIERR_MISSING_PARAMETER; /* not MCIERR_FLAGS_... */
1529 if (!ret) {
1530 if (lpParms->dwRetSize) {
1531 /* FIXME? Since NT, mciwave, mciseq and mcicda set dwRetSize
1532 * to the number of characters written, excluding \0. */
1533 lstrcpynW(lpParms->lpstrReturn, str ? str : L"", lpParms->dwRetSize);
1534 } else ret = MCIERR_PARAM_OVERFLOW;
1536 if (MMSYSERR_NOERROR==ret && (dwFlags & MCI_NOTIFY))
1537 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1538 return ret;
1541 /**************************************************************************
1542 * MIDI_mciSeek [internal]
1544 static DWORD MIDI_mciSeek(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
1546 DWORD position;
1548 TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
1550 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1552 position = dwFlags & (MCI_SEEK_TO_START|MCI_SEEK_TO_END|MCI_TO);
1553 if (!position) return MCIERR_MISSING_PARAMETER;
1554 if (position&(position-1)) return MCIERR_FLAGS_NOT_COMPATIBLE;
1556 MIDI_mciStop(wmm, MCI_WAIT, 0);
1558 if (dwFlags & MCI_TO) { /* FIXME: compare with length */
1559 wmm->dwPositionMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
1560 } else if (dwFlags & MCI_SEEK_TO_START) {
1561 wmm->dwPositionMS = 0;
1562 } else {
1563 wmm->dwPositionMS = 0xFFFFFFFF; /* FIXME */
1566 TRACE("Seeking to position=%u ms\n", wmm->dwPositionMS);
1568 if (dwFlags & MCI_NOTIFY)
1569 MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
1571 return 0;
1574 /*======================================================================*
1575 * MIDI entry points *
1576 *======================================================================*/
1578 /**************************************************************************
1579 * DriverProc (MCISEQ.@)
1581 LRESULT CALLBACK MCIMIDI_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
1582 LPARAM dwParam1, LPARAM dwParam2)
1584 WINE_MCIMIDI* wmm;
1585 switch (wMsg) {
1586 case DRV_LOAD: return 1;
1587 case DRV_FREE: return 1;
1588 case DRV_ENABLE: return 1;
1589 case DRV_DISABLE: return 1;
1590 case DRV_QUERYCONFIGURE: return 1;
1591 case DRV_CONFIGURE: MessageBoxA(0, "Sample Midi Driver !", "OSS Driver", MB_OK); return 1;
1592 case DRV_INSTALL: return DRVCNF_RESTART;
1593 case DRV_REMOVE: return DRVCNF_RESTART;
1594 case DRV_OPEN: return MIDI_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
1595 case DRV_CLOSE: return MIDI_drvClose(dwDevID);
1597 if ((wMsg < DRV_MCI_FIRST) || (wMsg > DRV_MCI_LAST)) {
1598 TRACE("Sending msg %04x to default driver proc\n", wMsg);
1599 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1602 wmm = MIDI_mciGetOpenDev(dwDevID, wMsg);
1603 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1605 switch (wMsg) {
1606 case MCI_OPEN_DRIVER: return MIDI_mciOpen (wmm, dwParam1, (LPMCI_OPEN_PARMSW) dwParam2);
1607 case MCI_CLOSE_DRIVER: return MIDI_mciClose (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1608 case MCI_PLAY: return MIDI_mciPlay (wmm, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
1609 case MCI_STOP: return MIDI_mciStop (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1610 case MCI_SET: return MIDI_mciSet (wmm, dwParam1, (LPMCI_SEQ_SET_PARMS) dwParam2);
1611 case MCI_PAUSE: return MIDI_mciPause (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1612 case MCI_RESUME: return MIDI_mciResume (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1613 case MCI_STATUS: return MIDI_mciStatus (wmm, dwParam1, (LPMCI_STATUS_PARMS) dwParam2);
1614 case MCI_GETDEVCAPS: return MIDI_mciGetDevCaps(wmm, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2);
1615 case MCI_INFO: return MIDI_mciInfo (wmm, dwParam1, (LPMCI_INFO_PARMSW) dwParam2);
1616 case MCI_SEEK: return MIDI_mciSeek (wmm, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
1617 case MCI_OPEN:
1618 case MCI_CLOSE:
1619 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1620 /* fall through */
1621 default:
1622 TRACE("Unsupported command [0x%x]\n", wMsg);
1623 return MCIERR_UNSUPPORTED_FUNCTION; /* Win9x: MCIERR_UNRECOGNIZED_COMMAND */