Release 20030408.
[wine/gsoc-2012-control.git] / dlls / winmm / mciseq / mcimidi.c
blobe410f82a9bfac3255400ed0af734c74b35ff77bd
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * Sample MIDI Wine Driver for Linux
6 * Copyright 1994 Martin Ayotte
7 * 1999 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Eric POUECH :
26 * 98/7 changes for making this MIDI driver work on OSS
27 * current support is limited to MIDI ports of OSS systems
28 * 98/9 rewriting MCI code for MIDI
29 * 98/11 splitted in midi.c and mcimidi.c
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
36 #include "windef.h"
37 #include "winbase.h"
38 #include "wingdi.h"
39 #include "winuser.h"
40 #include "wownt32.h"
41 #include "mmddk.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(mcimidi);
46 #define MIDI_NOTEOFF 0x80
47 #define MIDI_NOTEON 0x90
49 typedef struct {
50 DWORD dwFirst; /* offset in file of track */
51 DWORD dwLast; /* number of bytes in file of track */
52 DWORD dwIndex; /* current index in file (dwFirst <= dwIndex < dwLast) */
53 DWORD dwLength; /* number of pulses in this track */
54 DWORD dwEventPulse; /* current pulse # (event) pointed by dwIndex */
55 DWORD dwEventData; /* current data (event) pointed by dwIndex */
56 WORD wEventLength; /* current length (event) pointed by dwIndex */
57 WORD wStatus : 1, /* 1 : playing, 0 : done */
58 wTrackNr : 7,
59 wLastCommand : 8; /* last MIDI command on track */
60 } MCI_MIDITRACK;
62 typedef struct tagWINE_MCIMIDI {
63 UINT wDevID; /* the MCI one */
64 HMIDI hMidi;
65 int nUseCount; /* Incremented for each shared open */
66 WORD wNotifyDeviceID; /* MCI device ID with a pending notification */
67 HANDLE hCallback; /* Callback handle for pending notification */
68 HMMIO hFile; /* mmio file handle open as Element */
69 LPSTR lpstrElementName; /* Name of file */
70 LPSTR lpstrCopyright;
71 LPSTR lpstrName;
72 WORD dwStatus; /* one from MCI_MODE_xxxx */
73 DWORD dwMciTimeFormat; /* One of the supported MCI_FORMAT_xxxx */
74 WORD wFormat; /* Format of MIDI hFile (0, 1 or 2) */
75 WORD nTracks; /* Number of tracks in hFile */
76 WORD nDivision; /* Number of division in hFile PPQN or SMPTE */
77 WORD wStartedPlaying;
78 DWORD dwTempo; /* Tempo (# of 1/4 note per second */
79 MCI_MIDITRACK* tracks; /* Content of each track */
80 DWORD dwPulse;
81 DWORD dwPositionMS;
82 DWORD dwStartTicks;
83 } WINE_MCIMIDI;
85 /* ===================================================================
86 * ===================================================================
87 * FIXME: should be using the new mmThreadXXXX functions from WINMM
88 * instead of those
89 * it would require to add a wine internal flag to mmThreadCreate
90 * in order to pass a 32 bit function instead of a 16 bit
91 * ===================================================================
92 * =================================================================== */
94 struct SCA {
95 UINT wDevID;
96 UINT wMsg;
97 DWORD dwParam1;
98 DWORD dwParam2;
101 /* EPP DWORD WINAPI mciSendCommandA(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2); */
103 /**************************************************************************
104 * MCI_SCAStarter [internal]
106 static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
108 struct SCA* sca = (struct SCA*)arg;
109 DWORD ret;
111 TRACE("In thread before async command (%08x,%u,%08lx,%08lx)\n",
112 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
113 ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2);
114 TRACE("In thread after async command (%08x,%u,%08lx,%08lx)\n",
115 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
116 HeapFree(GetProcessHeap(), 0, sca);
117 ExitThread(ret);
118 WARN("Should not happen ? what's wrong \n");
119 /* should not go after this point */
120 return ret;
123 /**************************************************************************
124 * MCI_SendCommandAsync [internal]
126 static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD dwParam1,
127 DWORD dwParam2, UINT size)
129 struct SCA* sca = HeapAlloc(GetProcessHeap(), 0, sizeof(struct SCA) + size);
131 if (sca == 0)
132 return MCIERR_OUT_OF_MEMORY;
134 sca->wDevID = wDevID;
135 sca->wMsg = wMsg;
136 sca->dwParam1 = dwParam1;
138 if (size && dwParam2) {
139 sca->dwParam2 = (DWORD)sca + sizeof(struct SCA);
140 /* copy structure passed by program in dwParam2 to be sure
141 * we can still use it whatever the program does
143 memcpy((LPVOID)sca->dwParam2, (LPVOID)dwParam2, size);
144 } else {
145 sca->dwParam2 = dwParam2;
148 if (CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL) == 0) {
149 WARN("Couldn't allocate thread for async command handling, sending synchonously\n");
150 return MCI_SCAStarter(&sca);
152 return 0;
155 /*======================================================================*
156 * MCI MIDI implemantation *
157 *======================================================================*/
159 static DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
161 /**************************************************************************
162 * MIDI_drvOpen [internal]
164 static DWORD MIDI_drvOpen(LPSTR str, LPMCI_OPEN_DRIVER_PARMSA modp)
166 WINE_MCIMIDI* wmm;
168 if (!modp) return 0xFFFFFFFF;
170 wmm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIMIDI));
172 if (!wmm)
173 return 0;
175 wmm->wDevID = modp->wDeviceID;
176 mciSetDriverData(wmm->wDevID, (DWORD)wmm);
177 modp->wCustomCommandTable = MCI_NO_COMMAND_TABLE;
178 modp->wType = MCI_DEVTYPE_SEQUENCER;
179 return modp->wDeviceID;
182 /**************************************************************************
183 * MCIMIDI_drvClose [internal]
185 static DWORD MIDI_drvClose(DWORD dwDevID)
187 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(dwDevID);
189 if (wmm) {
190 HeapFree(GetProcessHeap(), 0, wmm);
191 mciSetDriverData(dwDevID, 0);
192 return 1;
194 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
197 /**************************************************************************
198 * MIDI_mciGetOpenDev [internal]
200 static WINE_MCIMIDI* MIDI_mciGetOpenDev(UINT wDevID)
202 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
204 if (wmm == NULL || wmm->nUseCount == 0) {
205 WARN("Invalid wDevID=%u\n", wDevID);
206 return 0;
208 return wmm;
211 /**************************************************************************
212 * MIDI_mciReadByte [internal]
214 static DWORD MIDI_mciReadByte(WINE_MCIMIDI* wmm, BYTE *lpbyt)
216 DWORD ret = 0;
218 if (lpbyt == NULL ||
219 mmioRead(wmm->hFile, (HPSTR)lpbyt, sizeof(BYTE)) != (long)sizeof(BYTE)) {
220 WARN("Error reading wmm=%p\n", wmm);
221 ret = MCIERR_INVALID_FILE;
224 return ret;
227 /**************************************************************************
228 * MIDI_mciReadWord [internal]
230 static DWORD MIDI_mciReadWord(WINE_MCIMIDI* wmm, LPWORD lpw)
232 BYTE hibyte, lobyte;
233 DWORD ret = MCIERR_INVALID_FILE;
235 if (lpw != NULL &&
236 MIDI_mciReadByte(wmm, &hibyte) == 0 &&
237 MIDI_mciReadByte(wmm, &lobyte) == 0) {
238 *lpw = ((WORD)hibyte << 8) + lobyte;
239 ret = 0;
241 return ret;
244 /**************************************************************************
245 * MIDI_mciReadLong [internal]
247 static DWORD MIDI_mciReadLong(WINE_MCIMIDI* wmm, LPDWORD lpdw)
249 WORD hiword, loword;
250 DWORD ret = MCIERR_INVALID_FILE;
252 if (lpdw != NULL &&
253 MIDI_mciReadWord(wmm, &hiword) == 0 &&
254 MIDI_mciReadWord(wmm, &loword) == 0) {
255 *lpdw = MAKELONG(loword, hiword);
256 ret = 0;
258 return ret;
261 /**************************************************************************
262 * MIDI_mciReadVaryLen [internal]
264 static WORD MIDI_mciReadVaryLen(WINE_MCIMIDI* wmm, LPDWORD lpdw)
266 BYTE byte;
267 DWORD value = 0;
268 WORD ret = 0;
270 if (lpdw == NULL) {
271 ret = MCIERR_INVALID_FILE;
272 } else {
273 do {
274 if (MIDI_mciReadByte(wmm, &byte) != 0) {
275 return 0;
277 value = (value << 7) + (byte & 0x7F);
278 ret++;
279 } while (byte & 0x80);
280 *lpdw = value;
282 TRACE("val=%08lX \n", value);
285 return ret;
288 /**************************************************************************
289 * MIDI_mciReadNextEvent [internal]
291 static DWORD MIDI_mciReadNextEvent(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
293 BYTE b1, b2 = 0, b3;
294 WORD hw = 0;
295 DWORD evtPulse;
296 DWORD evtLength;
297 DWORD tmp;
299 if (mmioSeek(wmm->hFile, mmt->dwIndex, SEEK_SET) != mmt->dwIndex) {
300 WARN("Can't seek at %08lX \n", mmt->dwIndex);
301 return MCIERR_INVALID_FILE;
303 evtLength = MIDI_mciReadVaryLen(wmm, &evtPulse) + 1; /* > 0 */
304 MIDI_mciReadByte(wmm, &b1);
305 switch (b1) {
306 case 0xF0:
307 case 0xF7:
308 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
309 evtLength += tmp;
310 break;
311 case 0xFF:
312 MIDI_mciReadByte(wmm, &b2); evtLength++;
314 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
315 if (evtLength >= 0x10000u) {
316 /* this limitation shouldn't be a problem */
317 WARN("Ouch !! Implementation limitation to 64k bytes for a MIDI event is overflowed\n");
318 hw = 0xFFFF;
319 } else {
320 hw = LOWORD(evtLength);
322 evtLength += tmp;
323 break;
324 default:
325 if (b1 & 0x80) { /* use running status ? */
326 mmt->wLastCommand = b1;
327 MIDI_mciReadByte(wmm, &b2); evtLength++;
328 } else {
329 b2 = b1;
330 b1 = mmt->wLastCommand;
332 switch ((b1 >> 4) & 0x07) {
333 case 0: case 1: case 2: case 3: case 6:
334 MIDI_mciReadByte(wmm, &b3); evtLength++;
335 hw = b3;
336 break;
337 case 4: case 5:
338 break;
339 case 7:
340 WARN("Strange indeed b1=0x%02x\n", b1);
342 break;
344 if (mmt->dwIndex + evtLength > mmt->dwLast)
345 return MCIERR_INTERNAL;
347 mmt->dwEventPulse += evtPulse;
348 mmt->dwEventData = (hw << 16) + (b2 << 8) + b1;
349 mmt->wEventLength = evtLength;
352 TRACE("[%u] => pulse=%08lx(%08lx), data=%08lx, length=%u\n",
353 mmt->wTrackNr, mmt->dwEventPulse, evtPulse,
354 mmt->dwEventData, mmt->wEventLength);
356 return 0;
359 /**************************************************************************
360 * MIDI_mciReadMTrk [internal]
362 static DWORD MIDI_mciReadMTrk(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
364 DWORD toberead;
365 FOURCC fourcc;
367 if (mmioRead(wmm->hFile, (HPSTR)&fourcc, (long)sizeof(FOURCC)) !=
368 (long)sizeof(FOURCC)) {
369 return MCIERR_INVALID_FILE;
372 if (fourcc != mmioFOURCC('M', 'T', 'r', 'k')) {
373 WARN("Can't synchronize on 'MTrk' !\n");
374 return MCIERR_INVALID_FILE;
377 if (MIDI_mciReadLong(wmm, &toberead) != 0) {
378 return MCIERR_INVALID_FILE;
380 mmt->dwFirst = mmioSeek(wmm->hFile, 0, SEEK_CUR); /* >= 0 */
381 mmt->dwLast = mmt->dwFirst + toberead;
383 /* compute # of pulses in this track */
384 mmt->dwIndex = mmt->dwFirst;
385 mmt->dwEventPulse = 0;
387 while (MIDI_mciReadNextEvent(wmm, mmt) == 0 && LOWORD(mmt->dwEventData) != 0x2FFF) {
388 char buf[1024];
389 WORD len;
391 mmt->dwIndex += mmt->wEventLength;
393 switch (LOWORD(mmt->dwEventData)) {
394 case 0x02FF:
395 case 0x03FF:
396 /* position after meta data header */
397 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
398 len = mmt->wEventLength - HIWORD(mmt->dwEventData);
400 if (len >= sizeof(buf)) {
401 WARN("Buffer for text is too small (%d bytes, when %u are needed)\n", sizeof(buf) - 1, len);
402 len = sizeof(buf) - 1;
404 if (mmioRead(wmm->hFile, (HPSTR)buf, len) == len) {
405 buf[len] = 0; /* end string in case */
406 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
407 case 0x02:
408 if (wmm->lpstrCopyright) {
409 WARN("Two copyright notices (%s|%s)\n", wmm->lpstrCopyright, buf);
410 } else {
411 wmm->lpstrCopyright = HeapAlloc( GetProcessHeap(), 0, strlen(buf)+1 );
412 strcpy( wmm->lpstrCopyright, buf );
414 break;
415 case 0x03:
416 if (wmm->lpstrName) {
417 WARN("Two names (%s|%s)\n", wmm->lpstrName, buf);
418 } else {
419 wmm->lpstrName = HeapAlloc( GetProcessHeap(), 0, strlen(buf)+1 );
420 strcpy( wmm->lpstrName, buf );
422 break;
425 break;
428 mmt->dwLength = mmt->dwEventPulse;
430 TRACE("Track %u has %lu bytes and %lu pulses\n", mmt->wTrackNr, toberead, mmt->dwLength);
432 /* reset track data */
433 mmt->wStatus = 1; /* ok, playing */
434 mmt->dwIndex = mmt->dwFirst;
435 mmt->dwEventPulse = 0;
437 if (mmioSeek(wmm->hFile, 0, SEEK_CUR) != mmt->dwLast) {
438 WARN("Ouch, out of sync seek=%lu track=%lu\n",
439 mmioSeek(wmm->hFile, 0, SEEK_CUR), mmt->dwLast);
440 /* position at end of this track, to be ready to read next track */
441 mmioSeek(wmm->hFile, mmt->dwLast, SEEK_SET);
444 return 0;
447 /**************************************************************************
448 * MIDI_mciReadMThd [internal]
450 static DWORD MIDI_mciReadMThd(WINE_MCIMIDI* wmm, DWORD dwOffset)
452 DWORD toberead;
453 FOURCC fourcc;
454 WORD nt;
456 TRACE("(%p, %08lX);\n", wmm, dwOffset);
458 if (mmioSeek(wmm->hFile, dwOffset, SEEK_SET) != dwOffset) {
459 WARN("Can't seek at %08lX begin of 'MThd' \n", dwOffset);
460 return MCIERR_INVALID_FILE;
462 if (mmioRead(wmm->hFile, (HPSTR)&fourcc,
463 (long) sizeof(FOURCC)) != (long) sizeof(FOURCC))
464 return MCIERR_INVALID_FILE;
466 if (fourcc != mmioFOURCC('M', 'T', 'h', 'd')) {
467 WARN("Can't synchronize on 'MThd' !\n");
468 return MCIERR_INVALID_FILE;
471 if (MIDI_mciReadLong(wmm, &toberead) != 0 || toberead < 3 * sizeof(WORD))
472 return MCIERR_INVALID_FILE;
474 if (MIDI_mciReadWord(wmm, &wmm->wFormat) != 0 ||
475 MIDI_mciReadWord(wmm, &wmm->nTracks) != 0 ||
476 MIDI_mciReadWord(wmm, &wmm->nDivision) != 0) {
477 return MCIERR_INVALID_FILE;
480 TRACE("toberead=0x%08lX, wFormat=0x%04X nTracks=0x%04X nDivision=0x%04X\n",
481 toberead, wmm->wFormat, wmm->nTracks, wmm->nDivision);
483 /* MS doc says that the MIDI MCI time format must be put by default to the format
484 * stored in the MIDI file...
486 if (wmm->nDivision > 0x8000) {
487 /* eric.pouech@lemel.fr 98/11
488 * In did not check this very code (pulses are expressed as SMPTE sub-frames).
489 * In about 40 MB of MIDI files I have, none was SMPTE based...
490 * I'm just wondering if this is widely used :-). So, if someone has one of
491 * these files, I'd like to know about.
493 FIXME("Handling SMPTE time in MIDI files has not been tested\n"
494 "Please report to comp.emulators.ms-windows.wine with MIDI file !\n");
496 switch (HIBYTE(wmm->nDivision)) {
497 case 0xE8: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24; break; /* -24 */
498 case 0xE7: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25; break; /* -25 */
499 case 0xE3: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
500 case 0xE2: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30; break; /* -30 */
501 default:
502 WARN("Unsupported number of frames %d\n", -(char)HIBYTE(wmm->nDivision));
503 return MCIERR_INVALID_FILE;
505 switch (LOBYTE(wmm->nDivision)) {
506 case 4: /* MIDI Time Code */
507 case 8:
508 case 10:
509 case 80: /* SMPTE bit resolution */
510 case 100:
511 default:
512 WARN("Unsupported number of sub-frames %d\n", LOBYTE(wmm->nDivision));
513 return MCIERR_INVALID_FILE;
515 } else if (wmm->nDivision == 0) {
516 WARN("Number of division is 0, can't support that !!\n");
517 return MCIERR_INVALID_FILE;
518 } else {
519 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
522 switch (wmm->wFormat) {
523 case 0:
524 if (wmm->nTracks != 1) {
525 WARN("Got type 0 file whose number of track is not 1. Setting it to 1\n");
526 wmm->nTracks = 1;
528 break;
529 case 1:
530 case 2:
531 break;
532 default:
533 WARN("Handling MIDI files which format = %d is not (yet) supported\n"
534 "Please report with MIDI file !\n", wmm->wFormat);
535 return MCIERR_INVALID_FILE;
538 if (wmm->nTracks & 0x8000) {
539 /* this shouldn't be a problem... */
540 WARN("Ouch !! Implementation limitation to 32k tracks per MIDI file is overflowed\n");
541 wmm->nTracks = 0x7FFF;
544 if ((wmm->tracks = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_MIDITRACK) * wmm->nTracks)) == NULL) {
545 return MCIERR_OUT_OF_MEMORY;
548 toberead -= 3 * sizeof(WORD);
549 if (toberead > 0) {
550 TRACE("Size of MThd > 6, skipping %ld extra bytes\n", toberead);
551 mmioSeek(wmm->hFile, toberead, SEEK_CUR);
554 for (nt = 0; nt < wmm->nTracks; nt++) {
555 wmm->tracks[nt].wTrackNr = nt;
556 if (MIDI_mciReadMTrk(wmm, &wmm->tracks[nt]) != 0) {
557 WARN("Can't read 'MTrk' header \n");
558 return MCIERR_INVALID_FILE;
562 wmm->dwTempo = 500000;
564 return 0;
567 /**************************************************************************
568 * MIDI_ConvertPulseToMS [internal]
570 static DWORD MIDI_ConvertPulseToMS(WINE_MCIMIDI* wmm, DWORD pulse)
572 DWORD ret = 0;
574 /* FIXME: this function may return false values since the tempo (wmm->dwTempo)
575 * may change during file playing
577 if (wmm->nDivision == 0) {
578 FIXME("Shouldn't happen. wmm->nDivision = 0\n");
579 } else if (wmm->nDivision > 0x8000) { /* SMPTE, unchecked FIXME? */
580 int nf = -(char)HIBYTE(wmm->nDivision); /* number of frames */
581 int nsf = LOBYTE(wmm->nDivision); /* number of sub-frames */
582 ret = (pulse * 1000) / (nf * nsf);
583 } else {
584 ret = (DWORD)((double)pulse * ((double)wmm->dwTempo / 1000) /
585 (double)wmm->nDivision);
589 TRACE("pulse=%lu tempo=%lu division=%u=0x%04x => ms=%lu\n",
590 pulse, wmm->dwTempo, wmm->nDivision, wmm->nDivision, ret);
593 return ret;
596 #define TIME_MS_IN_ONE_HOUR (60*60*1000)
597 #define TIME_MS_IN_ONE_MINUTE (60*1000)
598 #define TIME_MS_IN_ONE_SECOND (1000)
600 /**************************************************************************
601 * MIDI_ConvertTimeFormatToMS [internal]
603 static DWORD MIDI_ConvertTimeFormatToMS(WINE_MCIMIDI* wmm, DWORD val)
605 DWORD ret = 0;
607 switch (wmm->dwMciTimeFormat) {
608 case MCI_FORMAT_MILLISECONDS:
609 ret = val;
610 break;
611 case MCI_FORMAT_SMPTE_24:
612 ret =
613 (HIBYTE(HIWORD(val)) * 125) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
614 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
615 break;
616 case MCI_FORMAT_SMPTE_25:
617 ret =
618 HIBYTE(HIWORD(val)) * 40 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
619 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
620 break;
621 case MCI_FORMAT_SMPTE_30:
622 ret =
623 (HIBYTE(HIWORD(val)) * 100) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
624 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
625 break;
626 default:
627 WARN("Bad time format %lu!\n", wmm->dwMciTimeFormat);
630 TRACE("val=%lu=0x%08lx [tf=%lu] => ret=%lu\n", val, val, wmm->dwMciTimeFormat, ret);
632 return ret;
635 /**************************************************************************
636 * MIDI_ConvertMSToTimeFormat [internal]
638 static DWORD MIDI_ConvertMSToTimeFormat(WINE_MCIMIDI* wmm, DWORD _val)
640 DWORD ret = 0, val = _val;
641 DWORD h, m, s, f;
643 switch (wmm->dwMciTimeFormat) {
644 case MCI_FORMAT_MILLISECONDS:
645 ret = val;
646 break;
647 case MCI_FORMAT_SMPTE_24:
648 case MCI_FORMAT_SMPTE_25:
649 case MCI_FORMAT_SMPTE_30:
650 h = val / TIME_MS_IN_ONE_HOUR;
651 m = (val -= h * TIME_MS_IN_ONE_HOUR) / TIME_MS_IN_ONE_MINUTE;
652 s = (val -= m * TIME_MS_IN_ONE_MINUTE) / TIME_MS_IN_ONE_SECOND;
653 switch (wmm->dwMciTimeFormat) {
654 case MCI_FORMAT_SMPTE_24:
655 /* one frame is 1000/24 val long, 1000/24 == 125/3 */
656 f = (val * 3) / 125; val -= (f * 125) / 3;
657 break;
658 case MCI_FORMAT_SMPTE_25:
659 /* one frame is 1000/25 ms long, 1000/25 == 40 */
660 f = val / 40; val -= f * 40;
661 break;
662 case MCI_FORMAT_SMPTE_30:
663 /* one frame is 1000/30 ms long, 1000/30 == 100/3 */
664 f = (val * 3) / 100; val -= (f * 100) / 3;
665 break;
666 default:
667 FIXME("There must be some bad bad programmer\n");
668 f = 0;
670 /* val contains the number of ms which cannot make a complete frame */
671 /* FIXME: is this correct ? programs seem to be happy with that */
672 ret = (f << 24) | (s << 16) | (m << 8) | (h << 0);
673 break;
674 default:
675 WARN("Bad time format %lu!\n", wmm->dwMciTimeFormat);
678 TRACE("val=%lu [tf=%lu] => ret=%lu=0x%08lx\n", _val, wmm->dwMciTimeFormat, ret, ret);
680 return ret;
683 /**************************************************************************
684 * MIDI_GetMThdLengthMS [internal]
686 static DWORD MIDI_GetMThdLengthMS(WINE_MCIMIDI* wmm)
688 WORD nt;
689 DWORD ret = 0;
691 for (nt = 0; nt < wmm->nTracks; nt++) {
692 if (wmm->wFormat == 2) {
693 ret += wmm->tracks[nt].dwLength;
694 } else if (wmm->tracks[nt].dwLength > ret) {
695 ret = wmm->tracks[nt].dwLength;
698 /* FIXME: this is wrong if there is a tempo change inside the file */
699 return MIDI_ConvertPulseToMS(wmm, ret);
702 /**************************************************************************
703 * MIDI_mciOpen [internal]
705 static DWORD MIDI_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMSA lpParms)
707 DWORD dwRet = 0;
708 DWORD dwDeviceID;
709 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
711 TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
713 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
714 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
715 if (dwFlags & MCI_OPEN_SHAREABLE)
716 return MCIERR_HARDWARE;
718 if (wmm->nUseCount > 0) {
719 /* The driver is already opened on this channel
720 * MIDI sequencer cannot be shared
722 return MCIERR_DEVICE_OPEN;
724 wmm->nUseCount++;
726 wmm->hFile = 0;
727 wmm->hMidi = 0;
728 dwDeviceID = lpParms->wDeviceID;
730 TRACE("wDevID=%04X (lpParams->wDeviceID=%08lX)\n", wDevID, dwDeviceID);
731 /* lpParms->wDeviceID = wDevID;*/
733 if (dwFlags & MCI_OPEN_ELEMENT) {
734 TRACE("MCI_OPEN_ELEMENT '%s' !\n", lpParms->lpstrElementName);
735 if (lpParms->lpstrElementName && strlen(lpParms->lpstrElementName) > 0) {
736 wmm->hFile = mmioOpenA(lpParms->lpstrElementName, NULL,
737 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
738 if (wmm->hFile == 0) {
739 WARN("Can't find file '%s' !\n", lpParms->lpstrElementName);
740 wmm->nUseCount--;
741 return MCIERR_FILE_NOT_FOUND;
743 } else {
744 wmm->hFile = 0;
747 TRACE("hFile=%p\n", wmm->hFile);
749 /* FIXME: should I get a strdup() of it instead? */
750 wmm->lpstrElementName = HeapAlloc( GetProcessHeap(), 0, strlen(lpParms->lpstrElementName)+1 );
751 strcpy( wmm->lpstrElementName, lpParms->lpstrElementName );
752 wmm->lpstrCopyright = NULL;
753 wmm->lpstrName = NULL;
755 wmm->wNotifyDeviceID = dwDeviceID;
756 wmm->dwStatus = MCI_MODE_NOT_READY; /* while loading file contents */
757 /* spec says it should be the default format from the MIDI file... */
758 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
760 if (wmm->hFile != 0) {
761 MMCKINFO ckMainRIFF;
762 MMCKINFO mmckInfo;
763 DWORD dwOffset = 0;
765 if (mmioDescend(wmm->hFile, &ckMainRIFF, NULL, 0) != 0) {
766 dwRet = MCIERR_INVALID_FILE;
767 } else {
768 TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08lX \n",
769 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
771 if (ckMainRIFF.ckid == FOURCC_RIFF && ckMainRIFF.fccType == mmioFOURCC('R', 'M', 'I', 'D')) {
772 mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
773 mmioSeek(wmm->hFile, ckMainRIFF.dwDataOffset + ((ckMainRIFF.cksize + 1) & ~1), SEEK_SET);
774 if (mmioDescend(wmm->hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) {
775 TRACE("... is a 'RMID' file \n");
776 dwOffset = mmckInfo.dwDataOffset;
777 } else {
778 dwRet = MCIERR_INVALID_FILE;
781 if (dwRet == 0 && MIDI_mciReadMThd(wmm, dwOffset) != 0) {
782 WARN("Can't read 'MThd' header \n");
783 dwRet = MCIERR_INVALID_FILE;
786 } else {
787 TRACE("hFile==0, setting #tracks to 0; is this correct ?\n");
788 wmm->nTracks = 0;
789 wmm->wFormat = 0;
790 wmm->nDivision = 1;
792 if (dwRet != 0) {
793 wmm->nUseCount--;
794 if (wmm->hFile != 0)
795 mmioClose(wmm->hFile, 0);
796 wmm->hFile = 0;
797 } else {
798 wmm->dwPositionMS = 0;
799 wmm->dwStatus = MCI_MODE_STOP;
801 return dwRet;
804 /**************************************************************************
805 * MIDI_mciStop [internal]
807 static DWORD MIDI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
809 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
810 DWORD dwRet = 0;
812 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
814 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
816 if (wmm->dwStatus != MCI_MODE_STOP) {
817 int oldstat = wmm->dwStatus;
819 wmm->dwStatus = MCI_MODE_NOT_READY;
820 if (oldstat == MCI_MODE_PAUSE)
821 dwRet = midiOutReset((HMIDIOUT)wmm->hMidi);
823 while (wmm->dwStatus != MCI_MODE_STOP)
824 Sleep(10);
827 /* sanitiy reset */
828 wmm->dwStatus = MCI_MODE_STOP;
830 TRACE("wmm->dwStatus=%d\n", wmm->dwStatus);
832 if (lpParms && (dwFlags & MCI_NOTIFY)) {
833 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
834 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
835 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
837 return 0;
840 /**************************************************************************
841 * MIDI_mciClose [internal]
843 static DWORD MIDI_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
845 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
847 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
849 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
851 if (wmm->dwStatus != MCI_MODE_STOP) {
852 MIDI_mciStop(wDevID, MCI_WAIT, lpParms);
855 wmm->nUseCount--;
856 if (wmm->nUseCount == 0) {
857 if (wmm->hFile != 0) {
858 mmioClose(wmm->hFile, 0);
859 wmm->hFile = 0;
860 TRACE("hFile closed !\n");
862 HeapFree(GetProcessHeap(), 0, wmm->tracks);
863 HeapFree(GetProcessHeap(), 0, (LPSTR)wmm->lpstrElementName);
864 HeapFree(GetProcessHeap(), 0, (LPSTR)wmm->lpstrCopyright);
865 HeapFree(GetProcessHeap(), 0, (LPSTR)wmm->lpstrName);
866 } else {
867 TRACE("Shouldn't happen... nUseCount=%d\n", wmm->nUseCount);
868 return MCIERR_INTERNAL;
871 if (lpParms && (dwFlags & MCI_NOTIFY)) {
872 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
873 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
874 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
876 return 0;
879 /**************************************************************************
880 * MIDI_mciFindNextEvent [internal]
882 static MCI_MIDITRACK* MIDI_mciFindNextEvent(WINE_MCIMIDI* wmm, LPDWORD hiPulse)
884 WORD cnt, nt;
885 MCI_MIDITRACK* mmt;
887 *hiPulse = 0xFFFFFFFFul;
888 cnt = 0xFFFFu;
889 for (nt = 0; nt < wmm->nTracks; nt++) {
890 mmt = &wmm->tracks[nt];
892 if (mmt->wStatus == 0)
893 continue;
894 if (mmt->dwEventPulse < *hiPulse) {
895 *hiPulse = mmt->dwEventPulse;
896 cnt = nt;
899 return (cnt == 0xFFFFu) ? 0 /* no more event on all tracks */
900 : &wmm->tracks[cnt];
903 /**************************************************************************
904 * MIDI_mciPlay [internal]
906 static DWORD MIDI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
908 DWORD dwStartMS, dwEndMS;
909 DWORD dwRet = 0;
910 WORD doPlay, nt;
911 MCI_MIDITRACK* mmt;
912 DWORD hiPulse;
913 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
915 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
917 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
919 if (wmm->hFile == 0) {
920 WARN("Can't play: no file '%s' !\n", wmm->lpstrElementName);
921 return MCIERR_FILE_NOT_FOUND;
924 if (wmm->dwStatus != MCI_MODE_STOP) {
925 if (wmm->dwStatus == MCI_MODE_PAUSE) {
926 /* FIXME: parameters (start/end) in lpParams may not be used */
927 return MIDI_mciResume(wDevID, dwFlags, (LPMCI_GENERIC_PARMS)lpParms);
929 WARN("Can't play: device is not stopped !\n");
930 return MCIERR_INTERNAL;
933 if (!(dwFlags & MCI_WAIT)) {
934 /** FIXME: I'm not 100% sure that wNotifyDeviceID is the right value in all cases ??? */
935 return MCI_SendCommandAsync(wmm->wNotifyDeviceID, MCI_PLAY, dwFlags, (DWORD)lpParms, sizeof(LPMCI_PLAY_PARMS));
938 if (lpParms && (dwFlags & MCI_FROM)) {
939 dwStartMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwFrom);
940 } else {
941 dwStartMS = wmm->dwPositionMS;
944 if (lpParms && (dwFlags & MCI_TO)) {
945 dwEndMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
946 } else {
947 dwEndMS = 0xFFFFFFFFul;
950 TRACE("Playing from %lu to %lu\n", dwStartMS, dwEndMS);
952 /* init tracks */
953 for (nt = 0; nt < wmm->nTracks; nt++) {
954 mmt = &wmm->tracks[nt];
956 mmt->wStatus = 1; /* ok, playing */
957 mmt->dwIndex = mmt->dwFirst;
958 if (wmm->wFormat == 2 && nt > 0) {
959 mmt->dwEventPulse = wmm->tracks[nt - 1].dwLength;
960 } else {
961 mmt->dwEventPulse = 0;
963 MIDI_mciReadNextEvent(wmm, mmt); /* FIXME == 0 */
966 dwRet = midiOutOpen((LPHMIDIOUT)&wmm->hMidi, MIDIMAPPER, 0L, 0L, CALLBACK_NULL);
967 /* dwRet = midiInOpen(&wmm->hMidi, MIDIMAPPER, 0L, 0L, CALLBACK_NULL);*/
968 if (dwRet != MMSYSERR_NOERROR) {
969 return dwRet;
972 wmm->dwPulse = 0;
973 wmm->dwTempo = 500000;
974 wmm->dwStatus = MCI_MODE_PLAY;
975 wmm->dwPositionMS = 0;
976 wmm->wStartedPlaying = FALSE;
978 while (wmm->dwStatus != MCI_MODE_STOP && wmm->dwStatus != MCI_MODE_NOT_READY) {
979 /* it seems that in case of multi-threading, gcc is optimizing just a little bit
980 * too much. Tell gcc not to optimize status value using volatile.
982 while (((volatile WINE_MCIMIDI*)wmm)->dwStatus == MCI_MODE_PAUSE);
984 doPlay = (wmm->dwPositionMS >= dwStartMS && wmm->dwPositionMS <= dwEndMS);
986 TRACE("wmm->dwStatus=%d, doPlay=%c\n", wmm->dwStatus, doPlay ? 'T' : 'F');
988 if ((mmt = MIDI_mciFindNextEvent(wmm, &hiPulse)) == NULL)
989 break; /* no more event on tracks */
991 /* if starting playing, then set StartTicks to the value it would have had
992 * if play had started at position 0
994 if (doPlay && !wmm->wStartedPlaying) {
995 wmm->dwStartTicks = GetTickCount() - MIDI_ConvertPulseToMS(wmm, wmm->dwPulse);
996 wmm->wStartedPlaying = TRUE;
997 TRACE("Setting dwStartTicks to %lu\n", wmm->dwStartTicks);
1000 if (hiPulse > wmm->dwPulse) {
1001 wmm->dwPositionMS += MIDI_ConvertPulseToMS(wmm, hiPulse - wmm->dwPulse);
1002 if (doPlay) {
1003 DWORD togo = wmm->dwStartTicks + wmm->dwPositionMS;
1004 DWORD tc = GetTickCount();
1006 TRACE("Pulses hi=0x%08lx <> cur=0x%08lx\n", hiPulse, wmm->dwPulse);
1007 TRACE("Wait until %lu => %lu ms\n",
1008 tc - wmm->dwStartTicks, togo - wmm->dwStartTicks);
1009 if (tc < togo)
1010 Sleep(togo - tc);
1012 wmm->dwPulse = hiPulse;
1015 switch (LOBYTE(LOWORD(mmt->dwEventData))) {
1016 case 0xF0:
1017 case 0xF7: /* sysex events */
1019 FIXME("Not handling SysEx events (yet)\n");
1021 break;
1022 case 0xFF:
1023 /* position after meta data header */
1024 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
1025 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
1026 case 0x00: /* 16-bit sequence number */
1027 if (TRACE_ON(mcimidi)) {
1028 WORD twd;
1030 MIDI_mciReadWord(wmm, &twd); /* == 0 */
1031 TRACE("Got sequence number %u\n", twd);
1033 break;
1034 case 0x01: /* any text */
1035 case 0x02: /* Copyright Message text */
1036 case 0x03: /* Sequence/Track Name text */
1037 case 0x04: /* Instrument Name text */
1038 case 0x05: /* Lyric text */
1039 case 0x06: /* Marker text */
1040 case 0x07: /* Cue-point text */
1041 if (TRACE_ON(mcimidi)) {
1042 char buf[1024];
1043 WORD len = mmt->wEventLength - HIWORD(mmt->dwEventData);
1044 static char* info[8] = {"", "Text", "Copyright", "Seq/Trk name",
1045 "Instrument", "Lyric", "Marker", "Cue-point"};
1046 WORD idx = HIBYTE(LOWORD(mmt->dwEventData));
1048 if (len >= sizeof(buf)) {
1049 WARN("Buffer for text is too small (%d bytes, when %u are needed)\n", sizeof(buf) - 1, len);
1050 len = sizeof(buf) - 1;
1052 if (mmioRead(wmm->hFile, (HPSTR)buf, len) == len) {
1053 buf[len] = 0; /* end string in case */
1054 TRACE("%s => \"%s\"\n", (idx < 8 ) ? info[idx] : "", buf);
1055 } else {
1056 WARN("Couldn't read data for %s\n", (idx < 8) ? info[idx] : "");
1059 break;
1060 case 0x20:
1061 /* MIDI channel (cc) */
1062 if (FIXME_ON(mcimidi)) {
1063 BYTE bt;
1065 MIDI_mciReadByte(wmm, &bt); /* == 0 */
1066 FIXME("NIY: MIDI channel=%u, track=%u\n", bt, mmt->wTrackNr);
1068 break;
1069 case 0x21:
1070 /* MIDI port (pp) */
1071 if (FIXME_ON(mcimidi)) {
1072 BYTE bt;
1074 MIDI_mciReadByte(wmm, &bt); /* == 0 */
1075 FIXME("NIY: MIDI port=%u, track=%u\n", bt, mmt->wTrackNr);
1077 break;
1078 case 0x2F: /* end of track */
1079 mmt->wStatus = 0;
1080 break;
1081 case 0x51:/* set tempo */
1082 /* Tempo is expressed in µ-seconds per midi quarter note
1083 * for format 1 MIDI files, this can only be present on track #0
1085 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1086 WARN("For format #1 MIDI files, tempo can only be changed on track #0 (%u)\n", mmt->wTrackNr);
1087 } else {
1088 BYTE tbt;
1089 DWORD value = 0;
1091 MIDI_mciReadByte(wmm, &tbt); value = ((DWORD)tbt) << 16;
1092 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 8;
1093 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 0;
1094 TRACE("Setting tempo to %ld (BPM=%ld)\n", wmm->dwTempo, (value) ? (60000000l / value) : 0);
1095 wmm->dwTempo = value;
1097 break;
1098 case 0x54: /* (hour) (min) (second) (frame) (fractional-frame) - SMPTE track start */
1099 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1100 WARN("For format #1 MIDI files, SMPTE track start can only be expressed on track #0 (%u)\n", mmt->wTrackNr);
1101 } if (mmt->dwEventPulse != 0) {
1102 WARN("SMPTE track start can only be expressed at start of track (%lu)\n", mmt->dwEventPulse);
1103 } else {
1104 BYTE h, m, s, f, ff;
1106 MIDI_mciReadByte(wmm, &h);
1107 MIDI_mciReadByte(wmm, &m);
1108 MIDI_mciReadByte(wmm, &s);
1109 MIDI_mciReadByte(wmm, &f);
1110 MIDI_mciReadByte(wmm, &ff);
1111 FIXME("NIY: SMPTE track start %u:%u:%u %u.%u\n", h, m, s, f, ff);
1113 break;
1114 case 0x58: /* file rythm */
1115 if (TRACE_ON(mcimidi)) {
1116 BYTE num, den, cpmc, _32npqn;
1118 MIDI_mciReadByte(wmm, &num);
1119 MIDI_mciReadByte(wmm, &den); /* to notate e.g. 6/8 */
1120 MIDI_mciReadByte(wmm, &cpmc); /* number of MIDI clocks per metronome click */
1121 MIDI_mciReadByte(wmm, &_32npqn); /* number of notated 32nd notes per MIDI quarter note */
1123 TRACE("%u/%u, clock per metronome click=%u, 32nd notes by 1/4 note=%u\n", num, 1 << den, cpmc, _32npqn);
1125 break;
1126 case 0x59: /* key signature */
1127 if (TRACE_ON(mcimidi)) {
1128 BYTE sf, mm;
1130 MIDI_mciReadByte(wmm, &sf);
1131 MIDI_mciReadByte(wmm, &mm);
1133 if (sf >= 0x80) TRACE("%d flats\n", -(char)sf);
1134 else if (sf > 0) TRACE("%d sharps\n", (char)sf);
1135 else TRACE("Key of C\n");
1136 TRACE("Mode: %s\n", (mm = 0) ? "major" : "minor");
1138 break;
1139 default:
1140 WARN("Unknown MIDI meta event %02x. Skipping...\n", HIBYTE(LOWORD(mmt->dwEventData)));
1141 break;
1143 break;
1144 default:
1145 if (doPlay) {
1146 dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
1147 } else {
1148 switch (LOBYTE(LOWORD(mmt->dwEventData)) & 0xF0) {
1149 case MIDI_NOTEON:
1150 case MIDI_NOTEOFF:
1151 dwRet = 0;
1152 break;
1153 default:
1154 dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
1158 mmt->dwIndex += mmt->wEventLength;
1159 if (mmt->dwIndex < mmt->dwFirst || mmt->dwIndex >= mmt->dwLast) {
1160 mmt->wStatus = 0;
1162 if (mmt->wStatus) {
1163 MIDI_mciReadNextEvent(wmm, mmt);
1167 midiOutReset((HMIDIOUT)wmm->hMidi);
1169 dwRet = midiOutClose((HMIDIOUT)wmm->hMidi);
1170 /* to restart playing at beginning when it's over */
1171 wmm->dwPositionMS = 0;
1173 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1174 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1175 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1176 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1179 wmm->dwStatus = MCI_MODE_STOP;
1180 return dwRet;
1183 /**************************************************************************
1184 * MIDI_mciRecord [internal]
1186 static DWORD MIDI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
1188 int start, end;
1189 MIDIHDR midiHdr;
1190 DWORD dwRet;
1191 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1193 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1195 if (wmm == 0) return MCIERR_INVALID_DEVICE_ID;
1197 if (wmm->hFile == 0) {
1198 WARN("Can't find file='%s' !\n", wmm->lpstrElementName);
1199 return MCIERR_FILE_NOT_FOUND;
1201 start = 1; end = 99999;
1202 if (lpParms && (dwFlags & MCI_FROM)) {
1203 start = lpParms->dwFrom;
1204 TRACE("MCI_FROM=%d \n", start);
1206 if (lpParms && (dwFlags & MCI_TO)) {
1207 end = lpParms->dwTo;
1208 TRACE("MCI_TO=%d \n", end);
1210 midiHdr.lpData = (LPSTR) HeapAlloc(GetProcessHeap(), 0, 1200);
1211 if (!midiHdr.lpData)
1212 return MCIERR_OUT_OF_MEMORY;
1213 midiHdr.dwBufferLength = 1024;
1214 midiHdr.dwUser = 0L;
1215 midiHdr.dwFlags = 0L;
1216 dwRet = midiInPrepareHeader((HMIDIIN)wmm->hMidi, &midiHdr, sizeof(MIDIHDR));
1217 TRACE("After MIDM_PREPARE \n");
1218 wmm->dwStatus = MCI_MODE_RECORD;
1219 /* FIXME: there is no buffer added */
1220 while (wmm->dwStatus != MCI_MODE_STOP) {
1221 TRACE("wmm->dwStatus=%p %d\n",
1222 &wmm->dwStatus, wmm->dwStatus);
1223 midiHdr.dwBytesRecorded = 0;
1224 dwRet = midiInStart((HMIDIIN)wmm->hMidi);
1225 TRACE("midiInStart => dwBytesRecorded=%lu\n", midiHdr.dwBytesRecorded);
1226 if (midiHdr.dwBytesRecorded == 0) break;
1228 TRACE("Before MIDM_UNPREPARE \n");
1229 dwRet = midiInUnprepareHeader((HMIDIIN)wmm->hMidi, &midiHdr, sizeof(MIDIHDR));
1230 TRACE("After MIDM_UNPREPARE \n");
1231 if (midiHdr.lpData != NULL) {
1232 HeapFree(GetProcessHeap(), 0, midiHdr.lpData);
1233 midiHdr.lpData = NULL;
1235 wmm->dwStatus = MCI_MODE_STOP;
1236 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1237 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1238 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1239 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1241 return 0;
1244 /**************************************************************************
1245 * MIDI_mciPause [internal]
1247 static DWORD MIDI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1249 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1251 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1253 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1255 if (wmm->dwStatus == MCI_MODE_PLAY) {
1256 /* stop all notes */
1257 unsigned chn;
1258 for (chn = 0; chn < 16; chn++)
1259 midiOutShortMsg((HMIDIOUT)(wmm->hMidi), 0x78B0 | chn);
1260 wmm->dwStatus = MCI_MODE_PAUSE;
1262 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1263 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1264 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1265 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1268 return 0;
1271 /**************************************************************************
1272 * MIDI_mciResume [internal]
1274 static DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1276 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1278 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1280 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1282 if (wmm->dwStatus == MCI_MODE_PAUSE) {
1283 wmm->wStartedPlaying = FALSE;
1284 wmm->dwStatus = MCI_MODE_PLAY;
1286 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1287 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1288 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1289 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1291 return 0;
1294 /**************************************************************************
1295 * MIDI_mciSet [internal]
1297 static DWORD MIDI_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
1299 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1301 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1303 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1304 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1306 if (dwFlags & MCI_SET_TIME_FORMAT) {
1307 switch (lpParms->dwTimeFormat) {
1308 case MCI_FORMAT_MILLISECONDS:
1309 TRACE("MCI_FORMAT_MILLISECONDS !\n");
1310 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
1311 break;
1312 case MCI_FORMAT_SMPTE_24:
1313 TRACE("MCI_FORMAT_SMPTE_24 !\n");
1314 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24;
1315 break;
1316 case MCI_FORMAT_SMPTE_25:
1317 TRACE("MCI_FORMAT_SMPTE_25 !\n");
1318 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25;
1319 break;
1320 case MCI_FORMAT_SMPTE_30:
1321 TRACE("MCI_FORMAT_SMPTE_30 !\n");
1322 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30;
1323 break;
1324 default:
1325 WARN("Bad time format %lu!\n", lpParms->dwTimeFormat);
1326 return MCIERR_BAD_TIME_FORMAT;
1329 if (dwFlags & MCI_SET_VIDEO) {
1330 TRACE("No support for video !\n");
1331 return MCIERR_UNSUPPORTED_FUNCTION;
1333 if (dwFlags & MCI_SET_DOOR_OPEN) {
1334 TRACE("No support for door open !\n");
1335 return MCIERR_UNSUPPORTED_FUNCTION;
1337 if (dwFlags & MCI_SET_DOOR_CLOSED) {
1338 TRACE("No support for door close !\n");
1339 return MCIERR_UNSUPPORTED_FUNCTION;
1341 if (dwFlags & MCI_SET_AUDIO) {
1342 if (dwFlags & MCI_SET_ON) {
1343 TRACE("MCI_SET_ON audio !\n");
1344 } else if (dwFlags & MCI_SET_OFF) {
1345 TRACE("MCI_SET_OFF audio !\n");
1346 } else {
1347 WARN("MCI_SET_AUDIO without SET_ON or SET_OFF\n");
1348 return MCIERR_BAD_INTEGER;
1351 if (lpParms->dwAudio & MCI_SET_AUDIO_ALL)
1352 TRACE("MCI_SET_AUDIO_ALL !\n");
1353 if (lpParms->dwAudio & MCI_SET_AUDIO_LEFT)
1354 TRACE("MCI_SET_AUDIO_LEFT !\n");
1355 if (lpParms->dwAudio & MCI_SET_AUDIO_RIGHT)
1356 TRACE("MCI_SET_AUDIO_RIGHT !\n");
1359 if (dwFlags & MCI_SEQ_SET_MASTER)
1360 TRACE("MCI_SEQ_SET_MASTER !\n");
1361 if (dwFlags & MCI_SEQ_SET_SLAVE)
1362 TRACE("MCI_SEQ_SET_SLAVE !\n");
1363 if (dwFlags & MCI_SEQ_SET_OFFSET)
1364 TRACE("MCI_SEQ_SET_OFFSET !\n");
1365 if (dwFlags & MCI_SEQ_SET_PORT)
1366 TRACE("MCI_SEQ_SET_PORT !\n");
1367 if (dwFlags & MCI_SEQ_SET_TEMPO)
1368 TRACE("MCI_SEQ_SET_TEMPO !\n");
1369 return 0;
1372 /**************************************************************************
1373 * MIDI_mciStatus [internal]
1375 static DWORD MIDI_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
1377 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1378 DWORD ret = 0;
1380 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1382 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1383 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1385 if (dwFlags & MCI_STATUS_ITEM) {
1386 switch (lpParms->dwItem) {
1387 case MCI_STATUS_CURRENT_TRACK:
1388 /* FIXME in Format 2 */
1389 lpParms->dwReturn = 1;
1390 TRACE("MCI_STATUS_CURRENT_TRACK => %lu\n", lpParms->dwReturn);
1391 break;
1392 case MCI_STATUS_LENGTH:
1393 if ((dwFlags & MCI_TRACK) && wmm->wFormat == 2) {
1394 if (lpParms->dwTrack >= wmm->nTracks)
1395 return MCIERR_BAD_INTEGER;
1396 /* FIXME: this is wrong if there is a tempo change inside the file */
1397 lpParms->dwReturn = MIDI_ConvertPulseToMS(wmm, wmm->tracks[lpParms->dwTrack].dwLength);
1398 } else {
1399 lpParms->dwReturn = MIDI_GetMThdLengthMS(wmm);
1401 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm, lpParms->dwReturn);
1402 TRACE("MCI_STATUS_LENGTH => %lu\n", lpParms->dwReturn);
1403 break;
1404 case MCI_STATUS_MODE:
1405 TRACE("MCI_STATUS_MODE => %u\n", wmm->dwStatus);
1406 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwStatus, wmm->dwStatus);
1407 ret = MCI_RESOURCE_RETURNED;
1408 break;
1409 case MCI_STATUS_MEDIA_PRESENT:
1410 TRACE("MCI_STATUS_MEDIA_PRESENT => TRUE\n");
1411 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1412 ret = MCI_RESOURCE_RETURNED;
1413 break;
1414 case MCI_STATUS_NUMBER_OF_TRACKS:
1415 lpParms->dwReturn = (wmm->wFormat == 2) ? wmm->nTracks : 1;
1416 TRACE("MCI_STATUS_NUMBER_OF_TRACKS => %lu\n", lpParms->dwReturn);
1417 break;
1418 case MCI_STATUS_POSITION:
1419 /* FIXME: do I need to use MCI_TRACK ? */
1420 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm,
1421 (dwFlags & MCI_STATUS_START) ? 0 : wmm->dwPositionMS);
1422 TRACE("MCI_STATUS_POSITION %s => %lu\n",
1423 (dwFlags & MCI_STATUS_START) ? "start" : "current", lpParms->dwReturn);
1424 break;
1425 case MCI_STATUS_READY:
1426 lpParms->dwReturn = (wmm->dwStatus == MCI_MODE_NOT_READY) ?
1427 MAKEMCIRESOURCE(FALSE, MCI_FALSE) : MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1428 ret = MCI_RESOURCE_RETURNED;
1429 TRACE("MCI_STATUS_READY = %u\n", LOWORD(lpParms->dwReturn));
1430 break;
1431 case MCI_STATUS_TIME_FORMAT:
1432 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwMciTimeFormat, wmm->dwMciTimeFormat);
1433 TRACE("MCI_STATUS_TIME_FORMAT => %u\n", LOWORD(lpParms->dwReturn));
1434 ret = MCI_RESOURCE_RETURNED;
1435 break;
1436 case MCI_SEQ_STATUS_DIVTYPE:
1437 TRACE("MCI_SEQ_STATUS_DIVTYPE !\n");
1438 if (wmm->nDivision > 0x8000) {
1439 switch (wmm->nDivision) {
1440 case 0xE8: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_24; break; /* -24 */
1441 case 0xE7: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_25; break; /* -25 */
1442 case 0xE3: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
1443 case 0xE2: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30; break; /* -30 */
1444 default: FIXME("There is a bad bad programmer\n");
1446 } else {
1447 lpParms->dwReturn = MCI_SEQ_DIV_PPQN;
1449 lpParms->dwReturn = MAKEMCIRESOURCE(lpParms->dwReturn,lpParms->dwReturn);
1450 ret = MCI_RESOURCE_RETURNED;
1451 break;
1452 case MCI_SEQ_STATUS_MASTER:
1453 TRACE("MCI_SEQ_STATUS_MASTER !\n");
1454 lpParms->dwReturn = 0;
1455 break;
1456 case MCI_SEQ_STATUS_SLAVE:
1457 TRACE("MCI_SEQ_STATUS_SLAVE !\n");
1458 lpParms->dwReturn = 0;
1459 break;
1460 case MCI_SEQ_STATUS_OFFSET:
1461 TRACE("MCI_SEQ_STATUS_OFFSET !\n");
1462 lpParms->dwReturn = 0;
1463 break;
1464 case MCI_SEQ_STATUS_PORT:
1465 TRACE("MCI_SEQ_STATUS_PORT (%u)!\n", wmm->wDevID);
1466 lpParms->dwReturn = MIDI_MAPPER;
1467 break;
1468 case MCI_SEQ_STATUS_TEMPO:
1469 TRACE("MCI_SEQ_STATUS_TEMPO !\n");
1470 lpParms->dwReturn = wmm->dwTempo;
1471 break;
1472 default:
1473 FIXME("Unknowm command %08lX !\n", lpParms->dwItem);
1474 return MCIERR_UNRECOGNIZED_COMMAND;
1476 } else {
1477 WARN("No Status-Item!\n");
1478 return MCIERR_UNRECOGNIZED_COMMAND;
1480 if (dwFlags & MCI_NOTIFY) {
1481 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1482 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1483 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1485 return ret;
1488 /**************************************************************************
1489 * MIDI_mciGetDevCaps [internal]
1491 static DWORD MIDI_mciGetDevCaps(UINT wDevID, DWORD dwFlags,
1492 LPMCI_GETDEVCAPS_PARMS lpParms)
1494 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1495 DWORD ret;
1497 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1499 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1500 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1502 if (dwFlags & MCI_GETDEVCAPS_ITEM) {
1503 switch (lpParms->dwItem) {
1504 case MCI_GETDEVCAPS_DEVICE_TYPE:
1505 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE !\n");
1506 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_SEQUENCER, MCI_DEVTYPE_SEQUENCER);
1507 ret = MCI_RESOURCE_RETURNED;
1508 break;
1509 case MCI_GETDEVCAPS_HAS_AUDIO:
1510 TRACE("MCI_GETDEVCAPS_HAS_AUDIO !\n");
1511 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1512 ret = MCI_RESOURCE_RETURNED;
1513 break;
1514 case MCI_GETDEVCAPS_HAS_VIDEO:
1515 TRACE("MCI_GETDEVCAPS_HAS_VIDEO !\n");
1516 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1517 ret = MCI_RESOURCE_RETURNED;
1518 break;
1519 case MCI_GETDEVCAPS_USES_FILES:
1520 TRACE("MCI_GETDEVCAPS_USES_FILES !\n");
1521 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1522 ret = MCI_RESOURCE_RETURNED;
1523 break;
1524 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
1525 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE !\n");
1526 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1527 ret = MCI_RESOURCE_RETURNED;
1528 break;
1529 case MCI_GETDEVCAPS_CAN_EJECT:
1530 TRACE("MCI_GETDEVCAPS_CAN_EJECT !\n");
1531 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1532 ret = MCI_RESOURCE_RETURNED;
1533 break;
1534 case MCI_GETDEVCAPS_CAN_PLAY:
1535 TRACE("MCI_GETDEVCAPS_CAN_PLAY !\n");
1536 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1537 ret = MCI_RESOURCE_RETURNED;
1538 break;
1539 case MCI_GETDEVCAPS_CAN_RECORD:
1540 TRACE("MCI_GETDEVCAPS_CAN_RECORD !\n");
1541 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1542 ret = MCI_RESOURCE_RETURNED;
1543 break;
1544 case MCI_GETDEVCAPS_CAN_SAVE:
1545 TRACE("MCI_GETDEVCAPS_CAN_SAVE !\n");
1546 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1547 ret = MCI_RESOURCE_RETURNED;
1548 break;
1549 default:
1550 FIXME("Unknown capability (%08lx) !\n", lpParms->dwItem);
1551 return MCIERR_UNRECOGNIZED_COMMAND;
1553 } else {
1554 WARN("No GetDevCaps-Item !\n");
1555 return MCIERR_UNRECOGNIZED_COMMAND;
1557 return ret;
1560 /**************************************************************************
1561 * MIDI_mciInfo [internal]
1563 static DWORD MIDI_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMSA lpParms)
1565 LPCSTR str = 0;
1566 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1567 DWORD ret = 0;
1569 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1571 if (lpParms == NULL || lpParms->lpstrReturn == NULL)
1572 return MCIERR_NULL_PARAMETER_BLOCK;
1573 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1575 TRACE("buf=%p, len=%lu\n", lpParms->lpstrReturn, lpParms->dwRetSize);
1577 switch (dwFlags & ~(MCI_WAIT|MCI_NOTIFY)) {
1578 case MCI_INFO_PRODUCT:
1579 str = "Wine's MIDI sequencer";
1580 break;
1581 case MCI_INFO_FILE:
1582 str = wmm->lpstrElementName;
1583 break;
1584 case MCI_INFO_COPYRIGHT:
1585 str = wmm->lpstrCopyright;
1586 break;
1587 case MCI_INFO_NAME:
1588 str = wmm->lpstrName;
1589 break;
1590 default:
1591 WARN("Don't know this info command (%lu)\n", dwFlags);
1592 return MCIERR_UNRECOGNIZED_COMMAND;
1594 if (str) {
1595 if (lpParms->dwRetSize <= strlen(str)) {
1596 lstrcpynA(lpParms->lpstrReturn, str, lpParms->dwRetSize - 1);
1597 ret = MCIERR_PARAM_OVERFLOW;
1598 } else {
1599 strcpy(lpParms->lpstrReturn, str);
1601 } else {
1602 *lpParms->lpstrReturn = 0;
1604 return ret;
1607 /**************************************************************************
1608 * MIDI_mciSeek [internal]
1610 static DWORD MIDI_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
1612 DWORD ret = 0;
1613 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1615 TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
1617 if (lpParms == NULL) {
1618 ret = MCIERR_NULL_PARAMETER_BLOCK;
1619 } else if (wmm == NULL) {
1620 ret = MCIERR_INVALID_DEVICE_ID;
1621 } else {
1622 MIDI_mciStop(wDevID, MCI_WAIT, 0);
1624 if (dwFlags & MCI_SEEK_TO_START) {
1625 wmm->dwPositionMS = 0;
1626 } else if (dwFlags & MCI_SEEK_TO_END) {
1627 wmm->dwPositionMS = 0xFFFFFFFF; /* FIXME */
1628 } else if (dwFlags & MCI_TO) {
1629 wmm->dwPositionMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
1630 } else {
1631 WARN("dwFlag doesn't tell where to seek to...\n");
1632 return MCIERR_MISSING_PARAMETER;
1635 TRACE("Seeking to position=%lu ms\n", wmm->dwPositionMS);
1637 if (dwFlags & MCI_NOTIFY) {
1638 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1639 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1640 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1643 return ret;
1646 /*======================================================================*
1647 * MIDI entry points *
1648 *======================================================================*/
1650 /**************************************************************************
1651 * DriverProc (MCISEQ.@)
1653 LONG CALLBACK MCIMIDI_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg,
1654 DWORD dwParam1, DWORD dwParam2)
1656 switch (wMsg) {
1657 case DRV_LOAD: return 1;
1658 case DRV_FREE: return 1;
1659 case DRV_ENABLE: return 1;
1660 case DRV_DISABLE: return 1;
1661 case DRV_QUERYCONFIGURE: return 1;
1662 case DRV_CONFIGURE: MessageBoxA(0, "Sample Midi Driver !", "OSS Driver", MB_OK); return 1;
1663 case DRV_INSTALL: return DRVCNF_RESTART;
1664 case DRV_REMOVE: return DRVCNF_RESTART;
1665 case DRV_OPEN: return MIDI_drvOpen((LPSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSA)dwParam2);
1666 case DRV_CLOSE: return MIDI_drvClose(dwDevID);
1669 if (dwDevID == 0xFFFFFFFF) return MCIERR_UNSUPPORTED_FUNCTION;
1671 switch (wMsg) {
1672 case MCI_OPEN_DRIVER: return MIDI_mciOpen (dwDevID, dwParam1, (LPMCI_OPEN_PARMSA) dwParam2);
1673 case MCI_CLOSE_DRIVER: return MIDI_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1674 case MCI_PLAY: return MIDI_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
1675 case MCI_RECORD: return MIDI_mciRecord (dwDevID, dwParam1, (LPMCI_RECORD_PARMS) dwParam2);
1676 case MCI_STOP: return MIDI_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1677 case MCI_SET: return MIDI_mciSet (dwDevID, dwParam1, (LPMCI_SET_PARMS) dwParam2);
1678 case MCI_PAUSE: return MIDI_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1679 case MCI_RESUME: return MIDI_mciResume (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1680 case MCI_STATUS: return MIDI_mciStatus (dwDevID, dwParam1, (LPMCI_STATUS_PARMS) dwParam2);
1681 case MCI_GETDEVCAPS: return MIDI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2);
1682 case MCI_INFO: return MIDI_mciInfo (dwDevID, dwParam1, (LPMCI_INFO_PARMSA) dwParam2);
1683 case MCI_SEEK: return MIDI_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
1684 /* commands that should be supported */
1685 case MCI_LOAD:
1686 case MCI_SAVE:
1687 case MCI_FREEZE:
1688 case MCI_PUT:
1689 case MCI_REALIZE:
1690 case MCI_UNFREEZE:
1691 case MCI_UPDATE:
1692 case MCI_WHERE:
1693 case MCI_STEP:
1694 case MCI_SPIN:
1695 case MCI_ESCAPE:
1696 case MCI_COPY:
1697 case MCI_CUT:
1698 case MCI_DELETE:
1699 case MCI_PASTE:
1700 WARN("Unsupported command [%lu]\n", wMsg);
1701 break;
1702 /* commands that should report an error */
1703 case MCI_WINDOW:
1704 TRACE("Unsupported command [%lu]\n", wMsg);
1705 break;
1706 case MCI_OPEN:
1707 case MCI_CLOSE:
1708 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1709 break;
1710 default:
1711 TRACE("Sending msg [%lu] to default driver proc\n", wMsg);
1712 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1714 return MCIERR_UNRECOGNIZED_COMMAND;