2002-10-10 05:43:53 +02:00
|
|
|
/* -*- tab-width: 8; c-basic-offset: 4 -*- */
|
|
|
|
|
|
|
|
/*
|
2002-10-29 23:02:00 +01:00
|
|
|
* WINMM functions
|
2002-10-10 05:43:53 +02:00
|
|
|
*
|
|
|
|
* Copyright 1993 Martin Ayotte
|
|
|
|
* 1998-2002 Eric Pouech
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-10-10 05:43:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Eric POUECH :
|
|
|
|
* 98/9 added Win32 MCI support
|
|
|
|
* 99/4 added midiStream support
|
|
|
|
* 99/9 added support for loadable low level drivers
|
|
|
|
*/
|
|
|
|
|
2004-10-11 21:57:10 +02:00
|
|
|
/* TODO
|
|
|
|
* + it seems that some programs check what's installed in
|
|
|
|
* registry against the value returned by drivers. Wine is
|
|
|
|
* currently broken regarding this point.
|
|
|
|
* + check thread-safeness for MMSYSTEM and WINMM entry points
|
|
|
|
* + unicode entry points are badly supported (would require
|
|
|
|
* moving 32 bit drivers as Unicode as they are supposed to be)
|
|
|
|
* + allow joystick and timer external calls as we do for wave,
|
|
|
|
* midi, mixer and aux
|
|
|
|
*/
|
|
|
|
|
2004-06-01 21:40:48 +02:00
|
|
|
#include <stdio.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-10-10 05:43:53 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
2015-03-31 21:05:54 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-10-10 05:43:53 +02:00
|
|
|
#include "winbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "mmsystem.h"
|
2003-07-02 02:40:14 +02:00
|
|
|
#include "winuser.h"
|
2003-09-15 22:13:30 +02:00
|
|
|
#include "winnls.h"
|
2002-10-10 05:43:53 +02:00
|
|
|
#include "winternl.h"
|
|
|
|
#include "winemm.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2019-11-13 14:51:23 +01:00
|
|
|
#include "wine/rbtree.h"
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winmm);
|
|
|
|
|
|
|
|
/* ========================================================================
|
|
|
|
* G L O B A L S E T T I N G S
|
|
|
|
* ========================================================================*/
|
|
|
|
|
2007-06-07 17:50:28 +02:00
|
|
|
HINSTANCE hWinMM32Instance;
|
|
|
|
HANDLE psLastEvent;
|
|
|
|
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &WINMM_cs,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": WINMM_cs") }
|
|
|
|
};
|
|
|
|
CRITICAL_SECTION WINMM_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2019-11-13 14:51:23 +01:00
|
|
|
static struct wine_rb_tree wine_midi_streams;
|
|
|
|
static int wine_midi_stream_compare(const void *key, const struct wine_rb_entry *entry);
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
/**************************************************************************
|
2002-10-29 22:49:35 +01:00
|
|
|
* WINMM_CreateIData [internal]
|
2002-10-10 05:43:53 +02:00
|
|
|
*/
|
2002-10-29 22:49:35 +01:00
|
|
|
static BOOL WINMM_CreateIData(HINSTANCE hInstDLL)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2007-06-07 17:50:28 +02:00
|
|
|
hWinMM32Instance = hInstDLL;
|
2019-11-13 14:51:23 +01:00
|
|
|
wine_rb_init(&wine_midi_streams, wine_midi_stream_compare);
|
2007-06-07 17:50:28 +02:00
|
|
|
psLastEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2016-12-01 14:32:34 +01:00
|
|
|
return psLastEvent != NULL;
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
2004-06-01 21:40:48 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WINMM_ErrorToString
|
|
|
|
*/
|
|
|
|
const char* WINMM_ErrorToString(MMRESULT error)
|
|
|
|
{
|
|
|
|
#define ERR_TO_STR(dev) case dev: return #dev
|
|
|
|
switch (error) {
|
|
|
|
ERR_TO_STR(MMSYSERR_NOERROR);
|
|
|
|
ERR_TO_STR(MMSYSERR_ERROR);
|
|
|
|
ERR_TO_STR(MMSYSERR_BADDEVICEID);
|
|
|
|
ERR_TO_STR(MMSYSERR_NOTENABLED);
|
|
|
|
ERR_TO_STR(MMSYSERR_ALLOCATED);
|
|
|
|
ERR_TO_STR(MMSYSERR_INVALHANDLE);
|
|
|
|
ERR_TO_STR(MMSYSERR_NODRIVER);
|
|
|
|
ERR_TO_STR(MMSYSERR_NOMEM);
|
|
|
|
ERR_TO_STR(MMSYSERR_NOTSUPPORTED);
|
|
|
|
ERR_TO_STR(MMSYSERR_BADERRNUM);
|
|
|
|
ERR_TO_STR(MMSYSERR_INVALFLAG);
|
|
|
|
ERR_TO_STR(MMSYSERR_INVALPARAM);
|
2004-11-21 16:37:04 +01:00
|
|
|
ERR_TO_STR(MMSYSERR_HANDLEBUSY);
|
|
|
|
ERR_TO_STR(MMSYSERR_INVALIDALIAS);
|
|
|
|
ERR_TO_STR(MMSYSERR_BADDB);
|
|
|
|
ERR_TO_STR(MMSYSERR_KEYNOTFOUND);
|
|
|
|
ERR_TO_STR(MMSYSERR_READERROR);
|
|
|
|
ERR_TO_STR(MMSYSERR_WRITEERROR);
|
|
|
|
ERR_TO_STR(MMSYSERR_DELETEERROR);
|
|
|
|
ERR_TO_STR(MMSYSERR_VALNOTFOUND);
|
|
|
|
ERR_TO_STR(MMSYSERR_NODRIVERCB);
|
2004-06-01 21:40:48 +02:00
|
|
|
ERR_TO_STR(WAVERR_BADFORMAT);
|
|
|
|
ERR_TO_STR(WAVERR_STILLPLAYING);
|
|
|
|
ERR_TO_STR(WAVERR_UNPREPARED);
|
|
|
|
ERR_TO_STR(WAVERR_SYNC);
|
2010-01-27 18:18:18 +01:00
|
|
|
ERR_TO_STR(MIDIERR_INVALIDSETUP);
|
|
|
|
ERR_TO_STR(MIDIERR_NODEVICE);
|
|
|
|
ERR_TO_STR(MIDIERR_STILLPLAYING);
|
|
|
|
ERR_TO_STR(MIDIERR_UNPREPARED);
|
2004-06-01 21:40:48 +02:00
|
|
|
}
|
|
|
|
#undef ERR_TO_STR
|
2009-11-30 10:22:08 +01:00
|
|
|
return wine_dbg_sprintf("Unknown(0x%08x)", error);
|
2004-06-01 21:40:48 +02:00
|
|
|
}
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
/**************************************************************************
|
2002-11-05 00:53:41 +01:00
|
|
|
* DllMain (WINMM.init)
|
2002-10-10 05:43:53 +02:00
|
|
|
*
|
|
|
|
* WINMM DLL entry point
|
|
|
|
*
|
|
|
|
*/
|
2002-11-05 00:53:41 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("%p 0x%x %p\n", hInstDLL, fdwReason, fImpLoad);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
switch (fdwReason) {
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2003-06-30 22:53:48 +02:00
|
|
|
DisableThreadLibraryCalls(hInstDLL);
|
|
|
|
|
2016-12-01 14:32:34 +01:00
|
|
|
if (!WINMM_CreateIData(hInstDLL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
2002-10-10 05:43:53 +02:00
|
|
|
case DLL_PROCESS_DETACH:
|
2012-05-10 21:17:34 +02:00
|
|
|
if(fImpLoad)
|
|
|
|
break;
|
|
|
|
|
2009-10-17 12:05:04 +02:00
|
|
|
MCI_SendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, MCI_WAIT, 0L);
|
2002-11-11 20:53:01 +01:00
|
|
|
MMDRV_Exit();
|
2012-05-10 21:17:34 +02:00
|
|
|
DRIVER_UnloadAll();
|
|
|
|
WINMM_DeleteWaveform();
|
|
|
|
TIME_MMTimeStop();
|
|
|
|
CloseHandle(psLastEvent);
|
|
|
|
DeleteCriticalSection(&WINMM_cs);
|
|
|
|
break;
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-03-15 23:00:04 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* WINMM_CheckCallback [internal]
|
|
|
|
*/
|
2011-06-23 20:12:11 +02:00
|
|
|
MMRESULT WINMM_CheckCallback(DWORD_PTR dwCallback, DWORD fdwOpen, BOOL mixer)
|
2011-03-15 23:00:04 +01:00
|
|
|
{
|
|
|
|
switch (fdwOpen & CALLBACK_TYPEMASK) {
|
|
|
|
case CALLBACK_NULL: /* dwCallback need not be NULL */
|
|
|
|
break;
|
|
|
|
case CALLBACK_WINDOW:
|
|
|
|
if (dwCallback && !IsWindow((HWND)dwCallback))
|
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CALLBACK_FUNCTION:
|
|
|
|
/* a NULL cb is acceptable since w2k, MMSYSERR_INVALPARAM earlier */
|
|
|
|
if (mixer)
|
|
|
|
return MMSYSERR_INVALFLAG; /* since w2k, MMSYSERR_NOTSUPPORTED earlier */
|
|
|
|
break;
|
|
|
|
case CALLBACK_THREAD:
|
|
|
|
case CALLBACK_EVENT:
|
|
|
|
if (mixer) /* FIXME: mixer supports THREAD+EVENT since w2k */
|
|
|
|
return MMSYSERR_NOTSUPPORTED; /* w9X */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("Unknown callback type %d\n", HIWORD(fdwOpen));
|
|
|
|
}
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* auxGetNumDevs [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI auxGetNumDevs(void)
|
|
|
|
{
|
|
|
|
return MMDRV_GetNum(MMDRV_AUX);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* auxGetDevCapsW [WINMM.@]
|
|
|
|
*/
|
2004-01-01 00:49:45 +01:00
|
|
|
UINT WINAPI auxGetDevCapsW(UINT_PTR uDeviceID, LPAUXCAPSW lpCaps, UINT uSize)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
LPWINE_MLD wmld;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2007-05-24 16:41:17 +02:00
|
|
|
TRACE("(%04lX, %p, %d) !\n", uDeviceID, lpCaps, uSize);
|
2004-07-21 05:10:24 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
|
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
|
2010-01-30 22:09:12 +01:00
|
|
|
return MMSYSERR_BADDEVICEID;
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, AUXDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* auxGetDevCapsA [WINMM.@]
|
|
|
|
*/
|
2004-01-01 00:49:45 +01:00
|
|
|
UINT WINAPI auxGetDevCapsA(UINT_PTR uDeviceID, LPAUXCAPSA lpCaps, UINT uSize)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
AUXCAPSW acW;
|
|
|
|
UINT ret;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
ret = auxGetDevCapsW(uDeviceID, &acW, sizeof(acW));
|
2003-10-31 00:07:23 +01:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
if (ret == MMSYSERR_NOERROR) {
|
|
|
|
AUXCAPSA acA;
|
|
|
|
acA.wMid = acW.wMid;
|
|
|
|
acA.wPid = acW.wPid;
|
|
|
|
acA.vDriverVersion = acW.vDriverVersion;
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, acW.szPname, -1, acA.szPname,
|
|
|
|
sizeof(acA.szPname), NULL, NULL );
|
|
|
|
acA.wTechnology = acW.wTechnology;
|
2015-11-24 20:02:36 +01:00
|
|
|
acA.wReserved1 = acW.wReserved1;
|
2004-12-06 21:55:25 +01:00
|
|
|
acA.dwSupport = acW.dwSupport;
|
|
|
|
memcpy(lpCaps, &acA, min(uSize, sizeof(acA)));
|
|
|
|
}
|
|
|
|
return ret;
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* auxGetVolume [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI auxGetVolume(UINT uDeviceID, DWORD* lpdwVolume)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
|
|
|
TRACE("(%04X, %p) !\n", uDeviceID, lpdwVolume);
|
|
|
|
|
2010-01-23 18:56:36 +01:00
|
|
|
if ((wmld = MMDRV_Get((HANDLE)(DWORD_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
|
2002-10-10 05:43:53 +02:00
|
|
|
return MMSYSERR_INVALHANDLE;
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, AUXDM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* auxSetVolume [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI auxSetVolume(UINT uDeviceID, DWORD dwVolume)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("(%04X, %u) !\n", uDeviceID, dwVolume);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2010-01-23 18:56:36 +01:00
|
|
|
if ((wmld = MMDRV_Get((HANDLE)(DWORD_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
|
2002-10-10 05:43:53 +02:00
|
|
|
return MMSYSERR_INVALHANDLE;
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, AUXDM_SETVOLUME, dwVolume, 0L);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* auxOutMessage [WINMM.@]
|
|
|
|
*/
|
2004-01-01 00:49:45 +01:00
|
|
|
UINT WINAPI auxOutMessage(UINT uDeviceID, UINT uMessage, DWORD_PTR dw1, DWORD_PTR dw2)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2010-01-23 18:56:36 +01:00
|
|
|
if ((wmld = MMDRV_Get((HANDLE)(DWORD_PTR)uDeviceID, MMDRV_AUX, TRUE)) == NULL)
|
2002-10-10 05:43:53 +02:00
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, uMessage, dw1, dw2);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutGetNumDevs [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutGetNumDevs(void)
|
|
|
|
{
|
|
|
|
return MMDRV_GetNum(MMDRV_MIDIOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutGetDevCapsW [WINMM.@]
|
|
|
|
*/
|
2004-01-01 00:49:45 +01:00
|
|
|
UINT WINAPI midiOutGetDevCapsW(UINT_PTR uDeviceID, LPMIDIOUTCAPSW lpCaps,
|
2002-10-10 05:43:53 +02:00
|
|
|
UINT uSize)
|
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
LPWINE_MLD wmld;
|
2004-07-21 05:10:24 +02:00
|
|
|
|
2007-05-24 16:41:17 +02:00
|
|
|
TRACE("(%lu, %p, %u);\n", uDeviceID, lpCaps, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
|
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIOUT, TRUE)) == NULL)
|
2010-01-30 22:09:12 +01:00
|
|
|
return MMSYSERR_BADDEVICEID;
|
2004-12-06 21:55:25 +01:00
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MODM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutGetDevCapsA [WINMM.@]
|
|
|
|
*/
|
2004-01-01 00:49:45 +01:00
|
|
|
UINT WINAPI midiOutGetDevCapsA(UINT_PTR uDeviceID, LPMIDIOUTCAPSA lpCaps,
|
2002-10-10 05:43:53 +02:00
|
|
|
UINT uSize)
|
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
MIDIOUTCAPSW mocW;
|
|
|
|
UINT ret;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
ret = midiOutGetDevCapsW(uDeviceID, &mocW, sizeof(mocW));
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
if (ret == MMSYSERR_NOERROR) {
|
|
|
|
MIDIOUTCAPSA mocA;
|
|
|
|
mocA.wMid = mocW.wMid;
|
|
|
|
mocA.wPid = mocW.wPid;
|
|
|
|
mocA.vDriverVersion = mocW.vDriverVersion;
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, mocW.szPname, -1, mocA.szPname,
|
|
|
|
sizeof(mocA.szPname), NULL, NULL );
|
|
|
|
mocA.wTechnology = mocW.wTechnology;
|
|
|
|
mocA.wVoices = mocW.wVoices;
|
|
|
|
mocA.wNotes = mocW.wNotes;
|
|
|
|
mocA.wChannelMask = mocW.wChannelMask;
|
|
|
|
mocA.dwSupport = mocW.dwSupport;
|
|
|
|
memcpy(lpCaps, &mocA, min(uSize, sizeof(mocA)));
|
|
|
|
}
|
|
|
|
return ret;
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2005-02-09 23:26:25 +01:00
|
|
|
* midiOutGetErrorTextA [WINMM.@]
|
|
|
|
* midiInGetErrorTextA [WINMM.@]
|
2002-10-10 05:43:53 +02:00
|
|
|
*/
|
2005-02-09 23:26:25 +01:00
|
|
|
UINT WINAPI midiOutGetErrorTextA(UINT uError, LPSTR lpText, UINT uSize)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2005-02-09 23:26:25 +01:00
|
|
|
UINT ret;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2005-02-09 23:26:25 +01:00
|
|
|
if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
|
|
|
|
else if (uSize == 0) ret = MMSYSERR_NOERROR;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWSTR xstr = HeapAlloc(GetProcessHeap(), 0, uSize * sizeof(WCHAR));
|
|
|
|
if (!xstr) ret = MMSYSERR_NOMEM;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = midiOutGetErrorTextW(uError, xstr, uSize);
|
|
|
|
if (ret == MMSYSERR_NOERROR)
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, xstr, -1, lpText, uSize, NULL, NULL);
|
|
|
|
HeapFree(GetProcessHeap(), 0, xstr);
|
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutGetErrorTextW [WINMM.@]
|
2005-02-09 23:26:25 +01:00
|
|
|
* midiInGetErrorTextW [WINMM.@]
|
2002-10-10 05:43:53 +02:00
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutGetErrorTextW(UINT uError, LPWSTR lpText, UINT uSize)
|
|
|
|
{
|
2005-02-09 23:26:25 +01:00
|
|
|
UINT ret = MMSYSERR_BADERRNUM;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2005-02-09 23:26:25 +01:00
|
|
|
if (lpText == NULL) ret = MMSYSERR_INVALPARAM;
|
|
|
|
else if (uSize == 0) ret = MMSYSERR_NOERROR;
|
|
|
|
else if (
|
2008-01-03 18:04:28 +01:00
|
|
|
/* test has been removed because MMSYSERR_BASE is 0, and gcc did emit
|
2005-02-09 23:26:25 +01:00
|
|
|
* a warning for the test was always true */
|
|
|
|
(/*uError >= MMSYSERR_BASE && */ uError <= MMSYSERR_LASTERROR) ||
|
|
|
|
(uError >= MIDIERR_BASE && uError <= MIDIERR_LASTERROR)) {
|
2007-06-07 17:50:28 +02:00
|
|
|
if (LoadStringW(hWinMM32Instance, uError, lpText, uSize) > 0) {
|
2005-02-09 23:26:25 +01:00
|
|
|
ret = MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_OutAlloc [internal]
|
|
|
|
*/
|
2006-11-08 22:24:36 +01:00
|
|
|
static LPWINE_MIDI MIDI_OutAlloc(HMIDIOUT* lphMidiOut, DWORD_PTR* lpdwCallback,
|
|
|
|
DWORD_PTR* lpdwInstance, LPDWORD lpdwFlags,
|
2009-10-22 22:10:32 +02:00
|
|
|
DWORD cIDs, MIDIOPENSTRMID* lpIDs)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2002-10-31 02:02:41 +01:00
|
|
|
HANDLE hMidiOut;
|
2002-10-10 05:43:53 +02:00
|
|
|
LPWINE_MIDI lpwm;
|
|
|
|
UINT size;
|
|
|
|
|
|
|
|
size = sizeof(WINE_MIDI) + (cIDs ? (cIDs-1) : 0) * sizeof(MIDIOPENSTRMID);
|
|
|
|
|
|
|
|
lpwm = (LPWINE_MIDI)MMDRV_Alloc(size, MMDRV_MIDIOUT, &hMidiOut, lpdwFlags,
|
2009-10-22 22:10:32 +02:00
|
|
|
lpdwCallback, lpdwInstance);
|
2010-01-27 18:18:18 +01:00
|
|
|
*lphMidiOut = hMidiOut;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (lpwm) {
|
2009-02-20 10:23:08 +01:00
|
|
|
lpwm->mod.hMidi = hMidiOut;
|
2002-10-10 05:43:53 +02:00
|
|
|
lpwm->mod.dwCallback = *lpdwCallback;
|
|
|
|
lpwm->mod.dwInstance = *lpdwInstance;
|
|
|
|
lpwm->mod.dnDevNode = 0;
|
|
|
|
lpwm->mod.cIds = cIDs;
|
|
|
|
if (cIDs)
|
|
|
|
memcpy(&(lpwm->mod.rgIds), lpIDs, cIDs * sizeof(MIDIOPENSTRMID));
|
|
|
|
}
|
|
|
|
return lpwm;
|
|
|
|
}
|
|
|
|
|
2009-10-22 22:10:05 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* midiOutOpen [WINMM.@]
|
|
|
|
*/
|
2017-02-12 13:58:55 +01:00
|
|
|
MMRESULT WINAPI midiOutOpen(LPHMIDIOUT lphMidiOut, UINT uDeviceID,
|
2009-10-22 22:10:05 +02:00
|
|
|
DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
HMIDIOUT hMidiOut;
|
|
|
|
LPWINE_MIDI lpwm;
|
2017-02-12 13:58:55 +01:00
|
|
|
MMRESULT dwRet;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
|
2002-10-10 05:43:53 +02:00
|
|
|
lphMidiOut, uDeviceID, dwCallback, dwInstance, dwFlags);
|
|
|
|
|
|
|
|
if (lphMidiOut != NULL) *lphMidiOut = 0;
|
|
|
|
|
2011-03-15 23:00:04 +01:00
|
|
|
dwRet = WINMM_CheckCallback(dwCallback, dwFlags, FALSE);
|
|
|
|
if (dwRet != MMSYSERR_NOERROR)
|
|
|
|
return dwRet;
|
2010-03-09 22:20:55 +01:00
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &dwFlags, 0, NULL);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (lpwm == NULL)
|
|
|
|
return MMSYSERR_NOMEM;
|
|
|
|
|
|
|
|
lpwm->mld.uDeviceID = uDeviceID;
|
|
|
|
|
2009-05-20 17:50:54 +02:00
|
|
|
dwRet = MMDRV_Open((LPWINE_MLD)lpwm, MODM_OPEN, (DWORD_PTR)&lpwm->mod, dwFlags);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (dwRet != MMSYSERR_NOERROR) {
|
|
|
|
MMDRV_Free(hMidiOut, (LPWINE_MLD)lpwm);
|
|
|
|
hMidiOut = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lphMidiOut) *lphMidiOut = hMidiOut;
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("=> %d hMidi=%p\n", dwRet, hMidiOut);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
return dwRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutClose [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutClose(HMIDIOUT hMidiOut)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
DWORD dwRet;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)\n", hMidiOut);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
|
|
|
dwRet = MMDRV_Close(wmld, MODM_CLOSE);
|
|
|
|
MMDRV_Free(hMidiOut, wmld);
|
|
|
|
|
|
|
|
return dwRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutPrepareHeader [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutPrepareHeader(HMIDIOUT hMidiOut,
|
|
|
|
MIDIHDR* lpMidiOutHdr, UINT uSize)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
2010-01-31 21:19:39 +01:00
|
|
|
/* FIXME: detect MIDIStream handles and enforce 64KB buffer limit on those */
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MODM_PREPARE, (DWORD_PTR)lpMidiOutHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutUnprepareHeader [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutUnprepareHeader(HMIDIOUT hMidiOut,
|
|
|
|
MIDIHDR* lpMidiOutHdr, UINT uSize)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MODM_UNPREPARE, (DWORD_PTR)lpMidiOutHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutShortMsg [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutShortMsg(HMIDIOUT hMidiOut, DWORD dwMsg)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("(%p, %08X)\n", hMidiOut, dwMsg);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MODM_DATA, dwMsg, 0L);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutLongMsg [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutLongMsg(HMIDIOUT hMidiOut,
|
|
|
|
MIDIHDR* lpMidiOutHdr, UINT uSize)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %p, %d)\n", hMidiOut, lpMidiOutHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MODM_LONGDATA, (DWORD_PTR)lpMidiOutHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutReset [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutReset(HMIDIOUT hMidiOut)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)\n", hMidiOut);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MODM_RESET, 0L, 0L);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutGetVolume [WINMM.@]
|
|
|
|
*/
|
2002-12-15 03:59:50 +01:00
|
|
|
UINT WINAPI midiOutGetVolume(HMIDIOUT hMidiOut, DWORD* lpdwVolume)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-12-15 03:59:50 +01:00
|
|
|
TRACE("(%p, %p);\n", hMidiOut, lpdwVolume);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2002-12-15 03:59:50 +01:00
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
|
2002-10-10 05:43:53 +02:00
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MODM_GETVOLUME, (DWORD_PTR)lpdwVolume, 0L);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutSetVolume [WINMM.@]
|
|
|
|
*/
|
2002-12-15 03:59:50 +01:00
|
|
|
UINT WINAPI midiOutSetVolume(HMIDIOUT hMidiOut, DWORD dwVolume)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("(%p, %d);\n", hMidiOut, dwVolume);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2002-12-15 03:59:50 +01:00
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) == NULL)
|
2002-10-10 05:43:53 +02:00
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MODM_SETVOLUME, dwVolume, 0L);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutCachePatches [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutCachePatches(HMIDIOUT hMidiOut, UINT uBank,
|
|
|
|
WORD* lpwPatchArray, UINT uFlags)
|
|
|
|
{
|
|
|
|
/* not really necessary to support this */
|
2013-01-26 23:29:31 +01:00
|
|
|
FIXME("(%p, %u, %p, %x): Stub\n", hMidiOut, uBank, lpwPatchArray, uFlags);
|
2002-10-10 05:43:53 +02:00
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutCacheDrumPatches [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutCacheDrumPatches(HMIDIOUT hMidiOut, UINT uPatch,
|
|
|
|
WORD* lpwKeyArray, UINT uFlags)
|
|
|
|
{
|
2013-01-26 23:29:31 +01:00
|
|
|
FIXME("(%p, %u, %p, %x): Stub\n", hMidiOut, uPatch, lpwKeyArray, uFlags);
|
2002-10-10 05:43:53 +02:00
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutGetID [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiOutGetID(HMIDIOUT hMidiOut, UINT* lpuDeviceID)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %p)\n", hMidiOut, lpuDeviceID);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
|
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
|
|
|
*lpuDeviceID = wmld->uDeviceID;
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiOutMessage [WINMM.@]
|
|
|
|
*/
|
2003-09-15 22:13:30 +02:00
|
|
|
UINT WINAPI midiOutMessage(HMIDIOUT hMidiOut, UINT uMessage,
|
2004-01-01 00:49:45 +01:00
|
|
|
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiOut, uMessage, dwParam1, dwParam2);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, FALSE)) == NULL) {
|
|
|
|
/* HACK... */
|
|
|
|
if (uMessage == 0x0001) {
|
|
|
|
*(LPDWORD)dwParam1 = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((wmld = MMDRV_Get(hMidiOut, MMDRV_MIDIOUT, TRUE)) != NULL) {
|
2003-12-01 23:38:19 +01:00
|
|
|
return MMDRV_PhysicalFeatures(wmld, uMessage, dwParam1, dwParam2);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (uMessage) {
|
|
|
|
case MODM_OPEN:
|
|
|
|
case MODM_CLOSE:
|
|
|
|
FIXME("can't handle OPEN or CLOSE message!\n");
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInGetNumDevs [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiInGetNumDevs(void)
|
|
|
|
{
|
|
|
|
return MMDRV_GetNum(MMDRV_MIDIIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInGetDevCapsW [WINMM.@]
|
|
|
|
*/
|
2004-01-01 00:49:45 +01:00
|
|
|
UINT WINAPI midiInGetDevCapsW(UINT_PTR uDeviceID, LPMIDIINCAPSW lpCaps, UINT uSize)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
LPWINE_MLD wmld;
|
2004-07-21 05:10:24 +02:00
|
|
|
|
2007-05-24 16:41:17 +02:00
|
|
|
TRACE("(%ld, %p, %d);\n", uDeviceID, lpCaps, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
|
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get((HANDLE)uDeviceID, MMDRV_MIDIIN, TRUE)) == NULL)
|
2010-01-30 22:09:12 +01:00
|
|
|
return MMSYSERR_BADDEVICEID;
|
2004-12-06 21:55:25 +01:00
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MIDM_GETDEVCAPS, (DWORD_PTR)lpCaps, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInGetDevCapsA [WINMM.@]
|
|
|
|
*/
|
2004-01-01 00:49:45 +01:00
|
|
|
UINT WINAPI midiInGetDevCapsA(UINT_PTR uDeviceID, LPMIDIINCAPSA lpCaps, UINT uSize)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
MIDIINCAPSW micW;
|
|
|
|
UINT ret;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
|
2003-10-31 00:07:23 +01:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
ret = midiInGetDevCapsW(uDeviceID, &micW, sizeof(micW));
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
if (ret == MMSYSERR_NOERROR) {
|
|
|
|
MIDIINCAPSA micA;
|
|
|
|
micA.wMid = micW.wMid;
|
|
|
|
micA.wPid = micW.wPid;
|
|
|
|
micA.vDriverVersion = micW.vDriverVersion;
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, micW.szPname, -1, micA.szPname,
|
|
|
|
sizeof(micA.szPname), NULL, NULL );
|
|
|
|
micA.dwSupport = micW.dwSupport;
|
|
|
|
memcpy(lpCaps, &micA, min(uSize, sizeof(micA)));
|
|
|
|
}
|
|
|
|
return ret;
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
2009-10-22 22:09:58 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* midiInOpen [WINMM.@]
|
|
|
|
*/
|
2017-02-12 13:58:55 +01:00
|
|
|
MMRESULT WINAPI midiInOpen(HMIDIIN* lphMidiIn, UINT uDeviceID,
|
2009-10-22 22:09:58 +02:00
|
|
|
DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2002-10-31 02:02:41 +01:00
|
|
|
HANDLE hMidiIn;
|
2002-10-10 05:43:53 +02:00
|
|
|
LPWINE_MIDI lpwm;
|
2017-02-12 13:58:55 +01:00
|
|
|
MMRESULT dwRet;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("(%p, %d, %08lX, %08lX, %08X);\n",
|
2002-10-10 05:43:53 +02:00
|
|
|
lphMidiIn, uDeviceID, dwCallback, dwInstance, dwFlags);
|
|
|
|
|
|
|
|
if (lphMidiIn != NULL) *lphMidiIn = 0;
|
|
|
|
|
2011-03-15 23:00:04 +01:00
|
|
|
dwRet = WINMM_CheckCallback(dwCallback, dwFlags, FALSE);
|
|
|
|
if (dwRet != MMSYSERR_NOERROR)
|
|
|
|
return dwRet;
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
lpwm = (LPWINE_MIDI)MMDRV_Alloc(sizeof(WINE_MIDI), MMDRV_MIDIIN, &hMidiIn,
|
2009-10-22 22:10:32 +02:00
|
|
|
&dwFlags, &dwCallback, &dwInstance);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (lpwm == NULL)
|
|
|
|
return MMSYSERR_NOMEM;
|
|
|
|
|
2009-02-20 10:23:08 +01:00
|
|
|
lpwm->mod.hMidi = hMidiIn;
|
2002-10-10 05:43:53 +02:00
|
|
|
lpwm->mod.dwCallback = dwCallback;
|
|
|
|
lpwm->mod.dwInstance = dwInstance;
|
|
|
|
|
|
|
|
lpwm->mld.uDeviceID = uDeviceID;
|
2009-05-20 17:50:54 +02:00
|
|
|
dwRet = MMDRV_Open(&lpwm->mld, MIDM_OPEN, (DWORD_PTR)&lpwm->mod, dwFlags);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (dwRet != MMSYSERR_NOERROR) {
|
|
|
|
MMDRV_Free(hMidiIn, &lpwm->mld);
|
|
|
|
hMidiIn = 0;
|
|
|
|
}
|
|
|
|
if (lphMidiIn != NULL) *lphMidiIn = hMidiIn;
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("=> %d hMidi=%p\n", dwRet, hMidiIn);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
return dwRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInClose [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiInClose(HMIDIIN hMidiIn)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
DWORD dwRet;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)\n", hMidiIn);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
|
|
|
dwRet = MMDRV_Close(wmld, MIDM_CLOSE);
|
|
|
|
MMDRV_Free(hMidiIn, wmld);
|
|
|
|
return dwRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInPrepareHeader [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiInPrepareHeader(HMIDIIN hMidiIn,
|
|
|
|
MIDIHDR* lpMidiInHdr, UINT uSize)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MIDM_PREPARE, (DWORD_PTR)lpMidiInHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInUnprepareHeader [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiInUnprepareHeader(HMIDIIN hMidiIn,
|
|
|
|
MIDIHDR* lpMidiInHdr, UINT uSize)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MIDM_UNPREPARE, (DWORD_PTR)lpMidiInHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInAddBuffer [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiInAddBuffer(HMIDIIN hMidiIn,
|
|
|
|
MIDIHDR* lpMidiInHdr, UINT uSize)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %p, %d)\n", hMidiIn, lpMidiInHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MIDM_ADDBUFFER, (DWORD_PTR)lpMidiInHdr, uSize);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInStart [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiInStart(HMIDIIN hMidiIn)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)\n", hMidiIn);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MIDM_START, 0L, 0L);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInStop [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiInStop(HMIDIIN hMidiIn)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)\n", hMidiIn);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MIDM_STOP, 0L, 0L);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInReset [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiInReset(HMIDIIN hMidiIn)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)\n", hMidiIn);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, MIDM_RESET, 0L, 0L);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInGetID [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI midiInGetID(HMIDIIN hMidiIn, UINT* lpuDeviceID)
|
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %p)\n", hMidiIn, lpuDeviceID);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (lpuDeviceID == NULL) return MMSYSERR_INVALPARAM;
|
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, TRUE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
|
|
|
*lpuDeviceID = wmld->uDeviceID;
|
|
|
|
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiInMessage [WINMM.@]
|
|
|
|
*/
|
2003-09-15 22:13:30 +02:00
|
|
|
UINT WINAPI midiInMessage(HMIDIIN hMidiIn, UINT uMessage,
|
2004-01-01 00:49:45 +01:00
|
|
|
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
LPWINE_MLD wmld;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %04X, %08lX, %08lX)\n", hMidiIn, uMessage, dwParam1, dwParam2);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if ((wmld = MMDRV_Get(hMidiIn, MMDRV_MIDIIN, FALSE)) == NULL)
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
|
|
|
switch (uMessage) {
|
|
|
|
case MIDM_OPEN:
|
|
|
|
case MIDM_CLOSE:
|
|
|
|
FIXME("can't handle OPEN or CLOSE message!\n");
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
2009-10-22 22:10:32 +02:00
|
|
|
return MMDRV_Message(wmld, uMessage, dwParam1, dwParam2);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
2008-08-16 20:52:22 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* midiConnect [WINMM.@]
|
|
|
|
*/
|
|
|
|
MMRESULT WINAPI midiConnect(HMIDI hMidi, HMIDIOUT hmo, LPVOID pReserved)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %p): Stub\n", hMidi, hmo, pReserved);
|
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiDisconnect [WINMM.@]
|
|
|
|
*/
|
|
|
|
MMRESULT WINAPI midiDisconnect(HMIDI hMidi, HMIDIOUT hmo, LPVOID pReserved)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %p): Stub\n", hMidi, hmo, pReserved);
|
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
typedef struct WINE_MIDIStream {
|
|
|
|
HMIDIOUT hDevice;
|
|
|
|
HANDLE hThread;
|
|
|
|
DWORD dwThreadID;
|
2018-05-21 14:36:10 +02:00
|
|
|
CRITICAL_SECTION lock;
|
2002-10-10 05:43:53 +02:00
|
|
|
DWORD dwTempo;
|
|
|
|
DWORD dwTimeDiv;
|
2018-07-11 15:33:19 +02:00
|
|
|
ULONGLONG position_usec;
|
2002-10-10 05:43:53 +02:00
|
|
|
DWORD dwPulses;
|
|
|
|
DWORD dwStartTicks;
|
2018-05-29 15:18:36 +02:00
|
|
|
DWORD dwElapsedMS;
|
2018-07-11 15:33:23 +02:00
|
|
|
DWORD dwLastPositionMS;
|
2002-10-10 05:43:53 +02:00
|
|
|
WORD wFlags;
|
2018-05-21 14:36:12 +02:00
|
|
|
WORD status;
|
2002-10-10 05:43:53 +02:00
|
|
|
HANDLE hEvent;
|
|
|
|
LPMIDIHDR lpMidiHdr;
|
2019-11-13 14:51:23 +01:00
|
|
|
DWORD dwStreamID;
|
|
|
|
struct wine_rb_entry entry;
|
2002-10-10 05:43:53 +02:00
|
|
|
} WINE_MIDIStream;
|
|
|
|
|
|
|
|
#define WINE_MSM_HEADER (WM_USER+0)
|
|
|
|
#define WINE_MSM_STOP (WM_USER+1)
|
2012-02-06 18:13:16 +01:00
|
|
|
#define WINE_MSM_PAUSE (WM_USER+2)
|
|
|
|
#define WINE_MSM_RESUME (WM_USER+3)
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2018-05-21 14:36:12 +02:00
|
|
|
#define MSM_STATUS_STOPPED WINE_MSM_STOP
|
|
|
|
#define MSM_STATUS_PAUSED WINE_MSM_PAUSE
|
|
|
|
#define MSM_STATUS_PLAYING WINE_MSM_RESUME
|
|
|
|
|
2019-11-13 14:51:23 +01:00
|
|
|
static int wine_midi_stream_compare(const void *key, const struct wine_rb_entry *entry)
|
|
|
|
{
|
|
|
|
WINE_MIDIStream *stream = WINE_RB_ENTRY_VALUE(entry, struct WINE_MIDIStream, entry);
|
|
|
|
return memcmp(key, &stream->dwStreamID, sizeof(stream->dwStreamID));
|
|
|
|
}
|
|
|
|
|
|
|
|
static WINE_MIDIStream *wine_midi_stream_allocate(void)
|
|
|
|
{
|
|
|
|
DWORD stream_id = 1;
|
|
|
|
WINE_MIDIStream *stream = NULL;
|
|
|
|
|
|
|
|
EnterCriticalSection(&WINMM_cs);
|
|
|
|
|
|
|
|
while (stream_id < 0xFFFFFFFF && wine_rb_get(&wine_midi_streams, &stream_id))
|
|
|
|
stream_id++;
|
|
|
|
|
|
|
|
if (stream_id < 0xFFFFFFFF &&
|
|
|
|
(stream = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_MIDIStream))))
|
|
|
|
{
|
|
|
|
stream->dwStreamID = stream_id;
|
|
|
|
wine_rb_put(&wine_midi_streams, &stream_id, &stream->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&WINMM_cs);
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wine_midi_stream_free(WINE_MIDIStream *stream)
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&WINMM_cs);
|
|
|
|
|
|
|
|
wine_rb_remove(&wine_midi_streams, &stream->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, stream);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&WINMM_cs);
|
|
|
|
}
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* MMSYSTEM_GetMidiStream [internal]
|
|
|
|
*/
|
|
|
|
static BOOL MMSYSTEM_GetMidiStream(HMIDISTRM hMidiStrm, WINE_MIDIStream** lpMidiStrm, WINE_MIDI** lplpwm)
|
|
|
|
{
|
|
|
|
WINE_MIDI* lpwm = (LPWINE_MIDI)MMDRV_Get(hMidiStrm, MMDRV_MIDIOUT, FALSE);
|
2019-11-13 14:51:23 +01:00
|
|
|
struct wine_rb_entry *entry;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (lplpwm)
|
|
|
|
*lplpwm = lpwm;
|
|
|
|
|
|
|
|
if (lpwm == NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-13 14:51:23 +01:00
|
|
|
EnterCriticalSection(&WINMM_cs);
|
|
|
|
if ((entry = wine_rb_get(&wine_midi_streams, &lpwm->mod.rgIds.dwStreamID)))
|
|
|
|
*lpMidiStrm = WINE_RB_ENTRY_VALUE(entry, struct WINE_MIDIStream, entry);
|
|
|
|
LeaveCriticalSection(&WINMM_cs);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
return *lpMidiStrm != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMSYSTEM_MidiStream_Convert [internal]
|
|
|
|
*/
|
|
|
|
static DWORD MMSYSTEM_MidiStream_Convert(WINE_MIDIStream* lpMidiStrm, DWORD pulse)
|
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
|
|
|
|
|
|
|
if (lpMidiStrm->dwTimeDiv == 0) {
|
|
|
|
FIXME("Shouldn't happen. lpMidiStrm->dwTimeDiv = 0\n");
|
|
|
|
} else if (lpMidiStrm->dwTimeDiv > 0x8000) { /* SMPTE, unchecked FIXME? */
|
2018-05-08 15:02:12 +02:00
|
|
|
int nf = 256 - HIBYTE(lpMidiStrm->dwTimeDiv); /* number of frames */
|
2002-10-10 05:43:53 +02:00
|
|
|
int nsf = LOBYTE(lpMidiStrm->dwTimeDiv); /* number of sub-frames */
|
2018-06-26 15:10:47 +02:00
|
|
|
ret = (pulse * 1000000) / (nf * nsf);
|
2002-10-10 05:43:53 +02:00
|
|
|
} else {
|
2018-06-26 15:10:47 +02:00
|
|
|
ret = (DWORD)((double)pulse * (double)lpMidiStrm->dwTempo /
|
2002-10-10 05:43:53 +02:00
|
|
|
(double)lpMidiStrm->dwTimeDiv);
|
|
|
|
}
|
|
|
|
|
2018-06-26 15:10:47 +02:00
|
|
|
return ret; /* in microseconds */
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:18:36 +02:00
|
|
|
static DWORD midistream_get_playing_position(WINE_MIDIStream* lpMidiStrm)
|
|
|
|
{
|
|
|
|
switch (lpMidiStrm->status) {
|
|
|
|
case MSM_STATUS_STOPPED:
|
|
|
|
case MSM_STATUS_PAUSED:
|
|
|
|
return lpMidiStrm->dwElapsedMS;
|
|
|
|
case MSM_STATUS_PLAYING:
|
2020-08-25 09:54:00 +02:00
|
|
|
return timeGetTime() - lpMidiStrm->dwStartTicks;
|
2018-05-29 15:18:36 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unknown playing status %hu\n", lpMidiStrm->status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* MMSYSTEM_MidiStream_MessageHandler [internal]
|
|
|
|
*/
|
|
|
|
static BOOL MMSYSTEM_MidiStream_MessageHandler(WINE_MIDIStream* lpMidiStrm, LPWINE_MIDI lpwm, LPMSG msg)
|
|
|
|
{
|
|
|
|
LPMIDIHDR lpMidiHdr;
|
|
|
|
LPMIDIHDR* lpmh;
|
|
|
|
LPBYTE lpData;
|
2012-02-06 18:13:16 +01:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
switch (msg->message) {
|
|
|
|
case WM_QUIT:
|
|
|
|
return FALSE;
|
|
|
|
case WINE_MSM_STOP:
|
|
|
|
TRACE("STOP\n");
|
2018-05-29 15:18:36 +02:00
|
|
|
EnterCriticalSection(&lpMidiStrm->lock);
|
2018-05-21 14:36:12 +02:00
|
|
|
lpMidiStrm->status = MSM_STATUS_STOPPED;
|
2018-05-29 15:18:36 +02:00
|
|
|
lpMidiStrm->dwPulses = 0;
|
|
|
|
lpMidiStrm->dwElapsedMS = 0;
|
2018-07-11 15:33:19 +02:00
|
|
|
lpMidiStrm->position_usec = 0;
|
2018-07-11 15:33:23 +02:00
|
|
|
lpMidiStrm->dwLastPositionMS = 0;
|
2018-05-29 15:18:36 +02:00
|
|
|
LeaveCriticalSection(&lpMidiStrm->lock);
|
2012-02-06 18:13:16 +01:00
|
|
|
/* this is not quite what MS doc says... */
|
|
|
|
midiOutReset(lpMidiStrm->hDevice);
|
|
|
|
/* empty list of already submitted buffers */
|
2012-02-07 23:10:03 +01:00
|
|
|
lpMidiHdr = lpMidiStrm->lpMidiHdr;
|
|
|
|
lpMidiStrm->lpMidiHdr = NULL;
|
|
|
|
while (lpMidiHdr) {
|
2012-02-06 18:13:16 +01:00
|
|
|
LPMIDIHDR lphdr = lpMidiHdr;
|
|
|
|
lpMidiHdr = lpMidiHdr->lpNext;
|
|
|
|
lphdr->dwFlags |= MHDR_DONE;
|
|
|
|
lphdr->dwFlags &= ~MHDR_INQUEUE;
|
|
|
|
|
|
|
|
DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
|
|
|
|
(HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
|
|
|
|
lpwm->mod.dwInstance, (DWORD_PTR)lphdr, 0);
|
|
|
|
}
|
2018-05-29 15:18:05 +02:00
|
|
|
SetEvent((HANDLE)msg->wParam);
|
2012-02-06 18:13:16 +01:00
|
|
|
return TRUE;
|
|
|
|
case WINE_MSM_RESUME:
|
|
|
|
/* FIXME: send out cc64 0 (turn off sustain pedal) on every channel */
|
2018-05-29 15:18:36 +02:00
|
|
|
if (lpMidiStrm->status != MSM_STATUS_PLAYING) {
|
|
|
|
EnterCriticalSection(&lpMidiStrm->lock);
|
2020-08-25 09:54:00 +02:00
|
|
|
lpMidiStrm->dwStartTicks = timeGetTime() - lpMidiStrm->dwElapsedMS;
|
2018-05-29 15:18:36 +02:00
|
|
|
lpMidiStrm->status = MSM_STATUS_PLAYING;
|
|
|
|
LeaveCriticalSection(&lpMidiStrm->lock);
|
|
|
|
}
|
2018-05-29 15:18:05 +02:00
|
|
|
SetEvent((HANDLE)msg->wParam);
|
2012-02-06 18:13:16 +01:00
|
|
|
return TRUE;
|
|
|
|
case WINE_MSM_PAUSE:
|
|
|
|
/* FIXME: send out cc64 0 (turn off sustain pedal) on every channel */
|
2018-05-29 15:18:36 +02:00
|
|
|
if (lpMidiStrm->status != MSM_STATUS_PAUSED) {
|
|
|
|
EnterCriticalSection(&lpMidiStrm->lock);
|
2020-08-25 09:54:00 +02:00
|
|
|
lpMidiStrm->dwElapsedMS = timeGetTime() - lpMidiStrm->dwStartTicks;
|
2018-05-29 15:18:36 +02:00
|
|
|
lpMidiStrm->status = MSM_STATUS_PAUSED;
|
|
|
|
LeaveCriticalSection(&lpMidiStrm->lock);
|
|
|
|
}
|
2018-05-29 15:18:05 +02:00
|
|
|
SetEvent((HANDLE)msg->wParam);
|
2012-02-06 18:13:16 +01:00
|
|
|
break;
|
2002-10-10 05:43:53 +02:00
|
|
|
/* FIXME(EPP): "I don't understand the content of the first MIDIHDR sent
|
|
|
|
* by native mcimidi, it doesn't look like a correct one".
|
2012-05-15 10:15:32 +02:00
|
|
|
* this trick allows us to throw it away... but I don't like it.
|
2002-10-10 05:43:53 +02:00
|
|
|
* It looks like part of the file I'm trying to play and definitively looks
|
2012-05-15 10:15:32 +02:00
|
|
|
* like raw midi content.
|
2002-10-10 05:43:53 +02:00
|
|
|
* I'd really like to understand why native mcimidi sends it. Perhaps a bad
|
|
|
|
* synchronization issue where native mcimidi is still processing raw MIDI
|
|
|
|
* content before generating MIDIEVENTs ?
|
|
|
|
*
|
|
|
|
* 4c 04 89 3b 00 81 7c 99 3b 43 00 99 23 5e 04 89 L..;..|.;C..#^..
|
|
|
|
* 3b 00 00 89 23 00 7c 99 3b 45 00 99 28 62 04 89 ;...#.|.;E..(b..
|
|
|
|
* 3b 00 00 89 28 00 81 7c 99 3b 4e 00 99 23 5e 04 ;...(..|.;N..#^.
|
|
|
|
* 89 3b 00 00 89 23 00 7c 99 3b 45 00 99 23 78 04 .;...#.|.;E..#x.
|
|
|
|
* 89 3b 00 00 89 23 00 81 7c 99 3b 48 00 99 23 5e .;...#..|.;H..#^
|
|
|
|
* 04 89 3b 00 00 89 23 00 7c 99 3b 4e 00 99 28 62 ..;...#.|.;N..(b
|
|
|
|
* 04 89 3b 00 00 89 28 00 81 7c 99 39 4c 00 99 23 ..;...(..|.9L..#
|
|
|
|
* 5e 04 89 39 00 00 89 23 00 82 7c 99 3b 4c 00 99 ^..9...#..|.;L..
|
|
|
|
* 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 00 99 #^..;...#.|.;H..
|
|
|
|
* 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b 3f 04 (b..;...(..|.;?.
|
|
|
|
* 89 3b 00 1c 99 23 5e 04 89 23 00 5c 99 3b 45 00 .;...#^..#.\.;E.
|
|
|
|
* 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 3b 46 .#x..;...#..|.;F
|
|
|
|
* 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b 48 ..#^..;...#.|.;H
|
|
|
|
* 00 99 28 62 04 89 3b 00 00 89 28 00 81 7c 99 3b ..(b..;...(..|.;
|
|
|
|
* 46 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 3b F..#^..;...#.|.;
|
|
|
|
* 48 00 99 23 78 04 89 3b 00 00 89 23 00 81 7c 99 H..#x..;...#..|.
|
|
|
|
* 3b 4c 00 99 23 5e 04 89 3b 00 00 89 23 00 7c 99 ;L..#^..;...#.|.
|
|
|
|
*/
|
2012-02-06 18:13:16 +01:00
|
|
|
case WINE_MSM_HEADER:
|
|
|
|
/* sets initial tick count for first MIDIHDR */
|
|
|
|
if (!lpMidiStrm->dwStartTicks)
|
2020-08-25 09:54:00 +02:00
|
|
|
lpMidiStrm->dwStartTicks = timeGetTime();
|
2012-02-06 18:13:16 +01:00
|
|
|
lpMidiHdr = (LPMIDIHDR)msg->lParam;
|
|
|
|
lpData = (LPBYTE)lpMidiHdr->lpData;
|
|
|
|
TRACE("Adding %s lpMidiHdr=%p [lpData=0x%p dwBytesRecorded=%u/%u dwFlags=0x%08x size=%lu]\n",
|
|
|
|
(lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular", lpMidiHdr,
|
|
|
|
lpData, lpMidiHdr->dwBytesRecorded, lpMidiHdr->dwBufferLength,
|
|
|
|
lpMidiHdr->dwFlags, msg->wParam);
|
2002-10-10 05:43:53 +02:00
|
|
|
#if 0
|
2012-02-06 18:13:16 +01:00
|
|
|
/* dumps content of lpMidiHdr->lpData
|
|
|
|
* FIXME: there should be a debug routine somewhere that already does this
|
|
|
|
*/
|
|
|
|
for (dwToGo = 0; dwToGo < lpMidiHdr->dwBufferLength; dwToGo += 16) {
|
|
|
|
DWORD i;
|
|
|
|
BYTE ch;
|
|
|
|
|
|
|
|
for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
|
|
|
|
printf("%02x ", lpData[dwToGo + i]);
|
|
|
|
for (; i < 16; i++)
|
|
|
|
printf(" ");
|
|
|
|
for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
|
|
|
|
ch = lpData[dwToGo + i];
|
|
|
|
printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
#endif
|
2012-02-06 18:13:16 +01:00
|
|
|
if (((LPMIDIEVENT)lpData)->dwStreamID != 0 &&
|
|
|
|
((LPMIDIEVENT)lpData)->dwStreamID != 0xFFFFFFFF &&
|
2019-11-13 14:51:23 +01:00
|
|
|
((LPMIDIEVENT)lpData)->dwStreamID != lpMidiStrm->dwStreamID) {
|
2012-02-06 18:13:16 +01:00
|
|
|
FIXME("Dropping bad %s lpMidiHdr (streamID=%08x)\n",
|
|
|
|
(lpMidiHdr->dwFlags & MHDR_ISSTRM) ? "stream" : "regular",
|
|
|
|
((LPMIDIEVENT)lpData)->dwStreamID);
|
|
|
|
lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
|
|
|
|
lpMidiHdr->dwFlags |= MHDR_DONE;
|
|
|
|
|
|
|
|
DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
|
|
|
|
(HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
|
|
|
|
lpwm->mod.dwInstance, (DWORD_PTR)lpMidiHdr, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpMidiHdr->lpNext = 0;
|
|
|
|
for (lpmh = &lpMidiStrm->lpMidiHdr; *lpmh; lpmh = &(*lpmh)->lpNext);
|
|
|
|
*lpmh = lpMidiHdr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unknown message %d\n", msg->message);
|
|
|
|
break;
|
|
|
|
}
|
2018-05-21 14:36:12 +02:00
|
|
|
if (lpMidiStrm->status != MSM_STATUS_PAUSED)
|
2012-02-06 18:13:16 +01:00
|
|
|
return TRUE;
|
|
|
|
GetMessageA(msg, 0, 0, 0);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MMSYSTEM_MidiStream_Player [internal]
|
|
|
|
*/
|
|
|
|
static DWORD CALLBACK MMSYSTEM_MidiStream_Player(LPVOID pmt)
|
|
|
|
{
|
|
|
|
WINE_MIDIStream* lpMidiStrm = pmt;
|
|
|
|
WINE_MIDI* lpwm;
|
|
|
|
MSG msg;
|
|
|
|
DWORD dwToGo;
|
|
|
|
DWORD dwCurrTC;
|
|
|
|
LPMIDIHDR lpMidiHdr;
|
2010-02-16 10:31:05 +01:00
|
|
|
DWORD dwOffset;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
TRACE("(%p)!\n", lpMidiStrm);
|
|
|
|
|
|
|
|
if (!lpMidiStrm ||
|
|
|
|
(lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
|
|
|
|
goto the_end;
|
|
|
|
|
|
|
|
/* force thread's queue creation */
|
2010-02-11 04:15:43 +01:00
|
|
|
PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
lpMidiStrm->dwStartTicks = 0;
|
|
|
|
lpMidiStrm->dwPulses = 0;
|
|
|
|
|
|
|
|
lpMidiStrm->lpMidiHdr = 0;
|
|
|
|
|
2010-02-11 04:15:43 +01:00
|
|
|
/* midiStreamOpen is waiting for ack */
|
|
|
|
SetEvent(lpMidiStrm->hEvent);
|
|
|
|
|
2010-02-16 10:31:05 +01:00
|
|
|
start_header:
|
|
|
|
lpMidiHdr = lpMidiStrm->lpMidiHdr;
|
|
|
|
if (!lpMidiHdr) {
|
|
|
|
/* for first message, block until one arrives, then process all that are available */
|
|
|
|
GetMessageA(&msg, 0, 0, 0);
|
|
|
|
do {
|
|
|
|
if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
|
|
|
|
goto the_end;
|
|
|
|
} while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
|
|
|
|
goto start_header;
|
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2010-02-16 10:31:05 +01:00
|
|
|
dwOffset = 0;
|
|
|
|
while (dwOffset + offsetof(MIDIEVENT,dwParms) <= lpMidiHdr->dwBytesRecorded) {
|
|
|
|
LPMIDIEVENT me = (LPMIDIEVENT)(lpMidiHdr->lpData+dwOffset);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
/* do we have to wait ? */
|
|
|
|
if (me->dwDeltaTime) {
|
2018-05-21 14:36:10 +02:00
|
|
|
EnterCriticalSection(&lpMidiStrm->lock);
|
2018-07-11 15:33:19 +02:00
|
|
|
lpMidiStrm->position_usec += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
|
2018-05-21 14:36:10 +02:00
|
|
|
LeaveCriticalSection(&lpMidiStrm->lock);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2018-07-11 15:33:19 +02:00
|
|
|
dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->position_usec / 1000;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2020-08-25 09:54:00 +02:00
|
|
|
TRACE("%u/%u/%u\n", dwToGo, timeGetTime(), me->dwDeltaTime);
|
|
|
|
while (dwToGo - (dwCurrTC = timeGetTime()) <= MAXLONG) {
|
2002-10-10 05:43:53 +02:00
|
|
|
if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
|
|
|
|
/* got a message, handle it */
|
|
|
|
while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
|
|
|
|
if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
|
|
|
|
goto the_end;
|
2010-02-16 10:31:05 +01:00
|
|
|
/* is lpMidiHdr still current? */
|
|
|
|
if (lpMidiHdr != lpMidiStrm->lpMidiHdr) {
|
|
|
|
goto start_header;
|
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
2018-05-29 15:19:08 +02:00
|
|
|
/* reset dwToGo because dwStartTicks might be updated */
|
2018-07-11 15:33:19 +02:00
|
|
|
dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->position_usec / 1000;
|
2002-10-10 05:43:53 +02:00
|
|
|
} else {
|
|
|
|
/* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-07-11 15:33:23 +02:00
|
|
|
EnterCriticalSection(&lpMidiStrm->lock);
|
|
|
|
lpMidiStrm->dwPulses += me->dwDeltaTime;
|
|
|
|
lpMidiStrm->dwLastPositionMS = midistream_get_playing_position(lpMidiStrm);
|
|
|
|
LeaveCriticalSection(&lpMidiStrm->lock);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
|
|
|
|
case MEVT_COMMENT:
|
|
|
|
FIXME("NIY: MEVT_COMMENT\n");
|
|
|
|
/* do nothing, skip bytes */
|
|
|
|
break;
|
|
|
|
case MEVT_LONGMSG:
|
2018-04-04 17:41:24 +02:00
|
|
|
{
|
|
|
|
MIDIHDR mh;
|
|
|
|
memset(&mh, 0, sizeof(mh));
|
|
|
|
mh.lpData = (LPSTR)me->dwParms;
|
|
|
|
mh.dwBufferLength = MEVT_EVENTPARM(me->dwEvent);
|
|
|
|
midiOutPrepareHeader(lpMidiStrm->hDevice, &mh, sizeof(mh));
|
|
|
|
midiOutLongMsg(lpMidiStrm->hDevice, &mh, sizeof(mh));
|
|
|
|
midiOutUnprepareHeader(lpMidiStrm->hDevice, &mh, sizeof(mh));
|
|
|
|
break;
|
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
case MEVT_NOP:
|
|
|
|
break;
|
|
|
|
case MEVT_SHORTMSG:
|
|
|
|
midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
|
|
|
|
break;
|
|
|
|
case MEVT_TEMPO:
|
2018-05-21 14:36:10 +02:00
|
|
|
EnterCriticalSection(&lpMidiStrm->lock);
|
2002-10-10 05:43:53 +02:00
|
|
|
lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
|
2018-05-21 14:36:10 +02:00
|
|
|
LeaveCriticalSection(&lpMidiStrm->lock);
|
2002-10-10 05:43:53 +02:00
|
|
|
break;
|
|
|
|
case MEVT_VERSION:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (me->dwEvent & MEVT_F_CALLBACK) {
|
2010-02-16 10:31:05 +01:00
|
|
|
/* native fills dwOffset regardless of the cbMidiHdr size argument to midiStreamOut */
|
|
|
|
lpMidiHdr->dwOffset = dwOffset;
|
2002-10-10 05:43:53 +02:00
|
|
|
DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
|
|
|
|
(HDRVR)lpMidiStrm->hDevice, MM_MOM_POSITIONCB,
|
|
|
|
lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
|
|
|
|
}
|
2010-02-16 10:31:05 +01:00
|
|
|
dwOffset += offsetof(MIDIEVENT,dwParms);
|
2002-10-10 05:43:53 +02:00
|
|
|
if (me->dwEvent & MEVT_F_LONG)
|
2010-02-16 10:31:05 +01:00
|
|
|
dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
2010-02-16 10:31:05 +01:00
|
|
|
/* done with this header */
|
|
|
|
lpMidiStrm->lpMidiHdr = lpMidiHdr->lpNext;
|
|
|
|
lpMidiHdr->dwFlags |= MHDR_DONE;
|
|
|
|
lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
|
|
|
|
|
|
|
|
DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
|
|
|
|
(HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
|
|
|
|
lpwm->mod.dwInstance, (DWORD_PTR)lpMidiHdr, 0);
|
|
|
|
goto start_header;
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
the_end:
|
|
|
|
TRACE("End of thread\n");
|
2010-02-11 04:15:43 +01:00
|
|
|
return 0;
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiStreamClose [WINMM.@]
|
|
|
|
*/
|
|
|
|
MMRESULT WINAPI midiStreamClose(HMIDISTRM hMidiStrm)
|
|
|
|
{
|
2018-05-14 14:24:08 +02:00
|
|
|
WINE_MIDI* lpwm;
|
2002-10-10 05:43:53 +02:00
|
|
|
WINE_MIDIStream* lpMidiStrm;
|
2012-02-07 23:10:03 +01:00
|
|
|
MMRESULT ret = 0;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)!\n", hMidiStrm);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2018-05-14 14:24:08 +02:00
|
|
|
if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, &lpwm))
|
2002-10-10 05:43:53 +02:00
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
|
|
|
|
midiStreamStop(hMidiStrm);
|
2012-02-07 23:10:03 +01:00
|
|
|
PostThreadMessageA(lpMidiStrm->dwThreadID, WM_QUIT, 0, 0);
|
2002-10-10 05:43:53 +02:00
|
|
|
CloseHandle(lpMidiStrm->hEvent);
|
2012-02-07 23:10:03 +01:00
|
|
|
if (lpMidiStrm->hThread) {
|
|
|
|
if (GetCurrentThreadId() != lpMidiStrm->dwThreadID)
|
|
|
|
WaitForSingleObject(lpMidiStrm->hThread, INFINITE);
|
|
|
|
else {
|
|
|
|
FIXME("leak from call within function callback\n");
|
|
|
|
ret = MMSYSERR_HANDLEBUSY; /* yet don't signal it to app */
|
|
|
|
}
|
|
|
|
CloseHandle(lpMidiStrm->hThread);
|
|
|
|
}
|
2018-05-14 14:24:08 +02:00
|
|
|
DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
|
|
|
|
(HDRVR)lpMidiStrm->hDevice, MM_MOM_CLOSE,
|
|
|
|
lpwm->mod.dwInstance, 0, 0);
|
2018-05-21 14:36:10 +02:00
|
|
|
if(!ret) {
|
|
|
|
lpMidiStrm->lock.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&lpMidiStrm->lock);
|
2019-11-13 14:51:23 +01:00
|
|
|
wine_midi_stream_free(lpMidiStrm);
|
2018-05-21 14:36:10 +02:00
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
return midiOutClose((HMIDIOUT)hMidiStrm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2009-10-22 22:10:12 +02:00
|
|
|
* midiStreamOpen [WINMM.@]
|
2002-10-10 05:43:53 +02:00
|
|
|
*/
|
2009-10-22 22:10:12 +02:00
|
|
|
MMRESULT WINAPI midiStreamOpen(HMIDISTRM* lphMidiStrm, LPUINT lpuDeviceID,
|
|
|
|
DWORD cMidi, DWORD_PTR dwCallback,
|
|
|
|
DWORD_PTR dwInstance, DWORD fdwOpen)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
WINE_MIDIStream* lpMidiStrm;
|
|
|
|
MMRESULT ret;
|
|
|
|
MIDIOPENSTRMID mosm;
|
|
|
|
LPWINE_MIDI lpwm;
|
|
|
|
HMIDIOUT hMidiOut;
|
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("(%p, %p, %d, 0x%08lx, 0x%08lx, 0x%08x)!\n",
|
2002-10-10 05:43:53 +02:00
|
|
|
lphMidiStrm, lpuDeviceID, cMidi, dwCallback, dwInstance, fdwOpen);
|
|
|
|
|
|
|
|
if (cMidi != 1 || lphMidiStrm == NULL || lpuDeviceID == NULL)
|
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
|
2011-03-15 23:00:04 +01:00
|
|
|
ret = WINMM_CheckCallback(dwCallback, fdwOpen, FALSE);
|
|
|
|
if (ret != MMSYSERR_NOERROR)
|
|
|
|
return ret;
|
2010-03-09 22:20:55 +01:00
|
|
|
|
2019-11-13 14:51:23 +01:00
|
|
|
lpMidiStrm = wine_midi_stream_allocate();
|
2002-10-10 05:43:53 +02:00
|
|
|
if (!lpMidiStrm)
|
|
|
|
return MMSYSERR_NOMEM;
|
|
|
|
|
2018-07-11 15:33:19 +02:00
|
|
|
lpMidiStrm->dwTempo = 500000; /* microseconds per quarter note, i.e. 120 BPM */
|
2018-05-08 15:02:10 +02:00
|
|
|
lpMidiStrm->dwTimeDiv = 24; /* ticks per quarter note */
|
2018-07-11 15:33:19 +02:00
|
|
|
lpMidiStrm->position_usec = 0;
|
2018-07-11 15:33:23 +02:00
|
|
|
lpMidiStrm->dwLastPositionMS = 0;
|
2018-05-21 14:36:12 +02:00
|
|
|
lpMidiStrm->status = MSM_STATUS_PAUSED;
|
2018-05-29 15:18:36 +02:00
|
|
|
lpMidiStrm->dwElapsedMS = 0;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2019-11-13 14:51:23 +01:00
|
|
|
mosm.dwStreamID = lpMidiStrm->dwStreamID;
|
2002-10-10 05:43:53 +02:00
|
|
|
/* FIXME: the correct value is not allocated yet for MAPPER */
|
|
|
|
mosm.wDeviceID = *lpuDeviceID;
|
2009-10-22 22:10:32 +02:00
|
|
|
lpwm = MIDI_OutAlloc(&hMidiOut, &dwCallback, &dwInstance, &fdwOpen, 1, &mosm);
|
2010-01-27 18:16:55 +01:00
|
|
|
if (!lpwm) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpMidiStrm);
|
|
|
|
return MMSYSERR_NOMEM;
|
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
lpMidiStrm->hDevice = hMidiOut;
|
2010-01-27 18:18:18 +01:00
|
|
|
*lphMidiStrm = (HMIDISTRM)hMidiOut;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2003-11-26 04:39:13 +01:00
|
|
|
lpwm->mld.uDeviceID = *lpuDeviceID;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2018-05-14 14:24:08 +02:00
|
|
|
/* don't rely on midiOut callbacks */
|
|
|
|
ret = MMDRV_Open(&lpwm->mld, MODM_OPEN, (DWORD_PTR)&lpwm->mod, CALLBACK_NULL);
|
2010-01-27 18:16:55 +01:00
|
|
|
if (ret != MMSYSERR_NOERROR) {
|
|
|
|
MMDRV_Free(hMidiOut, &lpwm->mld);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpMidiStrm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-21 14:36:10 +02:00
|
|
|
InitializeCriticalSection(&lpMidiStrm->lock);
|
|
|
|
lpMidiStrm->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": WINMM_MidiStream.lock");
|
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
lpMidiStrm->hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2002-10-10 05:43:53 +02:00
|
|
|
lpMidiStrm->wFlags = HIWORD(fdwOpen);
|
|
|
|
|
|
|
|
lpMidiStrm->hThread = CreateThread(NULL, 0, MMSYSTEM_MidiStream_Player,
|
|
|
|
lpMidiStrm, 0, &(lpMidiStrm->dwThreadID));
|
|
|
|
|
|
|
|
if (!lpMidiStrm->hThread) {
|
|
|
|
midiStreamClose((HMIDISTRM)hMidiOut);
|
|
|
|
return MMSYSERR_NOMEM;
|
|
|
|
}
|
2005-04-27 11:39:55 +02:00
|
|
|
SetThreadPriority(lpMidiStrm->hThread, THREAD_PRIORITY_TIME_CRITICAL);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
/* wait for thread to have started, and for its queue to be created */
|
2009-12-24 12:29:24 +01:00
|
|
|
WaitForSingleObject(lpMidiStrm->hEvent, INFINITE);
|
2012-02-06 18:13:16 +01:00
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("=> (%u/%d) hMidi=%p ret=%d lpMidiStrm=%p\n",
|
2002-10-10 05:43:53 +02:00
|
|
|
*lpuDeviceID, lpwm->mld.uDeviceID, *lphMidiStrm, ret, lpMidiStrm);
|
2018-05-14 14:24:08 +02:00
|
|
|
|
|
|
|
DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
|
|
|
|
(HDRVR)lpMidiStrm->hDevice, MM_MOM_OPEN,
|
|
|
|
lpwm->mod.dwInstance, 0, 0);
|
2002-10-10 05:43:53 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiStreamOut [WINMM.@]
|
|
|
|
*/
|
|
|
|
MMRESULT WINAPI midiStreamOut(HMIDISTRM hMidiStrm, LPMIDIHDR lpMidiHdr,
|
|
|
|
UINT cbMidiHdr)
|
|
|
|
{
|
|
|
|
WINE_MIDIStream* lpMidiStrm;
|
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMidiHdr, cbMidiHdr);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2010-02-16 09:32:53 +01:00
|
|
|
if (cbMidiHdr < offsetof(MIDIHDR,dwOffset) || !lpMidiHdr || !lpMidiHdr->lpData
|
2010-03-09 22:20:55 +01:00
|
|
|
|| lpMidiHdr->dwBufferLength < lpMidiHdr->dwBytesRecorded
|
|
|
|
|| lpMidiHdr->dwBytesRecorded % 4 /* player expects DWORD padding */)
|
2010-01-27 18:18:18 +01:00
|
|
|
return MMSYSERR_INVALPARAM;
|
2010-03-20 15:24:53 +01:00
|
|
|
/* FIXME: Native additionally checks if the MIDIEVENTs in lpData
|
2010-02-16 09:08:46 +01:00
|
|
|
* exactly fit dwBytesRecorded. */
|
2010-01-27 18:18:18 +01:00
|
|
|
|
|
|
|
if (!(lpMidiHdr->dwFlags & MHDR_PREPARED))
|
|
|
|
return MIDIERR_UNPREPARED;
|
|
|
|
|
|
|
|
if (lpMidiHdr->dwFlags & MHDR_INQUEUE)
|
|
|
|
return MIDIERR_STILLPLAYING;
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
|
|
|
|
ret = MMSYSERR_INVALHANDLE;
|
|
|
|
} else {
|
2010-02-02 08:37:09 +01:00
|
|
|
lpMidiHdr->dwFlags |= MHDR_ISSTRM | MHDR_INQUEUE;
|
|
|
|
lpMidiHdr->dwFlags &= ~MHDR_DONE;
|
2002-10-10 05:43:53 +02:00
|
|
|
if (!PostThreadMessageA(lpMidiStrm->dwThreadID,
|
|
|
|
WINE_MSM_HEADER, cbMidiHdr,
|
2009-05-20 17:50:54 +02:00
|
|
|
(LPARAM)lpMidiHdr)) {
|
2010-02-11 04:15:43 +01:00
|
|
|
ERR("bad PostThreadMessageA\n");
|
2002-10-10 05:43:53 +02:00
|
|
|
ret = MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-29 15:18:05 +02:00
|
|
|
static MMRESULT midistream_post_message_and_wait(WINE_MIDIStream* lpMidiStrm, UINT msg, LPARAM lParam)
|
|
|
|
{
|
|
|
|
HANDLE hObjects[2];
|
|
|
|
|
|
|
|
hObjects[0] = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
if (!hObjects[0])
|
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
|
|
|
|
if (!PostThreadMessageA(lpMidiStrm->dwThreadID, msg, (WPARAM)hObjects[0], lParam)) {
|
|
|
|
WARN("bad PostThreadMessage\n");
|
|
|
|
CloseHandle(hObjects[0]);
|
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetCurrentThreadId() != lpMidiStrm->dwThreadID) {
|
|
|
|
DWORD ret;
|
|
|
|
hObjects[1] = lpMidiStrm->hThread;
|
2018-09-19 21:01:11 +02:00
|
|
|
ret = WaitForMultipleObjects(ARRAY_SIZE(hObjects), hObjects, FALSE, INFINITE);
|
2018-05-29 15:18:05 +02:00
|
|
|
if (ret != WAIT_OBJECT_0) {
|
|
|
|
CloseHandle(hObjects[0]);
|
|
|
|
WARN("bad WaitForSingleObject (%u)\n", ret);
|
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hObjects[0]);
|
|
|
|
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* midiStreamPause [WINMM.@]
|
|
|
|
*/
|
|
|
|
MMRESULT WINAPI midiStreamPause(HMIDISTRM hMidiStrm)
|
|
|
|
{
|
|
|
|
WINE_MIDIStream* lpMidiStrm;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)!\n", hMidiStrm);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2012-02-06 18:13:16 +01:00
|
|
|
if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
2018-05-29 15:18:05 +02:00
|
|
|
return midistream_post_message_and_wait(lpMidiStrm, WINE_MSM_PAUSE, 0);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
2018-07-11 15:33:23 +02:00
|
|
|
static DWORD midistream_get_current_pulse(WINE_MIDIStream* lpMidiStrm)
|
|
|
|
{
|
|
|
|
DWORD pulses = 0;
|
|
|
|
DWORD now = midistream_get_playing_position(lpMidiStrm);
|
|
|
|
DWORD delta = now - lpMidiStrm->dwLastPositionMS;
|
|
|
|
if (lpMidiStrm->dwTimeDiv > 0x8000) {
|
|
|
|
/* SMPTE, unchecked FIXME */
|
|
|
|
BYTE nf = 256 - HIBYTE(lpMidiStrm->dwTimeDiv);
|
|
|
|
BYTE nsf = LOBYTE(lpMidiStrm->dwTimeDiv);
|
|
|
|
pulses = (delta * nf * nsf) / 1000;
|
|
|
|
}
|
|
|
|
else if (lpMidiStrm->dwTimeDiv) {
|
|
|
|
pulses = (DWORD)((double)(delta * lpMidiStrm->dwTimeDiv) *
|
|
|
|
1000.0 / (double)lpMidiStrm->dwTempo);
|
|
|
|
}
|
|
|
|
return lpMidiStrm->dwPulses + pulses;
|
|
|
|
}
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* midiStreamPosition [WINMM.@]
|
|
|
|
*/
|
|
|
|
MMRESULT WINAPI midiStreamPosition(HMIDISTRM hMidiStrm, LPMMTIME lpMMT, UINT cbmmt)
|
|
|
|
{
|
|
|
|
WINE_MIDIStream* lpMidiStrm;
|
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p, %p, %u)!\n", hMidiStrm, lpMMT, cbmmt);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
|
|
|
|
ret = MMSYSERR_INVALHANDLE;
|
|
|
|
} else if (lpMMT == NULL || cbmmt != sizeof(MMTIME)) {
|
|
|
|
ret = MMSYSERR_INVALPARAM;
|
|
|
|
} else {
|
2018-05-21 14:36:10 +02:00
|
|
|
EnterCriticalSection(&lpMidiStrm->lock);
|
2002-10-10 05:43:53 +02:00
|
|
|
switch (lpMMT->wType) {
|
2018-07-11 15:33:25 +02:00
|
|
|
case TIME_MIDI:
|
|
|
|
if (lpMidiStrm->dwTimeDiv < 0x8000) {
|
|
|
|
DWORD tdiv, pulses;
|
|
|
|
tdiv = (lpMidiStrm->dwTimeDiv > 24) ? lpMidiStrm->dwTimeDiv : 24;
|
|
|
|
pulses = midistream_get_current_pulse(lpMidiStrm);
|
|
|
|
lpMMT->u.midi.songptrpos = (pulses + tdiv/8) / (tdiv/4);
|
|
|
|
if (!lpMMT->u.midi.songptrpos && pulses) lpMMT->u.midi.songptrpos++;
|
|
|
|
TRACE("=> song position %d (pulses %u, tdiv %u)\n", lpMMT->u.midi.songptrpos, pulses, tdiv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
2010-01-30 10:07:59 +01:00
|
|
|
case TIME_BYTES:
|
|
|
|
case TIME_SAMPLES:
|
|
|
|
lpMMT->wType = TIME_MS;
|
|
|
|
/* fall through to alternative format */
|
2002-10-10 05:43:53 +02:00
|
|
|
case TIME_MS:
|
2018-05-29 15:18:36 +02:00
|
|
|
lpMMT->u.ms = midistream_get_playing_position(lpMidiStrm);
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("=> %d ms\n", lpMMT->u.ms);
|
2002-10-10 05:43:53 +02:00
|
|
|
break;
|
|
|
|
case TIME_TICKS:
|
2018-07-11 15:33:23 +02:00
|
|
|
lpMMT->u.ticks = midistream_get_current_pulse(lpMidiStrm);
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("=> %d ticks\n", lpMMT->u.ticks);
|
2002-10-10 05:43:53 +02:00
|
|
|
break;
|
2018-07-11 15:33:25 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unsupported time type %x\n", lpMMT->wType);
|
|
|
|
/* use TIME_MS instead */
|
|
|
|
lpMMT->wType = TIME_MS;
|
|
|
|
lpMMT->u.ms = midistream_get_playing_position(lpMidiStrm);
|
|
|
|
TRACE("=> %d ms\n", lpMMT->u.ms);
|
|
|
|
break;
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
2018-05-21 14:36:10 +02:00
|
|
|
LeaveCriticalSection(&lpMidiStrm->lock);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiStreamProperty [WINMM.@]
|
|
|
|
*/
|
|
|
|
MMRESULT WINAPI midiStreamProperty(HMIDISTRM hMidiStrm, LPBYTE lpPropData, DWORD dwProperty)
|
|
|
|
{
|
|
|
|
WINE_MIDIStream* lpMidiStrm;
|
|
|
|
MMRESULT ret = MMSYSERR_NOERROR;
|
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("(%p, %p, %x)\n", hMidiStrm, lpPropData, dwProperty);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL)) {
|
|
|
|
ret = MMSYSERR_INVALHANDLE;
|
|
|
|
} else if ((dwProperty & (MIDIPROP_GET|MIDIPROP_SET)) == 0) {
|
|
|
|
ret = MMSYSERR_INVALPARAM;
|
|
|
|
} else if (dwProperty & MIDIPROP_TEMPO) {
|
|
|
|
MIDIPROPTEMPO* mpt = (MIDIPROPTEMPO*)lpPropData;
|
|
|
|
|
2018-05-21 14:36:10 +02:00
|
|
|
EnterCriticalSection(&lpMidiStrm->lock);
|
2002-10-10 05:43:53 +02:00
|
|
|
if (sizeof(MIDIPROPTEMPO) != mpt->cbStruct) {
|
|
|
|
ret = MMSYSERR_INVALPARAM;
|
|
|
|
} else if (dwProperty & MIDIPROP_SET) {
|
|
|
|
lpMidiStrm->dwTempo = mpt->dwTempo;
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("Setting tempo to %d\n", mpt->dwTempo);
|
2002-10-10 05:43:53 +02:00
|
|
|
} else if (dwProperty & MIDIPROP_GET) {
|
|
|
|
mpt->dwTempo = lpMidiStrm->dwTempo;
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("Getting tempo <= %d\n", mpt->dwTempo);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
2018-05-21 14:36:10 +02:00
|
|
|
LeaveCriticalSection(&lpMidiStrm->lock);
|
2002-10-10 05:43:53 +02:00
|
|
|
} else if (dwProperty & MIDIPROP_TIMEDIV) {
|
|
|
|
MIDIPROPTIMEDIV* mptd = (MIDIPROPTIMEDIV*)lpPropData;
|
|
|
|
|
|
|
|
if (sizeof(MIDIPROPTIMEDIV) != mptd->cbStruct) {
|
|
|
|
ret = MMSYSERR_INVALPARAM;
|
|
|
|
} else if (dwProperty & MIDIPROP_SET) {
|
2018-05-21 14:36:10 +02:00
|
|
|
EnterCriticalSection(&lpMidiStrm->lock);
|
2018-06-26 15:10:45 +02:00
|
|
|
if (lpMidiStrm->status != MSM_STATUS_PLAYING) {
|
|
|
|
lpMidiStrm->dwTimeDiv = mptd->dwTimeDiv;
|
|
|
|
TRACE("Setting time div to %d\n", mptd->dwTimeDiv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = MMSYSERR_INVALPARAM;
|
2018-05-21 14:36:10 +02:00
|
|
|
LeaveCriticalSection(&lpMidiStrm->lock);
|
2002-10-10 05:43:53 +02:00
|
|
|
} else if (dwProperty & MIDIPROP_GET) {
|
|
|
|
mptd->dwTimeDiv = lpMidiStrm->dwTimeDiv;
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("Getting time div <= %d\n", mptd->dwTimeDiv);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = MMSYSERR_INVALPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiStreamRestart [WINMM.@]
|
|
|
|
*/
|
|
|
|
MMRESULT WINAPI midiStreamRestart(HMIDISTRM hMidiStrm)
|
|
|
|
{
|
|
|
|
WINE_MIDIStream* lpMidiStrm;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)!\n", hMidiStrm);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2012-02-06 18:13:16 +01:00
|
|
|
if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
2018-05-29 15:18:05 +02:00
|
|
|
return midistream_post_message_and_wait(lpMidiStrm, WINE_MSM_RESUME, 0);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* midiStreamStop [WINMM.@]
|
|
|
|
*/
|
|
|
|
MMRESULT WINAPI midiStreamStop(HMIDISTRM hMidiStrm)
|
|
|
|
{
|
|
|
|
WINE_MIDIStream* lpMidiStrm;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)!\n", hMidiStrm);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2012-02-06 18:13:16 +01:00
|
|
|
if (!MMSYSTEM_GetMidiStream(hMidiStrm, &lpMidiStrm, NULL))
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
2018-05-29 15:18:05 +02:00
|
|
|
return midistream_post_message_and_wait(lpMidiStrm, WINE_MSM_STOP, 0);
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
2004-07-21 05:02:36 +02:00
|
|
|
struct mm_starter
|
|
|
|
{
|
|
|
|
LPTASKCALLBACK cb;
|
|
|
|
DWORD client;
|
|
|
|
HANDLE event;
|
|
|
|
};
|
|
|
|
|
2004-08-17 01:19:17 +02:00
|
|
|
static DWORD WINAPI mmTaskRun(void* pmt)
|
2004-07-21 05:02:36 +02:00
|
|
|
{
|
|
|
|
struct mm_starter mms;
|
|
|
|
|
|
|
|
memcpy(&mms, pmt, sizeof(struct mm_starter));
|
|
|
|
HeapFree(GetProcessHeap(), 0, pmt);
|
|
|
|
mms.cb(mms.client);
|
|
|
|
if (mms.event) SetEvent(mms.event);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-17 01:19:17 +02:00
|
|
|
/******************************************************************
|
|
|
|
* mmTaskCreate (WINMM.@)
|
|
|
|
*/
|
2007-08-30 16:16:14 +02:00
|
|
|
UINT WINAPI mmTaskCreate(LPTASKCALLBACK cb, HANDLE* ph, DWORD_PTR client)
|
2004-07-21 05:02:36 +02:00
|
|
|
{
|
|
|
|
HANDLE hThread;
|
|
|
|
HANDLE hEvent = 0;
|
|
|
|
struct mm_starter *mms;
|
|
|
|
|
|
|
|
mms = HeapAlloc(GetProcessHeap(), 0, sizeof(struct mm_starter));
|
2004-08-17 01:19:17 +02:00
|
|
|
if (mms == NULL) return TASKERR_OUTOFMEMORY;
|
2004-07-21 05:02:36 +02:00
|
|
|
|
|
|
|
mms->cb = cb;
|
|
|
|
mms->client = client;
|
|
|
|
if (ph) hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
mms->event = hEvent;
|
|
|
|
|
|
|
|
hThread = CreateThread(0, 0, mmTaskRun, mms, 0, NULL);
|
|
|
|
if (!hThread) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, mms);
|
|
|
|
if (hEvent) CloseHandle(hEvent);
|
|
|
|
return TASKERR_OUTOFMEMORY;
|
|
|
|
}
|
2005-04-27 11:39:55 +02:00
|
|
|
SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
|
2004-07-21 05:02:36 +02:00
|
|
|
if (ph) *ph = hEvent;
|
|
|
|
CloseHandle(hThread);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-17 01:19:17 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* mmTaskBlock (WINMM.@)
|
|
|
|
*/
|
2007-08-30 16:16:14 +02:00
|
|
|
VOID WINAPI mmTaskBlock(DWORD tid)
|
2004-08-17 01:19:17 +02:00
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
GetMessageA(&msg, 0, 0, 0);
|
|
|
|
if (msg.hwnd) DispatchMessageA(&msg);
|
|
|
|
} while (msg.message != WM_USER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* mmTaskSignal (WINMM.@)
|
|
|
|
*/
|
2007-08-30 16:16:14 +02:00
|
|
|
BOOL WINAPI mmTaskSignal(DWORD tid)
|
2004-08-17 01:19:17 +02:00
|
|
|
{
|
2007-08-30 16:16:14 +02:00
|
|
|
return PostThreadMessageW(tid, WM_USER, 0, 0);
|
2004-08-17 01:19:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* mmTaskYield (WINMM.@)
|
|
|
|
*/
|
2007-08-30 16:16:14 +02:00
|
|
|
VOID WINAPI mmTaskYield(VOID) {}
|
2004-08-17 01:19:17 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* mmGetCurrentTask (WINMM.@)
|
|
|
|
*/
|
2007-08-30 16:16:14 +02:00
|
|
|
DWORD WINAPI mmGetCurrentTask(VOID)
|
2004-08-17 01:19:17 +02:00
|
|
|
{
|
2007-08-30 16:16:14 +02:00
|
|
|
return GetCurrentThreadId();
|
2004-08-17 01:19:17 +02:00
|
|
|
}
|