4 * Copyright 2010 Jörg Höhle
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 extern const char* mmsys_error(MMRESULT error
); /* from wave.c */
29 /* Test in order of increasing probability to hang.
30 * On many UNIX systems, the Timidity softsynth provides
31 * MIDI sequencer services and it is not particularly robust.
34 #define MYCBINST 0x4CAFE5A8 /* not used with window or thread callbacks */
35 #define WHATEVER 0xFEEDF00D
37 static BOOL
spurious_message(LPMSG msg
)
39 /* WM_DEVICECHANGE 0x0219 appears randomly */
40 if(msg
->message
== WM_DEVICECHANGE
) {
41 trace("skipping spurious message %04x\n", msg
->message
);
47 static UINT cbmsg
= 0;
48 static DWORD_PTR cbval1
= WHATEVER
;
49 static DWORD_PTR cbval2
= 0;
50 static DWORD_PTR cbinst
= MYCBINST
;
52 static void CALLBACK
callback_func(HWAVEOUT hwo
, UINT uMsg
,
54 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
57 trace("Callback! msg=%x %lx %lx\n", uMsg
, dwParam1
, dwParam2
);
59 cbval1
= dwParam1
; /* mhdr or 0 */
60 cbval2
= dwParam2
; /* always 0 */
61 cbinst
= dwInstance
; /* MYCBINST, see midiOut/StreamOpen */
64 static void test_notification(HWND hwnd
, const char* command
, UINT m1
, DWORD_PTR p2
)
65 { /* Use message type 0 as meaning no message */
68 /* msg.wParam is hmidiout, msg.lParam is the mhdr (or 0) */
70 do { seen
= PeekMessageA(&msg
, hwnd
, 0, 0, PM_REMOVE
); }
71 while(seen
&& spurious_message(&msg
));
73 /* We observe transient delayed notification, mostly on native.
74 * Perhaps the OS preempts the player thread after setting MHDR_DONE
75 * or clearing MHDR_INQUEUE, before calling DriverCallback. */
77 trace("Waiting for delayed message %x from %s\n", m1
, command
);
78 SetLastError(0xDEADBEEF);
79 rc
= MsgWaitForMultipleObjects(0, NULL
, FALSE
, 3000, QS_POSTMESSAGE
);
80 ok(rc
==WAIT_OBJECT_0
, "Wait failed: %04x %d\n", rc
, GetLastError());
81 seen
= PeekMessageA(&msg
, hwnd
, 0, 0, PM_REMOVE
);
84 trace("Message %x, wParam=%lx, lParam=%lx from %s\n",
85 msg
.message
, msg
.wParam
, msg
.lParam
, command
);
86 ok(msg
.hwnd
==hwnd
, "Didn't get the handle to our test window\n");
87 ok(msg
.message
==m1
&& msg
.lParam
==p2
, "bad message %x/%lx from %s, expect %x/%lx\n", msg
.message
, msg
.lParam
, command
, m1
, p2
);
89 else ok(m1
==0, "Expect message %x from %s\n", m1
, command
);
92 /* FIXME: MOM_POSITIONCB and MOM_DONE are so close that a queue is needed. */
94 ok(cbmsg
==m1
&& cbval1
==p2
&& cbval2
==0, "bad callback %x/%lx/%lx from %s, expect %x/%lx\n", cbmsg
, cbval1
, cbval2
, command
, m1
, p2
);
95 cbmsg
= 0; /* Mark as read */
96 cbval1
= cbval2
= WHATEVER
;
97 ok(cbinst
==MYCBINST
, "callback dwInstance changed to %lx\n", cbinst
);
99 else ok(m1
==0, "Expect callback %x from %s\n", m1
, command
);
104 static void test_midiIn_device(UINT udev
, HWND hwnd
)
111 rc
= midiInGetDevCapsA(udev
, &capsA
, sizeof(capsA
));
112 ok((MIDIMAPPER
==udev
) ? (rc
==MMSYSERR_BADDEVICEID
|| broken(rc
==MMSYSERR_NODRIVER
/*nt,w2k*/)) : rc
==0,
113 "midiInGetDevCaps(dev=%d) rc=%s\n", udev
, mmsys_error(rc
));
115 /* MIDI IN capsA.dwSupport may contain garbage, absent in old MS-Windows */
116 trace("* %s: manufacturer=%d, product=%d, support=%X\n", capsA
.szPname
, capsA
.wMid
, capsA
.wPid
, capsA
.dwSupport
);
120 rc
= midiInOpen(&hm
, udev
, (DWORD_PTR
)hwnd
, (DWORD_PTR
)MYCBINST
, CALLBACK_WINDOW
);
122 rc
= midiInOpen(&hm
, udev
, (DWORD_PTR
)callback_func
, (DWORD_PTR
)MYCBINST
, CALLBACK_FUNCTION
);
123 ok((MIDIMAPPER
!=udev
) ? rc
==0 : (rc
==MMSYSERR_BADDEVICEID
|| broken(rc
==MMSYSERR_NODRIVER
/*nt,w2k*/)),
124 "midiInOpen(dev=%d) rc=%s\n", udev
, mmsys_error(rc
));
127 test_notification(hwnd
, "midiInOpen", MIM_OPEN
, 0);
130 mhdr
.dwUser
= 0x56FA552C;
131 mhdr
.dwBufferLength
= 70000; /* > 64KB! */
132 mhdr
.lpData
= HeapAlloc(GetProcessHeap(), 0 , mhdr
.dwBufferLength
);
133 ok(mhdr
.lpData
!=NULL
, "No %d bytes of memory!\n", mhdr
.dwBufferLength
);
135 rc
= midiInPrepareHeader(hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
)-1);
136 ok(rc
==MMSYSERR_INVALPARAM
, "midiInPrepare tiny rc=%s\n", mmsys_error(rc
));
137 rc
= midiInPrepareHeader(hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
));
138 ok(!rc
, "midiInPrepare old size rc=%s\n", mmsys_error(rc
));
139 rc
= midiInPrepareHeader(hm
, &mhdr
, sizeof(mhdr
));
140 ok(!rc
, "midiInPrepare rc=%s\n", mmsys_error(rc
));
141 rc
= midiInUnprepareHeader(hm
, &mhdr
, sizeof(mhdr
));
142 ok(!rc
, "midiInUnprepare rc=%s\n", mmsys_error(rc
));
143 trace("MIDIHDR flags=%x when unsent\n", mhdr
.dwFlags
);
145 HeapFree(GetProcessHeap(), 0, mhdr
.lpData
);
147 ok(mhdr
.dwUser
==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr
.dwUser
);
149 rc
= midiInReset(hm
); /* Return any pending buffer */
150 ok(!rc
, "midiInReset rc=%s\n", mmsys_error(rc
));
152 rc
= midiInClose(hm
);
153 ok(!rc
, "midiInClose rc=%s\n", mmsys_error(rc
));
154 test_notification(hwnd
, "midiInClose", MIM_CLOSE
, 0);
155 test_notification(hwnd
, "midiIn over", 0, WHATEVER
);
158 static void test_midi_infns(HWND hwnd
)
162 UINT udev
, ndevs
= midiInGetNumDevs();
164 rc
= midiInOpen(&hm
, ndevs
, 0, 0, CALLBACK_NULL
);
165 ok(rc
==MMSYSERR_BADDEVICEID
, "midiInOpen udev>max rc=%s\n", mmsys_error(rc
));
167 rc
= midiInClose(hm
);
168 ok(!rc
, "midiInClose rc=%s\n", mmsys_error(rc
));
171 trace("Found no MIDI IN device\n"); /* no skip for this common situation */
172 rc
= midiInOpen(&hm
, MIDIMAPPER
, 0, 0, CALLBACK_NULL
);
173 ok(rc
==MMSYSERR_BADDEVICEID
|| broken(rc
==MMSYSERR_NODRIVER
/*nt,w2k*/), "midiInOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc
));
175 rc
= midiInClose(hm
);
176 ok(!rc
, "midiInClose rc=%s\n", mmsys_error(rc
));
180 trace("Found %d MIDI IN devices\n", ndevs
);
181 for (udev
=0; udev
< ndevs
; udev
++) {
182 trace("** Testing device %d\n", udev
);
183 test_midiIn_device(udev
, hwnd
);
186 trace("** Testing MIDI mapper\n");
187 test_midiIn_device(MIDIMAPPER
, hwnd
);
191 static void test_midi_mci(HWND hwnd
)
195 memset(buf
, 0, sizeof(buf
));
197 err
= mciSendString("sysinfo sequencer quantity", buf
, sizeof(buf
), hwnd
);
198 ok(!err
, "mci sysinfo sequencer quantity returned %d\n", err
);
199 if (!err
) trace("Found %s MCI sequencer devices\n", buf
);
203 static void test_midiOut_device(UINT udev
, HWND hwnd
)
211 rc
= midiOutGetDevCapsA(udev
, &capsA
, sizeof(capsA
));
212 ok(!rc
, "midiOutGetDevCaps(dev=%d) rc=%s\n", udev
, mmsys_error(rc
));
214 trace("* %s: manufacturer=%d, product=%d, tech=%d, support=%X: %d voices, %d notes\n",
215 capsA
.szPname
, capsA
.wMid
, capsA
.wPid
, capsA
.wTechnology
, capsA
.dwSupport
, capsA
.wVoices
, capsA
.wNotes
);
219 rc
= midiOutOpen(&hm
, udev
, (DWORD_PTR
)hwnd
, (DWORD_PTR
)MYCBINST
, CALLBACK_WINDOW
);
221 rc
= midiOutOpen(&hm
, udev
, (DWORD_PTR
)callback_func
, (DWORD_PTR
)MYCBINST
, CALLBACK_FUNCTION
);
222 ok(!rc
, "midiOutOpen(dev=%d) rc=%s\n", udev
, mmsys_error(rc
));
225 test_notification(hwnd
, "midiOutOpen", MOM_OPEN
, 0);
227 rc
= midiOutGetVolume(hm
, &ovolume
);
228 ok((capsA
.dwSupport
& MIDICAPS_VOLUME
) ? rc
==MMSYSERR_NOERROR
: rc
==MMSYSERR_NOTSUPPORTED
, "midiOutGetVolume rc=%s\n", mmsys_error(rc
));
229 /* The native mapper responds with FFFFFFFF initially,
230 * real devices with the volume GUI SW-synth settings. */
231 if (!rc
) trace("Current volume %x on device %d\n", ovolume
, udev
);
233 /* Tests with midiOutSetvolume show that the midi mapper forwards
234 * the value to the real device, but Get initially always reports
235 * FFFFFFFF. Therefore, a Get+SetVolume pair with the mapper is
236 * not adequate to restore the value prior to tests.
238 if (winetest_interactive
&& (capsA
.dwSupport
& MIDICAPS_VOLUME
)) {
239 DWORD volume2
= (ovolume
< 0x80000000) ? 0xC000C000 : 0x40004000;
240 rc
= midiOutSetVolume(hm
, volume2
);
241 ok(!rc
, "midiOutSetVolume rc=%s\n", mmsys_error(rc
));
244 rc
= midiOutGetVolume(hm
, &volume3
);
245 ok(!rc
, "midiOutGetVolume new rc=%s\n", mmsys_error(rc
));
246 if (!rc
) trace("New volume %x on device %d\n", volume3
, udev
);
247 todo_wine
ok(volume2
==volume3
, "volume Set %x = Get %x\n", volume2
, volume3
);
249 rc
= midiOutSetVolume(hm
, ovolume
);
250 ok(!rc
, "midiOutSetVolume restore rc=%s\n", mmsys_error(rc
));
253 rc
= midiOutGetDevCapsA((UINT_PTR
)hm
, &capsA
, sizeof(capsA
));
254 ok(!rc
, "midiOutGetDevCaps(dev=%d) by handle rc=%s\n", udev
, mmsys_error(rc
));
255 rc
= midiInGetDevCapsA((UINT_PTR
)hm
, (LPMIDIINCAPSA
)&capsA
, sizeof(DWORD
));
256 ok(rc
==MMSYSERR_BADDEVICEID
, "midiInGetDevCaps(dev=%d) by out handle rc=%s\n", udev
, mmsys_error(rc
));
258 { DWORD e
= 0x006F4893; /* velocity, note (#69 would be 440Hz) channel */
259 trace("ShortMsg type %x\n", LOBYTE(LOWORD(e
)));
260 rc
= midiOutShortMsg(hm
, e
);
261 ok(!rc
, "midiOutShortMsg rc=%s\n", mmsys_error(rc
));
262 if (!rc
) Sleep(400); /* Hear note */
266 mhdr
.dwUser
= 0x56FA552C;
267 mhdr
.dwOffset
= 0xDEADBEEF;
268 mhdr
.dwBufferLength
= 70000; /* > 64KB! */
269 mhdr
.lpData
= HeapAlloc(GetProcessHeap(), 0 , mhdr
.dwBufferLength
);
270 ok(mhdr
.lpData
!=NULL
, "No %d bytes of memory!\n", mhdr
.dwBufferLength
);
272 rc
= midiOutLongMsg(hm
, &mhdr
, sizeof(mhdr
));
273 ok(rc
==MIDIERR_UNPREPARED
, "midiOutLongMsg unprepared rc=%s\n", mmsys_error(rc
));
274 test_notification(hwnd
, "midiOutLong unprepared", 0, WHATEVER
);
276 rc
= midiOutPrepareHeader(hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
)-1);
277 ok(rc
==MMSYSERR_INVALPARAM
, "midiOutPrepare tiny rc=%s\n", mmsys_error(rc
));
278 rc
= midiOutPrepareHeader(hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
));
279 ok(!rc
, "midiOutPrepare old size rc=%s\n", mmsys_error(rc
));
280 rc
= midiOutPrepareHeader(hm
, &mhdr
, sizeof(mhdr
));
281 ok(!rc
, "midiOutPrepare rc=%s\n", mmsys_error(rc
));
282 rc
= midiOutUnprepareHeader(hm
, &mhdr
, sizeof(mhdr
));
283 ok(!rc
, "midiOutUnprepare rc=%s\n", mmsys_error(rc
));
284 trace("MIDIHDR flags=%x when unsent\n", mhdr
.dwFlags
);
286 HeapFree(GetProcessHeap(), 0, mhdr
.lpData
);
288 ok(mhdr
.dwUser
==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr
.dwUser
);
289 ok(mhdr
.dwOffset
==0xDEADBEEF, "MIDIHDR.dwOffset changed to %x\n", mhdr
.dwOffset
);
291 rc
= midiOutReset(hm
); /* Quiet everything */
292 ok(!rc
, "midiOutReset rc=%s\n", mmsys_error(rc
));
294 rc
= midiOutClose(hm
);
295 ok(!rc
, "midiOutClose rc=%s\n", mmsys_error(rc
));
296 test_notification(hwnd
, "midiOutClose", MOM_CLOSE
, 0);
297 test_notification(hwnd
, "midiOut over", 0, WHATEVER
);
300 static void test_position(HMIDISTRM hm
, UINT typein
, UINT typeout
)
304 mmtime
.wType
= typein
;
305 rc
= midiStreamPosition(hm
, &mmtime
, sizeof(MMTIME
));
306 /* Ugly, but a single ok() herein enables using the todo_wine prefix */
307 ok(!rc
&& (mmtime
.wType
== typeout
), "midiStreamPosition type %x converted to %x rc=%s\n", typein
, mmtime
.wType
, mmsys_error(rc
));
308 if (!rc
) switch(mmtime
.wType
) {
310 trace("Stream position %ums\n", mmtime
.u
.ms
);
313 trace("Stream position %u ticks\n", mmtime
.u
.ticks
);
316 trace("Stream position song pointer %u\n", mmtime
.u
.midi
.songptrpos
);
321 /* Native crashes on a second run with the const qualifier set on this data! */
322 static BYTE strmEvents
[] = { /* A set of variable-sized MIDIEVENT structs */
323 0, 0, 0, 0, 0, 0, 0, 0, /* dwDeltaTime and dwStreamID */
324 0, 0, 0, MEVT_NOP
| 0x40, /* with MEVT_F_CALLBACK */
325 0, 0, 0, 0, 0, 0, 0, 0, /* dwDeltaTime and dwStreamID */
326 0x93, 0x48, 0x6F, MEVT_SHORTMSG
,
329 static BYTE strmNops
[] = { /* Test callback + dwOffset */
330 0, 0, 0, 0, 0, 0, 0, 0,
331 0, 0, 0, MEVT_NOP
| 0x40, /* with MEVT_F_CALLBACK */
332 0, 0, 0, 0, 0, 0, 0, 0,
333 0, 0, 0, MEVT_NOP
| 0x40, /* with MEVT_F_CALLBACK */
336 static MMRESULT
playStream(HMIDISTRM hm
, LPMIDIHDR lpMidiHdr
)
338 MMRESULT rc
= midiStreamOut(hm
, lpMidiHdr
, sizeof(MIDIHDR
));
339 /* virtual machines may return MIDIERR_STILLPLAYING from the next request
340 * even after MHDR_DONE is set. It's still too early, so add MHDR_INQUEUE. */
341 if (!rc
) while (!(lpMidiHdr
->dwFlags
& MHDR_DONE
) || (lpMidiHdr
->dwFlags
& MHDR_INQUEUE
)) { Sleep(100); }
345 static void test_midiStream(UINT udev
, HWND hwnd
)
352 MIDIPROPTIMEDIV tdiv
;
354 BYTE
* const evt1
= &strmNops
[1*offsetof(MIDIEVENT
,dwParms
)-1];
355 BYTE
* const evt2
= &strmNops
[2*offsetof(MIDIEVENT
,dwParms
)-1];
358 rc
= midiStreamOpen(&hm
, &udev
, 1, (DWORD_PTR
)hwnd
, (DWORD_PTR
)MYCBINST
, CALLBACK_WINDOW
);
360 rc
= midiStreamOpen(&hm
, &udev
, 1, (DWORD_PTR
)callback_func
, (DWORD_PTR
)MYCBINST
, CALLBACK_FUNCTION
);
361 ok(!rc
, "midiStreamOpen(dev=%d) rc=%s\n", udev
, mmsys_error(rc
));
364 test_notification(hwnd
, "midiStreamOpen", MOM_OPEN
, 0);
366 midiprop
.tempo
.cbStruct
= sizeof(midiprop
.tempo
);
367 rc
= midiStreamProperty(hm
, (void*)&midiprop
, MIDIPROP_GET
|MIDIPROP_TEMPO
);
368 ok(!rc
, "midiStreamProperty TEMPO rc=%s\n", mmsys_error(rc
));
369 ok(midiprop
.tempo
.dwTempo
==500000, "default stream tempo %u microsec per quarter note\n", midiprop
.tempo
.dwTempo
);
371 midiprop
.tdiv
.cbStruct
= sizeof(midiprop
.tdiv
);
372 rc
= midiStreamProperty(hm
, (void*)&midiprop
, MIDIPROP_GET
|MIDIPROP_TIMEDIV
);
373 ok(!rc
, "midiStreamProperty TIMEDIV rc=%s\n", mmsys_error(rc
));
374 todo_wine
ok(24==LOWORD(midiprop
.tdiv
.dwTimeDiv
), "default stream time division %u\n", midiprop
.tdiv
.dwTimeDiv
);
377 mhdr
.dwUser
= 0x56FA552C;
378 mhdr
.dwOffset
= 1234567890;
379 mhdr
.dwBufferLength
= sizeof(strmEvents
) * sizeof(strmEvents
[0]);
380 mhdr
.dwBytesRecorded
= mhdr
.dwBufferLength
;
381 mhdr
.lpData
= (LPSTR
)&strmEvents
[0];
383 rc
= midiOutLongMsg((HMIDIOUT
)hm
, &mhdr
, sizeof(mhdr
));
384 ok(rc
==MIDIERR_UNPREPARED
, "midiOutLongMsg unprepared rc=%s\n", mmsys_error(rc
));
385 test_notification(hwnd
, "midiOutLong unprepared", 0, WHATEVER
);
387 rc
= midiOutPrepareHeader((HMIDIOUT
)hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
)-1);
388 ok(rc
==MMSYSERR_INVALPARAM
, "midiOutPrepare tiny rc=%s\n", mmsys_error(rc
));
389 rc
= midiOutPrepareHeader((HMIDIOUT
)hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
));
390 ok(!rc
, "midiOutPrepare old size rc=%s\n", mmsys_error(rc
));
391 ok(mhdr
.dwFlags
& MHDR_PREPARED
, "MHDR.dwFlags when prepared %x\n", mhdr
.dwFlags
);
393 /* The device is still in paused mode and should queue the message. */
394 rc
= midiStreamOut(hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
));
395 ok(!rc
, "midiStreamOut old size rc=%s\n", mmsys_error(rc
));
397 trace("MIDIHDR flags=%x when submitted\n", mhdr
.dwFlags
);
398 /* w9X/me does not set MHDR_ISSTRM when StreamOut exits,
399 * but it will be set on all systems after the job is finished. */
402 /* Wine <1.1.39 started playing immediately */
403 test_notification(hwnd
, "midiStream still paused", 0, WHATEVER
);
405 /* MSDN asks to use midiStreamRestart prior to midiStreamOut()
406 * because the starting state is 'pause', but some apps seem to
407 * work with the inverse order.
410 rc
= midiStreamRestart(hm
);
411 ok(!rc
, "midiStreamRestart rc=%s\n", mmsys_error(rc
));
413 if (!rc2
) while(mhdr
.dwFlags
& MHDR_INQUEUE
) {
414 trace("async MIDI still queued\n");
416 } /* Checking INQUEUE is not the recommended way to wait for the end of a job, but we're testing. */
417 /* MHDR_ISSTRM is not necessarily set when midiStreamOut returns
418 * rather than when the queue is eventually processed. */
419 ok(mhdr
.dwFlags
& MHDR_ISSTRM
, "MHDR.dwFlags %x no ISSTRM when out of queue\n", mhdr
.dwFlags
);
420 if (!rc2
) while(!(mhdr
.dwFlags
& MHDR_DONE
)) {
421 /* Never to be seen except perhaps on multicore */
422 trace("async MIDI still not done\n");
425 ok(mhdr
.dwFlags
& MHDR_DONE
, "MHDR.dwFlags %x not DONE when out of queue\n", mhdr
.dwFlags
);
426 test_notification(hwnd
, "midiStream callback", MOM_POSITIONCB
, (DWORD_PTR
)&mhdr
);
427 test_notification(hwnd
, "midiStreamOut", MOM_DONE
, (DWORD_PTR
)&mhdr
);
429 /* Native fills dwOffset regardless of the cbMidiHdr size argument to midiStreamOut */
430 ok(1234567890!=mhdr
.dwOffset
, "play left MIDIHDR.dwOffset at %u\n", mhdr
.dwOffset
);
432 rc
= midiOutUnprepareHeader((HMIDIOUT
)hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
));
433 ok(!rc
, "midiOutUnprepare rc=%s\n", mmsys_error(rc
));
434 rc
= midiOutUnprepareHeader((HMIDIOUT
)hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
));
435 ok(!rc
, "midiOutUnprepare #2 rc=%s\n", mmsys_error(rc
));
437 trace("MIDIHDR stream flags=%x when finished\n", mhdr
.dwFlags
);
438 ok(mhdr
.dwFlags
& MHDR_DONE
, "MHDR.dwFlags when done %x\n", mhdr
.dwFlags
);
440 test_position(hm
, TIME_MS
, TIME_MS
);
441 test_position(hm
, TIME_TICKS
, TIME_TICKS
);
442 todo_wine
test_position(hm
, TIME_MIDI
, TIME_MIDI
);
443 test_position(hm
, TIME_SMPTE
, TIME_MS
);
444 test_position(hm
, TIME_SAMPLES
, TIME_MS
);
445 test_position(hm
, TIME_BYTES
, TIME_MS
);
447 Sleep(400); /* Hear note */
449 rc
= midiStreamRestart(hm
);
450 ok(!rc
, "midiStreamRestart #2 rc=%s\n", mmsys_error(rc
));
452 mhdr
.dwFlags
|= MHDR_ISSTRM
; /* just in case */
453 /* Preset flags (e.g. MHDR_ISSTRM) do not disturb. */
454 rc
= midiOutPrepareHeader((HMIDIOUT
)hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
));
455 ok(!rc
, "midiOutPrepare used flags %x rc=%s\n", mhdr
.dwFlags
, mmsys_error(rc
));
456 rc
= midiOutUnprepareHeader((HMIDIOUT
)hm
, &mhdr
, offsetof(MIDIHDR
,dwOffset
));
457 ok(!rc
, "midiOutUnprepare used flags %x rc=%s\n", mhdr
.dwFlags
, mmsys_error(rc
));
459 rc
= midiStreamRestart(hm
);
460 ok(!rc
, "midiStreamRestart #3 rc=%s\n", mmsys_error(rc
));
462 ok(mhdr
.dwUser
==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr
.dwUser
);
463 trace("dwStreamID set to %x\n", ((LPMIDIEVENT
)&strmEvents
[0])->dwStreamID
);
465 /* dwBytesRecorded controls how much is played, not dwBufferLength
466 * allowing to immediately forward packets from midiIn to midiOut */
467 mhdr
.dwOffset
= 1234123123;
468 mhdr
.dwBufferLength
= sizeof(strmNops
) * sizeof(strmNops
[0]);
469 mhdr
.dwBytesRecorded
= 0;
470 mhdr
.lpData
= (LPSTR
)&strmNops
[0];
471 *evt1
|= 0x40; /* MEVT_CALLBACK flag */
474 rc
= midiOutPrepareHeader((HMIDIOUT
)hm
, &mhdr
, sizeof(mhdr
));
475 ok(!rc
, "midiOutPrepare rc=%s\n", mmsys_error(rc
));
477 rc
= playStream(hm
, &mhdr
);
478 ok(!rc
, "midiStreamOut 0 bytes recorded rc=%s\n", mmsys_error(rc
));
480 test_notification(hwnd
, "midiStreamOut", MOM_DONE
, (DWORD_PTR
)&mhdr
);
481 test_notification(hwnd
, "0 bytes recorded", 0, WHATEVER
);
483 /* FIXME: check dwOffset within callback
484 * instead of the unspecified value afterwards */
485 ok(1234123123==mhdr
.dwOffset
|| broken(0==mhdr
.dwOffset
), "play 0 set MIDIHDR.dwOffset to %u\n", mhdr
.dwOffset
);
486 /* w2k and later only set dwOffset when processing MEVT_T_CALLBACK,
487 * while w9X/me/nt always sets it. Have Wine behave like w2k because the
488 * dwOffset slot does not exist in the small size MIDIHDR. */
490 mhdr
.dwOffset
= 1234123123;
491 mhdr
.dwBytesRecorded
= offsetof(MIDIEVENT
,dwParms
);
493 rc
= playStream(hm
, &mhdr
);
494 ok(!rc
, "midiStreamOut 1 event out of 2 rc=%s\n", mmsys_error(rc
));
496 test_notification(hwnd
, "1 of 2 events", MOM_POSITIONCB
, (DWORD_PTR
)&mhdr
);
497 test_notification(hwnd
, "1 of 2 events", MOM_DONE
, (DWORD_PTR
)&mhdr
);
498 test_notification(hwnd
, "1 of 2 events", 0, WHATEVER
);
499 ok(0==mhdr
.dwOffset
, "MIDIHDR.dwOffset 1/2 changed to %u\n", mhdr
.dwOffset
);
500 trace("MIDIHDR.dwOffset left at %u\n", mhdr
.dwOffset
);
502 mhdr
.dwOffset
= 1234123123;
503 mhdr
.dwBytesRecorded
= 2*offsetof(MIDIEVENT
,dwParms
);
505 rc
= playStream(hm
, &mhdr
);
506 ok(!rc
, "midiStreamOut 1 event out of 2 rc=%s\n", mmsys_error(rc
));
508 test_notification(hwnd
, "2 of 2 events", MOM_POSITIONCB
, (DWORD_PTR
)&mhdr
);
509 test_notification(hwnd
, "2 of 2 events", MOM_POSITIONCB
, (DWORD_PTR
)&mhdr
);
510 test_notification(hwnd
, "2 of 2 events", MOM_DONE
, (DWORD_PTR
)&mhdr
);
511 test_notification(hwnd
, "2 of 2 events", 0, WHATEVER
);
512 ok(3*sizeof(DWORD
)==mhdr
.dwOffset
, "MIDIHDR.dwOffset 2/2 changed to %u\n", mhdr
.dwOffset
);
513 trace("MIDIHDR.dwOffset left at %u\n", mhdr
.dwOffset
);
515 *evt1
&= ~0x40; /* MEVT_CALLBACK flag */
517 mhdr
.dwOffset
= 1234123123;
518 rc
= playStream(hm
, &mhdr
);
519 ok(!rc
, "midiStreamOut 1 event out of 2 rc=%s\n", mmsys_error(rc
));
521 test_notification(hwnd
, "0 CB in 2 events", MOM_DONE
, (DWORD_PTR
)&mhdr
);
522 test_notification(hwnd
, "0 CB in 2 events", 0, WHATEVER
);
523 /* w9X/me/nt set dwOffset to the position played last */
524 ok(1234123123==mhdr
.dwOffset
|| broken(3*sizeof(DWORD
)==mhdr
.dwOffset
), "MIDIHDR.dwOffset nocb changed to %u\n", mhdr
.dwOffset
);
526 mhdr
.dwBytesRecorded
= mhdr
.dwBufferLength
-1;
527 rc
= playStream(hm
, &mhdr
);
528 todo_wine
ok(rc
==MMSYSERR_INVALPARAM
,"midiStreamOut dwBytesRecorded/MIDIEVENT rc=%s\n", mmsys_error(rc
));
530 test_notification(hwnd
, "2 of 2 events", MOM_DONE
, (DWORD_PTR
)&mhdr
);
533 mhdr
.dwBytesRecorded
= mhdr
.dwBufferLength
+1;
534 rc
= playStream(hm
, &mhdr
);
535 ok(rc
==MMSYSERR_INVALPARAM
,"midiStreamOut dwBufferLength<dwBytesRecorded rc=%s\n", mmsys_error(rc
));
536 test_notification(hwnd
, "past MIDIHDR tests", 0, WHATEVER
);
538 rc
= midiStreamStop(hm
);
539 ok(!rc
, "midiStreamStop rc=%s\n", mmsys_error(rc
));
540 ok(mhdr
.dwUser
==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr
.dwUser
);
542 rc
= midiOutUnprepareHeader((HMIDIOUT
)hm
, &mhdr
, sizeof(mhdr
));
543 ok(!rc
, "midiOutUnprepare rc=%s\n", mmsys_error(rc
));
545 mhdr
.dwBufferLength
= 70000; /* > 64KB! */
546 mhdr
.lpData
= HeapAlloc(GetProcessHeap(), 0 , mhdr
.dwBufferLength
);
547 ok(mhdr
.lpData
!=NULL
, "No %d bytes of memory!\n", mhdr
.dwBufferLength
);
550 /* PrepareHeader detects the too large buffer is for a stream. */
551 rc
= midiOutPrepareHeader((HMIDIOUT
)hm
, &mhdr
, sizeof(mhdr
));
552 todo_wine
ok(rc
==MMSYSERR_INVALPARAM
, "midiOutPrepare stream too large rc=%s\n", mmsys_error(rc
));
554 rc
= midiOutUnprepareHeader((HMIDIOUT
)hm
, &mhdr
, sizeof(mhdr
));
555 ok(!rc
, "midiOutUnprepare rc=%s\n", mmsys_error(rc
));
557 HeapFree(GetProcessHeap(), 0, mhdr
.lpData
);
560 rc
= midiStreamClose(hm
);
561 ok(!rc
, "midiStreamClose rc=%s\n", mmsys_error(rc
));
562 test_notification(hwnd
, "midiStreamClose", MOM_CLOSE
, 0);
563 test_notification(hwnd
, "midiStream over", 0, WHATEVER
);
566 static void test_midi_outfns(HWND hwnd
)
570 UINT udev
, ndevs
= midiOutGetNumDevs();
572 rc
= midiOutOpen(&hm
, ndevs
, 0, 0, CALLBACK_NULL
);
573 ok(rc
==MMSYSERR_BADDEVICEID
, "midiOutOpen udev>max rc=%s\n", mmsys_error(rc
));
575 rc
= midiOutClose(hm
);
576 ok(!rc
, "midiOutClose rc=%s\n", mmsys_error(rc
));
580 skip("Found no MIDI out device\n");
582 rc
= midiOutGetDevCapsA(MIDIMAPPER
, &capsA
, sizeof(capsA
));
583 /* GetDevCaps and Open must return compatible results */
584 ok(rc
==MMSYSERR_BADDEVICEID
|| broken(rc
==MMSYSERR_NODRIVER
/*nt,w2k*/), "midiOutGetDevCaps MAPPER with no MIDI rc=%s\n", mmsys_error(rc
));
586 rc
= midiOutOpen(&hm
, MIDIMAPPER
, 0, 0, CALLBACK_NULL
);
587 if (rc
==MIDIERR_INVALIDSETUP
) todo_wine
/* Wine without snd-seq */
588 ok(rc
==MMSYSERR_BADDEVICEID
|| broken(rc
==MMSYSERR_NODRIVER
/*w2k*/), "midiOutOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc
));
590 ok(rc
==MMSYSERR_BADDEVICEID
|| broken(rc
==MMSYSERR_NODRIVER
/*w2k sound disabled*/),
591 "midiOutOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc
));
593 rc
= midiOutClose(hm
);
594 ok(!rc
, "midiOutClose rc=%s\n", mmsys_error(rc
));
598 trace("Found %d MIDI OUT devices\n", ndevs
);
602 for (udev
=0; udev
< ndevs
; udev
++) {
603 trace("** Testing device %d\n", udev
);
604 test_midiOut_device(udev
, hwnd
);
605 Sleep(800); /* Let the synth rest */
606 test_midiStream(udev
, hwnd
);
609 trace("** Testing MIDI mapper\n");
610 test_midiOut_device(MIDIMAPPER
, hwnd
);
612 test_midiStream(MIDIMAPPER
, hwnd
);
618 if (1) /* select 1 for CALLBACK_WINDOW or 0 for CALLBACK_FUNCTION */
619 hwnd
= CreateWindowExA(0, "static", "winmm midi test", WS_POPUP
, 0,0,100,100,
621 test_midi_infns(hwnd
);
622 test_midi_outfns(hwnd
);
623 if (hwnd
) DestroyWindow(hwnd
);