ReactOS 0.4.15-dev-5667-ged97270
midi.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "windows.h"
#include "mmsystem.h"
#include "objbase.h"
#include "wine/test.h"
Include dependency graph for midi.c:

Go to the source code of this file.

Classes

struct  midishortevent_tag
 
struct  time_stamp_records
 

Macros

#define _WINE
 
#define MYCBINST   0x4CAFE5A8 /* not used with window or thread callbacks */
 
#define WHATEVER   0xFEEDF00D
 
#define test_notification(hwnd, command, m1, p2)   test_notification_dbg(hwnd, command, m1, p2, __LINE__)
 
#define ROUNDUP4(n)   (((n) + 3) & ~3)
 

Typedefs

typedef struct midishortevent_tag MIDISHORTEVENT
 

Functions

const charmmsys_error (MMRESULT error)
 
static BOOL spurious_message (LPMSG msg)
 
static void CALLBACK callback_func (HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
 
static void test_notification_dbg (HWND hwnd, const char *command, UINT m1, DWORD_PTR p2, int line)
 
static void test_midiIn_device (UINT udev, HWND hwnd)
 
static void test_midi_infns (HWND hwnd)
 
static void test_midi_mci (HWND hwnd)
 
static void test_midiOut_device (UINT udev, HWND hwnd)
 
static void test_position (HMIDISTRM hm, UINT typein, UINT typeout)
 
static void CALLBACK time_stamp_callback (HMIDIOUT hmo, UINT msg, DWORD_PTR instance, DWORD_PTR p1, DWORD_PTR p2)
 
static DWORD get_position (HMIDISTRM hm, UINT type)
 
static MMRESULT playStream (HMIDISTRM hm, LPMIDIHDR lpMidiHdr)
 
static void test_midiStream (UINT udev, HWND hwnd)
 
static BOOL scan_subkeys (HKEY parent, const LPCSTR *sub_keys)
 
static BOOL on_vmware (void)
 
static void test_midi_outfns (HWND hwnd)
 
 START_TEST (midi)
 

Variables

static UINT cbmsg = 0
 
static DWORD_PTR cbval1 = WHATEVER
 
static DWORD_PTR cbval2 = 0
 
static DWORD_PTR cbinst = MYCBINST
 
static BYTE SysEx_reset []
 
static BYTE SysEx_volume_off []
 
static BYTE SysEx_volume_full []
 
static BOOL found_fluidsynth
 
static const char fluidsynth_prefix [] = "Synth input port "
 
static BYTE strmEvents []
 
static MIDISHORTEVENT strmNops []
 
static MIDISHORTEVENT strmNopsWithDelta []
 

Macro Definition Documentation

◆ _WINE

#define _WINE

Definition at line 21 of file midi.c.

◆ MYCBINST

#define MYCBINST   0x4CAFE5A8 /* not used with window or thread callbacks */

Definition at line 39 of file midi.c.

◆ ROUNDUP4

#define ROUNDUP4 (   n)    (((n) + 3) & ~3)

◆ test_notification

#define test_notification (   hwnd,
  command,
  m1,
  p2 
)    test_notification_dbg(hwnd, command, m1, p2, __LINE__)

Definition at line 69 of file midi.c.

◆ WHATEVER

#define WHATEVER   0xFEEDF00D

Definition at line 40 of file midi.c.

Typedef Documentation

◆ MIDISHORTEVENT

Function Documentation

◆ callback_func()

static void CALLBACK callback_func ( HWAVEOUT  hwo,
UINT  uMsg,
DWORD_PTR  dwInstance,
DWORD_PTR  dwParam1,
DWORD_PTR  dwParam2 
)
static

Definition at line 57 of file midi.c.

60{
61 if (winetest_debug>1)
62 trace("Callback! msg=%x %lx %lx\n", uMsg, dwParam1, dwParam2);
63 cbmsg = uMsg;
64 cbval1 = dwParam1; /* mhdr or 0 */
65 cbval2 = dwParam2; /* always 0 */
66 cbinst = dwInstance; /* MYCBINST, see midiOut/StreamOpen */
67}
#define trace
Definition: atltest.h:70
static DWORD_PTR cbval1
Definition: midi.c:53
static UINT cbmsg
Definition: midi.c:52
static DWORD_PTR cbval2
Definition: midi.c:54
static DWORD_PTR cbinst
Definition: midi.c:55
int winetest_debug

Referenced by test_midiIn_device(), test_midiOut_device(), and test_midiStream().

◆ get_position()

static DWORD get_position ( HMIDISTRM  hm,
UINT  type 
)
static

Definition at line 569 of file midi.c.

570{
571 MMRESULT rc;
572 MMTIME mmtime;
573 mmtime.wType = type;
574 rc = midiStreamPosition(hm, &mmtime, sizeof(mmtime));
575 if (rc != MMSYSERR_NOERROR || mmtime.wType != type)
576 return MAXDWORD;
577
578 switch (mmtime.wType) {
579 case TIME_MS:
580 return mmtime.u.ms;
581 case TIME_TICKS:
582 return mmtime.u.ticks;
583 case TIME_MIDI:
584 return mmtime.u.midi.songptrpos;
585 default:
586 return MAXDWORD;
587 }
588}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define TIME_TICKS
Definition: mmsystem.h:33
UINT MMRESULT
Definition: mmsystem.h:962
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define TIME_MIDI
Definition: mmsystem.h:32
#define TIME_MS
Definition: mmsystem.h:28
#define MAXDWORD
DWORD ms
Definition: mmsystem.h:967
struct mmtime_tag::@3013::@3015 midi
UINT wType
Definition: mmsystem.h:965
union mmtime_tag::@3013 u
DWORD ticks
Definition: mmsystem.h:970
MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
Definition: winmm.c:1928

Referenced by test_midiStream().

◆ mmsys_error()

const char * mmsys_error ( MMRESULT  error)

Definition at line 220 of file wave.c.

221{
222#define ERR_TO_STR(dev) case dev: return #dev
223 static char unknown[32];
224 switch (error) {
264 }
265 sprintf(unknown, "Unknown(0x%08x)", error);
266 return unknown;
267#undef ERR_TO_STR
268}
static WCHAR unknown[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1605
#define error(str)
Definition: mkdosfs.c:1605
#define WAVERR_STILLPLAYING
Definition: mmsystem.h:177
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
#define MMIOERR_CHUNKNOTFOUND
Definition: mmsystem.h:517
#define MMIOERR_CANNOTEXPAND
Definition: mmsystem.h:516
#define MMIOERR_FILENOTFOUND
Definition: mmsystem.h:509
#define MMSYSERR_NOTSUPPORTED
Definition: mmsystem.h:104
#define MIDIERR_INVALIDSETUP
Definition: mmsystem.h:236
#define MMIOERR_OUTOFMEMORY
Definition: mmsystem.h:510
#define MIDIERR_NODEVICE
Definition: mmsystem.h:235
#define MMSYSERR_NODRIVER
Definition: mmsystem.h:102
#define JOYERR_NOCANDO
Definition: mmsystem.h:431
#define MMIOERR_CANNOTREAD
Definition: mmsystem.h:513
#define MIDIERR_UNPREPARED
Definition: mmsystem.h:231
#define MIDIERR_NOTREADY
Definition: mmsystem.h:234
#define MMIOERR_CANNOTSEEK
Definition: mmsystem.h:515
#define TIMERR_STRUCT
Definition: mmsystem.h:420
#define MIXERR_INVALVALUE
Definition: mmsystem.h:297
#define JOYERR_UNPLUGGED
Definition: mmsystem.h:432
#define MMSYSERR_INVALHANDLE
Definition: mmsystem.h:101
#define MMSYSERR_INVALPARAM
Definition: mmsystem.h:107
#define MMIOERR_CANNOTOPEN
Definition: mmsystem.h:511
#define WAVERR_BADFORMAT
Definition: mmsystem.h:176
#define MMSYSERR_ALLOCATED
Definition: mmsystem.h:100
#define MIXERR_INVALLINE
Definition: mmsystem.h:295
#define MMSYSERR_ERROR
Definition: mmsystem.h:97
#define MIDIERR_STILLPLAYING
Definition: mmsystem.h:232
#define MMSYSERR_INVALFLAG
Definition: mmsystem.h:106
#define MMIOERR_UNBUFFERED
Definition: mmsystem.h:518
#define MMSYSERR_BADDEVICEID
Definition: mmsystem.h:98
#define WAVERR_UNPREPARED
Definition: mmsystem.h:178
#define MMIOERR_CANNOTCLOSE
Definition: mmsystem.h:512
#define JOYERR_PARMS
Definition: mmsystem.h:430
#define MMIOERR_CANNOTWRITE
Definition: mmsystem.h:514
#define MIXERR_INVALCONTROL
Definition: mmsystem.h:296
#define MMSYSERR_NOTENABLED
Definition: mmsystem.h:99
#define TIMERR_NOCANDO
Definition: mmsystem.h:419
#define WAVERR_SYNC
Definition: mmsystem.h:179
#define MMSYSERR_BADERRNUM
Definition: mmsystem.h:105
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define ERR_TO_STR(dev)

Referenced by mixer_test_controlA(), mixer_test_controlW(), mixer_test_deviceA(), mixer_test_deviceW(), mixer_testsA(), mixer_testsW(), test_midi_infns(), test_midi_outfns(), test_midiIn_device(), test_midiOut_device(), test_midiStream(), test_mixerClose(), test_mixerOpen(), test_position(), test_timeGetDevCaps(), test_timer(), wave_in_error(), and wave_in_test_deviceIn().

◆ on_vmware()

static BOOL on_vmware ( void  )
static

Definition at line 1103 of file midi.c.

1104{
1105 static const LPCSTR sub_keys[] = { "Scsi Port ", "Scsi Bus ", "Target Id ", "Logical Unit Id ", NULL };
1106 HKEY scsi;
1107 BOOL found_vmware = FALSE;
1108
1109 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi", 0, KEY_ENUMERATE_SUB_KEYS, &scsi) != ERROR_SUCCESS)
1110 return FALSE;
1111
1112 found_vmware = scan_subkeys(scsi, sub_keys);
1113
1114 RegCloseKey(scsi);
1115
1116 return found_vmware;
1117}
#define RegCloseKey(hKey)
Definition: registry.h:47
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3321
unsigned int BOOL
Definition: ntddk_ex.h:94
static BOOL scan_subkeys(HKEY parent, const LPCSTR *sub_keys)
Definition: midi.c:1053
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
const char * LPCSTR
Definition: xmlstorage.h:183

Referenced by test_midi_outfns().

◆ playStream()

static MMRESULT playStream ( HMIDISTRM  hm,
LPMIDIHDR  lpMidiHdr 
)
static

Definition at line 590 of file midi.c.

591{
592 MMRESULT rc = midiStreamOut(hm, lpMidiHdr, sizeof(MIDIHDR));
593 /* virtual machines may return MIDIERR_STILLPLAYING from the next request
594 * even after MHDR_DONE is set. It's still too early, so add MHDR_INQUEUE. */
595 if (!rc) while (!(lpMidiHdr->dwFlags & MHDR_DONE) || (lpMidiHdr->dwFlags & MHDR_INQUEUE)) { Sleep(100); }
596 return rc;
597}
#define MHDR_INQUEUE
Definition: mmsystem.h:270
#define MHDR_DONE
Definition: mmsystem.h:268
DWORD dwFlags
Definition: mmsystem.h:1155
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr, UINT cbMidiHdr)
Definition: winmm.c:1869

Referenced by test_midiStream().

◆ scan_subkeys()

static BOOL scan_subkeys ( HKEY  parent,
const LPCSTR sub_keys 
)
static

Definition at line 1053 of file midi.c.

1054{
1055 char name[64];
1056 DWORD index = 0;
1057 DWORD name_len = sizeof(name);
1058 BOOL found_vmware = FALSE;
1059
1060 if (sub_keys[0] == NULL)
1061 {
1062 /* We're at the deepest level, check "Identifier" value now */
1063 char *test;
1064 if (RegQueryValueExA(parent, "Identifier", NULL, NULL, (LPBYTE) name, &name_len) != ERROR_SUCCESS)
1065 return FALSE;
1066 for (test = name; test < name + lstrlenA(name) - 6 && ! found_vmware; test++)
1067 {
1068 char c = test[6];
1069 test[6] = '\0';
1070 found_vmware = (lstrcmpiA(test, "VMware") == 0);
1071 test[6] = c;
1072 }
1073 return found_vmware;
1074 }
1075
1076 while (RegEnumKeyExA(parent, index, name, &name_len, NULL, NULL, NULL, NULL) == ERROR_SUCCESS &&
1077 ! found_vmware) {
1078 char c = name[lstrlenA(sub_keys[0])];
1079 name[lstrlenA(sub_keys[0])] = '\0';
1080 if (lstrcmpiA(name, sub_keys[0]) == 0) {
1081 HKEY sub_key;
1082 name[lstrlenA(sub_keys[0])] = c;
1084 found_vmware = scan_subkeys(sub_key, sub_keys + 1);
1085 RegCloseKey(sub_key);
1086 }
1087 }
1088
1089 name_len = sizeof(name);
1090 index++;
1091 }
1092
1093 return found_vmware;
1094}
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4027
LONG WINAPI RegEnumKeyExA(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2442
r parent
Definition: btrfs.c:3010
unsigned long DWORD
Definition: ntddk_ex.h:95
const GLubyte * c
Definition: glext.h:8905
GLuint index
Definition: glext.h:6031
#define c
Definition: ke_i.h:80
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define test
Definition: rosglue.h:37
Definition: name.c:39
unsigned char * LPBYTE
Definition: typedefs.h:53

Referenced by on_vmware(), and scan_subkeys().

◆ spurious_message()

static BOOL spurious_message ( LPMSG  msg)
static

Definition at line 42 of file midi.c.

43{
44 /* WM_DEVICECHANGE 0x0219 appears randomly */
45 if(msg->message == WM_DEVICECHANGE) {
46 trace("skipping spurious message %04x\n", msg->message);
47 return TRUE;
48 }
49 return FALSE;
50}
#define msg(x)
Definition: auth_time.c:54
#define TRUE
Definition: types.h:120
#define WM_DEVICECHANGE
Definition: winuser.h:1801

Referenced by test_notification_dbg().

◆ START_TEST()

START_TEST ( midi  )

Definition at line 1172 of file midi.c.

1173{
1174 HWND hwnd = 0;
1175
1176 CoInitialize(NULL); /* Needed for Win 10 */
1177
1178 if (1) /* select 1 for CALLBACK_WINDOW or 0 for CALLBACK_FUNCTION */
1179 hwnd = CreateWindowExA(0, "static", "winmm midi test", WS_POPUP, 0,0,100,100,
1180 0, 0, 0, NULL);
1183 if (hwnd) DestroyWindow(hwnd);
1184
1186}
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
static void test_midi_outfns(HWND hwnd)
Definition: midi.c:1119
static void test_midi_infns(HWND hwnd)
Definition: midi.c:213
#define WS_POPUP
Definition: pedump.c:616
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
HWND WINAPI CreateWindowExA(_In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
BOOL WINAPI DestroyWindow(_In_ HWND)

◆ test_midi_infns()

static void test_midi_infns ( HWND  hwnd)
static

Definition at line 213 of file midi.c.

214{
215 HMIDIIN hm;
216 MMRESULT rc;
217 UINT udev, ndevs = midiInGetNumDevs();
218
219 rc = midiInOpen(&hm, ndevs, 0, 0, CALLBACK_NULL);
220 ok(rc==MMSYSERR_BADDEVICEID, "midiInOpen udev>max rc=%s\n", mmsys_error(rc));
221 if (!rc) {
222 rc = midiInClose(hm);
223 ok(!rc, "midiInClose rc=%s\n", mmsys_error(rc));
224 }
225 if (!ndevs) {
226 trace("Found no MIDI IN device\n"); /* no skip for this common situation */
227 rc = midiInOpen(&hm, MIDIMAPPER, 0, 0, CALLBACK_NULL);
228 ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/), "midiInOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc));
229 if (!rc) {
230 rc = midiInClose(hm);
231 ok(!rc, "midiInClose rc=%s\n", mmsys_error(rc));
232 }
233 return;
234 }
235 trace("Found %d MIDI IN devices\n", ndevs);
236 for (udev=0; udev < ndevs; udev++) {
237 trace("** Testing device %d\n", udev);
239 Sleep(50);
240 }
241 trace("** Testing MIDI mapper\n");
243}
#define broken(x)
Definition: _sntprintf.h:21
#define ok(value,...)
Definition: atltest.h:57
#define MIDIMAPPER
Definition: mmsystem.h:252
#define CALLBACK_NULL
Definition: mmsystem.h:147
const char * mmsys_error(MMRESULT error)
Definition: wave.c:220
static void test_midiIn_device(UINT udev, HWND hwnd)
Definition: midi.c:110
unsigned int UINT
Definition: ndis.h:50
UINT WINAPI midiInGetNumDevs(void)
Definition: winmm.c:1187
MMRESULT WINAPI midiInOpen(HMIDIIN *lphMidiIn, UINT uDeviceID, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
Definition: winmm.c:1237
UINT WINAPI midiInClose(HMIDIIN hMidiIn)
Definition: winmm.c:1279

Referenced by START_TEST().

◆ test_midi_mci()

static void test_midi_mci ( HWND  hwnd)
static

Definition at line 246 of file midi.c.

247{
249 char buf[1024];
250 memset(buf, 0, sizeof(buf));
251
252 err = mciSendStringA("sysinfo sequencer quantity", buf, sizeof(buf), hwnd);
253 ok(!err, "mci sysinfo sequencer quantity returned %d\n", err);
254 if (!err) trace("Found %s MCI sequencer devices\n", buf);
255
256 if (!strcmp(buf, "0")) return;
257
258 err = mciSendStringA("capability sequencer can record", buf, sizeof(buf), hwnd);
259 ok(!err, "mci sysinfo sequencer quantity returned %d\n", err);
260 if(!err) ok(!strcmp(buf, "false"), "capability can record is %s\n", buf);
261}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
DWORD WINAPI mciSendStringA(LPCSTR lpstrCommand, LPSTR lpstrRet, UINT uRetLen, HWND hwndCallback)
Definition: mci.c:1586
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
DWORD MCIERROR
Definition: mmsystem.h:958
#define err(...)
#define memset(x, y, z)
Definition: compat.h:39

Referenced by test_midi_outfns().

◆ test_midi_outfns()

static void test_midi_outfns ( HWND  hwnd)
static

Definition at line 1119 of file midi.c.

1120{
1121 HMIDIOUT hm;
1122 MMRESULT rc;
1123 UINT udev, ndevs = midiOutGetNumDevs();
1124
1125 rc = midiOutOpen(&hm, ndevs, 0, 0, CALLBACK_NULL);
1126 ok(rc==MMSYSERR_BADDEVICEID, "midiOutOpen udev>max rc=%s\n", mmsys_error(rc));
1127 if (!rc) {
1128 rc = midiOutClose(hm);
1129 ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
1130 }
1131 if (!ndevs) {
1132 MIDIOUTCAPSA capsA;
1133 skip("Found no MIDI out device\n");
1134
1135 rc = midiOutGetDevCapsA(MIDIMAPPER, &capsA, sizeof(capsA));
1136 /* GetDevCaps and Open must return compatible results */
1137 ok(rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/), "midiOutGetDevCaps MAPPER with no MIDI rc=%s\n", mmsys_error(rc));
1138
1139 rc = midiOutOpen(&hm, MIDIMAPPER, 0, 0, CALLBACK_NULL);
1140 todo_wine_if (rc == MIDIERR_INVALIDSETUP) /* Wine without snd-seq */
1141 ok(rc == MMSYSERR_BADDEVICEID || broken(rc == MMSYSERR_NODRIVER /*w2k sound disabled*/),
1142 "midiOutOpen MAPPER with no MIDI rc=%s\n", mmsys_error(rc));
1143 if (!rc) {
1144 rc = midiOutClose(hm);
1145 ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
1146 }
1147 return;
1148 }
1149 trace("Found %d MIDI OUT devices\n", ndevs);
1150
1152
1153 for (udev=0; udev < ndevs; udev++) {
1154 MIDIOUTCAPSA capsA;
1155 rc = midiOutGetDevCapsA(udev, &capsA, sizeof(capsA));
1156 if (rc || strcmp(capsA.szPname, "Creative Sound Blaster MPU-401") != 0 || ! on_vmware()) {
1157 trace("** Testing device %d\n", udev);
1159 Sleep(800); /* Let the synth rest */
1160 test_midiStream(udev, hwnd);
1161 Sleep(800);
1162 }
1163 else
1164 win_skip("Skipping this device on VMware, driver problem\n");
1165 }
1166 trace("** Testing MIDI mapper\n");
1168 Sleep(800);
1170}
#define skip(...)
Definition: atltest.h:64
#define todo_wine_if(is_todo)
Definition: custom.c:76
static void test_midi_mci(HWND hwnd)
Definition: midi.c:246
static BOOL on_vmware(void)
Definition: midi.c:1103
static void test_midiStream(UINT udev, HWND hwnd)
Definition: midi.c:599
static void test_midiOut_device(UINT udev, HWND hwnd)
Definition: midi.c:275
#define win_skip
Definition: test.h:160
CHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1114
UINT WINAPI midiOutGetNumDevs(void)
Definition: winmm.c:809
UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
Definition: winmm.c:981
MMRESULT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
Definition: winmm.c:942
UINT WINAPI midiOutGetDevCapsA(UINT_PTR uDeviceID, LPMIDIOUTCAPSA lpCaps, UINT uSize)
Definition: winmm.c:835

Referenced by START_TEST().

◆ test_midiIn_device()

static void test_midiIn_device ( UINT  udev,
HWND  hwnd 
)
static

Definition at line 110 of file midi.c.

111{
112 HMIDIIN hm;
113 MMRESULT rc;
114 MIDIINCAPSA capsA;
115 MIDIHDR mhdr;
116
117 rc = midiInGetDevCapsA(udev, &capsA, sizeof(capsA));
118 ok((MIDIMAPPER==udev) ? (rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/)) : rc==0,
119 "midiInGetDevCaps(dev=%d) rc=%s\n", udev, mmsys_error(rc));
120 if (!rc) {
121 /* MIDI IN capsA.dwSupport may contain garbage, absent in old MS-Windows */
122 trace("* %s: manufacturer=%d, product=%d, support=%X\n", capsA.szPname, capsA.wMid, capsA.wPid, capsA.dwSupport);
123 }
124
125 if (hwnd)
127 else
129 ok((MIDIMAPPER!=udev) ? rc==0 : (rc==MMSYSERR_BADDEVICEID || broken(rc==MMSYSERR_NODRIVER /*nt,w2k*/)),
130 "midiInOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
131 if (rc) return;
132
133 test_notification(hwnd, "midiInOpen", MIM_OPEN, 0);
134
135 memset(&mhdr, 0, sizeof(mhdr));
136 mhdr.dwFlags = MHDR_DONE;
137 mhdr.dwUser = 0x56FA552C;
138 mhdr.dwBufferLength = 70000; /* > 64KB! */
139 mhdr.dwBytesRecorded = 5;
140 mhdr.lpData = HeapAlloc(GetProcessHeap(), 0 , mhdr.dwBufferLength);
141 ok(mhdr.lpData!=NULL, "No %d bytes of memory!\n", mhdr.dwBufferLength);
142 if (mhdr.lpData) {
143 rc = midiInPrepareHeader(hm, &mhdr, offsetof(MIDIHDR,dwOffset)-1);
144 ok(rc==MMSYSERR_INVALPARAM, "midiInPrepare tiny rc=%s\n", mmsys_error(rc));
145 ok(mhdr.dwFlags == MHDR_DONE, "dwFlags=%x\n", mhdr.dwFlags);
146
147 mhdr.dwFlags |= MHDR_INQUEUE;
149 ok(!rc, "midiInPrepare old size rc=%s\n", mmsys_error(rc));
150 ok(mhdr.dwFlags == (MHDR_PREPARED|MHDR_INQUEUE|MHDR_DONE)/*w9x*/ ||
151 mhdr.dwFlags == MHDR_PREPARED, "dwFlags=%x\n", mhdr.dwFlags);
152 trace("MIDIHDR flags=%x when unsent\n", mhdr.dwFlags);
153
155 rc = midiInPrepareHeader(hm, &mhdr, sizeof(mhdr));
156 ok(!rc, "midiInPrepare rc=%s\n", mmsys_error(rc));
157 ok(mhdr.dwFlags == (MHDR_PREPARED|MHDR_INQUEUE|MHDR_DONE), "dwFlags=%x\n", mhdr.dwFlags);
158
159 mhdr.dwFlags &= ~MHDR_INQUEUE;
160 rc = midiInUnprepareHeader(hm, &mhdr, sizeof(mhdr));
161 ok(!rc, "midiInUnprepare rc=%s\n", mmsys_error(rc));
162 ok(mhdr.dwFlags == MHDR_DONE, "dwFlags=%x\n", mhdr.dwFlags);
163
164 mhdr.dwFlags &= ~MHDR_DONE;
165 rc = midiInUnprepareHeader(hm, &mhdr, sizeof(mhdr));
166 ok(!rc, "midiInUnprepare rc=%s\n", mmsys_error(rc));
167 ok(mhdr.dwFlags == 0, "dwFlags=%x\n", mhdr.dwFlags);
168
170 ok(!rc, "midiInPrepare rc=%s\n", mmsys_error(rc));
171 ok(mhdr.dwFlags == MHDR_PREPARED, "dwFlags=%x\n", mhdr.dwFlags);
172
173 mhdr.dwFlags |= MHDR_DONE;
175 ok(!rc, "midiInPrepare rc=%s\n", mmsys_error(rc));
176 ok(mhdr.dwBytesRecorded == 5, "BytesRec=%u\n", mhdr.dwBytesRecorded);
177
178 mhdr.dwFlags |= MHDR_DONE;
179 rc = midiInAddBuffer(hm, &mhdr, sizeof(mhdr));
180 ok(!rc, "midiAddBuffer rc=%s\n", mmsys_error(rc));
181 ok(mhdr.dwFlags == (MHDR_PREPARED|MHDR_INQUEUE), "dwFlags=%x\n", mhdr.dwFlags);
182
183 /* w95 does not set dwBytesRecorded=0 within midiInAddBuffer. Wine does. */
184 if (mhdr.dwBytesRecorded != 0)
185 trace("dwBytesRecorded %u\n", mhdr.dwBytesRecorded);
186
187 rc = midiInAddBuffer(hm, &mhdr, sizeof(mhdr));
188 ok(rc==MIDIERR_STILLPLAYING, "midiAddBuffer rc=%s\n", mmsys_error(rc));
189
191 ok(!rc, "midiInPrepare rc=%s\n", mmsys_error(rc));
192 ok(mhdr.dwFlags == (MHDR_PREPARED|MHDR_INQUEUE), "dwFlags=%x\n", mhdr.dwFlags);
193 }
194 rc = midiInReset(hm); /* Return any pending buffer */
195 ok(!rc, "midiInReset rc=%s\n", mmsys_error(rc));
196 test_notification(hwnd, "midiInReset", MIM_LONGDATA, (DWORD_PTR)&mhdr);
197
198 ok(mhdr.dwFlags == (MHDR_PREPARED|MHDR_DONE), "dwFlags=%x\n", mhdr.dwFlags);
199 rc = midiInUnprepareHeader(hm, &mhdr, sizeof(mhdr));
200 ok(!rc, "midiInUnprepare rc=%s\n", mmsys_error(rc));
201
202 ok(mhdr.dwBytesRecorded == 0, "Did some MIDI HW send %u bytes?\n", mhdr.dwBytesRecorded);
203
204 rc = midiInClose(hm);
205 ok(!rc, "midiInClose rc=%s\n", mmsys_error(rc));
206
207 ok(mhdr.dwUser==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr.dwUser);
208 HeapFree(GetProcessHeap(), 0, mhdr.lpData);
209 test_notification(hwnd, "midiInClose", MIM_CLOSE, 0);
210 test_notification(hwnd, "midiIn over", 0, WHATEVER);
211}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK_WINDOW
Definition: mmsystem.h:148
#define MIM_OPEN
Definition: mmsystem.h:241
#define MIM_CLOSE
Definition: mmsystem.h:242
#define MHDR_PREPARED
Definition: mmsystem.h:269
#define CALLBACK_FUNCTION
Definition: mmsystem.h:150
#define MIM_LONGDATA
Definition: mmsystem.h:244
#define MYCBINST
Definition: midi.c:39
#define test_notification(hwnd, command, m1, p2)
Definition: midi.c:69
#define WHATEVER
Definition: midi.c:40
static void CALLBACK callback_func(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
Definition: midi.c:57
_In_ DWORD _In_ DWORD dwOffset
Definition: ntgdi.h:2033
#define offsetof(TYPE, MEMBER)
DWORD dwBufferLength
Definition: mmsystem.h:1152
DWORD dwBytesRecorded
Definition: mmsystem.h:1153
DWORD_PTR dwUser
Definition: mmsystem.h:1154
LPSTR lpData
Definition: mmsystem.h:1151
DWORD dwSupport
Definition: mmsystem.h:1139
CHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1138
uint32_t DWORD_PTR
Definition: typedefs.h:65
UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn, MIDIHDR *lpMidiInHdr, UINT uSize)
Definition: winmm.c:1316
UINT WINAPI midiInReset(HMIDIIN hMidiIn)
Definition: winmm.c:1385
UINT WINAPI midiInGetDevCapsA(UINT_PTR uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
Definition: winmm.c:1212
UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn, MIDIHDR *lpMidiInHdr, UINT uSize)
Definition: winmm.c:1339
UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn, MIDIHDR *lpMidiInHdr, UINT uSize)
Definition: winmm.c:1297

Referenced by test_midi_infns().

◆ test_midiOut_device()

static void test_midiOut_device ( UINT  udev,
HWND  hwnd 
)
static

Definition at line 275 of file midi.c.

276{
277 HMIDIOUT hm;
278 MMRESULT rc;
279 MIDIOUTCAPSA capsA;
280 DWORD ovolume;
281 UINT udevid;
282 MIDIHDR mhdr;
283
284 rc = midiOutGetDevCapsA(udev, &capsA, sizeof(capsA));
285 ok(!rc, "midiOutGetDevCaps(dev=%d) rc=%s\n", udev, mmsys_error(rc));
286 if (!rc) {
287 trace("* %s: manufacturer=%d, product=%d, tech=%d, support=%X: %d voices, %d notes\n",
288 capsA.szPname, capsA.wMid, capsA.wPid, capsA.wTechnology, capsA.dwSupport, capsA.wVoices, capsA.wNotes);
289 ok(!((MIDIMAPPER==udev) ^ (MOD_MAPPER==capsA.wTechnology)), "technology %d on device %d\n", capsA.wTechnology, udev);
290 if (MOD_MIDIPORT == capsA.wTechnology) {
291 ok(capsA.wVoices == 0 && capsA.wNotes == 0, "external device with notes or voices\n");
292 ok(capsA.wChannelMask == 0xFFFF, "external device channel mask %x\n", capsA.wChannelMask);
293 ok(!(capsA.dwSupport & (MIDICAPS_VOLUME|MIDICAPS_LRVOLUME|MIDICAPS_CACHE)), "external device support=%X\n", capsA.dwSupport);
294 }
295 }
296
297 if (hwnd)
299 else
301 if (rc == MMSYSERR_NOTSUPPORTED || rc == MMSYSERR_NODRIVER)
302 {
303 skip( "MIDI out not supported\n" );
304 return;
305 }
306 ok(!rc, "midiOutOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
307 if (rc) return;
308
309 test_notification(hwnd, "midiOutOpen", MOM_OPEN, 0);
310
311 rc = midiOutGetVolume(hm, &ovolume);
312 ok((capsA.dwSupport & MIDICAPS_VOLUME) ? rc==MMSYSERR_NOERROR : rc==MMSYSERR_NOTSUPPORTED, "midiOutGetVolume rc=%s\n", mmsys_error(rc));
313 /* The native mapper responds with FFFFFFFF initially,
314 * real devices with the volume GUI SW-synth settings. */
315 if (!rc) trace("Current volume %x on device %d\n", ovolume, udev);
316
317 /* The W95 ESFM Synthesis device reports NOTENABLED although
318 * GetVolume by handle works and music plays. */
319 rc = midiOutGetVolume(UlongToHandle(udev), &ovolume);
320 ok((capsA.dwSupport & MIDICAPS_VOLUME) ? rc==MMSYSERR_NOERROR || broken(rc==MMSYSERR_NOTENABLED) : rc==MMSYSERR_NOTSUPPORTED, "midiOutGetVolume(dev=%d) rc=%s\n", udev, mmsys_error(rc));
321
322 rc = midiOutGetVolume(hm, NULL);
323 ok(rc==MMSYSERR_INVALPARAM, "midiOutGetVolume NULL rc=%s\n", mmsys_error(rc));
324
325 /* Tests with midiOutSetvolume show that the midi mapper forwards
326 * the value to the real device, but Get initially always reports
327 * FFFFFFFF. Therefore, a Get+SetVolume pair with the mapper is
328 * not adequate to restore the value prior to tests.
329 */
331 DWORD volume2 = (ovolume < 0x80000000) ? 0xC000C000 : 0x40004000;
332 rc = midiOutSetVolume(hm, volume2);
333 ok(!rc, "midiOutSetVolume rc=%s\n", mmsys_error(rc));
334 if (!rc) {
335 DWORD volume3;
336 rc = midiOutGetVolume(hm, &volume3);
337 ok(!rc, "midiOutGetVolume new rc=%s\n", mmsys_error(rc));
338 if (!rc) trace("New volume %x on device %d\n", volume3, udev);
339 todo_wine ok(volume2==volume3, "volume Set %x = Get %x\n", volume2, volume3);
340
341 rc = midiOutSetVolume(hm, ovolume);
342 ok(!rc, "midiOutSetVolume restore rc=%s\n", mmsys_error(rc));
343 }
344 }
345 rc = midiOutGetDevCapsA((UINT_PTR)hm, &capsA, sizeof(capsA));
346 ok(!rc, "midiOutGetDevCaps(dev=%d) by handle rc=%s\n", udev, mmsys_error(rc));
347 rc = midiInGetDevCapsA((UINT_PTR)hm, (LPMIDIINCAPSA)&capsA, sizeof(DWORD));
348 ok(rc==MMSYSERR_BADDEVICEID, "midiInGetDevCaps(dev=%d) by out handle rc=%s\n", udev, mmsys_error(rc));
349
350 { DWORD e = 0x006F4893; /* velocity, note (#69 would be 440Hz) channel */
351 trace("ShortMsg type %x\n", LOBYTE(LOWORD(e)));
352 rc = midiOutShortMsg(hm, e);
353 ok(!rc, "midiOutShortMsg rc=%s\n", mmsys_error(rc));
354 if (!rc) Sleep(400); /* Hear note */
355 }
356
357 memset(&mhdr, 0, sizeof(mhdr));
358 mhdr.dwFlags = MHDR_DONE;
359 mhdr.dwUser = 0x56FA552C;
360 mhdr.dwOffset = 0xDEADBEEF;
361 mhdr.dwBufferLength = 70000; /* > 64KB! */
362 mhdr.lpData = HeapAlloc(GetProcessHeap(), 0 , mhdr.dwBufferLength);
363 ok(mhdr.lpData!=NULL, "No %d bytes of memory!\n", mhdr.dwBufferLength);
364 if (mhdr.lpData) {
365 rc = midiOutLongMsg(hm, &mhdr, sizeof(mhdr));
366 ok(rc==MIDIERR_UNPREPARED, "midiOutLongMsg unprepared rc=%s\n", mmsys_error(rc));
367 ok(mhdr.dwFlags == MHDR_DONE, "dwFlags=%x\n", mhdr.dwFlags);
368 test_notification(hwnd, "midiOutLong unprepared", 0, WHATEVER);
369
370 rc = midiOutPrepareHeader(hm, &mhdr, offsetof(MIDIHDR,dwOffset)-1);
371 ok(rc==MMSYSERR_INVALPARAM, "midiOutPrepare tiny rc=%s\n", mmsys_error(rc));
372 ok(mhdr.dwFlags == MHDR_DONE, "dwFlags=%x\n", mhdr.dwFlags);
373
374 /* Since at least w2k, midiOutPrepare clears the DONE and INQUEUE flags. w95 didn't. */
375 /* mhdr.dwFlags |= MHDR_INQUEUE; would cause w95 to return STILLPLAYING from Unprepare */
377 ok(!rc, "midiOutPrepare old size rc=%s\n", mmsys_error(rc));
378 ok(mhdr.dwFlags == (MHDR_PREPARED|MHDR_DONE)/*w9x*/ ||
379 mhdr.dwFlags == MHDR_PREPARED, "dwFlags=%x\n", mhdr.dwFlags);
380 trace("MIDIHDR flags=%x when unsent\n", mhdr.dwFlags);
381
382 /* No flag is cleared when already prepared. */
384 rc = midiOutPrepareHeader(hm, &mhdr, sizeof(mhdr));
385 ok(!rc, "midiOutPrepare rc=%s\n", mmsys_error(rc));
386 ok(mhdr.dwFlags == (MHDR_PREPARED|MHDR_DONE|MHDR_INQUEUE), "dwFlags=%x\n", mhdr.dwFlags);
387
388 mhdr.dwFlags |= MHDR_INQUEUE;
389 rc = midiOutUnprepareHeader(hm, &mhdr, sizeof(mhdr));
390 ok(rc==MIDIERR_STILLPLAYING, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
391 ok(mhdr.dwFlags == (MHDR_PREPARED|MHDR_DONE|MHDR_INQUEUE), "dwFlags=%x\n", mhdr.dwFlags);
392
393 mhdr.dwFlags &= ~MHDR_INQUEUE;
394 rc = midiOutUnprepareHeader(hm, &mhdr, sizeof(mhdr));
395 ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
396 ok(mhdr.dwFlags == MHDR_DONE, "dwFlags=%x\n", mhdr.dwFlags);
397
398 mhdr.dwFlags |= MHDR_INQUEUE;
399 rc = midiOutUnprepareHeader(hm, &mhdr, sizeof(mhdr));
400 ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
401 ok(mhdr.dwFlags == (MHDR_INQUEUE|MHDR_DONE), "dwFlags=%x\n", mhdr.dwFlags);
402
403 HeapFree(GetProcessHeap(), 0, mhdr.lpData);
404 }
405 ok(mhdr.dwUser==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr.dwUser);
406 ok(mhdr.dwOffset==0xDEADBEEF, "MIDIHDR.dwOffset changed to %x\n", mhdr.dwOffset);
407
408 rc = midiOutGetID(hm, &udevid);
409 ok(!rc, "midiOutGetID rc=%s\n", mmsys_error(rc));
410 if(!rc) ok(udevid==udev, "midiOutGetID gives %d, expect %d\n", udevid, udev);
411
412 rc = midiOutReset(hm); /* Quiet everything */
413 ok(!rc, "midiOutReset rc=%s\n", mmsys_error(rc));
414
415 rc = midiOutClose(hm);
416 ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
417 test_notification(hwnd, "midiOutClose", MOM_CLOSE, 0);
418
419 rc = midiOutOpen(&hm, udev, 0, (DWORD_PTR)MYCBINST, CALLBACK_WINDOW);
420 /* w95 broken(rc==MMSYSERR_INVALPARAM) see WINMM_CheckCallback */
421 ok(!rc, "midiOutOpen(dev=%d) 0 CALLBACK_WINDOW rc=%s\n", udev, mmsys_error(rc));
422 /* PostMessage(hwnd=0) redirects to PostThreadMessage(GetCurrentThreadId())
423 * which PeekMessage((HWND)-1) queries. */
424 test_notification((HWND)-1, "midiOutOpen WINDOW->THREAD", 0, WHATEVER);
425 test_notification(hwnd, "midiOutOpen WINDOW", 0, WHATEVER);
426 if (!rc) {
427 rc = midiOutClose(hm);
428 ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
429 test_notification((HWND)-1, "midiOutClose WINDOW->THREAD", 0, WHATEVER);
430 test_notification(hwnd, "midiOutClose", 0, WHATEVER);
431 }
432 test_notification(hwnd, "midiOut over", 0, WHATEVER);
434 (udev == MIDIMAPPER && found_fluidsynth)) {
436 skip("FluidSynth (at least 1.1.6) doesn't support desired System Exclusive message.\n");
437 return;
438 }
439
440 if (hwnd)
442 else
444 ok(!rc, "midiOutOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
445 test_notification(hwnd, "midiOutOpen", MOM_OPEN, 0);
446
447 memset(&mhdr, 0, sizeof(mhdr));
448 mhdr.lpData = (LPSTR)SysEx_reset;
449 mhdr.dwBufferLength = sizeof(SysEx_reset);
450 rc = midiOutPrepareHeader(hm, &mhdr, sizeof(mhdr));
451 ok(!rc, "midiOutPrepareHeader rc=%s\n", mmsys_error(rc));
452 rc = midiOutLongMsg(hm, &mhdr, sizeof(mhdr));
453 ok(!rc, "midiOutLongMsg rc=%s\n", mmsys_error(rc));
454 rc = midiOutUnprepareHeader(hm, &mhdr, sizeof(mhdr));
455 ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
456 test_notification(hwnd, "midiOutLongMsg", MOM_DONE, (DWORD_PTR)&mhdr);
457 Sleep(60);
458
460 mhdr.dwBufferLength = sizeof(SysEx_volume_off);
461 rc = midiOutPrepareHeader(hm, &mhdr, sizeof(mhdr));
462 ok(!rc, "midiOutPrepareHeader rc=%s\n", mmsys_error(rc));
463 rc = midiOutLongMsg(hm, &mhdr, sizeof(mhdr));
464 ok(!rc, "midiOutLongMsg rc=%s\n", mmsys_error(rc));
465 rc = midiOutUnprepareHeader(hm, &mhdr, sizeof(mhdr));
466 ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
467 test_notification(hwnd, "midiOutLongMsg", MOM_DONE, (DWORD_PTR)&mhdr);
468
469 {
470 DWORD e = 0x006F4593; /* velocity 111, note #69, channel 4 */
471 trace("ShortMsg type %x (muted)\n", LOBYTE(LOWORD(e)));
472 rc = midiOutShortMsg(hm, e);
473 ok(!rc, "midiOutShortMsg rc=%s\n", mmsys_error(rc));
474 /* We can't hear this voice due to volume settings */
475 if (!rc) Sleep(200);
476
477 rc = midiOutShortMsg(hm, 0x00004593); /* velocity 0 */
478 ok(!rc, "midiOutShortMsg rc=%s\n", mmsys_error(rc));
479 }
480
482 mhdr.dwBufferLength = sizeof(SysEx_volume_full);
483 rc = midiOutPrepareHeader(hm, &mhdr, sizeof(mhdr));
484 ok(!rc, "midiOutPrepareHeader rc=%s\n", mmsys_error(rc));
485 rc = midiOutLongMsg(hm, &mhdr, sizeof(mhdr));
486 ok(!rc, "midiOutLongMsg rc=%s\n", mmsys_error(rc));
487 rc = midiOutUnprepareHeader(hm, &mhdr, sizeof(mhdr));
488 ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
489 test_notification(hwnd, "midiOutLongMsg", MOM_DONE, (DWORD_PTR)&mhdr);
490
491 rc = midiOutClose(hm);
492 ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
493 test_notification(hwnd, "midiOuClose", MOM_CLOSE, 0);
494}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define UlongToHandle(ul)
Definition: basetsd.h:97
#define LOBYTE(W)
Definition: jmemdos.c:487
#define e
Definition: ke_i.h:82
#define MIDICAPS_LRVOLUME
Definition: mmsystem.h:265
#define MIDICAPS_VOLUME
Definition: mmsystem.h:264
#define MOM_DONE
Definition: mmsystem.h:249
#define MOM_CLOSE
Definition: mmsystem.h:248
#define MOM_OPEN
Definition: mmsystem.h:247
#define MOD_MAPPER
Definition: mmsystem.h:263
#define MIDICAPS_CACHE
Definition: mmsystem.h:266
#define MOD_MIDIPORT
Definition: mmsystem.h:259
#define todo_wine
Definition: custom.c:79
static const char fluidsynth_prefix[]
Definition: midi.c:273
static BYTE SysEx_volume_full[]
Definition: midi.c:269
static BOOL found_fluidsynth
Definition: midi.c:272
static BYTE SysEx_reset[]
Definition: midi.c:263
static BYTE SysEx_volume_off[]
Definition: midi.c:266
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
#define LOWORD(l)
Definition: pedump.c:82
int winetest_interactive
DWORD dwOffset
Definition: mmsystem.h:1158
UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
Definition: winmm.c:1073
UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut, MIDIHDR *lpMidiOutHdr, UINT uSize)
Definition: winmm.c:1057
UINT WINAPI midiOutSetVolume(HMIDIOUT hMidiOut, DWORD dwVolume)
Definition: winmm.c:1103
UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut, MIDIHDR *lpMidiOutHdr, UINT uSize)
Definition: winmm.c:1019
UINT WINAPI midiOutGetVolume(HMIDIOUT hMidiOut, DWORD *lpdwVolume)
Definition: winmm.c:1088
UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT *lpuDeviceID)
Definition: winmm.c:1139
UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
Definition: winmm.c:1042
UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut, MIDIHDR *lpMidiOutHdr, UINT uSize)
Definition: winmm.c:1000
char * LPSTR
Definition: xmlstorage.h:182

Referenced by test_midi_outfns().

◆ test_midiStream()

static void test_midiStream ( UINT  udev,
HWND  hwnd 
)
static

Definition at line 599 of file midi.c.

600{
601 HMIDISTRM hm;
602 MMRESULT rc, rc2;
603 MIDIHDR mhdr;
604 union {
605 MIDIPROPTEMPO tempo;
606 MIDIPROPTIMEDIV tdiv;
607 } midiprop;
608 DWORD diff, expected, ret;
609 const DWORD MARGIN = 50;
610 struct time_stamp_records records;
611 MIDIOUTCAPSA capsA;
612
613 if (hwnd)
615 else
617 if (rc == MMSYSERR_NOTSUPPORTED || rc == MMSYSERR_NODRIVER)
618 {
619 skip( "MIDI stream not supported\n" );
620 return;
621 }
622 ok(!rc, "midiStreamOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
623 if (rc) return;
624
625 test_notification(hwnd, "midiStreamOpen", MOM_OPEN, 0);
626
627 midiprop.tempo.cbStruct = sizeof(midiprop.tempo);
628 rc = midiStreamProperty(hm, (void*)&midiprop, MIDIPROP_GET|MIDIPROP_TEMPO);
629 ok(!rc, "midiStreamProperty TEMPO rc=%s\n", mmsys_error(rc));
630 ok(midiprop.tempo.dwTempo==500000, "default stream tempo %u microsec per quarter note\n", midiprop.tempo.dwTempo);
631
632 midiprop.tdiv.cbStruct = sizeof(midiprop.tdiv);
633 rc = midiStreamProperty(hm, (void*)&midiprop, MIDIPROP_GET|MIDIPROP_TIMEDIV);
634 ok(!rc, "midiStreamProperty TIMEDIV rc=%s\n", mmsys_error(rc));
635 ok(24==LOWORD(midiprop.tdiv.dwTimeDiv), "default stream time division %u\n", midiprop.tdiv.dwTimeDiv);
636
637 memset(&mhdr, 0, sizeof(mhdr));
638 mhdr.dwUser = 0x56FA552C;
639 mhdr.dwOffset = 1234567890;
640 mhdr.dwBufferLength = sizeof(strmEvents);
642 mhdr.lpData = (LPSTR)&strmEvents[0];
643 if (mhdr.lpData) {
644 rc = midiOutLongMsg((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
645 ok(rc==MIDIERR_UNPREPARED, "midiOutLongMsg unprepared rc=%s\n", mmsys_error(rc));
646 test_notification(hwnd, "midiOutLong unprepared", 0, WHATEVER);
647
648 rc = midiOutPrepareHeader((HMIDIOUT)hm, &mhdr, offsetof(MIDIHDR,dwOffset)-1);
649 ok(rc==MMSYSERR_INVALPARAM, "midiOutPrepare tiny rc=%s\n", mmsys_error(rc));
650 rc = midiOutPrepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
651 ok(!rc, "midiOutPrepare size rc=%s\n", mmsys_error(rc));
652 ok(mhdr.dwFlags & MHDR_PREPARED, "MHDR.dwFlags when prepared %x\n", mhdr.dwFlags);
653
654 /* The device is still in paused mode and should queue the message. */
655 rc = midiStreamOut(hm, &mhdr, offsetof(MIDIHDR,dwOffset));
656 ok(!rc, "midiStreamOut old size rc=%s\n", mmsys_error(rc));
657 rc2 = rc;
658 trace("MIDIHDR flags=%x when submitted\n", mhdr.dwFlags);
659 /* w9X/me does not set MHDR_ISSTRM when StreamOut exits,
660 * but it will be set on all systems after the job is finished. */
661
662 Sleep(90);
663 /* Wine <1.1.39 started playing immediately */
664 test_notification(hwnd, "midiStream still paused", 0, WHATEVER);
665
666 /* MSDN asks to use midiStreamRestart prior to midiStreamOut()
667 * because the starting state is 'pause', but some apps seem to
668 * work with the inverse order: queue everything, then play.
669 */
670
671 rc = midiStreamRestart(hm);
672 ok(!rc, "midiStreamRestart rc=%s\n", mmsys_error(rc));
673
674 if (!rc2) while(mhdr.dwFlags & MHDR_INQUEUE) {
675 trace("async MIDI still queued\n");
676 Sleep(100);
677 } /* Checking INQUEUE is not the recommended way to wait for the end of a job, but we're testing. */
678 /* MHDR_ISSTRM is not necessarily set when midiStreamOut returns
679 * rather than when the queue is eventually processed. */
680 ok(mhdr.dwFlags & MHDR_ISSTRM, "MHDR.dwFlags %x no ISSTRM when out of queue\n", mhdr.dwFlags);
681 if (!rc2) while(!(mhdr.dwFlags & MHDR_DONE)) {
682 /* Never to be seen except perhaps on multicore */
683 trace("async MIDI still not done\n");
684 Sleep(100);
685 }
686 ok(mhdr.dwFlags & MHDR_DONE, "MHDR.dwFlags %x not DONE when out of queue\n", mhdr.dwFlags);
687 test_notification(hwnd, "midiStream callback", MOM_POSITIONCB, (DWORD_PTR)&mhdr);
688 test_notification(hwnd, "midiStreamOut", MOM_DONE, (DWORD_PTR)&mhdr);
689
690 /* Native fills dwOffset regardless of the cbMidiHdr size argument to midiStreamOut */
691 ok(1234567890!=mhdr.dwOffset, "play left MIDIHDR.dwOffset at %u\n", mhdr.dwOffset);
692
693 rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
694 ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
695 rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
696 ok(!rc, "midiOutUnprepare #2 rc=%s\n", mmsys_error(rc));
697
698 trace("MIDIHDR stream flags=%x when finished\n", mhdr.dwFlags);
699 ok(mhdr.dwFlags & MHDR_DONE, "MHDR.dwFlags when done %x\n", mhdr.dwFlags);
700
707
708 Sleep(400); /* Hear note */
709
710 midiprop.tempo.cbStruct = sizeof(midiprop.tempo);
711 rc = midiStreamProperty(hm, (void*)&midiprop, MIDIPROP_GET|MIDIPROP_TEMPO);
712 ok(!rc, "midiStreamProperty TEMPO rc=%s\n", mmsys_error(rc));
713 ok(0x0493E0==midiprop.tempo.dwTempo, "stream set tempo %u\n", midiprop.tdiv.dwTimeDiv);
714
715 rc = midiStreamRestart(hm);
716 ok(!rc, "midiStreamRestart #2 rc=%s\n", mmsys_error(rc));
717
718 mhdr.dwFlags |= MHDR_ISSTRM;
719 /* Preset flags (e.g. MHDR_ISSTRM) do not disturb. */
720 rc = midiOutPrepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
721 ok(!rc, "midiOutPrepare used flags %x rc=%s\n", mhdr.dwFlags, mmsys_error(rc));
722 rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
723 ok(!rc, "midiOutUnprepare used flags %x rc=%s\n", mhdr.dwFlags, mmsys_error(rc));
724
725 rc = midiStreamRestart(hm);
726 ok(!rc, "midiStreamRestart #3 rc=%s\n", mmsys_error(rc));
727 }
728 ok(mhdr.dwUser==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr.dwUser);
729 ok(0==((MIDISHORTEVENT*)&strmEvents)[0].dwStreamID, "dwStreamID set to %x\n", ((LPMIDIEVENT)&strmEvents[0])->dwStreamID);
730
731 /* dwBytesRecorded controls how much is played, not dwBufferLength
732 * allowing to immediately forward packets from midiIn to midiOut */
733 mhdr.dwOffset = 1234123123;
734 mhdr.dwBufferLength = sizeof(strmNops);
735 trace("buffer: %u\n", mhdr.dwBufferLength);
736 mhdr.dwBytesRecorded = 0;
737 mhdr.lpData = (LPSTR)&strmNops[0];
740
741 rc = midiOutPrepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
742 ok(!rc, "midiOutPrepare rc=%s\n", mmsys_error(rc));
743
744 rc = playStream(hm, &mhdr);
745 ok(!rc, "midiStreamOut 0 bytes recorded rc=%s\n", mmsys_error(rc));
746
747 test_notification(hwnd, "midiStreamOut", MOM_DONE, (DWORD_PTR)&mhdr);
748 test_notification(hwnd, "0 bytes recorded", 0, WHATEVER);
749
750 /* FIXME: check dwOffset within callback
751 * instead of the unspecified value afterwards */
752 ok(1234123123==mhdr.dwOffset || broken(0==mhdr.dwOffset), "play 0 set MIDIHDR.dwOffset to %u\n", mhdr.dwOffset);
753 /* w2k and later only set dwOffset when processing MEVT_T_CALLBACK,
754 * while w9X/me/nt always sets it. Have Wine behave like w2k because the
755 * dwOffset slot does not exist in the small size MIDIHDR. */
756
757 mhdr.dwOffset = 1234123123;
758 mhdr.dwBytesRecorded = 1*sizeof(MIDISHORTEVENT);
759
760 rc = playStream(hm, &mhdr);
761 ok(!rc, "midiStreamOut 1 event out of 2 rc=%s\n", mmsys_error(rc));
762
763 test_notification(hwnd, "1 of 2 events", MOM_POSITIONCB, (DWORD_PTR)&mhdr);
764 test_notification(hwnd, "1 of 2 events", MOM_DONE, (DWORD_PTR)&mhdr);
765 test_notification(hwnd, "1 of 2 events", 0, WHATEVER);
766 ok(0==mhdr.dwOffset, "MIDIHDR.dwOffset 1/2 changed to %u\n", mhdr.dwOffset);
767
768 mhdr.dwOffset = 1234123123;
769 mhdr.dwBytesRecorded = 2*sizeof(MIDISHORTEVENT);
770
771 rc = playStream(hm, &mhdr);
772 ok(!rc, "midiStreamOut 1 event out of 2 rc=%s\n", mmsys_error(rc));
773
774 test_notification(hwnd, "2 of 2 events", MOM_POSITIONCB, (DWORD_PTR)&mhdr);
775 test_notification(hwnd, "2 of 2 events", MOM_POSITIONCB, (DWORD_PTR)&mhdr);
776 test_notification(hwnd, "2 of 2 events", MOM_DONE, (DWORD_PTR)&mhdr);
777 test_notification(hwnd, "2 of 2 events", 0, WHATEVER);
778 ok(sizeof(MIDISHORTEVENT)==mhdr.dwOffset, "MIDIHDR.dwOffset 2/2 changed to %u\n", mhdr.dwOffset);
779 ok(mhdr.dwBytesRecorded == 2*sizeof(MIDISHORTEVENT), "dwBytesRecorded changed to %u\n", mhdr.dwBytesRecorded);
780
781 strmNops[0].dwEvent &= ~MEVT_F_CALLBACK;
782 strmNops[1].dwEvent &= ~MEVT_F_CALLBACK;
783 mhdr.dwOffset = 1234123123;
784 rc = playStream(hm, &mhdr);
785 ok(!rc, "midiStreamOut 1 event out of 2 rc=%s\n", mmsys_error(rc));
786
787 test_notification(hwnd, "0 CB in 2 events", MOM_DONE, (DWORD_PTR)&mhdr);
788 test_notification(hwnd, "0 CB in 2 events", 0, WHATEVER);
789 /* w9X/me/nt set dwOffset to the position played last */
790 ok(1234123123==mhdr.dwOffset || broken(sizeof(MIDISHORTEVENT)==mhdr.dwOffset), "MIDIHDR.dwOffset nocb changed to %u\n", mhdr.dwOffset);
791
792 mhdr.dwBytesRecorded = mhdr.dwBufferLength-1;
793 rc = playStream(hm, &mhdr);
794 ok(rc==MMSYSERR_INVALPARAM,"midiStreamOut dwBytesRecorded modulo MIDIEVENT rc=%s\n", mmsys_error(rc));
795 if (!rc) {
796 test_notification(hwnd, "2 of 2 events", MOM_DONE, (DWORD_PTR)&mhdr);
797 }
798
799 mhdr.dwBytesRecorded = mhdr.dwBufferLength+1;
800 rc = playStream(hm, &mhdr);
801 ok(rc==MMSYSERR_INVALPARAM,"midiStreamOut dwBufferLength<dwBytesRecorded rc=%s\n", mmsys_error(rc));
802 test_notification(hwnd, "past MIDIHDR tests", 0, WHATEVER);
803
804 rc = midiStreamStop(hm);
805 ok(!rc, "midiStreamStop rc=%s\n", mmsys_error(rc));
806 ok(mhdr.dwUser==0x56FA552C, "MIDIHDR.dwUser changed to %lx\n", mhdr.dwUser);
807
808 rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
809 ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
810 ok(0==strmNops[0].dwStreamID, "dwStreamID[0] set to %x\n", strmNops[0].dwStreamID);
811 ok(0==strmNops[1].dwStreamID, "dwStreamID[1] set to %x\n", strmNops[1].dwStreamID);
812
813 mhdr.dwBufferLength = 70000; /* > 64KB! */
814 mhdr.lpData = HeapAlloc(GetProcessHeap(), 0 , mhdr.dwBufferLength);
815 ok(mhdr.lpData!=NULL, "No %d bytes of memory!\n", mhdr.dwBufferLength);
816 if (mhdr.lpData) {
817 mhdr.dwFlags = 0;
818 /* PrepareHeader detects the too large buffer is for a stream. */
819 rc = midiOutPrepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
820 todo_wine ok(rc==MMSYSERR_INVALPARAM, "midiOutPrepare stream too large rc=%s\n", mmsys_error(rc));
821
822 rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
823 ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
824
825 HeapFree(GetProcessHeap(), 0, mhdr.lpData);
826 }
827
828 rc = midiStreamClose(hm);
829 ok(!rc, "midiStreamClose rc=%s\n", mmsys_error(rc));
830 test_notification(hwnd, "midiStreamClose", MOM_CLOSE, 0);
831 test_notification(hwnd, "midiStream over", 0, WHATEVER);
832
833 rc = midiStreamOpen(&hm, &udev, 1, 0, (DWORD_PTR)MYCBINST, CALLBACK_FUNCTION);
834 ok(!rc /*w2k*/|| rc==MMSYSERR_INVALPARAM/*w98*/, "midiStreamOpen NULL function rc=%s\n", mmsys_error(rc));
835 if (!rc) {
836 trace("Device %d accepts NULL CALLBACK_FUNCTION\n", udev);
837 rc = midiStreamClose(hm);
838 ok(!rc, "midiStreamClose rc=%s\n", mmsys_error(rc));
839 }
840
841 rc = midiStreamOpen(&hm, &udev, 1, (DWORD_PTR)0xDEADBEEF, (DWORD_PTR)MYCBINST, CALLBACK_WINDOW);
842 ok(rc==MMSYSERR_INVALPARAM, "midiStreamOpen bad window rc=%s\n", mmsys_error(rc));
843 if (!rc) {
844 rc = midiStreamClose(hm);
845 ok(!rc, "midiStreamClose rc=%s\n", mmsys_error(rc));
846 }
847
848 /* Test the player time clock and positions */
849 memset(&records, 0, sizeof(records));
850 records.done = CreateEventA(NULL, FALSE, FALSE, NULL);
851 ok(records.done != NULL, "CreateEvent failed (dev=%d)\n", udev);
852
854 ok(!rc, "midiStreamOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
855
856 expected = 0;
857 ret = get_position(hm, TIME_MS);
858 ok(ret == expected, "expected %u, got %u\n", expected, ret);
859
860 memset(&mhdr, 0, sizeof(mhdr));
863 rc = midiOutPrepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
864 ok(!rc, "midiOutPrepareHeader(dev=%d) rc=%s\n", udev, mmsys_error(rc));
865
866 rc = midiStreamOut(hm, &mhdr, sizeof(mhdr));
867 ok(!rc, "midiStreamOut(dev=%d) rc=%s\n", udev, mmsys_error(rc));
868
869 ret = get_position(hm, TIME_MS);
870 ok(ret == expected, "expected %u, got %u\n", expected, ret);
871
872 rc = midiStreamRestart(hm);
873 ok(!rc, "midiStreamRestart(dev=%d) rc=%s\n", udev, mmsys_error(rc));
874 Sleep(50);
875
876 rc = midiStreamPause(hm);
877 ok(!rc, "midiStreamPause(dev=%d) rc=%s\n", udev, mmsys_error(rc));
878
879 expected = 50;
880 ret = get_position(hm, TIME_MS);
881 ok(ret >= expected && ret < expected + MARGIN, "expected %ums or greater, got %ums\n", expected, ret);
882 expected = ret;
883
884 Sleep(100);
885
886 ret = get_position(hm, TIME_MS);
887 ok(ret == expected, "expected %ums, got %ums\n", expected, ret);
888
889 rc = midiStreamRestart(hm);
890 ok(!rc, "midiStreamRestart(dev=%d) rc=%s\n", udev, mmsys_error(rc));
891
892 Sleep(1);
893 ret = get_position(hm, TIME_MS);
894 ok(ret > expected && ret < expected + MARGIN, "expected greater than %ums, got %ums\n", expected, ret);
895 expected = ret;
896
898 ok(ret > strmNopsWithDelta[0].dwDeltaTime && ret < strmNopsWithDelta[1].dwDeltaTime,
899 "TIME_TICKS position is continuous, got %u\n", ret);
900
901 /* shouldn't set time division property while playing */
902 midiprop.tdiv.cbStruct = sizeof(midiprop.tdiv);
903 midiprop.tdiv.dwTimeDiv = 24;
904 rc = midiStreamProperty(hm, (void*)&midiprop, MIDIPROP_SET | MIDIPROP_TIMEDIV);
905 ok(rc == MMSYSERR_INVALPARAM, "midiStreamProperty(SET|TIMEDIV, dev=%d) rc=%s\n", udev, mmsys_error(rc));
906
907 ret = WaitForSingleObject(records.done, INFINITE);
908 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed, got %d\n", ret);
909
910 rc = midiStreamPause(hm);
911 ok(!rc, "midiStreamPause(dev=%d) rc=%s\n", udev, mmsys_error(rc));
912
913 expected = 250; /* = 12 ticks in 120 BPM */
914 ret = get_position(hm, TIME_MS);
915 ok(ret >= expected - MARGIN && ret <= expected + MARGIN,
916 "expected greater than %ums, got %ums\n", expected, ret);
917 trace("after playing, got %ums\n", ret);
918
919 /* set tempo to 240 BPM */
920 midiprop.tempo.cbStruct = sizeof(midiprop.tempo);
921 midiprop.tempo.dwTempo = 250000;
922 rc = midiStreamProperty(hm, (void*)&midiprop, MIDIPROP_SET | MIDIPROP_TEMPO);
923 ok(!rc, "midiStreamProperty(SET|TEMPO, dev=%d) rc=%s\n", udev, mmsys_error(rc));
924
925 /* a tempo change doesn't affect elapsed ticks */
927 ok(ret >= strmNopsWithDelta[1].dwDeltaTime && ret < strmNopsWithDelta[1].dwDeltaTime + 3,
928 "expected %u ticks, got %u\n", strmNopsWithDelta[1].dwDeltaTime, ret);
929
930 midiprop.tdiv.cbStruct = sizeof(midiprop.tdiv);
931 rc = midiStreamProperty(hm, (void*)&midiprop, MIDIPROP_GET | MIDIPROP_TIMEDIV);
932 ok(!rc, "midiStreamProperty(GET|TIMEDIV, dev=%d) rc=%s\n", udev, mmsys_error(rc));
933 ok(midiprop.tdiv.dwTimeDiv == 24, "expected 24, got %u\n", midiprop.tdiv.dwTimeDiv);
934
935 /* TIME_MIDI value is a quarter of TIME_TICKS, rounded */
936 expected = (ret + midiprop.tdiv.dwTimeDiv/8) / (midiprop.tdiv.dwTimeDiv/4);
938 ok(ret == expected, "expected song pointer %u, got %u\n", expected, ret);
939
940 ok(records.count == 2, "expected 2 MM_MOM_DONE messages, got %d\n", records.count);
941
942 /* Time between midiStreamPause and midiStreamRestart isn't counted.
943 So, the second event happens at dwDeltaTime(250ms) + 100ms after the first event. */
944 expected = 250 + 100;
945 diff = records.time_stamp[1] - records.time_stamp[0];
946 ok(diff >= expected - MARGIN && diff <= expected + MARGIN,
947 "expected %u ~ %ums, got %ums (dev=%d)\n", expected - MARGIN, expected + MARGIN, diff, udev);
948
949 rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
950 ok(!rc, "midiOutUnprepareHeader(dev=%d) rc=%s\n", udev, mmsys_error(rc));
951
952 rc = midiStreamStop(hm);
953 ok(!rc, "midiStreamStop(dev=%d) rc=%s\n", udev, mmsys_error(rc));
954
955 ret = get_position(hm, TIME_MS);
956 ok(ret == 0, "expected 0ms, got %ums\n", ret);
957
958 midiprop.tdiv.cbStruct = sizeof(midiprop.tdiv);
959 midiprop.tdiv.dwTimeDiv = 0xe204; /* 30 fps, 4 ticks/frame */
960 rc = midiStreamProperty(hm, (void*)&midiprop, MIDIPROP_SET | MIDIPROP_TIMEDIV);
961 ok(!rc, "midiStreamProperty(SET|TIMEDIV, dev=%d) rc=%s\n", udev, mmsys_error(rc));
962
969
970 rc = midiStreamClose(hm);
971 ok(!rc, "midiStreamClose(dev=%d) rc=%s\n", udev, mmsys_error(rc));
972 CloseHandle(records.done);
973
974 rc = midiOutGetDevCapsA((UINT_PTR)udev, &capsA, sizeof(capsA));
975 ok(!rc, "midiOutGetDevCaps(dev=%d) rc=%s\n", udev, mmsys_error(rc));
976 if (!strncmp(capsA.szPname, fluidsynth_prefix, strlen(fluidsynth_prefix)) ||
977 (udev == MIDIMAPPER && found_fluidsynth)) {
979 skip("FluidSynth (at least 1.1.6) doesn't support desired System Exclusive message.\n");
980 return;
981 }
982
983#define ROUNDUP4(n) (((n) + 3) & ~3)
984 hm = NULL;
985 if (hwnd)
987 else
989 ok(!rc, "midiOutOpen(dev=%d) rc=%s\n", udev, mmsys_error(rc));
990 test_notification(hwnd, "midiStreamOpen", MOM_OPEN, 0);
991
992 midiprop.tdiv.cbStruct = sizeof(midiprop.tdiv);
993 midiprop.tdiv.dwTimeDiv = 480;
995 ok(!rc, "midiStreamProperty(TimeDiv) rc=%s\n", mmsys_error(rc));
996
997 rc = midiStreamRestart(hm);
998 ok(!rc, "midiStreamRestart rc=%s\n", mmsys_error(rc));
999
1000 memset(&mhdr, 0, sizeof(mhdr));
1001 mhdr.dwBufferLength = sizeof(MIDISHORTEVENT) * 5 + ROUNDUP4(sizeof(SysEx_reset)) +
1004 ok(mhdr.lpData!=NULL, "No %d bytes of memory!\n", mhdr.dwBufferLength);
1005 if (mhdr.lpData) {
1006 MIDIEVENT *e;
1007 char *p = mhdr.lpData;
1008 /* GM System ON */
1009 e = (MIDIEVENT *)p;
1010 e->dwEvent = MEVT_F_LONG | sizeof(SysEx_reset);
1011 memcpy(&e->dwParms[0], SysEx_reset, sizeof(SysEx_reset));
1012 p += sizeof(MIDISHORTEVENT) + ROUNDUP4(sizeof(SysEx_reset));
1013 /* Master volume: off */
1014 e = (MIDIEVENT *)p;
1015 e->dwDeltaTime = 96;
1016 e->dwEvent = MEVT_F_LONG | sizeof(SysEx_volume_off);
1017 memcpy(&e->dwParms[0], SysEx_volume_off, sizeof(SysEx_volume_off));
1018 p += sizeof(MIDISHORTEVENT) + ROUNDUP4(sizeof(SysEx_volume_off));
1019 /* Note On (We can't hear this voice due to volume settings) */
1020 e = (MIDIEVENT *)p;
1021 e->dwEvent = MEVT_F_SHORT | 0x6F4593; /* note #69 */
1022 p += sizeof(MIDISHORTEVENT);
1023 /* Note Off */
1024 e = (MIDIEVENT *)p;
1025 e->dwDeltaTime = 240;
1026 e->dwEvent = MEVT_F_SHORT | 0x004593; /* velocity 0 */
1027 p += sizeof(MIDISHORTEVENT);
1028 /* Master volume: full */
1029 e = (MIDIEVENT *)p;
1030 e->dwEvent = MEVT_F_LONG | sizeof(SysEx_volume_full);
1031 memcpy(&e->dwParms[0], SysEx_volume_full, sizeof(SysEx_volume_full));
1032 p += sizeof(MIDISHORTEVENT) + ROUNDUP4(sizeof(SysEx_volume_full));
1033 mhdr.dwBytesRecorded = (DWORD)(p - mhdr.lpData);
1034#undef ROUNDUP4
1035
1036 rc = midiOutPrepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
1037 ok(!rc, "midiOutPrepareHeader rc=%s\n", mmsys_error(rc));
1038
1039 rc = playStream(hm, &mhdr);
1040 ok(!rc, "midiStreamOut rc=%s\n", mmsys_error(rc));
1041 test_notification(hwnd, "midiStreamOut", MOM_DONE, (DWORD_PTR)&mhdr);
1042
1043 rc = midiOutUnprepareHeader((HMIDIOUT)hm, &mhdr, sizeof(mhdr));
1044 ok(!rc, "midiOutUnprepare rc=%s\n", mmsys_error(rc));
1045
1046 HeapFree(GetProcessHeap(), 0, mhdr.lpData);
1047 }
1048 rc = midiStreamClose(hm);
1049 ok(!rc, "midiOutClose rc=%s\n", mmsys_error(rc));
1050 test_notification(hwnd, "midiStreamClose", MOM_CLOSE, 0);
1051}
static const WCHAR rc2[]
Definition: oid.c:1216
#define CloseHandle
Definition: compat.h:739
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define INFINITE
Definition: serial.h:102
GLfloat GLfloat p
Definition: glext.h:8902
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define TIME_BYTES
Definition: mmsystem.h:30
#define MIDIPROP_TEMPO
Definition: mmsystem.h:287
#define MIDIPROP_TIMEDIV
Definition: mmsystem.h:286
#define MEVT_F_SHORT
Definition: mmsystem.h:272
#define MEVT_F_LONG
Definition: mmsystem.h:273
#define MIDIPROP_GET
Definition: mmsystem.h:285
#define MEVT_F_CALLBACK
Definition: mmsystem.h:274
#define MIDIPROP_SET
Definition: mmsystem.h:284
#define TIME_SAMPLES
Definition: mmsystem.h:29
#define MHDR_ISSTRM
Definition: mmsystem.h:271
#define MOM_POSITIONCB
Definition: mmsystem.h:251
#define TIME_SMPTE
Definition: mmsystem.h:31
static void test_position(void)
Definition: trackbar.c:666
BOOL expected
Definition: store.c:2063
static DWORD get_position(HMIDISTRM hm, UINT type)
Definition: midi.c:569
#define ROUNDUP4(n)
static MIDISHORTEVENT strmNopsWithDelta[]
Definition: midi.c:543
static void CALLBACK time_stamp_callback(HMIDIOUT hmo, UINT msg, DWORD_PTR instance, DWORD_PTR p1, DWORD_PTR p2)
Definition: midi.c:554
static MIDISHORTEVENT strmNops[]
Definition: midi.c:538
static MMRESULT playStream(HMIDISTRM hm, LPMIDIHDR lpMidiHdr)
Definition: midi.c:590
struct midishortevent_tag MIDISHORTEVENT
static BYTE strmEvents[]
Definition: midi.c:529
#define DWORD
Definition: nt_native.h:44
DWORD dwEvent
Definition: midi.c:525
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
int ret
#define WAIT_OBJECT_0
Definition: winbase.h:406
MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
Definition: winmm.c:1962
MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
Definition: winmm.c:2007
MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
Definition: winmm.c:1778
MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
Definition: winmm.c:2038
MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
Definition: winmm.c:1907
MMRESULT WINAPI midiStreamOpen(HMIDISTRM *lphMidiStrm, LPUINT lpuDeviceID, DWORD cMidi, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen)
Definition: winmm.c:1798

Referenced by test_midi_outfns().

◆ test_notification_dbg()

static void test_notification_dbg ( HWND  hwnd,
const char command,
UINT  m1,
DWORD_PTR  p2,
int  line 
)
static

Definition at line 70 of file midi.c.

71{ /* Use message type 0 as meaning no message */
72 MSG msg;
73 if (hwnd) {
74 /* msg.wParam is hmidiout, msg.lParam is the mhdr (or 0) */
75 BOOL seen;
76 do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
77 while(seen && spurious_message(&msg));
78 if (m1 && !seen) {
79 /* We observe transient delayed notification, mostly on native.
80 * Perhaps the OS preempts the player thread after setting MHDR_DONE
81 * or clearing MHDR_INQUEUE, before calling DriverCallback. */
82 DWORD rc;
83 trace_(__FILE__,line)("Waiting for delayed message %x from %s\n", m1, command);
84 SetLastError(0xDEADBEEF);
86 ok_(__FILE__,line)(rc==WAIT_OBJECT_0, "Wait failed: %04x %d\n", rc, GetLastError());
87 seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE);
88 }
89 if (seen) {
90 trace_(__FILE__,line)("Message %x, wParam=%lx, lParam=%lx from %s\n",
91 msg.message, msg.wParam, msg.lParam, command);
92 ok_(__FILE__,line)(msg.hwnd==hwnd, "Didn't get the handle to our test window\n");
93 ok_(__FILE__,line)(msg.message==m1 && msg.lParam==p2, "bad message %x/%lx from %s, expect %x/%lx\n", msg.message, msg.lParam, command, m1, p2);
94 }
95 else ok_(__FILE__,line)(m1==0, "Expect message %x from %s\n", m1, command);
96 }
97 else {
98 /* FIXME: MOM_POSITIONCB and MOM_DONE are so close that a queue is needed. */
99 if (cbmsg) {
100 ok_(__FILE__,line)(cbmsg==m1 && cbval1==p2 && cbval2==0, "bad callback %x/%lx/%lx from %s, expect %x/%lx\n", cbmsg, cbval1, cbval2, command, m1, p2);
101 cbmsg = 0; /* Mark as read */
103 ok_(__FILE__,line)(cbinst==MYCBINST, "callback dwInstance changed to %lx\n", cbinst);
104 }
105 else ok_(__FILE__,line)(m1==0, "Expect callback %x from %s\n", m1, command);
106 }
107}
#define ok_(x1, x2)
Definition: atltest.h:61
#define SetLastError(x)
Definition: compat.h:752
#define trace_(file, line,...)
Definition: kmt_test.h:223
static BOOL spurious_message(LPMSG msg)
Definition: midi.c:42
Definition: parser.c:49
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
#define PM_REMOVE
Definition: winuser.h:1186
#define QS_POSTMESSAGE
Definition: winuser.h:871
BOOL WINAPI PeekMessageA(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)

◆ test_position()

static void test_position ( HMIDISTRM  hm,
UINT  typein,
UINT  typeout 
)
static

Definition at line 496 of file midi.c.

497{
498 MMRESULT rc;
499 MMTIME mmtime;
500 mmtime.wType = typein;
501 rc = midiStreamPosition(hm, &mmtime, sizeof(MMTIME));
502 /* Ugly, but a single ok() herein enables using the todo_wine prefix */
503 ok(!rc && (mmtime.wType == typeout), "midiStreamPosition type %x converted to %x rc=%s\n", typein, mmtime.wType, mmsys_error(rc));
504 if (!rc) switch(mmtime.wType) {
505 case TIME_MS:
506 trace("Stream position %ums\n", mmtime.u.ms);
507 break;
508 case TIME_TICKS:
509 trace("Stream position %u ticks\n", mmtime.u.ticks);
510 break;
511 case TIME_MIDI:
512 trace("Stream position song pointer %u\n", mmtime.u.midi.songptrpos);
513 break;
514 case TIME_SMPTE:
515 trace("Stream position %02u:%02u:%02u.%02u/%02u\n",
516 mmtime.u.smpte.hour, mmtime.u.smpte.min, mmtime.u.smpte.sec,
517 mmtime.u.smpte.frame, mmtime.u.smpte.fps);
518 break;
519 }
520}
struct mmtime_tag::@3013::@3014 smpte

◆ time_stamp_callback()

static void CALLBACK time_stamp_callback ( HMIDIOUT  hmo,
UINT  msg,
DWORD_PTR  instance,
DWORD_PTR  p1,
DWORD_PTR  p2 
)
static

Definition at line 554 of file midi.c.

555{
556 struct time_stamp_records *records = (struct time_stamp_records *)instance;
557 switch (msg) {
559 if (records->count < ARRAY_SIZE(records->time_stamp))
560 records->time_stamp[records->count] = GetTickCount();
561 records->count++;
562 break;
563 case MM_MOM_DONE:
564 SetEvent(records->done);
565 break;
566 }
567}
#define ARRAY_SIZE(a)
Definition: main.h:24
static HINSTANCE instance
Definition: main.c:40
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
#define MM_MOM_POSITIONCB
Definition: mmsystem.h:79
#define MM_MOM_DONE
Definition: mmsystem.h:70
HANDLE done
Definition: midi.c:551
DWORD time_stamp[2]
Definition: midi.c:550
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733

Referenced by test_midiStream().

Variable Documentation

◆ cbinst

DWORD_PTR cbinst = MYCBINST
static

Definition at line 55 of file midi.c.

Referenced by callback_func(), and test_notification_dbg().

◆ cbmsg

UINT cbmsg = 0
static

Definition at line 52 of file midi.c.

Referenced by callback_func(), and test_notification_dbg().

◆ cbval1

DWORD_PTR cbval1 = WHATEVER
static

Definition at line 53 of file midi.c.

Referenced by callback_func(), and test_notification_dbg().

◆ cbval2

DWORD_PTR cbval2 = 0
static

Definition at line 54 of file midi.c.

Referenced by callback_func(), and test_notification_dbg().

◆ fluidsynth_prefix

const char fluidsynth_prefix[] = "Synth input port "
static

Definition at line 273 of file midi.c.

Referenced by test_midiOut_device(), and test_midiStream().

◆ found_fluidsynth

BOOL found_fluidsynth
static

Definition at line 272 of file midi.c.

Referenced by test_midiOut_device(), and test_midiStream().

◆ strmEvents

BYTE strmEvents[]
static
Initial value:
= {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, MEVT_NOP | 0x40,
0, 0, 0, 0, 0, 0, 0, 0,
0xE0, 0x93, 0x04, MEVT_TEMPO,
0, 0, 0, 0, 0, 0, 0, 0,
0x93, 0x48, 0x6F, MEVT_SHORTMSG,
}
#define MEVT_SHORTMSG
Definition: mmsystem.h:277
#define MEVT_TEMPO
Definition: mmsystem.h:278
#define MEVT_NOP
Definition: mmsystem.h:279

Definition at line 529 of file midi.c.

Referenced by test_midiStream().

◆ strmNops

MIDISHORTEVENT strmNops[]
static
Initial value:
= {
{ 0, 0, (MEVT_NOP <<24)| MEVT_F_CALLBACK },
{ 0, 0, (MEVT_NOP <<24)| MEVT_F_CALLBACK },
}

Definition at line 538 of file midi.c.

Referenced by test_midiStream().

◆ strmNopsWithDelta

MIDISHORTEVENT strmNopsWithDelta[]
static
Initial value:
= {
{ 0, 0, (MEVT_NOP <<24)| MEVT_F_CALLBACK },
{ 12, 0, (MEVT_NOP <<24)| MEVT_F_CALLBACK },
}

Definition at line 543 of file midi.c.

Referenced by test_midiStream().

◆ SysEx_reset

BYTE SysEx_reset[]
static
Initial value:
= {
0xF0, 0x7E, 0x7F, 0x09, 0x01, 0xF7
}

Definition at line 263 of file midi.c.

Referenced by test_midiOut_device(), and test_midiStream().

◆ SysEx_volume_full

BYTE SysEx_volume_full[]
static
Initial value:
= {
0xF0, 0x7F, 0x7F, 0x04, 0x01, 0x00, 0x7F, 0xF7
}

Definition at line 269 of file midi.c.

Referenced by test_midiOut_device(), and test_midiStream().

◆ SysEx_volume_off

BYTE SysEx_volume_off[]
static
Initial value:
= {
0xF0, 0x7F, 0x7F, 0x04, 0x01, 0x00, 0x00, 0xF7
}

Definition at line 266 of file midi.c.

Referenced by test_midiOut_device(), and test_midiStream().