shell32: DragQueryFile doesn't count the null terminator.
[wine/multimedia.git] / dlls / mciseq / mcimidi.c
blob7fc8c6a61c9c6f82dd3088a533f9a115f0b82fb8
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 (especially for reading/record)
25 * + better implement non waiting command (without the MCI_WAIT flag).
26 * + implement the recording features
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <stdio.h>
32 #include <string.h>
34 #include "windef.h"
35 #include "winbase.h"
36 #include "wingdi.h"
37 #include "winuser.h"
38 #include "wownt32.h"
39 #include "mmddk.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mcimidi);
45 #define MIDI_NOTEOFF 0x80
46 #define MIDI_NOTEON 0x90
48 typedef struct {
49 DWORD dwFirst; /* offset in file of track */
50 DWORD dwLast; /* number of bytes in file of track */
51 DWORD dwIndex; /* current index in file (dwFirst <= dwIndex < dwLast) */
52 DWORD dwLength; /* number of pulses in this track */
53 DWORD dwEventPulse; /* current pulse # (event) pointed by dwIndex */
54 DWORD dwEventData; /* current data (event) pointed by dwIndex */
55 WORD wEventLength; /* current length (event) pointed by dwIndex */
56 WORD wStatus : 1, /* 1 : playing, 0 : done */
57 wTrackNr : 7,
58 wLastCommand : 8; /* last MIDI command on track */
59 } MCI_MIDITRACK;
61 typedef struct tagWINE_MCIMIDI {
62 UINT wDevID; /* the MCI one */
63 HMIDI hMidi;
64 int nUseCount; /* Incremented for each shared open */
65 WORD wNotifyDeviceID; /* MCI device ID with a pending notification */
66 HANDLE hCallback; /* Callback handle for pending notification */
67 HMMIO hFile; /* mmio file handle open as Element */
68 LPWSTR lpstrElementName; /* Name of file (if any) */
69 LPWSTR lpstrCopyright;
70 LPWSTR lpstrName;
71 WORD dwStatus; /* one from MCI_MODE_xxxx */
72 DWORD dwMciTimeFormat; /* One of the supported MCI_FORMAT_xxxx */
73 WORD wFormat; /* Format of MIDI hFile (0, 1 or 2) */
74 WORD nTracks; /* Number of tracks in hFile */
75 WORD nDivision; /* Number of division in hFile PPQN or SMPTE */
76 WORD wStartedPlaying;
77 DWORD dwTempo; /* Tempo (# of 1/4 note per second */
78 MCI_MIDITRACK* tracks; /* Content of each track */
79 DWORD dwPulse;
80 DWORD dwPositionMS;
81 DWORD dwStartTicks;
82 } WINE_MCIMIDI;
84 /* ===================================================================
85 * ===================================================================
86 * FIXME: should be using the new mmThreadXXXX functions from WINMM
87 * instead of those
88 * it would require to add a wine internal flag to mmThreadCreate
89 * in order to pass a 32 bit function instead of a 16 bit
90 * ===================================================================
91 * =================================================================== */
93 struct SCA {
94 UINT wDevID;
95 UINT wMsg;
96 DWORD_PTR dwParam1;
97 DWORD_PTR dwParam2;
100 /* EPP DWORD WINAPI mciSendCommandA(UINT wDevID, UINT wMsg, DWORD dwParam1, DWORD dwParam2); */
102 /**************************************************************************
103 * MCI_SCAStarter [internal]
105 static DWORD CALLBACK MCI_SCAStarter(LPVOID arg)
107 struct SCA* sca = (struct SCA*)arg;
108 DWORD ret;
110 TRACE("In thread before async command (%08x,%u,%08lx,%08lx)\n",
111 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
112 ret = mciSendCommandA(sca->wDevID, sca->wMsg, sca->dwParam1 | MCI_WAIT, sca->dwParam2);
113 TRACE("In thread after async command (%08x,%u,%08lx,%08lx)\n",
114 sca->wDevID, sca->wMsg, sca->dwParam1, sca->dwParam2);
115 HeapFree(GetProcessHeap(), 0, sca);
116 ExitThread(ret);
117 WARN("Should not happen ? what's wrong\n");
118 /* should not go after this point */
119 return ret;
122 /**************************************************************************
123 * MCI_SendCommandAsync [internal]
125 static DWORD MCI_SendCommandAsync(UINT wDevID, UINT wMsg, DWORD_PTR dwParam1,
126 DWORD_PTR dwParam2, UINT size)
128 HANDLE handle;
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_PTR)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 ((handle = CreateThread(NULL, 0, MCI_SCAStarter, sca, 0, NULL)) == 0) {
149 WARN("Couldn't allocate thread for async command handling, sending synchronously\n");
150 return MCI_SCAStarter(&sca);
152 SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
153 CloseHandle(handle);
154 return 0;
157 /*======================================================================*
158 * MCI MIDI implementation *
159 *======================================================================*/
161 static DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
163 /**************************************************************************
164 * MIDI_drvOpen [internal]
166 static DWORD MIDI_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
168 WINE_MCIMIDI* wmm;
170 if (!modp) return 0xFFFFFFFF;
172 wmm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIMIDI));
174 if (!wmm)
175 return 0;
177 wmm->wDevID = modp->wDeviceID;
178 mciSetDriverData(wmm->wDevID, (DWORD_PTR)wmm);
179 modp->wCustomCommandTable = MCI_NO_COMMAND_TABLE;
180 modp->wType = MCI_DEVTYPE_SEQUENCER;
181 return modp->wDeviceID;
184 /**************************************************************************
185 * MCIMIDI_drvClose [internal]
187 static DWORD MIDI_drvClose(DWORD dwDevID)
189 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(dwDevID);
191 if (wmm) {
192 HeapFree(GetProcessHeap(), 0, wmm);
193 mciSetDriverData(dwDevID, 0);
194 return 1;
196 return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
199 /**************************************************************************
200 * MIDI_mciGetOpenDev [internal]
202 static WINE_MCIMIDI* MIDI_mciGetOpenDev(UINT wDevID)
204 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
206 if (wmm == NULL || wmm->nUseCount == 0) {
207 WARN("Invalid wDevID=%u\n", wDevID);
208 return 0;
210 return wmm;
213 /**************************************************************************
214 * MIDI_mciReadByte [internal]
216 static DWORD MIDI_mciReadByte(WINE_MCIMIDI* wmm, BYTE *lpbyt)
218 DWORD ret = 0;
220 if (lpbyt == NULL ||
221 mmioRead(wmm->hFile, (HPSTR)lpbyt, sizeof(BYTE)) != (long)sizeof(BYTE)) {
222 WARN("Error reading wmm=%p\n", wmm);
223 ret = MCIERR_INVALID_FILE;
226 return ret;
229 /**************************************************************************
230 * MIDI_mciReadWord [internal]
232 static DWORD MIDI_mciReadWord(WINE_MCIMIDI* wmm, LPWORD lpw)
234 BYTE hibyte, lobyte;
235 DWORD ret = MCIERR_INVALID_FILE;
237 if (lpw != NULL &&
238 MIDI_mciReadByte(wmm, &hibyte) == 0 &&
239 MIDI_mciReadByte(wmm, &lobyte) == 0) {
240 *lpw = ((WORD)hibyte << 8) + lobyte;
241 ret = 0;
243 return ret;
246 /**************************************************************************
247 * MIDI_mciReadLong [internal]
249 static DWORD MIDI_mciReadLong(WINE_MCIMIDI* wmm, LPDWORD lpdw)
251 WORD hiword, loword;
252 DWORD ret = MCIERR_INVALID_FILE;
254 if (lpdw != NULL &&
255 MIDI_mciReadWord(wmm, &hiword) == 0 &&
256 MIDI_mciReadWord(wmm, &loword) == 0) {
257 *lpdw = MAKELONG(loword, hiword);
258 ret = 0;
260 return ret;
263 /**************************************************************************
264 * MIDI_mciReadVaryLen [internal]
266 static WORD MIDI_mciReadVaryLen(WINE_MCIMIDI* wmm, LPDWORD lpdw)
268 BYTE byte;
269 DWORD value = 0;
270 WORD ret = 0;
272 if (lpdw == NULL) {
273 ret = MCIERR_INVALID_FILE;
274 } else {
275 do {
276 if (MIDI_mciReadByte(wmm, &byte) != 0) {
277 return 0;
279 value = (value << 7) + (byte & 0x7F);
280 ret++;
281 } while (byte & 0x80);
282 *lpdw = value;
284 TRACE("val=%08X\n", value);
287 return ret;
290 /**************************************************************************
291 * MIDI_mciReadNextEvent [internal]
293 static DWORD MIDI_mciReadNextEvent(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
295 BYTE b1, b2 = 0, b3;
296 WORD hw = 0;
297 DWORD evtPulse;
298 DWORD evtLength;
299 DWORD tmp;
301 if (mmioSeek(wmm->hFile, mmt->dwIndex, SEEK_SET) != mmt->dwIndex) {
302 WARN("Can't seek at %08X\n", mmt->dwIndex);
303 return MCIERR_INVALID_FILE;
305 evtLength = MIDI_mciReadVaryLen(wmm, &evtPulse) + 1; /* > 0 */
306 MIDI_mciReadByte(wmm, &b1);
307 switch (b1) {
308 case 0xF0:
309 case 0xF7:
310 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
311 evtLength += tmp;
312 break;
313 case 0xFF:
314 MIDI_mciReadByte(wmm, &b2); evtLength++;
316 evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
317 if (evtLength >= 0x10000u) {
318 /* this limitation shouldn't be a problem */
319 WARN("Ouch !! Implementation limitation to 64k bytes for a MIDI event is overflowed\n");
320 hw = 0xFFFF;
321 } else {
322 hw = LOWORD(evtLength);
324 evtLength += tmp;
325 break;
326 default:
327 if (b1 & 0x80) { /* use running status ? */
328 mmt->wLastCommand = b1;
329 MIDI_mciReadByte(wmm, &b2); evtLength++;
330 } else {
331 b2 = b1;
332 b1 = mmt->wLastCommand;
334 switch ((b1 >> 4) & 0x07) {
335 case 0: case 1: case 2: case 3: case 6:
336 MIDI_mciReadByte(wmm, &b3); evtLength++;
337 hw = b3;
338 break;
339 case 4: case 5:
340 break;
341 case 7:
342 WARN("Strange indeed b1=0x%02x\n", b1);
344 break;
346 if (mmt->dwIndex + evtLength > mmt->dwLast)
347 return MCIERR_INTERNAL;
349 mmt->dwEventPulse += evtPulse;
350 mmt->dwEventData = (hw << 16) + (b2 << 8) + b1;
351 mmt->wEventLength = evtLength;
354 TRACE("[%u] => pulse=%08x(%08x), data=%08x, length=%u\n",
355 mmt->wTrackNr, mmt->dwEventPulse, evtPulse,
356 mmt->dwEventData, mmt->wEventLength);
358 return 0;
361 /**************************************************************************
362 * MIDI_mciReadMTrk [internal]
364 static DWORD MIDI_mciReadMTrk(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
366 DWORD toberead;
367 FOURCC fourcc;
369 if (mmioRead(wmm->hFile, (HPSTR)&fourcc, (long)sizeof(FOURCC)) !=
370 (long)sizeof(FOURCC)) {
371 return MCIERR_INVALID_FILE;
374 if (fourcc != mmioFOURCC('M', 'T', 'r', 'k')) {
375 WARN("Can't synchronize on 'MTrk' !\n");
376 return MCIERR_INVALID_FILE;
379 if (MIDI_mciReadLong(wmm, &toberead) != 0) {
380 return MCIERR_INVALID_FILE;
382 mmt->dwFirst = mmioSeek(wmm->hFile, 0, SEEK_CUR); /* >= 0 */
383 mmt->dwLast = mmt->dwFirst + toberead;
385 /* compute # of pulses in this track */
386 mmt->dwIndex = mmt->dwFirst;
387 mmt->dwEventPulse = 0;
389 while (MIDI_mciReadNextEvent(wmm, mmt) == 0 && LOWORD(mmt->dwEventData) != 0x2FFF) {
390 char buf[1024];
391 WORD len;
393 mmt->dwIndex += mmt->wEventLength;
395 switch (LOWORD(mmt->dwEventData)) {
396 case 0x02FF:
397 case 0x03FF:
398 /* position after meta data header */
399 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
400 len = mmt->wEventLength - HIWORD(mmt->dwEventData);
402 if (len >= sizeof(buf)) {
403 WARN("Buffer for text is too small (%u are needed)\n", len);
404 len = sizeof(buf) - 1;
406 if (mmioRead(wmm->hFile, (HPSTR)buf, len) == len) {
407 buf[len] = 0; /* end string in case */
408 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
409 case 0x02:
410 if (wmm->lpstrCopyright) {
411 WARN("Two copyright notices (%s|%s)\n", debugstr_w(wmm->lpstrCopyright), buf);
412 } else {
413 len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
414 wmm->lpstrCopyright = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
415 len = MultiByteToWideChar( CP_ACP, 0, buf, -1, wmm->lpstrCopyright, len );
417 break;
418 case 0x03:
419 if (wmm->lpstrName) {
420 WARN("Two names (%s|%s)\n", debugstr_w(wmm->lpstrName), buf);
421 } else {
422 len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
423 wmm->lpstrName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
424 len = MultiByteToWideChar( CP_ACP, 0, buf, -1, wmm->lpstrName, len );
426 break;
429 break;
432 mmt->dwLength = mmt->dwEventPulse;
434 TRACE("Track %u has %u bytes and %u pulses\n", mmt->wTrackNr, toberead, mmt->dwLength);
436 /* reset track data */
437 mmt->wStatus = 1; /* ok, playing */
438 mmt->dwIndex = mmt->dwFirst;
439 mmt->dwEventPulse = 0;
441 if (mmioSeek(wmm->hFile, 0, SEEK_CUR) != mmt->dwLast) {
442 WARN("Ouch, out of sync seek=%u track=%u\n",
443 mmioSeek(wmm->hFile, 0, SEEK_CUR), mmt->dwLast);
444 /* position at end of this track, to be ready to read next track */
445 mmioSeek(wmm->hFile, mmt->dwLast, SEEK_SET);
448 return 0;
451 /**************************************************************************
452 * MIDI_mciReadMThd [internal]
454 static DWORD MIDI_mciReadMThd(WINE_MCIMIDI* wmm, DWORD dwOffset)
456 DWORD toberead;
457 FOURCC fourcc;
458 WORD nt;
460 TRACE("(%p, %08X);\n", wmm, dwOffset);
462 if (mmioSeek(wmm->hFile, dwOffset, SEEK_SET) != dwOffset) {
463 WARN("Can't seek at %08X begin of 'MThd'\n", dwOffset);
464 return MCIERR_INVALID_FILE;
466 if (mmioRead(wmm->hFile, (HPSTR)&fourcc,
467 (long) sizeof(FOURCC)) != (long) sizeof(FOURCC))
468 return MCIERR_INVALID_FILE;
470 if (fourcc != mmioFOURCC('M', 'T', 'h', 'd')) {
471 WARN("Can't synchronize on 'MThd' !\n");
472 return MCIERR_INVALID_FILE;
475 if (MIDI_mciReadLong(wmm, &toberead) != 0 || toberead < 3 * sizeof(WORD))
476 return MCIERR_INVALID_FILE;
478 if (MIDI_mciReadWord(wmm, &wmm->wFormat) != 0 ||
479 MIDI_mciReadWord(wmm, &wmm->nTracks) != 0 ||
480 MIDI_mciReadWord(wmm, &wmm->nDivision) != 0) {
481 return MCIERR_INVALID_FILE;
484 TRACE("toberead=0x%08X, wFormat=0x%04X nTracks=0x%04X nDivision=0x%04X\n",
485 toberead, wmm->wFormat, wmm->nTracks, wmm->nDivision);
487 /* MS doc says that the MIDI MCI time format must be put by default to the format
488 * stored in the MIDI file...
490 if (wmm->nDivision > 0x8000) {
491 /* eric.pouech@lemel.fr 98/11
492 * I did not check this very code (pulses are expressed as SMPTE sub-frames).
493 * In about 40 MB of MIDI files I have, none was SMPTE based...
494 * I'm just wondering if this is widely used :-). So, if someone has one of
495 * these files, I'd like to know about it.
497 FIXME("Handling SMPTE time in MIDI files has not been tested\n"
498 "Please report to comp.emulators.ms-windows.wine with MIDI file !\n");
500 switch (HIBYTE(wmm->nDivision)) {
501 case 0xE8: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24; break; /* -24 */
502 case 0xE7: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25; break; /* -25 */
503 case 0xE3: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
504 case 0xE2: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30; break; /* -30 */
505 default:
506 WARN("Unsupported number of frames %d\n", -(char)HIBYTE(wmm->nDivision));
507 return MCIERR_INVALID_FILE;
509 switch (LOBYTE(wmm->nDivision)) {
510 case 4: /* MIDI Time Code */
511 case 8:
512 case 10:
513 case 80: /* SMPTE bit resolution */
514 case 100:
515 default:
516 WARN("Unsupported number of sub-frames %d\n", LOBYTE(wmm->nDivision));
517 return MCIERR_INVALID_FILE;
519 } else if (wmm->nDivision == 0) {
520 WARN("Number of division is 0, can't support that !!\n");
521 return MCIERR_INVALID_FILE;
522 } else {
523 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
526 switch (wmm->wFormat) {
527 case 0:
528 if (wmm->nTracks != 1) {
529 WARN("Got type 0 file whose number of track is not 1. Setting it to 1\n");
530 wmm->nTracks = 1;
532 break;
533 case 1:
534 case 2:
535 break;
536 default:
537 WARN("Handling MIDI files which format = %d is not (yet) supported\n"
538 "Please report with MIDI file !\n", wmm->wFormat);
539 return MCIERR_INVALID_FILE;
542 if (wmm->nTracks & 0x8000) {
543 /* this shouldn't be a problem... */
544 WARN("Ouch !! Implementation limitation to 32k tracks per MIDI file is overflowed\n");
545 wmm->nTracks = 0x7FFF;
548 if ((wmm->tracks = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_MIDITRACK) * wmm->nTracks)) == NULL) {
549 return MCIERR_OUT_OF_MEMORY;
552 toberead -= 3 * sizeof(WORD);
553 if (toberead > 0) {
554 TRACE("Size of MThd > 6, skipping %d extra bytes\n", toberead);
555 mmioSeek(wmm->hFile, toberead, SEEK_CUR);
558 for (nt = 0; nt < wmm->nTracks; nt++) {
559 wmm->tracks[nt].wTrackNr = nt;
560 if (MIDI_mciReadMTrk(wmm, &wmm->tracks[nt]) != 0) {
561 WARN("Can't read 'MTrk' header\n");
562 return MCIERR_INVALID_FILE;
566 wmm->dwTempo = 500000;
568 return 0;
571 /**************************************************************************
572 * MIDI_ConvertPulseToMS [internal]
574 static DWORD MIDI_ConvertPulseToMS(WINE_MCIMIDI* wmm, DWORD pulse)
576 DWORD ret = 0;
578 /* FIXME: this function may return false values since the tempo (wmm->dwTempo)
579 * may change during file playing
581 if (wmm->nDivision == 0) {
582 FIXME("Shouldn't happen. wmm->nDivision = 0\n");
583 } else if (wmm->nDivision > 0x8000) { /* SMPTE, unchecked FIXME? */
584 int nf = -(char)HIBYTE(wmm->nDivision); /* number of frames */
585 int nsf = LOBYTE(wmm->nDivision); /* number of sub-frames */
586 ret = (pulse * 1000) / (nf * nsf);
587 } else {
588 ret = (DWORD)((double)pulse * ((double)wmm->dwTempo / 1000) /
589 (double)wmm->nDivision);
593 TRACE("pulse=%u tempo=%u division=%u=0x%04x => ms=%u\n",
594 pulse, wmm->dwTempo, wmm->nDivision, wmm->nDivision, ret);
597 return ret;
600 #define TIME_MS_IN_ONE_HOUR (60*60*1000)
601 #define TIME_MS_IN_ONE_MINUTE (60*1000)
602 #define TIME_MS_IN_ONE_SECOND (1000)
604 /**************************************************************************
605 * MIDI_ConvertTimeFormatToMS [internal]
607 static DWORD MIDI_ConvertTimeFormatToMS(WINE_MCIMIDI* wmm, DWORD val)
609 DWORD ret = 0;
611 switch (wmm->dwMciTimeFormat) {
612 case MCI_FORMAT_MILLISECONDS:
613 ret = val;
614 break;
615 case MCI_FORMAT_SMPTE_24:
616 ret =
617 (HIBYTE(HIWORD(val)) * 125) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
618 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
619 break;
620 case MCI_FORMAT_SMPTE_25:
621 ret =
622 HIBYTE(HIWORD(val)) * 40 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
623 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
624 break;
625 case MCI_FORMAT_SMPTE_30:
626 ret =
627 (HIBYTE(HIWORD(val)) * 100) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
628 HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
629 break;
630 default:
631 WARN("Bad time format %u!\n", wmm->dwMciTimeFormat);
634 TRACE("val=%u=0x%08x [tf=%u] => ret=%u\n", val, val, wmm->dwMciTimeFormat, ret);
636 return ret;
639 /**************************************************************************
640 * MIDI_ConvertMSToTimeFormat [internal]
642 static DWORD MIDI_ConvertMSToTimeFormat(WINE_MCIMIDI* wmm, DWORD _val)
644 DWORD ret = 0, val = _val;
645 DWORD h, m, s, f;
647 switch (wmm->dwMciTimeFormat) {
648 case MCI_FORMAT_MILLISECONDS:
649 ret = val;
650 break;
651 case MCI_FORMAT_SMPTE_24:
652 case MCI_FORMAT_SMPTE_25:
653 case MCI_FORMAT_SMPTE_30:
654 h = val / TIME_MS_IN_ONE_HOUR;
655 m = (val -= h * TIME_MS_IN_ONE_HOUR) / TIME_MS_IN_ONE_MINUTE;
656 s = (val -= m * TIME_MS_IN_ONE_MINUTE) / TIME_MS_IN_ONE_SECOND;
657 switch (wmm->dwMciTimeFormat) {
658 case MCI_FORMAT_SMPTE_24:
659 /* one frame is 1000/24 val long, 1000/24 == 125/3 */
660 f = (val * 3) / 125; val -= (f * 125) / 3;
661 break;
662 case MCI_FORMAT_SMPTE_25:
663 /* one frame is 1000/25 ms long, 1000/25 == 40 */
664 f = val / 40; val -= f * 40;
665 break;
666 case MCI_FORMAT_SMPTE_30:
667 /* one frame is 1000/30 ms long, 1000/30 == 100/3 */
668 f = (val * 3) / 100; val -= (f * 100) / 3;
669 break;
670 default:
671 FIXME("There must be some bad bad programmer\n");
672 f = 0;
674 /* val contains the number of ms which cannot make a complete frame */
675 /* FIXME: is this correct ? programs seem to be happy with that */
676 ret = (f << 24) | (s << 16) | (m << 8) | (h << 0);
677 break;
678 default:
679 WARN("Bad time format %u!\n", wmm->dwMciTimeFormat);
682 TRACE("val=%u [tf=%u] => ret=%u=0x%08x\n", _val, wmm->dwMciTimeFormat, ret, ret);
684 return ret;
687 /**************************************************************************
688 * MIDI_GetMThdLengthMS [internal]
690 static DWORD MIDI_GetMThdLengthMS(WINE_MCIMIDI* wmm)
692 WORD nt;
693 DWORD ret = 0;
695 for (nt = 0; nt < wmm->nTracks; nt++) {
696 if (wmm->wFormat == 2) {
697 ret += wmm->tracks[nt].dwLength;
698 } else if (wmm->tracks[nt].dwLength > ret) {
699 ret = wmm->tracks[nt].dwLength;
702 /* FIXME: this is wrong if there is a tempo change inside the file */
703 return MIDI_ConvertPulseToMS(wmm, ret);
706 /**************************************************************************
707 * MIDI_mciOpen [internal]
709 static DWORD MIDI_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMSW lpParms)
711 DWORD dwRet = 0;
712 DWORD dwDeviceID;
713 WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
715 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
717 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
718 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
719 if (dwFlags & MCI_OPEN_SHAREABLE)
720 return MCIERR_HARDWARE;
722 if (wmm->nUseCount > 0) {
723 /* The driver is already opened on this channel
724 * MIDI sequencer cannot be shared
726 return MCIERR_DEVICE_OPEN;
728 wmm->nUseCount++;
730 wmm->hFile = 0;
731 wmm->hMidi = 0;
732 wmm->lpstrElementName = NULL;
733 dwDeviceID = lpParms->wDeviceID;
735 TRACE("wDevID=%04X (lpParams->wDeviceID=%08X)\n", wDevID, dwDeviceID);
736 /* lpParms->wDeviceID = wDevID;*/
738 if (dwFlags & MCI_OPEN_ELEMENT) {
739 TRACE("MCI_OPEN_ELEMENT %s!\n", debugstr_w(lpParms->lpstrElementName));
740 if (lpParms->lpstrElementName && strlenW(lpParms->lpstrElementName) > 0) {
741 wmm->hFile = mmioOpenW((LPWSTR)lpParms->lpstrElementName, NULL,
742 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
743 if (wmm->hFile == 0) {
744 WARN("Can't find file %s!\n", debugstr_w(lpParms->lpstrElementName));
745 wmm->nUseCount--;
746 return MCIERR_FILE_NOT_FOUND;
748 wmm->lpstrElementName = HeapAlloc(GetProcessHeap(), 0,
749 (strlenW(lpParms->lpstrElementName) + 1) * sizeof(WCHAR));
750 strcpyW(wmm->lpstrElementName, lpParms->lpstrElementName);
753 TRACE("hFile=%p\n", wmm->hFile);
755 wmm->lpstrCopyright = NULL;
756 wmm->lpstrName = NULL;
758 wmm->wNotifyDeviceID = dwDeviceID;
759 wmm->dwStatus = MCI_MODE_NOT_READY; /* while loading file contents */
760 /* spec says it should be the default format from the MIDI file... */
761 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
763 if (wmm->hFile != 0) {
764 MMCKINFO ckMainRIFF;
765 MMCKINFO mmckInfo;
766 DWORD dwOffset = 0;
768 if (mmioDescend(wmm->hFile, &ckMainRIFF, NULL, 0) != 0) {
769 dwRet = MCIERR_INVALID_FILE;
770 } else {
771 TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08X\n",
772 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
774 if (ckMainRIFF.ckid == FOURCC_RIFF && ckMainRIFF.fccType == mmioFOURCC('R', 'M', 'I', 'D')) {
775 mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
776 mmioSeek(wmm->hFile, ckMainRIFF.dwDataOffset + ((ckMainRIFF.cksize + 1) & ~1), SEEK_SET);
777 if (mmioDescend(wmm->hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) {
778 TRACE("... is a 'RMID' file\n");
779 dwOffset = mmckInfo.dwDataOffset;
780 } else {
781 dwRet = MCIERR_INVALID_FILE;
784 if (dwRet == 0 && MIDI_mciReadMThd(wmm, dwOffset) != 0) {
785 WARN("Can't read 'MThd' header\n");
786 dwRet = MCIERR_INVALID_FILE;
789 } else {
790 TRACE("hFile==0, setting #tracks to 0; is this correct ?\n");
791 wmm->nTracks = 0;
792 wmm->wFormat = 0;
793 wmm->nDivision = 1;
795 if (dwRet != 0) {
796 wmm->nUseCount--;
797 if (wmm->hFile != 0)
798 mmioClose(wmm->hFile, 0);
799 wmm->hFile = 0;
800 } else {
801 wmm->dwPositionMS = 0;
802 wmm->dwStatus = MCI_MODE_STOP;
804 return dwRet;
807 /**************************************************************************
808 * MIDI_mciStop [internal]
810 static DWORD MIDI_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
812 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
813 DWORD dwRet = 0;
815 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
817 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
819 if (wmm->dwStatus != MCI_MODE_STOP) {
820 int oldstat = wmm->dwStatus;
822 wmm->dwStatus = MCI_MODE_NOT_READY;
823 if (oldstat == MCI_MODE_PAUSE)
824 dwRet = midiOutReset((HMIDIOUT)wmm->hMidi);
826 while (wmm->dwStatus != MCI_MODE_STOP)
827 Sleep(10);
830 /* sanitiy reset */
831 wmm->dwStatus = MCI_MODE_STOP;
833 TRACE("wmm->dwStatus=%d\n", wmm->dwStatus);
835 if (lpParms && (dwFlags & MCI_NOTIFY)) {
836 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
837 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
838 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
840 return 0;
843 /**************************************************************************
844 * MIDI_mciClose [internal]
846 static DWORD MIDI_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
848 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
850 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
852 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
854 if (wmm->dwStatus != MCI_MODE_STOP) {
855 MIDI_mciStop(wDevID, MCI_WAIT, lpParms);
858 wmm->nUseCount--;
859 if (wmm->nUseCount == 0) {
860 if (wmm->hFile != 0) {
861 mmioClose(wmm->hFile, 0);
862 wmm->hFile = 0;
863 TRACE("hFile closed !\n");
865 HeapFree(GetProcessHeap(), 0, wmm->tracks);
866 HeapFree(GetProcessHeap(), 0, (LPWSTR)wmm->lpstrElementName);
867 HeapFree(GetProcessHeap(), 0, (LPSTR)wmm->lpstrCopyright);
868 HeapFree(GetProcessHeap(), 0, (LPSTR)wmm->lpstrName);
869 } else {
870 TRACE("Shouldn't happen... nUseCount=%d\n", wmm->nUseCount);
871 return MCIERR_INTERNAL;
874 if (lpParms && (dwFlags & MCI_NOTIFY)) {
875 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
876 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
877 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
879 return 0;
882 /**************************************************************************
883 * MIDI_mciFindNextEvent [internal]
885 static MCI_MIDITRACK* MIDI_mciFindNextEvent(WINE_MCIMIDI* wmm, LPDWORD hiPulse)
887 WORD cnt, nt;
888 MCI_MIDITRACK* mmt;
890 *hiPulse = 0xFFFFFFFFul;
891 cnt = 0xFFFFu;
892 for (nt = 0; nt < wmm->nTracks; nt++) {
893 mmt = &wmm->tracks[nt];
895 if (mmt->wStatus == 0)
896 continue;
897 if (mmt->dwEventPulse < *hiPulse) {
898 *hiPulse = mmt->dwEventPulse;
899 cnt = nt;
902 return (cnt == 0xFFFFu) ? 0 /* no more event on all tracks */
903 : &wmm->tracks[cnt];
906 /**************************************************************************
907 * MIDI_mciPlay [internal]
909 static DWORD MIDI_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
911 DWORD dwStartMS, dwEndMS;
912 DWORD dwRet = 0;
913 WORD doPlay, nt;
914 MCI_MIDITRACK* mmt;
915 DWORD hiPulse;
916 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
918 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
920 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
922 if (wmm->hFile == 0) {
923 WARN("Can't play: no file %s!\n", debugstr_w(wmm->lpstrElementName));
924 return MCIERR_FILE_NOT_FOUND;
927 if (wmm->dwStatus != MCI_MODE_STOP) {
928 if (wmm->dwStatus == MCI_MODE_PAUSE) {
929 /* FIXME: parameters (start/end) in lpParams may not be used */
930 return MIDI_mciResume(wDevID, dwFlags, (LPMCI_GENERIC_PARMS)lpParms);
932 WARN("Can't play: device is not stopped !\n");
933 return MCIERR_INTERNAL;
936 if (!(dwFlags & MCI_WAIT)) {
937 /** FIXME: I'm not 100% sure that wNotifyDeviceID is the right value in all cases ??? */
938 return MCI_SendCommandAsync(wmm->wNotifyDeviceID, MCI_PLAY, dwFlags, (DWORD_PTR)lpParms, sizeof(LPMCI_PLAY_PARMS));
941 if (lpParms && (dwFlags & MCI_FROM)) {
942 dwStartMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwFrom);
943 } else {
944 dwStartMS = wmm->dwPositionMS;
947 if (lpParms && (dwFlags & MCI_TO)) {
948 dwEndMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
949 } else {
950 dwEndMS = 0xFFFFFFFFul;
953 TRACE("Playing from %u to %u\n", dwStartMS, dwEndMS);
955 /* init tracks */
956 for (nt = 0; nt < wmm->nTracks; nt++) {
957 mmt = &wmm->tracks[nt];
959 mmt->wStatus = 1; /* ok, playing */
960 mmt->dwIndex = mmt->dwFirst;
961 if (wmm->wFormat == 2 && nt > 0) {
962 mmt->dwEventPulse = wmm->tracks[nt - 1].dwLength;
963 } else {
964 mmt->dwEventPulse = 0;
966 MIDI_mciReadNextEvent(wmm, mmt); /* FIXME == 0 */
969 dwRet = midiOutOpen((LPHMIDIOUT)&wmm->hMidi, MIDIMAPPER, 0L, 0L, CALLBACK_NULL);
970 /* dwRet = midiInOpen(&wmm->hMidi, MIDIMAPPER, 0L, 0L, CALLBACK_NULL);*/
971 if (dwRet != MMSYSERR_NOERROR) {
972 return dwRet;
975 wmm->dwPulse = 0;
976 wmm->dwTempo = 500000;
977 wmm->dwStatus = MCI_MODE_PLAY;
978 wmm->dwPositionMS = 0;
979 wmm->wStartedPlaying = FALSE;
981 while (wmm->dwStatus != MCI_MODE_STOP && wmm->dwStatus != MCI_MODE_NOT_READY) {
982 /* it seems that in case of multi-threading, gcc is optimizing just a little bit
983 * too much. Tell gcc not to optimize status value using volatile.
985 while (((volatile WINE_MCIMIDI*)wmm)->dwStatus == MCI_MODE_PAUSE);
987 doPlay = (wmm->dwPositionMS >= dwStartMS && wmm->dwPositionMS <= dwEndMS);
989 TRACE("wmm->dwStatus=%d, doPlay=%c\n", wmm->dwStatus, doPlay ? 'T' : 'F');
991 if ((mmt = MIDI_mciFindNextEvent(wmm, &hiPulse)) == NULL)
992 break; /* no more event on tracks */
994 /* if starting playing, then set StartTicks to the value it would have had
995 * if play had started at position 0
997 if (doPlay && !wmm->wStartedPlaying) {
998 wmm->dwStartTicks = GetTickCount() - MIDI_ConvertPulseToMS(wmm, wmm->dwPulse);
999 wmm->wStartedPlaying = TRUE;
1000 TRACE("Setting dwStartTicks to %u\n", wmm->dwStartTicks);
1003 if (hiPulse > wmm->dwPulse) {
1004 wmm->dwPositionMS += MIDI_ConvertPulseToMS(wmm, hiPulse - wmm->dwPulse);
1005 if (doPlay) {
1006 DWORD togo = wmm->dwStartTicks + wmm->dwPositionMS;
1007 DWORD tc = GetTickCount();
1009 TRACE("Pulses hi=0x%08x <> cur=0x%08x\n", hiPulse, wmm->dwPulse);
1010 TRACE("Wait until %u => %u ms\n",
1011 tc - wmm->dwStartTicks, togo - wmm->dwStartTicks);
1012 if (tc < togo)
1013 Sleep(togo - tc);
1015 wmm->dwPulse = hiPulse;
1018 switch (LOBYTE(LOWORD(mmt->dwEventData))) {
1019 case 0xF0:
1020 case 0xF7: /* sysex events */
1022 FIXME("Not handling SysEx events (yet)\n");
1024 break;
1025 case 0xFF:
1026 /* position after meta data header */
1027 mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
1028 switch (HIBYTE(LOWORD(mmt->dwEventData))) {
1029 case 0x00: /* 16-bit sequence number */
1030 if (TRACE_ON(mcimidi)) {
1031 WORD twd;
1033 MIDI_mciReadWord(wmm, &twd); /* == 0 */
1034 TRACE("Got sequence number %u\n", twd);
1036 break;
1037 case 0x01: /* any text */
1038 case 0x02: /* Copyright Message text */
1039 case 0x03: /* Sequence/Track Name text */
1040 case 0x04: /* Instrument Name text */
1041 case 0x05: /* Lyric text */
1042 case 0x06: /* Marker text */
1043 case 0x07: /* Cue-point text */
1044 if (TRACE_ON(mcimidi)) {
1045 char buf[1024];
1046 WORD len = mmt->wEventLength - HIWORD(mmt->dwEventData);
1047 static const char* const info[8] = {"", "Text", "Copyright", "Seq/Trk name",
1048 "Instrument", "Lyric", "Marker", "Cue-point"};
1049 WORD idx = HIBYTE(LOWORD(mmt->dwEventData));
1051 if (len >= sizeof(buf)) {
1052 WARN("Buffer for text is too small (%u are needed)\n", len);
1053 len = sizeof(buf) - 1;
1055 if (mmioRead(wmm->hFile, (HPSTR)buf, len) == len) {
1056 buf[len] = 0; /* end string in case */
1057 TRACE("%s => \"%s\"\n", (idx < 8 ) ? info[idx] : "", buf);
1058 } else {
1059 WARN("Couldn't read data for %s\n", (idx < 8) ? info[idx] : "");
1062 break;
1063 case 0x20:
1064 /* MIDI channel (cc) */
1065 if (FIXME_ON(mcimidi)) {
1066 BYTE bt;
1068 MIDI_mciReadByte(wmm, &bt); /* == 0 */
1069 FIXME("NIY: MIDI channel=%u, track=%u\n", bt, mmt->wTrackNr);
1071 break;
1072 case 0x21:
1073 /* MIDI port (pp) */
1074 if (FIXME_ON(mcimidi)) {
1075 BYTE bt;
1077 MIDI_mciReadByte(wmm, &bt); /* == 0 */
1078 FIXME("NIY: MIDI port=%u, track=%u\n", bt, mmt->wTrackNr);
1080 break;
1081 case 0x2F: /* end of track */
1082 mmt->wStatus = 0;
1083 break;
1084 case 0x51:/* set tempo */
1085 /* Tempo is expressed in -seconds per midi quarter note
1086 * for format 1 MIDI files, this can only be present on track #0
1088 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1089 WARN("For format #1 MIDI files, tempo can only be changed on track #0 (%u)\n", mmt->wTrackNr);
1090 } else {
1091 BYTE tbt;
1092 DWORD value = 0;
1094 MIDI_mciReadByte(wmm, &tbt); value = ((DWORD)tbt) << 16;
1095 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 8;
1096 MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 0;
1097 TRACE("Setting tempo to %d (BPM=%d)\n", wmm->dwTempo, (value) ? (60000000 / value) : 0);
1098 wmm->dwTempo = value;
1100 break;
1101 case 0x54: /* (hour) (min) (second) (frame) (fractional-frame) - SMPTE track start */
1102 if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
1103 WARN("For format #1 MIDI files, SMPTE track start can only be expressed on track #0 (%u)\n", mmt->wTrackNr);
1104 } if (mmt->dwEventPulse != 0) {
1105 WARN("SMPTE track start can only be expressed at start of track (%u)\n", mmt->dwEventPulse);
1106 } else {
1107 BYTE h, m, s, f, ff;
1109 MIDI_mciReadByte(wmm, &h);
1110 MIDI_mciReadByte(wmm, &m);
1111 MIDI_mciReadByte(wmm, &s);
1112 MIDI_mciReadByte(wmm, &f);
1113 MIDI_mciReadByte(wmm, &ff);
1114 FIXME("NIY: SMPTE track start %u:%u:%u %u.%u\n", h, m, s, f, ff);
1116 break;
1117 case 0x58: /* file rhythm */
1118 if (TRACE_ON(mcimidi)) {
1119 BYTE num, den, cpmc, _32npqn;
1121 MIDI_mciReadByte(wmm, &num);
1122 MIDI_mciReadByte(wmm, &den); /* to notate e.g. 6/8 */
1123 MIDI_mciReadByte(wmm, &cpmc); /* number of MIDI clocks per metronome click */
1124 MIDI_mciReadByte(wmm, &_32npqn); /* number of notated 32nd notes per MIDI quarter note */
1126 TRACE("%u/%u, clock per metronome click=%u, 32nd notes by 1/4 note=%u\n", num, 1 << den, cpmc, _32npqn);
1128 break;
1129 case 0x59: /* key signature */
1130 if (TRACE_ON(mcimidi)) {
1131 BYTE sf, mm;
1133 MIDI_mciReadByte(wmm, &sf);
1134 MIDI_mciReadByte(wmm, &mm);
1136 if (sf >= 0x80) TRACE("%d flats\n", -(char)sf);
1137 else if (sf > 0) TRACE("%d sharps\n", (char)sf);
1138 else TRACE("Key of C\n");
1139 TRACE("Mode: %s\n", (mm == 0) ? "major" : "minor");
1141 break;
1142 default:
1143 WARN("Unknown MIDI meta event %02x. Skipping...\n", HIBYTE(LOWORD(mmt->dwEventData)));
1144 break;
1146 break;
1147 default:
1148 if (doPlay) {
1149 dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
1150 } else {
1151 switch (LOBYTE(LOWORD(mmt->dwEventData)) & 0xF0) {
1152 case MIDI_NOTEON:
1153 case MIDI_NOTEOFF:
1154 dwRet = 0;
1155 break;
1156 default:
1157 dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
1161 mmt->dwIndex += mmt->wEventLength;
1162 if (mmt->dwIndex < mmt->dwFirst || mmt->dwIndex >= mmt->dwLast) {
1163 mmt->wStatus = 0;
1165 if (mmt->wStatus) {
1166 MIDI_mciReadNextEvent(wmm, mmt);
1170 midiOutReset((HMIDIOUT)wmm->hMidi);
1172 dwRet = midiOutClose((HMIDIOUT)wmm->hMidi);
1173 /* to restart playing at beginning when it's over */
1174 wmm->dwPositionMS = 0;
1176 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1177 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1178 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1179 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1182 wmm->dwStatus = MCI_MODE_STOP;
1183 return dwRet;
1186 /**************************************************************************
1187 * MIDI_mciRecord [internal]
1189 static DWORD MIDI_mciRecord(UINT wDevID, DWORD dwFlags, LPMCI_RECORD_PARMS lpParms)
1191 int start, end;
1192 MIDIHDR midiHdr;
1193 DWORD dwRet;
1194 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1196 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1198 if (wmm == 0) return MCIERR_INVALID_DEVICE_ID;
1200 if (wmm->hFile == 0) {
1201 WARN("Can't find file=%s!\n", debugstr_w(wmm->lpstrElementName));
1202 return MCIERR_FILE_NOT_FOUND;
1204 start = 1; end = 99999;
1205 if (lpParms && (dwFlags & MCI_FROM)) {
1206 start = lpParms->dwFrom;
1207 TRACE("MCI_FROM=%d\n", start);
1209 if (lpParms && (dwFlags & MCI_TO)) {
1210 end = lpParms->dwTo;
1211 TRACE("MCI_TO=%d\n", end);
1213 midiHdr.lpData = HeapAlloc(GetProcessHeap(), 0, 1200);
1214 if (!midiHdr.lpData)
1215 return MCIERR_OUT_OF_MEMORY;
1216 midiHdr.dwBufferLength = 1024;
1217 midiHdr.dwUser = 0L;
1218 midiHdr.dwFlags = 0L;
1219 dwRet = midiInPrepareHeader((HMIDIIN)wmm->hMidi, &midiHdr, sizeof(MIDIHDR));
1220 TRACE("After MIDM_PREPARE\n");
1221 wmm->dwStatus = MCI_MODE_RECORD;
1222 /* FIXME: there is no buffer added */
1223 while (wmm->dwStatus != MCI_MODE_STOP) {
1224 TRACE("wmm->dwStatus=%p %d\n",
1225 &wmm->dwStatus, wmm->dwStatus);
1226 midiHdr.dwBytesRecorded = 0;
1227 dwRet = midiInStart((HMIDIIN)wmm->hMidi);
1228 TRACE("midiInStart => dwBytesRecorded=%u\n", midiHdr.dwBytesRecorded);
1229 if (midiHdr.dwBytesRecorded == 0) break;
1231 TRACE("Before MIDM_UNPREPARE\n");
1232 dwRet = midiInUnprepareHeader((HMIDIIN)wmm->hMidi, &midiHdr, sizeof(MIDIHDR));
1233 TRACE("After MIDM_UNPREPARE\n");
1234 HeapFree(GetProcessHeap(), 0, midiHdr.lpData);
1235 midiHdr.lpData = NULL;
1236 wmm->dwStatus = MCI_MODE_STOP;
1237 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1238 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1239 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1240 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1242 return 0;
1245 /**************************************************************************
1246 * MIDI_mciPause [internal]
1248 static DWORD MIDI_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1250 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1252 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1254 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1256 if (wmm->dwStatus == MCI_MODE_PLAY) {
1257 /* stop all notes */
1258 unsigned chn;
1259 for (chn = 0; chn < 16; chn++)
1260 midiOutShortMsg((HMIDIOUT)(wmm->hMidi), 0x78B0 | chn);
1261 wmm->dwStatus = MCI_MODE_PAUSE;
1263 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1264 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1265 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1266 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1269 return 0;
1272 /**************************************************************************
1273 * MIDI_mciResume [internal]
1275 static DWORD MIDI_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
1277 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1279 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1281 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1283 if (wmm->dwStatus == MCI_MODE_PAUSE) {
1284 wmm->wStartedPlaying = FALSE;
1285 wmm->dwStatus = MCI_MODE_PLAY;
1287 if (lpParms && (dwFlags & MCI_NOTIFY)) {
1288 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1289 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1290 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1292 return 0;
1295 /**************************************************************************
1296 * MIDI_mciSet [internal]
1298 static DWORD MIDI_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
1300 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1302 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1304 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1305 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1307 if (dwFlags & MCI_SET_TIME_FORMAT) {
1308 switch (lpParms->dwTimeFormat) {
1309 case MCI_FORMAT_MILLISECONDS:
1310 TRACE("MCI_FORMAT_MILLISECONDS !\n");
1311 wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
1312 break;
1313 case MCI_FORMAT_SMPTE_24:
1314 TRACE("MCI_FORMAT_SMPTE_24 !\n");
1315 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24;
1316 break;
1317 case MCI_FORMAT_SMPTE_25:
1318 TRACE("MCI_FORMAT_SMPTE_25 !\n");
1319 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25;
1320 break;
1321 case MCI_FORMAT_SMPTE_30:
1322 TRACE("MCI_FORMAT_SMPTE_30 !\n");
1323 wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30;
1324 break;
1325 default:
1326 WARN("Bad time format %u!\n", lpParms->dwTimeFormat);
1327 return MCIERR_BAD_TIME_FORMAT;
1330 if (dwFlags & MCI_SET_VIDEO) {
1331 TRACE("No support for video !\n");
1332 return MCIERR_UNSUPPORTED_FUNCTION;
1334 if (dwFlags & MCI_SET_DOOR_OPEN) {
1335 TRACE("No support for door open !\n");
1336 return MCIERR_UNSUPPORTED_FUNCTION;
1338 if (dwFlags & MCI_SET_DOOR_CLOSED) {
1339 TRACE("No support for door close !\n");
1340 return MCIERR_UNSUPPORTED_FUNCTION;
1342 if (dwFlags & MCI_SET_AUDIO) {
1343 if (dwFlags & MCI_SET_ON) {
1344 TRACE("MCI_SET_ON audio !\n");
1345 } else if (dwFlags & MCI_SET_OFF) {
1346 TRACE("MCI_SET_OFF audio !\n");
1347 } else {
1348 WARN("MCI_SET_AUDIO without SET_ON or SET_OFF\n");
1349 return MCIERR_BAD_INTEGER;
1352 switch (lpParms->dwAudio)
1354 case MCI_SET_AUDIO_ALL: TRACE("MCI_SET_AUDIO_ALL !\n"); break;
1355 case MCI_SET_AUDIO_LEFT: TRACE("MCI_SET_AUDIO_LEFT !\n"); break;
1356 case MCI_SET_AUDIO_RIGHT: TRACE("MCI_SET_AUDIO_RIGHT !\n"); break;
1357 default: WARN("Unknown audio channel %u\n", lpParms->dwAudio); break;
1361 if (dwFlags & MCI_SEQ_SET_MASTER)
1362 TRACE("MCI_SEQ_SET_MASTER !\n");
1363 if (dwFlags & MCI_SEQ_SET_SLAVE)
1364 TRACE("MCI_SEQ_SET_SLAVE !\n");
1365 if (dwFlags & MCI_SEQ_SET_OFFSET)
1366 TRACE("MCI_SEQ_SET_OFFSET !\n");
1367 if (dwFlags & MCI_SEQ_SET_PORT)
1368 TRACE("MCI_SEQ_SET_PORT !\n");
1369 if (dwFlags & MCI_SEQ_SET_TEMPO)
1370 TRACE("MCI_SEQ_SET_TEMPO !\n");
1371 return 0;
1374 /**************************************************************************
1375 * MIDI_mciStatus [internal]
1377 static DWORD MIDI_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
1379 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1380 DWORD ret = 0;
1382 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1384 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1385 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1387 if (dwFlags & MCI_STATUS_ITEM) {
1388 switch (lpParms->dwItem) {
1389 case MCI_STATUS_CURRENT_TRACK:
1390 /* FIXME in Format 2 */
1391 lpParms->dwReturn = 1;
1392 TRACE("MCI_STATUS_CURRENT_TRACK => %u\n", lpParms->dwReturn);
1393 break;
1394 case MCI_STATUS_LENGTH:
1395 if ((dwFlags & MCI_TRACK) && wmm->wFormat == 2) {
1396 if (lpParms->dwTrack >= wmm->nTracks)
1397 return MCIERR_BAD_INTEGER;
1398 /* FIXME: this is wrong if there is a tempo change inside the file */
1399 lpParms->dwReturn = MIDI_ConvertPulseToMS(wmm, wmm->tracks[lpParms->dwTrack].dwLength);
1400 } else {
1401 lpParms->dwReturn = MIDI_GetMThdLengthMS(wmm);
1403 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm, lpParms->dwReturn);
1404 TRACE("MCI_STATUS_LENGTH => %u\n", lpParms->dwReturn);
1405 break;
1406 case MCI_STATUS_MODE:
1407 TRACE("MCI_STATUS_MODE => %u\n", wmm->dwStatus);
1408 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwStatus, wmm->dwStatus);
1409 ret = MCI_RESOURCE_RETURNED;
1410 break;
1411 case MCI_STATUS_MEDIA_PRESENT:
1412 TRACE("MCI_STATUS_MEDIA_PRESENT => TRUE\n");
1413 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1414 ret = MCI_RESOURCE_RETURNED;
1415 break;
1416 case MCI_STATUS_NUMBER_OF_TRACKS:
1417 lpParms->dwReturn = (wmm->wFormat == 2) ? wmm->nTracks : 1;
1418 TRACE("MCI_STATUS_NUMBER_OF_TRACKS => %u\n", lpParms->dwReturn);
1419 break;
1420 case MCI_STATUS_POSITION:
1421 /* FIXME: do I need to use MCI_TRACK ? */
1422 lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm,
1423 (dwFlags & MCI_STATUS_START) ? 0 : wmm->dwPositionMS);
1424 TRACE("MCI_STATUS_POSITION %s => %u\n",
1425 (dwFlags & MCI_STATUS_START) ? "start" : "current", lpParms->dwReturn);
1426 break;
1427 case MCI_STATUS_READY:
1428 lpParms->dwReturn = (wmm->dwStatus == MCI_MODE_NOT_READY) ?
1429 MAKEMCIRESOURCE(FALSE, MCI_FALSE) : MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1430 ret = MCI_RESOURCE_RETURNED;
1431 TRACE("MCI_STATUS_READY = %u\n", LOWORD(lpParms->dwReturn));
1432 break;
1433 case MCI_STATUS_TIME_FORMAT:
1434 lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwMciTimeFormat, MCI_FORMAT_RETURN_BASE + wmm->dwMciTimeFormat);
1435 TRACE("MCI_STATUS_TIME_FORMAT => %u\n", LOWORD(lpParms->dwReturn));
1436 ret = MCI_RESOURCE_RETURNED;
1437 break;
1438 case MCI_SEQ_STATUS_DIVTYPE:
1439 TRACE("MCI_SEQ_STATUS_DIVTYPE !\n");
1440 if (wmm->nDivision > 0x8000) {
1441 switch (wmm->nDivision) {
1442 case 0xE8: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_24; break; /* -24 */
1443 case 0xE7: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_25; break; /* -25 */
1444 case 0xE3: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
1445 case 0xE2: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30; break; /* -30 */
1446 default: FIXME("There is a bad bad programmer\n");
1448 } else {
1449 lpParms->dwReturn = MCI_SEQ_DIV_PPQN;
1451 lpParms->dwReturn = MAKEMCIRESOURCE(lpParms->dwReturn,lpParms->dwReturn);
1452 ret = MCI_RESOURCE_RETURNED;
1453 break;
1454 case MCI_SEQ_STATUS_MASTER:
1455 TRACE("MCI_SEQ_STATUS_MASTER !\n");
1456 lpParms->dwReturn = 0;
1457 break;
1458 case MCI_SEQ_STATUS_SLAVE:
1459 TRACE("MCI_SEQ_STATUS_SLAVE !\n");
1460 lpParms->dwReturn = 0;
1461 break;
1462 case MCI_SEQ_STATUS_OFFSET:
1463 TRACE("MCI_SEQ_STATUS_OFFSET !\n");
1464 lpParms->dwReturn = 0;
1465 break;
1466 case MCI_SEQ_STATUS_PORT:
1467 TRACE("MCI_SEQ_STATUS_PORT (%u)!\n", wmm->wDevID);
1468 lpParms->dwReturn = MIDI_MAPPER;
1469 break;
1470 case MCI_SEQ_STATUS_TEMPO:
1471 TRACE("MCI_SEQ_STATUS_TEMPO !\n");
1472 lpParms->dwReturn = wmm->dwTempo;
1473 break;
1474 default:
1475 FIXME("Unknowm command %08X !\n", lpParms->dwItem);
1476 return MCIERR_UNRECOGNIZED_COMMAND;
1478 } else {
1479 WARN("No Status-Item!\n");
1480 return MCIERR_UNRECOGNIZED_COMMAND;
1482 if (dwFlags & MCI_NOTIFY) {
1483 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1484 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1485 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1487 return ret;
1490 /**************************************************************************
1491 * MIDI_mciGetDevCaps [internal]
1493 static DWORD MIDI_mciGetDevCaps(UINT wDevID, DWORD dwFlags,
1494 LPMCI_GETDEVCAPS_PARMS lpParms)
1496 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1497 DWORD ret;
1499 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1501 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1502 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1504 if (dwFlags & MCI_GETDEVCAPS_ITEM) {
1505 switch (lpParms->dwItem) {
1506 case MCI_GETDEVCAPS_DEVICE_TYPE:
1507 TRACE("MCI_GETDEVCAPS_DEVICE_TYPE !\n");
1508 lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_SEQUENCER, MCI_DEVTYPE_SEQUENCER);
1509 ret = MCI_RESOURCE_RETURNED;
1510 break;
1511 case MCI_GETDEVCAPS_HAS_AUDIO:
1512 TRACE("MCI_GETDEVCAPS_HAS_AUDIO !\n");
1513 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1514 ret = MCI_RESOURCE_RETURNED;
1515 break;
1516 case MCI_GETDEVCAPS_HAS_VIDEO:
1517 TRACE("MCI_GETDEVCAPS_HAS_VIDEO !\n");
1518 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1519 ret = MCI_RESOURCE_RETURNED;
1520 break;
1521 case MCI_GETDEVCAPS_USES_FILES:
1522 TRACE("MCI_GETDEVCAPS_USES_FILES !\n");
1523 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1524 ret = MCI_RESOURCE_RETURNED;
1525 break;
1526 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
1527 TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE !\n");
1528 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1529 ret = MCI_RESOURCE_RETURNED;
1530 break;
1531 case MCI_GETDEVCAPS_CAN_EJECT:
1532 TRACE("MCI_GETDEVCAPS_CAN_EJECT !\n");
1533 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1534 ret = MCI_RESOURCE_RETURNED;
1535 break;
1536 case MCI_GETDEVCAPS_CAN_PLAY:
1537 TRACE("MCI_GETDEVCAPS_CAN_PLAY !\n");
1538 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1539 ret = MCI_RESOURCE_RETURNED;
1540 break;
1541 case MCI_GETDEVCAPS_CAN_RECORD:
1542 TRACE("MCI_GETDEVCAPS_CAN_RECORD !\n");
1543 lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
1544 ret = MCI_RESOURCE_RETURNED;
1545 break;
1546 case MCI_GETDEVCAPS_CAN_SAVE:
1547 TRACE("MCI_GETDEVCAPS_CAN_SAVE !\n");
1548 lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
1549 ret = MCI_RESOURCE_RETURNED;
1550 break;
1551 default:
1552 FIXME("Unknown capability (%08x) !\n", lpParms->dwItem);
1553 return MCIERR_UNRECOGNIZED_COMMAND;
1555 } else {
1556 WARN("No GetDevCaps-Item !\n");
1557 return MCIERR_UNRECOGNIZED_COMMAND;
1559 return ret;
1562 /**************************************************************************
1563 * MIDI_mciInfo [internal]
1565 static DWORD MIDI_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMSW lpParms)
1567 LPCWSTR str = 0;
1568 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1569 DWORD ret = 0;
1570 static const WCHAR wszMidiSeq[] = {'W','i','n','e','\'','s',' ','M','I','D','I',' ','s','e','q','u','e','n','c','e','r',0};
1572 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1574 if (lpParms == NULL || lpParms->lpstrReturn == NULL)
1575 return MCIERR_NULL_PARAMETER_BLOCK;
1576 if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
1578 TRACE("buf=%p, len=%u\n", lpParms->lpstrReturn, lpParms->dwRetSize);
1580 switch (dwFlags & ~(MCI_WAIT|MCI_NOTIFY)) {
1581 case MCI_INFO_PRODUCT: str = wszMidiSeq; break;
1582 case MCI_INFO_FILE: str = wmm->lpstrElementName; break;
1583 case MCI_INFO_COPYRIGHT: str = wmm->lpstrCopyright; break;
1584 case MCI_INFO_NAME: str = wmm->lpstrName; break;
1585 default:
1586 WARN("Don't know this info command (%u)\n", dwFlags);
1587 return MCIERR_UNRECOGNIZED_COMMAND;
1589 if (str) {
1590 if (lpParms->dwRetSize <= strlenW(str)) {
1591 lstrcpynW(lpParms->lpstrReturn, str, lpParms->dwRetSize - 1);
1592 ret = MCIERR_PARAM_OVERFLOW;
1593 } else {
1594 strcpyW(lpParms->lpstrReturn, str);
1596 } else {
1597 *lpParms->lpstrReturn = 0;
1599 return ret;
1602 /**************************************************************************
1603 * MIDI_mciSeek [internal]
1605 static DWORD MIDI_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
1607 DWORD ret = 0;
1608 WINE_MCIMIDI* wmm = MIDI_mciGetOpenDev(wDevID);
1610 TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1612 if (lpParms == NULL) {
1613 ret = MCIERR_NULL_PARAMETER_BLOCK;
1614 } else if (wmm == NULL) {
1615 ret = MCIERR_INVALID_DEVICE_ID;
1616 } else {
1617 MIDI_mciStop(wDevID, MCI_WAIT, 0);
1619 if (dwFlags & MCI_SEEK_TO_START) {
1620 wmm->dwPositionMS = 0;
1621 } else if (dwFlags & MCI_SEEK_TO_END) {
1622 wmm->dwPositionMS = 0xFFFFFFFF; /* FIXME */
1623 } else if (dwFlags & MCI_TO) {
1624 wmm->dwPositionMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
1625 } else {
1626 WARN("dwFlag doesn't tell where to seek to...\n");
1627 return MCIERR_MISSING_PARAMETER;
1630 TRACE("Seeking to position=%u ms\n", wmm->dwPositionMS);
1632 if (dwFlags & MCI_NOTIFY) {
1633 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
1634 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1635 wmm->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1638 return ret;
1641 /*======================================================================*
1642 * MIDI entry points *
1643 *======================================================================*/
1645 /**************************************************************************
1646 * DriverProc (MCISEQ.@)
1648 LRESULT CALLBACK MCIMIDI_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
1649 LPARAM dwParam1, LPARAM dwParam2)
1651 switch (wMsg) {
1652 case DRV_LOAD: return 1;
1653 case DRV_FREE: return 1;
1654 case DRV_ENABLE: return 1;
1655 case DRV_DISABLE: return 1;
1656 case DRV_QUERYCONFIGURE: return 1;
1657 case DRV_CONFIGURE: MessageBoxA(0, "Sample Midi Driver !", "OSS Driver", MB_OK); return 1;
1658 case DRV_INSTALL: return DRVCNF_RESTART;
1659 case DRV_REMOVE: return DRVCNF_RESTART;
1660 case DRV_OPEN: return MIDI_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
1661 case DRV_CLOSE: return MIDI_drvClose(dwDevID);
1664 if (dwDevID == 0xFFFFFFFF) return MCIERR_UNSUPPORTED_FUNCTION;
1666 switch (wMsg) {
1667 case MCI_OPEN_DRIVER: return MIDI_mciOpen (dwDevID, dwParam1, (LPMCI_OPEN_PARMSW) dwParam2);
1668 case MCI_CLOSE_DRIVER: return MIDI_mciClose (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1669 case MCI_PLAY: return MIDI_mciPlay (dwDevID, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
1670 case MCI_RECORD: return MIDI_mciRecord (dwDevID, dwParam1, (LPMCI_RECORD_PARMS) dwParam2);
1671 case MCI_STOP: return MIDI_mciStop (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1672 case MCI_SET: return MIDI_mciSet (dwDevID, dwParam1, (LPMCI_SET_PARMS) dwParam2);
1673 case MCI_PAUSE: return MIDI_mciPause (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1674 case MCI_RESUME: return MIDI_mciResume (dwDevID, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
1675 case MCI_STATUS: return MIDI_mciStatus (dwDevID, dwParam1, (LPMCI_STATUS_PARMS) dwParam2);
1676 case MCI_GETDEVCAPS: return MIDI_mciGetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2);
1677 case MCI_INFO: return MIDI_mciInfo (dwDevID, dwParam1, (LPMCI_INFO_PARMSW) dwParam2);
1678 case MCI_SEEK: return MIDI_mciSeek (dwDevID, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
1679 /* commands that should be supported */
1680 case MCI_LOAD:
1681 case MCI_SAVE:
1682 case MCI_FREEZE:
1683 case MCI_PUT:
1684 case MCI_REALIZE:
1685 case MCI_UNFREEZE:
1686 case MCI_UPDATE:
1687 case MCI_WHERE:
1688 case MCI_STEP:
1689 case MCI_SPIN:
1690 case MCI_ESCAPE:
1691 case MCI_COPY:
1692 case MCI_CUT:
1693 case MCI_DELETE:
1694 case MCI_PASTE:
1695 WARN("Unsupported command [%u]\n", wMsg);
1696 break;
1697 /* commands that should report an error */
1698 case MCI_WINDOW:
1699 TRACE("Unsupported command [%u]\n", wMsg);
1700 break;
1701 case MCI_OPEN:
1702 case MCI_CLOSE:
1703 FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1704 break;
1705 default:
1706 TRACE("Sending msg [%u] to default driver proc\n", wMsg);
1707 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1709 return MCIERR_UNRECOGNIZED_COMMAND;