1998-11-24 18:30:37 +01:00
|
|
|
/*
|
|
|
|
* Sample MIDI Wine Driver for Linux
|
|
|
|
*
|
2005-08-17 14:15:35 +02:00
|
|
|
* Copyright 1994 Martin Ayotte
|
|
|
|
* Copyright 1999 Eric Pouech
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
|
2004-10-11 21:57:10 +02:00
|
|
|
/* TODO:
|
|
|
|
* + implement it correctly
|
2010-06-01 22:33:43 +02:00
|
|
|
* + finish asynchronous commands
|
2004-10-11 21:57:10 +02:00
|
|
|
* + better implement non waiting command (without the MCI_WAIT flag).
|
|
|
|
*/
|
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
#include <stdlib.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-02-10 23:15:21 +01:00
|
|
|
#include <stdio.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2000-12-19 05:53:20 +01:00
|
|
|
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "windef.h"
|
2000-12-19 05:53:20 +01:00
|
|
|
#include "winbase.h"
|
2019-06-10 10:58:47 +02:00
|
|
|
#include "winnls.h"
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "wingdi.h"
|
1999-04-22 17:26:11 +02:00
|
|
|
#include "winuser.h"
|
2002-10-17 18:43:42 +02:00
|
|
|
#include "wownt32.h"
|
1999-09-05 18:31:37 +02:00
|
|
|
#include "mmddk.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1998-11-24 18:30:37 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mcimidi);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1999-09-05 18:31:37 +02:00
|
|
|
#define MIDI_NOTEOFF 0x80
|
|
|
|
#define MIDI_NOTEON 0x90
|
1999-07-31 15:13:23 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
typedef struct {
|
|
|
|
DWORD dwFirst; /* offset in file of track */
|
|
|
|
DWORD dwLast; /* number of bytes in file of track */
|
|
|
|
DWORD dwIndex; /* current index in file (dwFirst <= dwIndex < dwLast) */
|
|
|
|
DWORD dwLength; /* number of pulses in this track */
|
|
|
|
DWORD dwEventPulse; /* current pulse # (event) pointed by dwIndex */
|
|
|
|
DWORD dwEventData; /* current data (event) pointed by dwIndex */
|
|
|
|
WORD wEventLength; /* current length (event) pointed by dwIndex */
|
|
|
|
WORD wStatus : 1, /* 1 : playing, 0 : done */
|
|
|
|
wTrackNr : 7,
|
1999-07-24 12:45:24 +02:00
|
|
|
wLastCommand : 8; /* last MIDI command on track */
|
1998-11-24 18:30:37 +01:00
|
|
|
} MCI_MIDITRACK;
|
|
|
|
|
1999-07-15 16:42:14 +02:00
|
|
|
typedef struct tagWINE_MCIMIDI {
|
1999-09-22 18:42:03 +02:00
|
|
|
UINT wDevID; /* the MCI one */
|
1999-09-05 18:31:37 +02:00
|
|
|
HMIDI hMidi;
|
1998-11-24 18:30:37 +01:00
|
|
|
int nUseCount; /* Incremented for each shared open */
|
1999-09-05 18:31:37 +02:00
|
|
|
HANDLE hCallback; /* Callback handle for pending notification */
|
2012-10-04 12:34:07 +02:00
|
|
|
HANDLE hThread; /* Player thread */
|
1999-02-26 12:11:13 +01:00
|
|
|
HMMIO hFile; /* mmio file handle open as Element */
|
2005-02-09 23:26:25 +01:00
|
|
|
LPWSTR lpstrElementName; /* Name of file (if any) */
|
|
|
|
LPWSTR lpstrCopyright;
|
|
|
|
LPWSTR lpstrName;
|
2009-12-05 05:40:59 +01:00
|
|
|
WORD wPort; /* the WINMM device unit */
|
1998-11-24 18:30:37 +01:00
|
|
|
WORD dwStatus; /* one from MCI_MODE_xxxx */
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD dwMciTimeFormat; /* One of the supported MCI_FORMAT_xxxx */
|
1998-11-24 18:30:37 +01:00
|
|
|
WORD wFormat; /* Format of MIDI hFile (0, 1 or 2) */
|
|
|
|
WORD nTracks; /* Number of tracks in hFile */
|
|
|
|
WORD nDivision; /* Number of division in hFile PPQN or SMPTE */
|
|
|
|
WORD wStartedPlaying;
|
|
|
|
DWORD dwTempo; /* Tempo (# of 1/4 note per second */
|
|
|
|
MCI_MIDITRACK* tracks; /* Content of each track */
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD dwPulse;
|
1998-11-24 18:30:37 +01:00
|
|
|
DWORD dwPositionMS;
|
2012-10-04 12:34:07 +02:00
|
|
|
DWORD dwEndMS;
|
1998-11-24 18:30:37 +01:00
|
|
|
DWORD dwStartTicks;
|
|
|
|
} WINE_MCIMIDI;
|
|
|
|
|
|
|
|
/*======================================================================*
|
2006-08-06 12:28:32 +02:00
|
|
|
* MCI MIDI implementation *
|
1998-11-24 18:30:37 +01:00
|
|
|
*======================================================================*/
|
|
|
|
|
2012-09-14 16:46:32 +02:00
|
|
|
static DWORD mmr2mci(DWORD ret)
|
|
|
|
{
|
|
|
|
switch (ret) {
|
|
|
|
case MMSYSERR_ALLOCATED:
|
|
|
|
return MCIERR_SEQ_PORT_INUSE;
|
|
|
|
case MMSYSERR_NOMEM:
|
|
|
|
return MCIERR_OUT_OF_MEMORY;
|
|
|
|
case MMSYSERR_BADDEVICEID: /* wine*.drv disabled */
|
|
|
|
return MCIERR_SEQ_PORT_NONEXISTENT;
|
|
|
|
case MIDIERR_INVALIDSETUP: /* from midimap.dll without snd-seq module */
|
|
|
|
return MCIERR_SEQ_PORT_MAPNODEVICE;
|
|
|
|
default:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciResume(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
|
1999-05-24 10:17:54 +02:00
|
|
|
|
1999-05-02 12:21:49 +02:00
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDI_drvOpen [internal]
|
1999-05-02 12:21:49 +02:00
|
|
|
*/
|
2005-02-09 23:26:25 +01:00
|
|
|
static DWORD MIDI_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
|
1999-05-02 12:21:49 +02:00
|
|
|
{
|
2002-05-12 01:02:55 +02:00
|
|
|
WINE_MCIMIDI* wmm;
|
|
|
|
|
|
|
|
if (!modp) return 0xFFFFFFFF;
|
|
|
|
|
|
|
|
wmm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCIMIDI));
|
1999-05-02 12:21:49 +02:00
|
|
|
|
1999-07-15 16:42:14 +02:00
|
|
|
if (!wmm)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
wmm->wDevID = modp->wDeviceID;
|
2007-05-31 16:01:16 +02:00
|
|
|
mciSetDriverData(wmm->wDevID, (DWORD_PTR)wmm);
|
1999-07-24 12:45:24 +02:00
|
|
|
modp->wCustomCommandTable = MCI_NO_COMMAND_TABLE;
|
1999-07-15 16:42:14 +02:00
|
|
|
modp->wType = MCI_DEVTYPE_SEQUENCER;
|
|
|
|
return modp->wDeviceID;
|
1999-05-02 12:21:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MCIMIDI_drvClose [internal]
|
1999-05-02 12:21:49 +02:00
|
|
|
*/
|
|
|
|
static DWORD MIDI_drvClose(DWORD dwDevID)
|
|
|
|
{
|
1999-07-15 16:42:14 +02:00
|
|
|
WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(dwDevID);
|
1999-05-02 12:21:49 +02:00
|
|
|
|
|
|
|
if (wmm) {
|
2002-06-01 01:06:46 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, wmm);
|
1999-07-15 16:42:14 +02:00
|
|
|
mciSetDriverData(dwDevID, 0);
|
1999-05-02 12:21:49 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2002-05-12 01:02:55 +02:00
|
|
|
return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
|
1999-05-02 12:21:49 +02:00
|
|
|
}
|
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDI_mciGetOpenDev [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
2010-12-15 22:47:45 +01:00
|
|
|
static WINE_MCIMIDI* MIDI_mciGetOpenDev(MCIDEVICEID wDevID, UINT wMsg)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
1999-07-15 16:42:14 +02:00
|
|
|
WINE_MCIMIDI* wmm = (WINE_MCIMIDI*)mciGetDriverData(wDevID);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-12-15 22:47:45 +01:00
|
|
|
if (wmm == NULL || ((wmm->nUseCount == 0) ^ (wMsg == MCI_OPEN_DRIVER))) {
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Invalid wDevID=%u\n", wDevID);
|
1998-11-24 18:30:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
1999-05-02 12:21:49 +02:00
|
|
|
return wmm;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
|
2009-12-05 05:40:59 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciNotify [internal]
|
|
|
|
*
|
|
|
|
* Notifications in MCI work like a 1-element queue.
|
|
|
|
* Each new notification request supersedes the previous one.
|
|
|
|
* This affects Play and Record; other commands are immediate.
|
|
|
|
*/
|
|
|
|
static void MIDI_mciNotify(DWORD_PTR hWndCallBack, WINE_MCIMIDI* wmm, UINT wStatus)
|
|
|
|
{
|
|
|
|
/* We simply save one parameter by not passing the wDevID local
|
|
|
|
* to the command. They are the same (via mciGetDriverData).
|
|
|
|
*/
|
2010-12-15 22:56:08 +01:00
|
|
|
MCIDEVICEID wDevID = wmm->wDevID;
|
2009-12-05 05:40:59 +01:00
|
|
|
HANDLE old = InterlockedExchangePointer(&wmm->hCallback, NULL);
|
|
|
|
if (old) mciDriverNotify(old, wDevID, MCI_NOTIFY_SUPERSEDED);
|
|
|
|
mciDriverNotify(HWND_32(LOWORD(hWndCallBack)), wDevID, wStatus);
|
|
|
|
}
|
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDI_mciReadByte [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
static DWORD MIDI_mciReadByte(WINE_MCIMIDI* wmm, BYTE *lpbyt)
|
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2011-07-19 09:15:15 +02:00
|
|
|
if (mmioRead(wmm->hFile, (HPSTR)lpbyt, sizeof(BYTE)) != (long)sizeof(BYTE)) {
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Error reading wmm=%p\n", wmm);
|
1999-05-02 12:21:49 +02:00
|
|
|
ret = MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDI_mciReadWord [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
static DWORD MIDI_mciReadWord(WINE_MCIMIDI* wmm, LPWORD lpw)
|
|
|
|
{
|
|
|
|
BYTE hibyte, lobyte;
|
1999-05-02 12:21:49 +02:00
|
|
|
DWORD ret = MCIERR_INVALID_FILE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2011-07-19 09:15:15 +02:00
|
|
|
if (MIDI_mciReadByte(wmm, &hibyte) == 0 &&
|
1998-11-24 18:30:37 +01:00
|
|
|
MIDI_mciReadByte(wmm, &lobyte) == 0) {
|
|
|
|
*lpw = ((WORD)hibyte << 8) + lobyte;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDI_mciReadLong [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
static DWORD MIDI_mciReadLong(WINE_MCIMIDI* wmm, LPDWORD lpdw)
|
|
|
|
{
|
|
|
|
WORD hiword, loword;
|
1999-05-02 12:21:49 +02:00
|
|
|
DWORD ret = MCIERR_INVALID_FILE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2011-07-19 09:15:15 +02:00
|
|
|
if (MIDI_mciReadWord(wmm, &hiword) == 0 &&
|
1998-11-24 18:30:37 +01:00
|
|
|
MIDI_mciReadWord(wmm, &loword) == 0) {
|
|
|
|
*lpdw = MAKELONG(loword, hiword);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDI_mciReadVaryLen [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
static WORD MIDI_mciReadVaryLen(WINE_MCIMIDI* wmm, LPDWORD lpdw)
|
|
|
|
{
|
|
|
|
BYTE byte;
|
|
|
|
DWORD value = 0;
|
2011-07-19 09:15:15 +02:00
|
|
|
WORD len = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (MIDI_mciReadByte(wmm, &byte) != 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
value = (value << 7) + (byte & 0x7F);
|
|
|
|
len++;
|
|
|
|
} while (byte & 0x80);
|
|
|
|
*lpdw = value;
|
|
|
|
return len;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDI_mciReadNextEvent [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static DWORD MIDI_mciReadNextEvent(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
|
|
|
BYTE b1, b2 = 0, b3;
|
|
|
|
WORD hw = 0;
|
|
|
|
DWORD evtPulse;
|
|
|
|
DWORD evtLength;
|
|
|
|
DWORD tmp;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if (mmioSeek(wmm->hFile, mmt->dwIndex, SEEK_SET) != mmt->dwIndex) {
|
2006-10-13 02:50:35 +02:00
|
|
|
WARN("Can't seek at %08X\n", mmt->dwIndex);
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
evtLength = MIDI_mciReadVaryLen(wmm, &evtPulse) + 1; /* > 0 */
|
|
|
|
MIDI_mciReadByte(wmm, &b1);
|
|
|
|
switch (b1) {
|
|
|
|
case 0xF0:
|
|
|
|
case 0xF7:
|
|
|
|
evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
|
|
|
|
evtLength += tmp;
|
|
|
|
break;
|
|
|
|
case 0xFF:
|
|
|
|
MIDI_mciReadByte(wmm, &b2); evtLength++;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
evtLength += MIDI_mciReadVaryLen(wmm, &tmp);
|
|
|
|
if (evtLength >= 0x10000u) {
|
|
|
|
/* this limitation shouldn't be a problem */
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Ouch !! Implementation limitation to 64k bytes for a MIDI event is overflowed\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
hw = 0xFFFF;
|
|
|
|
} else {
|
|
|
|
hw = LOWORD(evtLength);
|
|
|
|
}
|
|
|
|
evtLength += tmp;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (b1 & 0x80) { /* use running status ? */
|
|
|
|
mmt->wLastCommand = b1;
|
|
|
|
MIDI_mciReadByte(wmm, &b2); evtLength++;
|
|
|
|
} else {
|
|
|
|
b2 = b1;
|
|
|
|
b1 = mmt->wLastCommand;
|
|
|
|
}
|
|
|
|
switch ((b1 >> 4) & 0x07) {
|
|
|
|
case 0: case 1: case 2: case 3: case 6:
|
|
|
|
MIDI_mciReadByte(wmm, &b3); evtLength++;
|
|
|
|
hw = b3;
|
|
|
|
break;
|
|
|
|
case 4: case 5:
|
|
|
|
break;
|
|
|
|
case 7:
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Strange indeed b1=0x%02x\n", b1);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mmt->dwIndex + evtLength > mmt->dwLast)
|
|
|
|
return MCIERR_INTERNAL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
mmt->dwEventPulse += evtPulse;
|
|
|
|
mmt->dwEventData = (hw << 16) + (b2 << 8) + b1;
|
|
|
|
mmt->wEventLength = evtLength;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
/*
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("[%u] => pulse=%08x(%08x), data=%08x, length=%u\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
mmt->wTrackNr, mmt->dwEventPulse, evtPulse,
|
1999-02-13 13:38:09 +01:00
|
|
|
mmt->dwEventData, mmt->wEventLength);
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDI_mciReadMTrk [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
static DWORD MIDI_mciReadMTrk(WINE_MCIMIDI* wmm, MCI_MIDITRACK* mmt)
|
|
|
|
{
|
|
|
|
DWORD toberead;
|
|
|
|
FOURCC fourcc;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
if (mmioRead(wmm->hFile, (HPSTR)&fourcc, (long)sizeof(FOURCC)) !=
|
1998-11-24 18:30:37 +01:00
|
|
|
(long)sizeof(FOURCC)) {
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (fourcc != mmioFOURCC('M', 'T', 'r', 'k')) {
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Can't synchronize on 'MTrk' !\n");
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (MIDI_mciReadLong(wmm, &toberead) != 0) {
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
1999-02-26 12:11:13 +01:00
|
|
|
mmt->dwFirst = mmioSeek(wmm->hFile, 0, SEEK_CUR); /* >= 0 */
|
1998-11-24 18:30:37 +01:00
|
|
|
mmt->dwLast = mmt->dwFirst + toberead;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
/* compute # of pulses in this track */
|
|
|
|
mmt->dwIndex = mmt->dwFirst;
|
|
|
|
mmt->dwEventPulse = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-01-04 01:25:22 +01:00
|
|
|
while (MIDI_mciReadNextEvent(wmm, mmt) == 0 && LOWORD(mmt->dwEventData) != 0x2FFF) {
|
|
|
|
char buf[1024];
|
|
|
|
WORD len;
|
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
mmt->dwIndex += mmt->wEventLength;
|
2000-01-04 01:25:22 +01:00
|
|
|
|
|
|
|
switch (LOWORD(mmt->dwEventData)) {
|
|
|
|
case 0x02FF:
|
|
|
|
case 0x03FF:
|
|
|
|
len = mmt->wEventLength - HIWORD(mmt->dwEventData);
|
|
|
|
if (len >= sizeof(buf)) {
|
2006-06-13 14:10:47 +02:00
|
|
|
WARN("Buffer for text is too small (%u are needed)\n", len);
|
2000-01-04 01:25:22 +01:00
|
|
|
len = sizeof(buf) - 1;
|
|
|
|
}
|
2009-01-15 09:44:25 +01:00
|
|
|
if (mmioRead(wmm->hFile, buf, len) == len) {
|
2000-01-04 01:25:22 +01:00
|
|
|
buf[len] = 0; /* end string in case */
|
|
|
|
switch (HIBYTE(LOWORD(mmt->dwEventData))) {
|
|
|
|
case 0x02:
|
|
|
|
if (wmm->lpstrCopyright) {
|
2005-02-09 23:26:25 +01:00
|
|
|
WARN("Two copyright notices (%s|%s)\n", debugstr_w(wmm->lpstrCopyright), buf);
|
2012-09-19 22:26:17 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, wmm->lpstrCopyright);
|
2000-01-04 01:25:22 +01:00
|
|
|
}
|
2012-09-19 22:26:17 +02:00
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
|
|
|
|
wmm->lpstrCopyright = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, buf, -1, wmm->lpstrCopyright, len );
|
2000-01-04 01:25:22 +01:00
|
|
|
break;
|
|
|
|
case 0x03:
|
2001-01-29 00:10:52 +01:00
|
|
|
if (wmm->lpstrName) {
|
2005-02-09 23:26:25 +01:00
|
|
|
WARN("Two names (%s|%s)\n", debugstr_w(wmm->lpstrName), buf);
|
2012-09-19 22:26:17 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, wmm->lpstrName);
|
|
|
|
} /* last name or name from last track wins */
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
|
|
|
|
wmm->lpstrName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, buf, -1, wmm->lpstrName, len );
|
2000-01-04 01:25:22 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
mmt->dwLength = mmt->dwEventPulse;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("Track %u has %u bytes and %u pulses\n", mmt->wTrackNr, toberead, mmt->dwLength);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
/* reset track data */
|
|
|
|
mmt->wStatus = 1; /* ok, playing */
|
|
|
|
mmt->dwIndex = mmt->dwFirst;
|
|
|
|
mmt->dwEventPulse = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if (mmioSeek(wmm->hFile, 0, SEEK_CUR) != mmt->dwLast) {
|
2006-10-13 02:50:35 +02:00
|
|
|
WARN("Ouch, out of sync seek=%u track=%u\n",
|
1999-02-26 12:11:13 +01:00
|
|
|
mmioSeek(wmm->hFile, 0, SEEK_CUR), mmt->dwLast);
|
1998-11-24 18:30:37 +01:00
|
|
|
/* position at end of this track, to be ready to read next track */
|
1999-02-26 12:11:13 +01:00
|
|
|
mmioSeek(wmm->hFile, mmt->dwLast, SEEK_SET);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDI_mciReadMThd [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
static DWORD MIDI_mciReadMThd(WINE_MCIMIDI* wmm, DWORD dwOffset)
|
|
|
|
{
|
|
|
|
DWORD toberead;
|
|
|
|
FOURCC fourcc;
|
|
|
|
WORD nt;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("(%p, %08X);\n", wmm, dwOffset);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if (mmioSeek(wmm->hFile, dwOffset, SEEK_SET) != dwOffset) {
|
2006-10-13 02:50:35 +02:00
|
|
|
WARN("Can't seek at %08X begin of 'MThd'\n", dwOffset);
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
1999-02-26 12:11:13 +01:00
|
|
|
if (mmioRead(wmm->hFile, (HPSTR)&fourcc,
|
1998-11-24 18:30:37 +01:00
|
|
|
(long) sizeof(FOURCC)) != (long) sizeof(FOURCC))
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (fourcc != mmioFOURCC('M', 'T', 'h', 'd')) {
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Can't synchronize on 'MThd' !\n");
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (MIDI_mciReadLong(wmm, &toberead) != 0 || toberead < 3 * sizeof(WORD))
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (MIDI_mciReadWord(wmm, &wmm->wFormat) != 0 ||
|
|
|
|
MIDI_mciReadWord(wmm, &wmm->nTracks) != 0 ||
|
|
|
|
MIDI_mciReadWord(wmm, &wmm->nDivision) != 0) {
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("toberead=0x%08X, wFormat=0x%04X nTracks=0x%04X nDivision=0x%04X\n",
|
1998-11-24 18:30:37 +01:00
|
|
|
toberead, wmm->wFormat, wmm->nTracks, wmm->nDivision);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
/* MS doc says that the MIDI MCI time format must be put by default to the format
|
|
|
|
* stored in the MIDI file...
|
|
|
|
*/
|
|
|
|
if (wmm->nDivision > 0x8000) {
|
|
|
|
/* eric.pouech@lemel.fr 98/11
|
2006-08-06 12:28:32 +02:00
|
|
|
* I did not check this very code (pulses are expressed as SMPTE sub-frames).
|
1998-11-24 18:30:37 +01:00
|
|
|
* In about 40 MB of MIDI files I have, none was SMPTE based...
|
2002-06-01 01:06:46 +02:00
|
|
|
* I'm just wondering if this is widely used :-). So, if someone has one of
|
2006-08-06 12:28:32 +02:00
|
|
|
* these files, I'd like to know about it.
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
1999-05-24 10:17:54 +02:00
|
|
|
FIXME("Handling SMPTE time in MIDI files has not been tested\n"
|
1999-02-13 13:38:09 +01:00
|
|
|
"Please report to comp.emulators.ms-windows.wine with MIDI file !\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
switch (HIBYTE(wmm->nDivision)) {
|
|
|
|
case 0xE8: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24; break; /* -24 */
|
|
|
|
case 0xE7: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25; break; /* -25 */
|
|
|
|
case 0xE3: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
|
|
|
|
case 0xE2: wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30; break; /* -30 */
|
|
|
|
default:
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Unsupported number of frames %d\n", -(char)HIBYTE(wmm->nDivision));
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
switch (LOBYTE(wmm->nDivision)) {
|
|
|
|
case 4: /* MIDI Time Code */
|
|
|
|
case 8:
|
|
|
|
case 10:
|
|
|
|
case 80: /* SMPTE bit resolution */
|
|
|
|
case 100:
|
|
|
|
default:
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Unsupported number of sub-frames %d\n", LOBYTE(wmm->nDivision));
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
} else if (wmm->nDivision == 0) {
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Number of division is 0, can't support that !!\n");
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
} else {
|
|
|
|
wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
switch (wmm->wFormat) {
|
|
|
|
case 0:
|
|
|
|
if (wmm->nTracks != 1) {
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Got type 0 file whose number of track is not 1. Setting it to 1\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->nTracks = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
default:
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Handling MIDI files which format = %d is not (yet) supported\n"
|
1999-02-13 13:38:09 +01:00
|
|
|
"Please report with MIDI file !\n", wmm->wFormat);
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2012-09-26 09:04:39 +02:00
|
|
|
if (wmm->nTracks > 0x80) {
|
|
|
|
/* wTrackNr is 7 bits only */
|
|
|
|
FIXME("Truncating MIDI file with %u tracks\n", wmm->nTracks);
|
|
|
|
wmm->nTracks = 0x80;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-07-15 16:42:14 +02:00
|
|
|
if ((wmm->tracks = HeapAlloc(GetProcessHeap(), 0, sizeof(MCI_MIDITRACK) * wmm->nTracks)) == NULL) {
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
toberead -= 3 * sizeof(WORD);
|
1998-11-24 18:30:37 +01:00
|
|
|
if (toberead > 0) {
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("Size of MThd > 6, skipping %d extra bytes\n", toberead);
|
1999-02-26 12:11:13 +01:00
|
|
|
mmioSeek(wmm->hFile, toberead, SEEK_CUR);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
for (nt = 0; nt < wmm->nTracks; nt++) {
|
|
|
|
wmm->tracks[nt].wTrackNr = nt;
|
|
|
|
if (MIDI_mciReadMTrk(wmm, &wmm->tracks[nt]) != 0) {
|
2005-11-10 13:14:56 +01:00
|
|
|
WARN("Can't read 'MTrk' header\n");
|
1999-05-02 12:21:49 +02:00
|
|
|
return MCIERR_INVALID_FILE;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->dwTempo = 500000;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_ConvertPulseToMS [internal]
|
|
|
|
*/
|
|
|
|
static DWORD MIDI_ConvertPulseToMS(WINE_MCIMIDI* wmm, DWORD pulse)
|
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
/* FIXME: this function may return false values since the tempo (wmm->dwTempo)
|
|
|
|
* may change during file playing
|
|
|
|
*/
|
|
|
|
if (wmm->nDivision == 0) {
|
1999-05-24 10:17:54 +02:00
|
|
|
FIXME("Shouldn't happen. wmm->nDivision = 0\n");
|
1998-12-01 09:28:43 +01:00
|
|
|
} else if (wmm->nDivision > 0x8000) { /* SMPTE, unchecked FIXME? */
|
1998-11-24 18:30:37 +01:00
|
|
|
int nf = -(char)HIBYTE(wmm->nDivision); /* number of frames */
|
|
|
|
int nsf = LOBYTE(wmm->nDivision); /* number of sub-frames */
|
|
|
|
ret = (pulse * 1000) / (nf * nsf);
|
|
|
|
} else {
|
2002-06-01 01:06:46 +02:00
|
|
|
ret = (DWORD)((double)pulse * ((double)wmm->dwTempo / 1000) /
|
1998-11-24 18:30:37 +01:00
|
|
|
(double)wmm->nDivision);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
/*
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("pulse=%u tempo=%u division=%u=0x%04x => ms=%u\n",
|
1998-11-24 18:30:37 +01:00
|
|
|
pulse, wmm->dwTempo, wmm->nDivision, wmm->nDivision, ret);
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TIME_MS_IN_ONE_HOUR (60*60*1000)
|
|
|
|
#define TIME_MS_IN_ONE_MINUTE (60*1000)
|
|
|
|
#define TIME_MS_IN_ONE_SECOND (1000)
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_ConvertTimeFormatToMS [internal]
|
|
|
|
*/
|
|
|
|
static DWORD MIDI_ConvertTimeFormatToMS(WINE_MCIMIDI* wmm, DWORD val)
|
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
switch (wmm->dwMciTimeFormat) {
|
2002-06-01 01:06:46 +02:00
|
|
|
case MCI_FORMAT_MILLISECONDS:
|
|
|
|
ret = val;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_FORMAT_SMPTE_24:
|
2002-06-01 01:06:46 +02:00
|
|
|
ret =
|
1998-11-24 18:30:37 +01:00
|
|
|
(HIBYTE(HIWORD(val)) * 125) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
|
|
|
|
HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
case MCI_FORMAT_SMPTE_25:
|
|
|
|
ret =
|
1998-11-24 18:30:37 +01:00
|
|
|
HIBYTE(HIWORD(val)) * 40 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
|
|
|
|
HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
case MCI_FORMAT_SMPTE_30:
|
|
|
|
ret =
|
1998-11-24 18:30:37 +01:00
|
|
|
(HIBYTE(HIWORD(val)) * 100) / 3 + LOBYTE(HIWORD(val)) * TIME_MS_IN_ONE_SECOND +
|
|
|
|
HIBYTE(LOWORD(val)) * TIME_MS_IN_ONE_MINUTE + LOBYTE(LOWORD(val)) * TIME_MS_IN_ONE_HOUR;
|
|
|
|
break;
|
|
|
|
default:
|
2006-10-13 02:50:35 +02:00
|
|
|
WARN("Bad time format %u!\n", wmm->dwMciTimeFormat);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
/*
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("val=%u=0x%08x [tf=%u] => ret=%u\n", val, val, wmm->dwMciTimeFormat, ret);
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
return ret;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
1998-11-24 18:30:37 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_ConvertMSToTimeFormat [internal]
|
|
|
|
*/
|
|
|
|
static DWORD MIDI_ConvertMSToTimeFormat(WINE_MCIMIDI* wmm, DWORD _val)
|
|
|
|
{
|
|
|
|
DWORD ret = 0, val = _val;
|
|
|
|
DWORD h, m, s, f;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
switch (wmm->dwMciTimeFormat) {
|
2002-06-01 01:06:46 +02:00
|
|
|
case MCI_FORMAT_MILLISECONDS:
|
|
|
|
ret = val;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_FORMAT_SMPTE_24:
|
2002-06-01 01:06:46 +02:00
|
|
|
case MCI_FORMAT_SMPTE_25:
|
|
|
|
case MCI_FORMAT_SMPTE_30:
|
|
|
|
h = val / TIME_MS_IN_ONE_HOUR;
|
|
|
|
m = (val -= h * TIME_MS_IN_ONE_HOUR) / TIME_MS_IN_ONE_MINUTE;
|
1998-11-24 18:30:37 +01:00
|
|
|
s = (val -= m * TIME_MS_IN_ONE_MINUTE) / TIME_MS_IN_ONE_SECOND;
|
|
|
|
switch (wmm->dwMciTimeFormat) {
|
|
|
|
case MCI_FORMAT_SMPTE_24:
|
|
|
|
/* one frame is 1000/24 val long, 1000/24 == 125/3 */
|
|
|
|
f = (val * 3) / 125; val -= (f * 125) / 3;
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
case MCI_FORMAT_SMPTE_25:
|
1998-11-24 18:30:37 +01:00
|
|
|
/* one frame is 1000/25 ms long, 1000/25 == 40 */
|
|
|
|
f = val / 40; val -= f * 40;
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
case MCI_FORMAT_SMPTE_30:
|
1998-11-24 18:30:37 +01:00
|
|
|
/* one frame is 1000/30 ms long, 1000/30 == 100/3 */
|
|
|
|
f = (val * 3) / 100; val -= (f * 100) / 3;
|
|
|
|
break;
|
|
|
|
default:
|
1999-05-24 10:17:54 +02:00
|
|
|
FIXME("There must be some bad bad programmer\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
f = 0;
|
|
|
|
}
|
|
|
|
/* val contains the number of ms which cannot make a complete frame */
|
|
|
|
/* FIXME: is this correct ? programs seem to be happy with that */
|
|
|
|
ret = (f << 24) | (s << 16) | (m << 8) | (h << 0);
|
|
|
|
break;
|
|
|
|
default:
|
2006-10-13 02:50:35 +02:00
|
|
|
WARN("Bad time format %u!\n", wmm->dwMciTimeFormat);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
/*
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("val=%u [tf=%u] => ret=%u=0x%08x\n", _val, wmm->dwMciTimeFormat, ret, ret);
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
return ret;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
1998-11-24 18:30:37 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_GetMThdLengthMS [internal]
|
|
|
|
*/
|
|
|
|
static DWORD MIDI_GetMThdLengthMS(WINE_MCIMIDI* wmm)
|
|
|
|
{
|
|
|
|
WORD nt;
|
|
|
|
DWORD ret = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
for (nt = 0; nt < wmm->nTracks; nt++) {
|
|
|
|
if (wmm->wFormat == 2) {
|
|
|
|
ret += wmm->tracks[nt].dwLength;
|
|
|
|
} else if (wmm->tracks[nt].dwLength > ret) {
|
|
|
|
ret = wmm->tracks[nt].dwLength;
|
|
|
|
}
|
|
|
|
}
|
1998-12-01 09:28:43 +01:00
|
|
|
/* FIXME: this is wrong if there is a tempo change inside the file */
|
1998-11-24 18:30:37 +01:00
|
|
|
return MIDI_ConvertPulseToMS(wmm, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDI_mciOpen [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciOpen(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_OPEN_PARMSW lpParms)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
1998-12-01 09:28:43 +01:00
|
|
|
DWORD dwRet = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("(%d, %08X, %p)\n", wmm->wDevID, dwFlags, lpParms);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
|
1999-02-14 12:26:34 +01:00
|
|
|
if (dwFlags & MCI_OPEN_SHAREABLE)
|
|
|
|
return MCIERR_HARDWARE;
|
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (wmm->nUseCount > 0) {
|
|
|
|
/* The driver is already opened on this channel
|
|
|
|
* MIDI sequencer cannot be shared
|
|
|
|
*/
|
|
|
|
return MCIERR_DEVICE_OPEN;
|
|
|
|
}
|
|
|
|
wmm->nUseCount++;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-12-01 09:28:43 +01:00
|
|
|
wmm->hFile = 0;
|
1999-09-05 18:31:37 +02:00
|
|
|
wmm->hMidi = 0;
|
2010-03-14 12:49:14 +01:00
|
|
|
wmm->wPort = MIDI_MAPPER;
|
2004-01-08 01:42:02 +01:00
|
|
|
wmm->lpstrElementName = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("wDevID=%d (lpParams->wDeviceID=%d)\n", wmm->wDevID, lpParms->wDeviceID);
|
1998-11-24 18:30:37 +01:00
|
|
|
/* lpParms->wDeviceID = wDevID;*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (dwFlags & MCI_OPEN_ELEMENT) {
|
2005-02-09 23:26:25 +01:00
|
|
|
TRACE("MCI_OPEN_ELEMENT %s!\n", debugstr_w(lpParms->lpstrElementName));
|
2014-11-17 11:07:02 +01:00
|
|
|
if (lpParms->lpstrElementName && lpParms->lpstrElementName[0]) {
|
2005-08-18 12:53:58 +02:00
|
|
|
wmm->hFile = mmioOpenW((LPWSTR)lpParms->lpstrElementName, NULL,
|
1999-07-15 16:42:14 +02:00
|
|
|
MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
|
1998-11-24 18:30:37 +01:00
|
|
|
if (wmm->hFile == 0) {
|
2005-02-09 23:26:25 +01:00
|
|
|
WARN("Can't find file %s!\n", debugstr_w(lpParms->lpstrElementName));
|
1998-12-01 09:28:43 +01:00
|
|
|
wmm->nUseCount--;
|
1998-11-24 18:30:37 +01:00
|
|
|
return MCIERR_FILE_NOT_FOUND;
|
|
|
|
}
|
2005-02-09 23:26:25 +01:00
|
|
|
wmm->lpstrElementName = HeapAlloc(GetProcessHeap(), 0,
|
2019-06-10 10:58:47 +02:00
|
|
|
(lstrlenW(lpParms->lpstrElementName) + 1) * sizeof(WCHAR));
|
|
|
|
lstrcpyW(wmm->lpstrElementName, lpParms->lpstrElementName);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
}
|
2002-10-19 01:48:57 +02:00
|
|
|
TRACE("hFile=%p\n", wmm->hFile);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-01-04 01:25:22 +01:00
|
|
|
wmm->lpstrCopyright = NULL;
|
|
|
|
wmm->lpstrName = NULL;
|
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->dwStatus = MCI_MODE_NOT_READY; /* while loading file contents */
|
1998-12-01 09:28:43 +01:00
|
|
|
/* spec says it should be the default format from the MIDI file... */
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (wmm->hFile != 0) {
|
|
|
|
MMCKINFO ckMainRIFF;
|
1998-12-01 09:28:43 +01:00
|
|
|
MMCKINFO mmckInfo;
|
1998-11-24 18:30:37 +01:00
|
|
|
DWORD dwOffset = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (mmioDescend(wmm->hFile, &ckMainRIFF, NULL, 0) != 0) {
|
1998-12-01 09:28:43 +01:00
|
|
|
dwRet = MCIERR_INVALID_FILE;
|
|
|
|
} else {
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08X\n",
|
1999-02-13 13:38:09 +01:00
|
|
|
(LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-12-01 09:28:43 +01:00
|
|
|
if (ckMainRIFF.ckid == FOURCC_RIFF && ckMainRIFF.fccType == mmioFOURCC('R', 'M', 'I', 'D')) {
|
|
|
|
mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
|
1999-07-15 16:42:14 +02:00
|
|
|
mmioSeek(wmm->hFile, ckMainRIFF.dwDataOffset + ((ckMainRIFF.cksize + 1) & ~1), SEEK_SET);
|
1998-12-01 09:28:43 +01:00
|
|
|
if (mmioDescend(wmm->hFile, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK) == 0) {
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("... is a 'RMID' file\n");
|
1998-12-01 09:28:43 +01:00
|
|
|
dwOffset = mmckInfo.dwDataOffset;
|
|
|
|
} else {
|
|
|
|
dwRet = MCIERR_INVALID_FILE;
|
1999-02-13 13:38:09 +01:00
|
|
|
}
|
1998-12-01 09:28:43 +01:00
|
|
|
}
|
|
|
|
if (dwRet == 0 && MIDI_mciReadMThd(wmm, dwOffset) != 0) {
|
2005-11-10 13:14:56 +01:00
|
|
|
WARN("Can't read 'MThd' header\n");
|
1998-12-01 09:28:43 +01:00
|
|
|
dwRet = MCIERR_INVALID_FILE;
|
1999-02-13 13:38:09 +01:00
|
|
|
}
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("hFile==0, setting #tracks to 0; is this correct ?\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->nTracks = 0;
|
|
|
|
wmm->wFormat = 0;
|
|
|
|
wmm->nDivision = 1;
|
|
|
|
}
|
1998-12-01 09:28:43 +01:00
|
|
|
if (dwRet != 0) {
|
|
|
|
wmm->nUseCount--;
|
|
|
|
if (wmm->hFile != 0)
|
1999-02-26 12:11:13 +01:00
|
|
|
mmioClose(wmm->hFile, 0);
|
1998-12-01 09:28:43 +01:00
|
|
|
wmm->hFile = 0;
|
2012-09-18 18:26:26 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, wmm->tracks);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wmm->lpstrElementName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wmm->lpstrCopyright);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wmm->lpstrName);
|
1998-12-01 09:28:43 +01:00
|
|
|
} else {
|
1999-02-13 13:38:09 +01:00
|
|
|
wmm->dwPositionMS = 0;
|
|
|
|
wmm->dwStatus = MCI_MODE_STOP;
|
2009-12-05 05:40:59 +01:00
|
|
|
if (dwFlags & MCI_NOTIFY)
|
|
|
|
MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
|
1998-12-01 09:28:43 +01:00
|
|
|
}
|
|
|
|
return dwRet;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
1998-12-01 09:28:43 +01:00
|
|
|
* MIDI_mciStop [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciStop(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2009-12-05 05:40:59 +01:00
|
|
|
DWORD dwRet = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-12-05 05:40:59 +01:00
|
|
|
if (wmm->dwStatus != MCI_MODE_STOP) {
|
|
|
|
HANDLE old = InterlockedExchangePointer(&wmm->hCallback, NULL);
|
2010-12-15 22:36:01 +01:00
|
|
|
if (old) mciDriverNotify(old, wmm->wDevID, MCI_NOTIFY_ABORTED);
|
2009-12-05 05:40:59 +01:00
|
|
|
}
|
|
|
|
|
1999-07-15 16:42:14 +02:00
|
|
|
if (wmm->dwStatus != MCI_MODE_STOP) {
|
2000-09-22 22:56:45 +02:00
|
|
|
int oldstat = wmm->dwStatus;
|
|
|
|
|
|
|
|
wmm->dwStatus = MCI_MODE_NOT_READY;
|
|
|
|
if (oldstat == MCI_MODE_PAUSE)
|
2009-12-05 05:40:59 +01:00
|
|
|
dwRet = midiOutReset((HMIDIOUT)wmm->hMidi);
|
2000-09-22 22:56:45 +02:00
|
|
|
|
2015-07-22 17:07:48 +02:00
|
|
|
if (wmm->hThread)
|
2012-10-04 12:34:07 +02:00
|
|
|
WaitForSingleObject(wmm->hThread, INFINITE);
|
1999-07-15 16:42:14 +02:00
|
|
|
}
|
2000-09-22 22:56:45 +02:00
|
|
|
|
2008-04-04 21:23:01 +02:00
|
|
|
/* sanity reset */
|
2000-09-22 22:56:45 +02:00
|
|
|
wmm->dwStatus = MCI_MODE_STOP;
|
|
|
|
|
2009-12-05 05:40:59 +01:00
|
|
|
if ((dwFlags & MCI_NOTIFY) && lpParms && MMSYSERR_NOERROR==dwRet)
|
|
|
|
MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
|
|
|
|
return dwRet;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciClose [internal]
|
|
|
|
*/
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciClose(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (wmm->dwStatus != MCI_MODE_STOP) {
|
2009-12-05 05:40:59 +01:00
|
|
|
/* mciStop handles MCI_NOTIFY_ABORTED */
|
2010-12-15 22:36:01 +01:00
|
|
|
MIDI_mciStop(wmm, MCI_WAIT, lpParms);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->nUseCount--;
|
|
|
|
if (wmm->nUseCount == 0) {
|
|
|
|
if (wmm->hFile != 0) {
|
1999-02-26 12:11:13 +01:00
|
|
|
mmioClose(wmm->hFile, 0);
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->hFile = 0;
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("hFile closed !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2015-07-22 17:07:48 +02:00
|
|
|
if (wmm->hThread) {
|
|
|
|
CloseHandle(wmm->hThread);
|
|
|
|
wmm->hThread = 0;
|
|
|
|
}
|
1999-07-15 16:42:14 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, wmm->tracks);
|
2007-12-20 23:45:37 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, wmm->lpstrElementName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wmm->lpstrCopyright);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wmm->lpstrName);
|
1998-11-24 18:30:37 +01:00
|
|
|
} else {
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("Shouldn't happen... nUseCount=%d\n", wmm->nUseCount);
|
1998-11-24 18:30:37 +01:00
|
|
|
return MCIERR_INTERNAL;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-12-05 05:40:59 +01:00
|
|
|
if ((dwFlags & MCI_NOTIFY) && lpParms) {
|
|
|
|
MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-12-01 09:28:43 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciFindNextEvent [internal]
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static MCI_MIDITRACK* MIDI_mciFindNextEvent(WINE_MCIMIDI* wmm, LPDWORD hiPulse)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
|
|
|
WORD cnt, nt;
|
|
|
|
MCI_MIDITRACK* mmt;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
*hiPulse = 0xFFFFFFFFul;
|
|
|
|
cnt = 0xFFFFu;
|
|
|
|
for (nt = 0; nt < wmm->nTracks; nt++) {
|
|
|
|
mmt = &wmm->tracks[nt];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (mmt->wStatus == 0)
|
|
|
|
continue;
|
|
|
|
if (mmt->dwEventPulse < *hiPulse) {
|
|
|
|
*hiPulse = mmt->dwEventPulse;
|
|
|
|
cnt = nt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (cnt == 0xFFFFu) ? 0 /* no more event on all tracks */
|
|
|
|
: &wmm->tracks[cnt];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2012-10-04 12:02:35 +02:00
|
|
|
* MIDI_player [internal]
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
2012-10-04 12:34:07 +02:00
|
|
|
static DWORD MIDI_player(WINE_MCIMIDI* wmm, DWORD dwFlags)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
2012-10-04 12:02:35 +02:00
|
|
|
DWORD dwRet;
|
1998-11-24 18:30:37 +01:00
|
|
|
WORD doPlay, nt;
|
|
|
|
MCI_MIDITRACK* mmt;
|
2012-10-04 12:34:07 +02:00
|
|
|
DWORD hiPulse, dwStartMS = wmm->dwPositionMS;
|
2012-10-04 12:02:35 +02:00
|
|
|
HANDLE oldcb = NULL;
|
2009-12-05 05:40:59 +01:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
/* init tracks */
|
|
|
|
for (nt = 0; nt < wmm->nTracks; nt++) {
|
|
|
|
mmt = &wmm->tracks[nt];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
mmt->wStatus = 1; /* ok, playing */
|
|
|
|
mmt->dwIndex = mmt->dwFirst;
|
|
|
|
if (wmm->wFormat == 2 && nt > 0) {
|
|
|
|
mmt->dwEventPulse = wmm->tracks[nt - 1].dwLength;
|
|
|
|
} else {
|
|
|
|
mmt->dwEventPulse = 0;
|
|
|
|
}
|
|
|
|
MIDI_mciReadNextEvent(wmm, mmt); /* FIXME == 0 */
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-03-14 12:49:14 +01:00
|
|
|
dwRet = midiOutOpen((LPHMIDIOUT)&wmm->hMidi, wmm->wPort, 0L, 0L, CALLBACK_NULL);
|
2002-05-12 01:02:55 +02:00
|
|
|
if (dwRet != MMSYSERR_NOERROR) {
|
2012-09-14 16:46:32 +02:00
|
|
|
return mmr2mci(dwRet);
|
2002-05-12 01:02:55 +02:00
|
|
|
}
|
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->dwPulse = 0;
|
|
|
|
wmm->dwTempo = 500000;
|
|
|
|
wmm->dwPositionMS = 0;
|
|
|
|
wmm->wStartedPlaying = FALSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-09-22 22:56:45 +02:00
|
|
|
while (wmm->dwStatus != MCI_MODE_STOP && wmm->dwStatus != MCI_MODE_NOT_READY) {
|
2002-06-01 01:06:46 +02:00
|
|
|
/* it seems that in case of multi-threading, gcc is optimizing just a little bit
|
|
|
|
* too much. Tell gcc not to optimize status value using volatile.
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
|
|
|
while (((volatile WINE_MCIMIDI*)wmm)->dwStatus == MCI_MODE_PAUSE);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2012-10-04 12:34:07 +02:00
|
|
|
doPlay = (wmm->dwPositionMS >= dwStartMS && wmm->dwPositionMS <= wmm->dwEndMS);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-09-27 15:38:57 +02:00
|
|
|
TRACE("wmm->dwStatus=%d, doPlay=%c\n", wmm->dwStatus, doPlay ? 'T' : 'F');
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if ((mmt = MIDI_mciFindNextEvent(wmm, &hiPulse)) == NULL)
|
|
|
|
break; /* no more event on tracks */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-12-01 09:28:43 +01:00
|
|
|
/* if starting playing, then set StartTicks to the value it would have had
|
|
|
|
* if play had started at position 0
|
|
|
|
*/
|
1998-11-24 18:30:37 +01:00
|
|
|
if (doPlay && !wmm->wStartedPlaying) {
|
|
|
|
wmm->dwStartTicks = GetTickCount() - MIDI_ConvertPulseToMS(wmm, wmm->dwPulse);
|
|
|
|
wmm->wStartedPlaying = TRUE;
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("Setting dwStartTicks to %u\n", wmm->dwStartTicks);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (hiPulse > wmm->dwPulse) {
|
1999-04-11 14:19:04 +02:00
|
|
|
wmm->dwPositionMS += MIDI_ConvertPulseToMS(wmm, hiPulse - wmm->dwPulse);
|
1998-11-24 18:30:37 +01:00
|
|
|
if (doPlay) {
|
1999-04-11 14:19:04 +02:00
|
|
|
DWORD togo = wmm->dwStartTicks + wmm->dwPositionMS;
|
1998-11-24 18:30:37 +01:00
|
|
|
DWORD tc = GetTickCount();
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("Pulses hi=0x%08x <> cur=0x%08x\n", hiPulse, wmm->dwPulse);
|
|
|
|
TRACE("Wait until %u => %u ms\n",
|
1998-11-24 18:30:37 +01:00
|
|
|
tc - wmm->dwStartTicks, togo - wmm->dwStartTicks);
|
2002-06-01 01:06:46 +02:00
|
|
|
if (tc < togo)
|
1998-11-24 18:30:37 +01:00
|
|
|
Sleep(togo - tc);
|
|
|
|
}
|
|
|
|
wmm->dwPulse = hiPulse;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
switch (LOBYTE(LOWORD(mmt->dwEventData))) {
|
|
|
|
case 0xF0:
|
|
|
|
case 0xF7: /* sysex events */
|
|
|
|
{
|
1999-05-24 10:17:54 +02:00
|
|
|
FIXME("Not handling SysEx events (yet)\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xFF:
|
|
|
|
/* position after meta data header */
|
1999-02-26 12:11:13 +01:00
|
|
|
mmioSeek(wmm->hFile, mmt->dwIndex + HIWORD(mmt->dwEventData), SEEK_SET);
|
1998-11-24 18:30:37 +01:00
|
|
|
switch (HIBYTE(LOWORD(mmt->dwEventData))) {
|
|
|
|
case 0x00: /* 16-bit sequence number */
|
1999-05-24 10:17:54 +02:00
|
|
|
if (TRACE_ON(mcimidi)) {
|
1998-11-24 18:30:37 +01:00
|
|
|
WORD twd;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
MIDI_mciReadWord(wmm, &twd); /* == 0 */
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("Got sequence number %u\n", twd);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x01: /* any text */
|
|
|
|
case 0x02: /* Copyright Message text */
|
|
|
|
case 0x03: /* Sequence/Track Name text */
|
|
|
|
case 0x04: /* Instrument Name text */
|
|
|
|
case 0x05: /* Lyric text */
|
|
|
|
case 0x06: /* Marker text */
|
|
|
|
case 0x07: /* Cue-point text */
|
|
|
|
if (TRACE_ON(mcimidi)) {
|
|
|
|
char buf[1024];
|
|
|
|
WORD len = mmt->wEventLength - HIWORD(mmt->dwEventData);
|
2007-02-16 17:40:58 +01:00
|
|
|
static const char* const info[8] = {"", "Text", "Copyright", "Seq/Trk name",
|
|
|
|
"Instrument", "Lyric", "Marker", "Cue-point"};
|
1998-11-24 18:30:37 +01:00
|
|
|
WORD idx = HIBYTE(LOWORD(mmt->dwEventData));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (len >= sizeof(buf)) {
|
2006-06-13 14:10:47 +02:00
|
|
|
WARN("Buffer for text is too small (%u are needed)\n", len);
|
1998-11-24 18:30:37 +01:00
|
|
|
len = sizeof(buf) - 1;
|
|
|
|
}
|
2009-01-15 09:44:25 +01:00
|
|
|
if (mmioRead(wmm->hFile, buf, len) == len) {
|
1998-11-24 18:30:37 +01:00
|
|
|
buf[len] = 0; /* end string in case */
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("%s => \"%s\"\n", (idx < 8 ) ? info[idx] : "", buf);
|
1998-11-24 18:30:37 +01:00
|
|
|
} else {
|
2000-01-04 01:25:22 +01:00
|
|
|
WARN("Couldn't read data for %s\n", (idx < 8) ? info[idx] : "");
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
case 0x20:
|
1998-11-24 18:30:37 +01:00
|
|
|
/* MIDI channel (cc) */
|
|
|
|
if (FIXME_ON(mcimidi)) {
|
|
|
|
BYTE bt;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
MIDI_mciReadByte(wmm, &bt); /* == 0 */
|
1999-05-24 10:17:54 +02:00
|
|
|
FIXME("NIY: MIDI channel=%u, track=%u\n", bt, mmt->wTrackNr);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x21:
|
|
|
|
/* MIDI port (pp) */
|
|
|
|
if (FIXME_ON(mcimidi)) {
|
|
|
|
BYTE bt;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
MIDI_mciReadByte(wmm, &bt); /* == 0 */
|
1999-05-24 10:17:54 +02:00
|
|
|
FIXME("NIY: MIDI port=%u, track=%u\n", bt, mmt->wTrackNr);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x2F: /* end of track */
|
|
|
|
mmt->wStatus = 0;
|
|
|
|
break;
|
|
|
|
case 0x51:/* set tempo */
|
2005-08-17 14:15:35 +02:00
|
|
|
/* Tempo is expressed in -seconds per midi quarter note
|
1998-11-24 18:30:37 +01:00
|
|
|
* for format 1 MIDI files, this can only be present on track #0
|
|
|
|
*/
|
|
|
|
if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("For format #1 MIDI files, tempo can only be changed on track #0 (%u)\n", mmt->wTrackNr);
|
2002-06-01 01:06:46 +02:00
|
|
|
} else {
|
1998-11-24 18:30:37 +01:00
|
|
|
BYTE tbt;
|
1998-12-01 09:28:43 +01:00
|
|
|
DWORD value = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-12-01 09:28:43 +01:00
|
|
|
MIDI_mciReadByte(wmm, &tbt); value = ((DWORD)tbt) << 16;
|
|
|
|
MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 8;
|
|
|
|
MIDI_mciReadByte(wmm, &tbt); value |= ((DWORD)tbt) << 0;
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("Setting tempo to %d (BPM=%d)\n", wmm->dwTempo, (value) ? (60000000 / value) : 0);
|
1998-12-01 09:28:43 +01:00
|
|
|
wmm->dwTempo = value;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x54: /* (hour) (min) (second) (frame) (fractional-frame) - SMPTE track start */
|
|
|
|
if (mmt->wTrackNr != 0 && wmm->wFormat == 1) {
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("For format #1 MIDI files, SMPTE track start can only be expressed on track #0 (%u)\n", mmt->wTrackNr);
|
1998-11-24 18:30:37 +01:00
|
|
|
} if (mmt->dwEventPulse != 0) {
|
2006-10-13 02:50:35 +02:00
|
|
|
WARN("SMPTE track start can only be expressed at start of track (%u)\n", mmt->dwEventPulse);
|
1998-11-24 18:30:37 +01:00
|
|
|
} else {
|
|
|
|
BYTE h, m, s, f, ff;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
MIDI_mciReadByte(wmm, &h);
|
|
|
|
MIDI_mciReadByte(wmm, &m);
|
|
|
|
MIDI_mciReadByte(wmm, &s);
|
|
|
|
MIDI_mciReadByte(wmm, &f);
|
|
|
|
MIDI_mciReadByte(wmm, &ff);
|
1999-05-24 10:17:54 +02:00
|
|
|
FIXME("NIY: SMPTE track start %u:%u:%u %u.%u\n", h, m, s, f, ff);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
break;
|
2006-11-07 00:37:42 +01:00
|
|
|
case 0x58: /* file rhythm */
|
1998-11-24 18:30:37 +01:00
|
|
|
if (TRACE_ON(mcimidi)) {
|
|
|
|
BYTE num, den, cpmc, _32npqn;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
MIDI_mciReadByte(wmm, &num);
|
1998-11-24 18:30:37 +01:00
|
|
|
MIDI_mciReadByte(wmm, &den); /* to notate e.g. 6/8 */
|
2002-06-01 01:06:46 +02:00
|
|
|
MIDI_mciReadByte(wmm, &cpmc); /* number of MIDI clocks per metronome click */
|
1999-02-13 13:38:09 +01:00
|
|
|
MIDI_mciReadByte(wmm, &_32npqn); /* number of notated 32nd notes per MIDI quarter note */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("%u/%u, clock per metronome click=%u, 32nd notes by 1/4 note=%u\n", num, 1 << den, cpmc, _32npqn);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x59: /* key signature */
|
|
|
|
if (TRACE_ON(mcimidi)) {
|
|
|
|
BYTE sf, mm;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
MIDI_mciReadByte(wmm, &sf);
|
|
|
|
MIDI_mciReadByte(wmm, &mm);
|
|
|
|
|
|
|
|
if (sf >= 0x80) TRACE("%d flats\n", -(char)sf);
|
|
|
|
else if (sf > 0) TRACE("%d sharps\n", (char)sf);
|
1999-05-24 10:17:54 +02:00
|
|
|
else TRACE("Key of C\n");
|
2005-02-09 23:26:25 +01:00
|
|
|
TRACE("Mode: %s\n", (mm == 0) ? "major" : "minor");
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("Unknown MIDI meta event %02x. Skipping...\n", HIBYTE(LOWORD(mmt->dwEventData)));
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (doPlay) {
|
2002-08-01 20:17:51 +02:00
|
|
|
dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
|
1998-11-24 18:30:37 +01:00
|
|
|
} else {
|
|
|
|
switch (LOBYTE(LOWORD(mmt->dwEventData)) & 0xF0) {
|
|
|
|
case MIDI_NOTEON:
|
|
|
|
case MIDI_NOTEOFF:
|
2002-06-01 01:06:46 +02:00
|
|
|
dwRet = 0;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
default:
|
2002-08-01 20:17:51 +02:00
|
|
|
dwRet = midiOutShortMsg((HMIDIOUT)wmm->hMidi, mmt->dwEventData);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mmt->dwIndex += mmt->wEventLength;
|
|
|
|
if (mmt->dwIndex < mmt->dwFirst || mmt->dwIndex >= mmt->dwLast) {
|
|
|
|
mmt->wStatus = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
|
|
|
if (mmt->wStatus) {
|
1998-11-24 18:30:37 +01:00
|
|
|
MIDI_mciReadNextEvent(wmm, mmt);
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-08-01 20:17:51 +02:00
|
|
|
midiOutReset((HMIDIOUT)wmm->hMidi);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-08-01 20:17:51 +02:00
|
|
|
dwRet = midiOutClose((HMIDIOUT)wmm->hMidi);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-12-05 05:40:59 +01:00
|
|
|
if (dwFlags & MCI_NOTIFY)
|
|
|
|
oldcb = InterlockedExchangePointer(&wmm->hCallback, NULL);
|
2000-09-22 22:56:45 +02:00
|
|
|
|
|
|
|
wmm->dwStatus = MCI_MODE_STOP;
|
2009-12-05 05:40:59 +01:00
|
|
|
|
|
|
|
/* Let the potentially asynchronous commands support FAILURE notification. */
|
2010-12-15 22:36:01 +01:00
|
|
|
if (oldcb) mciDriverNotify(oldcb, wmm->wDevID,
|
2009-12-05 05:40:59 +01:00
|
|
|
dwRet ? MCI_NOTIFY_FAILURE : MCI_NOTIFY_SUCCESSFUL);
|
2012-09-14 16:46:32 +02:00
|
|
|
return mmr2mci(dwRet);
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
|
2012-10-04 12:34:07 +02:00
|
|
|
static DWORD CALLBACK MIDI_Starter(void *ptr)
|
|
|
|
{
|
|
|
|
WINE_MCIMIDI* wmm = ptr;
|
|
|
|
return MIDI_player(wmm, MCI_NOTIFY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD ensurePlayerThread(WINE_MCIMIDI* wmm)
|
|
|
|
{
|
|
|
|
if (1) {
|
|
|
|
DWORD dwRet;
|
|
|
|
|
|
|
|
switch (wmm->dwStatus) {
|
|
|
|
default:
|
|
|
|
return MCIERR_NONAPPLICABLE_FUNCTION;
|
|
|
|
case MCI_MODE_PAUSE:
|
|
|
|
return MIDI_mciResume(wmm, 0, NULL);
|
|
|
|
case MCI_MODE_PLAY:
|
|
|
|
/* the player was not stopped, use it */
|
|
|
|
return 0;
|
|
|
|
case MCI_MODE_STOP:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wmm->dwStatus = MCI_MODE_PLAY;
|
|
|
|
if (wmm->hThread) {
|
|
|
|
WaitForSingleObject(wmm->hThread, INFINITE);
|
|
|
|
CloseHandle(wmm->hThread);
|
|
|
|
wmm->hThread = 0;
|
|
|
|
}
|
|
|
|
wmm->hThread = CreateThread(NULL, 0, MIDI_Starter, wmm, 0, NULL);
|
|
|
|
if (!wmm->hThread) {
|
|
|
|
dwRet = MCIERR_OUT_OF_MEMORY;
|
|
|
|
} else {
|
|
|
|
SetThreadPriority(wmm->hThread, THREAD_PRIORITY_TIME_CRITICAL);
|
|
|
|
dwRet = 0;
|
|
|
|
}
|
|
|
|
if (dwRet)
|
|
|
|
wmm->dwStatus = MCI_MODE_STOP;
|
|
|
|
return dwRet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-04 12:02:35 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciPlay [internal]
|
|
|
|
*/
|
|
|
|
static DWORD MIDI_mciPlay(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
|
|
|
|
{
|
|
|
|
DWORD dwStartMS, dwEndMS;
|
2012-10-04 12:34:07 +02:00
|
|
|
DWORD dwRet;
|
2012-10-04 12:02:35 +02:00
|
|
|
HANDLE oldcb;
|
|
|
|
|
|
|
|
TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
|
|
|
|
|
|
|
|
if (wmm->hFile == 0) {
|
|
|
|
WARN("Can't play: no file %s!\n", debugstr_w(wmm->lpstrElementName));
|
|
|
|
return MCIERR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2011-03-01 21:35:23 +01:00
|
|
|
if (lpParms && (dwFlags & MCI_TO)) {
|
|
|
|
dwEndMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
|
|
|
|
/* FIXME: if (dwEndMS > length) return MCIERR_OUTOFRANGE; */
|
|
|
|
} else {
|
|
|
|
dwEndMS = 0xFFFFFFFFul; /* FIXME: dwEndMS = length; */
|
|
|
|
}
|
2012-10-04 12:02:35 +02:00
|
|
|
if (lpParms && (dwFlags & MCI_FROM)) {
|
|
|
|
dwStartMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwFrom);
|
|
|
|
} else {
|
|
|
|
dwStartMS = wmm->dwPositionMS;
|
|
|
|
}
|
2011-03-01 21:35:23 +01:00
|
|
|
if (dwEndMS < dwStartMS)
|
|
|
|
return MCIERR_OUTOFRANGE;
|
2012-10-04 12:02:35 +02:00
|
|
|
|
2012-10-04 12:34:07 +02:00
|
|
|
if (dwFlags & MCI_FROM) {
|
|
|
|
/* Stop with MCI_NOTIFY_ABORTED and set new position. */
|
|
|
|
MIDI_mciStop(wmm, MCI_WAIT, NULL);
|
|
|
|
wmm->dwPositionMS = dwStartMS;
|
|
|
|
} /* else use existing player. */
|
2012-10-01 21:53:04 +02:00
|
|
|
if (wmm->dwEndMS != dwEndMS) {
|
|
|
|
oldcb = InterlockedExchangePointer(&wmm->hCallback, NULL);
|
|
|
|
if (oldcb) mciDriverNotify(oldcb, wmm->wDevID, MCI_NOTIFY_ABORTED);
|
|
|
|
wmm->dwEndMS = dwEndMS;
|
|
|
|
}
|
2012-10-04 12:34:07 +02:00
|
|
|
|
2012-10-04 12:02:35 +02:00
|
|
|
TRACE("Playing from %u to %u\n", dwStartMS, dwEndMS);
|
|
|
|
|
2012-10-01 21:53:04 +02:00
|
|
|
if ((dwFlags & MCI_NOTIFY) && lpParms) {
|
|
|
|
oldcb = InterlockedExchangePointer(&wmm->hCallback, HWND_32(LOWORD(lpParms->dwCallback)));
|
|
|
|
if (oldcb) mciDriverNotify(oldcb, wmm->wDevID, MCI_NOTIFY_SUPERSEDED);
|
|
|
|
}
|
2012-10-04 12:02:35 +02:00
|
|
|
|
2012-10-04 12:34:07 +02:00
|
|
|
dwRet = ensurePlayerThread(wmm);
|
|
|
|
|
|
|
|
if (!dwRet && (dwFlags & MCI_WAIT)) {
|
|
|
|
WaitForSingleObject(wmm->hThread, INFINITE);
|
|
|
|
GetExitCodeThread(wmm->hThread, &dwRet);
|
|
|
|
/* STATUS_PENDING cannot happen. It folds onto MCIERR_UNRECOGNIZED_KEYWORD */
|
|
|
|
}
|
|
|
|
/* The player thread performs notification at exit. */
|
|
|
|
return dwRet;
|
2012-10-04 12:02:35 +02:00
|
|
|
}
|
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciPause [internal]
|
|
|
|
*/
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciPause(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (wmm->dwStatus == MCI_MODE_PLAY) {
|
|
|
|
/* stop all notes */
|
|
|
|
unsigned chn;
|
|
|
|
for (chn = 0; chn < 16; chn++)
|
2002-08-01 20:17:51 +02:00
|
|
|
midiOutShortMsg((HMIDIOUT)(wmm->hMidi), 0x78B0 | chn);
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->dwStatus = MCI_MODE_PAUSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2009-12-05 05:40:59 +01:00
|
|
|
if ((dwFlags & MCI_NOTIFY) && lpParms)
|
|
|
|
MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
|
1998-11-24 18:30:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciResume [internal]
|
|
|
|
*/
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciResume(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (wmm->dwStatus == MCI_MODE_PAUSE) {
|
|
|
|
wmm->wStartedPlaying = FALSE;
|
|
|
|
wmm->dwStatus = MCI_MODE_PLAY;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2009-12-05 05:40:59 +01:00
|
|
|
if ((dwFlags & MCI_NOTIFY) && lpParms)
|
|
|
|
MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
|
1998-11-24 18:30:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciSet [internal]
|
|
|
|
*/
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciSet(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_SEQ_SET_PARMS lpParms)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (dwFlags & MCI_SET_TIME_FORMAT) {
|
|
|
|
switch (lpParms->dwTimeFormat) {
|
|
|
|
case MCI_FORMAT_MILLISECONDS:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_FORMAT_MILLISECONDS !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->dwMciTimeFormat = MCI_FORMAT_MILLISECONDS;
|
|
|
|
break;
|
|
|
|
case MCI_FORMAT_SMPTE_24:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_FORMAT_SMPTE_24 !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_24;
|
|
|
|
break;
|
|
|
|
case MCI_FORMAT_SMPTE_25:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_FORMAT_SMPTE_25 !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_25;
|
|
|
|
break;
|
|
|
|
case MCI_FORMAT_SMPTE_30:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_FORMAT_SMPTE_30 !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
wmm->dwMciTimeFormat = MCI_FORMAT_SMPTE_30;
|
|
|
|
break;
|
|
|
|
default:
|
2006-10-13 02:50:35 +02:00
|
|
|
WARN("Bad time format %u!\n", lpParms->dwTimeFormat);
|
1998-11-24 18:30:37 +01:00
|
|
|
return MCIERR_BAD_TIME_FORMAT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dwFlags & MCI_SET_VIDEO) {
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("No support for video !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
return MCIERR_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
if (dwFlags & MCI_SET_DOOR_OPEN) {
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("No support for door open !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
return MCIERR_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
if (dwFlags & MCI_SET_DOOR_CLOSED) {
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("No support for door close !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
return MCIERR_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
if (dwFlags & MCI_SET_AUDIO) {
|
|
|
|
if (dwFlags & MCI_SET_ON) {
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SET_ON audio !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
} else if (dwFlags & MCI_SET_OFF) {
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SET_OFF audio !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
} else {
|
1999-05-24 10:17:54 +02:00
|
|
|
WARN("MCI_SET_AUDIO without SET_ON or SET_OFF\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
return MCIERR_BAD_INTEGER;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-02-09 23:26:25 +01:00
|
|
|
switch (lpParms->dwAudio)
|
|
|
|
{
|
|
|
|
case MCI_SET_AUDIO_ALL: TRACE("MCI_SET_AUDIO_ALL !\n"); break;
|
|
|
|
case MCI_SET_AUDIO_LEFT: TRACE("MCI_SET_AUDIO_LEFT !\n"); break;
|
|
|
|
case MCI_SET_AUDIO_RIGHT: TRACE("MCI_SET_AUDIO_RIGHT !\n"); break;
|
2006-10-13 02:50:35 +02:00
|
|
|
default: WARN("Unknown audio channel %u\n", lpParms->dwAudio); break;
|
2005-02-09 23:26:25 +01:00
|
|
|
}
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (dwFlags & MCI_SEQ_SET_MASTER)
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SEQ_SET_MASTER !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
if (dwFlags & MCI_SEQ_SET_SLAVE)
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SEQ_SET_SLAVE !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
if (dwFlags & MCI_SEQ_SET_OFFSET)
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SEQ_SET_OFFSET !\n");
|
2010-03-14 12:49:14 +01:00
|
|
|
if (dwFlags & MCI_SEQ_SET_PORT) {
|
|
|
|
TRACE("MCI_SEQ_SET_PORT = %d\n", lpParms->dwPort);
|
|
|
|
if ((UINT16)lpParms->dwPort != (UINT16)MIDI_MAPPER &&
|
|
|
|
(UINT16)lpParms->dwPort >= midiOutGetNumDevs())
|
|
|
|
/* FIXME: input/output port distinction? */
|
|
|
|
return MCIERR_SEQ_PORT_NONEXISTENT;
|
|
|
|
/* FIXME: Native manages to swap the device while playing! */
|
|
|
|
wmm->wPort = lpParms->dwPort;
|
|
|
|
}
|
1998-11-24 18:30:37 +01:00
|
|
|
if (dwFlags & MCI_SEQ_SET_TEMPO)
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SEQ_SET_TEMPO !\n");
|
2009-12-05 05:40:59 +01:00
|
|
|
if (dwFlags & MCI_NOTIFY)
|
|
|
|
MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
|
1998-11-24 18:30:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciStatus [internal]
|
|
|
|
*/
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciStatus(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
1999-07-24 12:45:24 +02:00
|
|
|
DWORD ret = 0;
|
|
|
|
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (dwFlags & MCI_STATUS_ITEM) {
|
|
|
|
switch (lpParms->dwItem) {
|
|
|
|
case MCI_STATUS_CURRENT_TRACK:
|
|
|
|
/* FIXME in Format 2 */
|
|
|
|
lpParms->dwReturn = 1;
|
2009-01-09 17:46:46 +01:00
|
|
|
TRACE("MCI_STATUS_CURRENT_TRACK => %lu\n", lpParms->dwReturn);
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_STATUS_LENGTH:
|
|
|
|
if ((dwFlags & MCI_TRACK) && wmm->wFormat == 2) {
|
|
|
|
if (lpParms->dwTrack >= wmm->nTracks)
|
2012-09-16 01:07:12 +02:00
|
|
|
return MCIERR_OUTOFRANGE;
|
1998-12-01 09:28:43 +01:00
|
|
|
/* FIXME: this is wrong if there is a tempo change inside the file */
|
1998-11-24 18:30:37 +01:00
|
|
|
lpParms->dwReturn = MIDI_ConvertPulseToMS(wmm, wmm->tracks[lpParms->dwTrack].dwLength);
|
|
|
|
} else {
|
|
|
|
lpParms->dwReturn = MIDI_GetMThdLengthMS(wmm);
|
|
|
|
}
|
|
|
|
lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm, lpParms->dwReturn);
|
2012-09-16 01:07:12 +02:00
|
|
|
/* FIXME: ret = MCI_COLONIZED4_RETURN if SMPTE */
|
2009-01-09 17:46:46 +01:00
|
|
|
TRACE("MCI_STATUS_LENGTH => %lu\n", lpParms->dwReturn);
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_STATUS_MODE:
|
1999-07-24 12:45:24 +02:00
|
|
|
TRACE("MCI_STATUS_MODE => %u\n", wmm->dwStatus);
|
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwStatus, wmm->dwStatus);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_STATUS_MEDIA_PRESENT:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_STATUS_MEDIA_PRESENT => TRUE\n");
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_STATUS_NUMBER_OF_TRACKS:
|
|
|
|
lpParms->dwReturn = (wmm->wFormat == 2) ? wmm->nTracks : 1;
|
2009-01-09 17:46:46 +01:00
|
|
|
TRACE("MCI_STATUS_NUMBER_OF_TRACKS => %lu\n", lpParms->dwReturn);
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_STATUS_POSITION:
|
2012-09-16 01:07:12 +02:00
|
|
|
/* FIXME: check MCI_TRACK == 1 if set */
|
2002-06-01 01:06:46 +02:00
|
|
|
lpParms->dwReturn = MIDI_ConvertMSToTimeFormat(wmm,
|
1998-11-24 18:30:37 +01:00
|
|
|
(dwFlags & MCI_STATUS_START) ? 0 : wmm->dwPositionMS);
|
2012-09-16 01:07:12 +02:00
|
|
|
/* FIXME: ret = MCI_COLONIZED4_RETURN if SMPTE */
|
2009-01-09 17:46:46 +01:00
|
|
|
TRACE("MCI_STATUS_POSITION %s => %lu\n",
|
1998-11-24 18:30:37 +01:00
|
|
|
(dwFlags & MCI_STATUS_START) ? "start" : "current", lpParms->dwReturn);
|
|
|
|
break;
|
|
|
|
case MCI_STATUS_READY:
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = (wmm->dwStatus == MCI_MODE_NOT_READY) ?
|
|
|
|
MAKEMCIRESOURCE(FALSE, MCI_FALSE) : MAKEMCIRESOURCE(TRUE, MCI_TRUE);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
|
|
|
TRACE("MCI_STATUS_READY = %u\n", LOWORD(lpParms->dwReturn));
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_STATUS_TIME_FORMAT:
|
2004-01-08 01:42:02 +01:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(wmm->dwMciTimeFormat, MCI_FORMAT_RETURN_BASE + wmm->dwMciTimeFormat);
|
1999-07-24 12:45:24 +02:00
|
|
|
TRACE("MCI_STATUS_TIME_FORMAT => %u\n", LOWORD(lpParms->dwReturn));
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_SEQ_STATUS_DIVTYPE:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SEQ_STATUS_DIVTYPE !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
if (wmm->nDivision > 0x8000) {
|
2012-09-16 01:07:12 +02:00
|
|
|
switch (HIBYTE(wmm->nDivision)) {
|
1998-11-24 18:30:37 +01:00
|
|
|
case 0xE8: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_24; break; /* -24 */
|
|
|
|
case 0xE7: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_25; break; /* -25 */
|
|
|
|
case 0xE3: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30DROP; break; /* -29 */ /* is the MCI constant correct ? */
|
|
|
|
case 0xE2: lpParms->dwReturn = MCI_SEQ_DIV_SMPTE_30; break; /* -30 */
|
1999-05-24 10:17:54 +02:00
|
|
|
default: FIXME("There is a bad bad programmer\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lpParms->dwReturn = MCI_SEQ_DIV_PPQN;
|
|
|
|
}
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(lpParms->dwReturn,lpParms->dwReturn);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_SEQ_STATUS_MASTER:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SEQ_STATUS_MASTER !\n");
|
2012-09-16 01:07:12 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(MCI_SEQ_NONE, MCI_SEQ_NONE_S);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_SEQ_STATUS_SLAVE:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SEQ_STATUS_SLAVE !\n");
|
2012-09-16 01:07:12 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(MCI_SEQ_FILE, MCI_SEQ_FILE_S);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_SEQ_STATUS_OFFSET:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SEQ_STATUS_OFFSET !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
lpParms->dwReturn = 0;
|
|
|
|
break;
|
|
|
|
case MCI_SEQ_STATUS_PORT:
|
2010-03-14 12:49:14 +01:00
|
|
|
if (wmm->wPort != (UINT16)MIDI_MAPPER)
|
|
|
|
lpParms->dwReturn = wmm->wPort;
|
|
|
|
else {
|
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(MIDI_MAPPER, MCI_SEQ_MAPPER_S);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
|
|
|
}
|
|
|
|
TRACE("MCI_SEQ_STATUS_PORT (%u) => %d\n", wmm->wDevID, wmm->wPort);
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_SEQ_STATUS_TEMPO:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_SEQ_STATUS_TEMPO !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
lpParms->dwReturn = wmm->dwTempo;
|
|
|
|
break;
|
|
|
|
default:
|
2008-12-23 11:54:51 +01:00
|
|
|
FIXME("Unknown command %08X !\n", lpParms->dwItem);
|
2012-09-16 01:07:12 +02:00
|
|
|
return MCIERR_UNSUPPORTED_FUNCTION;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
2012-09-16 01:07:12 +02:00
|
|
|
return MCIERR_MISSING_PARAMETER;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2009-12-05 05:40:59 +01:00
|
|
|
if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
|
|
|
|
MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
|
1999-07-24 12:45:24 +02:00
|
|
|
return ret;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciGetDevCaps [internal]
|
|
|
|
*/
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciGetDevCaps(WINE_MCIMIDI* wmm, DWORD dwFlags,
|
1998-11-24 18:30:37 +01:00
|
|
|
LPMCI_GETDEVCAPS_PARMS lpParms)
|
|
|
|
{
|
1999-07-24 12:45:24 +02:00
|
|
|
DWORD ret;
|
|
|
|
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1998-11-24 18:30:37 +01:00
|
|
|
if (dwFlags & MCI_GETDEVCAPS_ITEM) {
|
|
|
|
switch (lpParms->dwItem) {
|
|
|
|
case MCI_GETDEVCAPS_DEVICE_TYPE:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_GETDEVCAPS_DEVICE_TYPE !\n");
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_SEQUENCER, MCI_DEVTYPE_SEQUENCER);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_GETDEVCAPS_HAS_AUDIO:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_GETDEVCAPS_HAS_AUDIO !\n");
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_GETDEVCAPS_HAS_VIDEO:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_GETDEVCAPS_HAS_VIDEO !\n");
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_GETDEVCAPS_USES_FILES:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_GETDEVCAPS_USES_FILES !\n");
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_GETDEVCAPS_COMPOUND_DEVICE:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_GETDEVCAPS_COMPOUND_DEVICE !\n");
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_GETDEVCAPS_CAN_EJECT:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_GETDEVCAPS_CAN_EJECT !\n");
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_GETDEVCAPS_CAN_PLAY:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_GETDEVCAPS_CAN_PLAY !\n");
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_GETDEVCAPS_CAN_RECORD:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_GETDEVCAPS_CAN_RECORD !\n");
|
2010-06-01 22:33:43 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
|
1999-07-24 12:45:24 +02:00
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
case MCI_GETDEVCAPS_CAN_SAVE:
|
1999-05-24 10:17:54 +02:00
|
|
|
TRACE("MCI_GETDEVCAPS_CAN_SAVE !\n");
|
1999-07-24 12:45:24 +02:00
|
|
|
lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
|
|
|
|
ret = MCI_RESOURCE_RETURNED;
|
1998-11-24 18:30:37 +01:00
|
|
|
break;
|
|
|
|
default:
|
2006-10-13 02:50:35 +02:00
|
|
|
FIXME("Unknown capability (%08x) !\n", lpParms->dwItem);
|
1998-11-24 18:30:37 +01:00
|
|
|
return MCIERR_UNRECOGNIZED_COMMAND;
|
|
|
|
}
|
|
|
|
} else {
|
1999-07-24 12:45:24 +02:00
|
|
|
WARN("No GetDevCaps-Item !\n");
|
1998-11-24 18:30:37 +01:00
|
|
|
return MCIERR_UNRECOGNIZED_COMMAND;
|
|
|
|
}
|
2009-12-05 05:40:59 +01:00
|
|
|
if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
|
|
|
|
MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
|
1999-07-24 12:45:24 +02:00
|
|
|
return ret;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciInfo [internal]
|
|
|
|
*/
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciInfo(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_INFO_PARMSW lpParms)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
2005-02-09 23:26:25 +01:00
|
|
|
LPCWSTR str = 0;
|
1999-09-27 15:38:57 +02:00
|
|
|
DWORD ret = 0;
|
2005-02-09 23:26:25 +01:00
|
|
|
static const WCHAR wszMidiSeq[] = {'W','i','n','e','\'','s',' ','M','I','D','I',' ','s','e','q','u','e','n','c','e','r',0};
|
1999-09-27 15:38:57 +02:00
|
|
|
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-07-24 12:45:24 +02:00
|
|
|
if (lpParms == NULL || lpParms->lpstrReturn == NULL)
|
|
|
|
return MCIERR_NULL_PARAMETER_BLOCK;
|
|
|
|
|
2006-10-13 02:50:35 +02:00
|
|
|
TRACE("buf=%p, len=%u\n", lpParms->lpstrReturn, lpParms->dwRetSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-01-04 01:25:22 +01:00
|
|
|
switch (dwFlags & ~(MCI_WAIT|MCI_NOTIFY)) {
|
2005-02-09 23:26:25 +01:00
|
|
|
case MCI_INFO_PRODUCT: str = wszMidiSeq; break;
|
|
|
|
case MCI_INFO_FILE: str = wmm->lpstrElementName; break;
|
|
|
|
case MCI_INFO_COPYRIGHT: str = wmm->lpstrCopyright; break;
|
|
|
|
case MCI_INFO_NAME: str = wmm->lpstrName; break;
|
1999-07-24 12:45:24 +02:00
|
|
|
default:
|
2006-10-13 02:50:35 +02:00
|
|
|
WARN("Don't know this info command (%u)\n", dwFlags);
|
2012-09-19 22:26:17 +02:00
|
|
|
return MCIERR_MISSING_PARAMETER; /* not MCIERR_FLAGS_... */
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2010-10-05 21:09:11 +02:00
|
|
|
if (!ret) {
|
|
|
|
if (lpParms->dwRetSize) {
|
|
|
|
WCHAR zero = 0;
|
|
|
|
/* FIXME? Since NT, mciwave, mciseq and mcicda set dwRetSize
|
|
|
|
* to the number of characters written, excluding \0. */
|
|
|
|
lstrcpynW(lpParms->lpstrReturn, str ? str : &zero, lpParms->dwRetSize);
|
|
|
|
} else ret = MCIERR_PARAM_OVERFLOW;
|
1999-09-27 15:38:57 +02:00
|
|
|
}
|
2009-12-05 05:40:59 +01:00
|
|
|
if (MMSYSERR_NOERROR==ret && (dwFlags & MCI_NOTIFY))
|
|
|
|
MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
|
1999-09-27 15:38:57 +02:00
|
|
|
return ret;
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* MIDI_mciSeek [internal]
|
|
|
|
*/
|
2010-12-15 22:36:01 +01:00
|
|
|
static DWORD MIDI_mciSeek(WINE_MCIMIDI* wmm, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
2012-09-16 00:50:15 +02:00
|
|
|
DWORD position;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-12-15 22:36:01 +01:00
|
|
|
TRACE("(%d, %08X, %p);\n", wmm->wDevID, dwFlags, lpParms);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2012-09-16 00:50:15 +02:00
|
|
|
if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2012-09-16 00:50:15 +02:00
|
|
|
position = dwFlags & (MCI_SEEK_TO_START|MCI_SEEK_TO_END|MCI_TO);
|
|
|
|
if (!position) return MCIERR_MISSING_PARAMETER;
|
|
|
|
if (position&(position-1)) return MCIERR_FLAGS_NOT_COMPATIBLE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2012-09-16 00:50:15 +02:00
|
|
|
MIDI_mciStop(wmm, MCI_WAIT, 0);
|
|
|
|
|
|
|
|
if (dwFlags & MCI_TO) { /* FIXME: compare with length */
|
|
|
|
wmm->dwPositionMS = MIDI_ConvertTimeFormatToMS(wmm, lpParms->dwTo);
|
|
|
|
} else if (dwFlags & MCI_SEEK_TO_START) {
|
|
|
|
wmm->dwPositionMS = 0;
|
|
|
|
} else {
|
|
|
|
wmm->dwPositionMS = 0xFFFFFFFF; /* FIXME */
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
2012-09-16 00:50:15 +02:00
|
|
|
|
|
|
|
TRACE("Seeking to position=%u ms\n", wmm->dwPositionMS);
|
|
|
|
|
|
|
|
if (dwFlags & MCI_NOTIFY)
|
|
|
|
MIDI_mciNotify(lpParms->dwCallback, wmm, MCI_NOTIFY_SUCCESSFUL);
|
|
|
|
|
|
|
|
return 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
1998-11-24 18:30:37 +01:00
|
|
|
|
|
|
|
/*======================================================================*
|
|
|
|
* MIDI entry points *
|
|
|
|
*======================================================================*/
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* DriverProc (MCISEQ.@)
|
1998-11-24 18:30:37 +01:00
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
LRESULT CALLBACK MCIMIDI_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
|
|
|
|
LPARAM dwParam1, LPARAM dwParam2)
|
1998-11-24 18:30:37 +01:00
|
|
|
{
|
2010-12-15 22:36:01 +01:00
|
|
|
WINE_MCIMIDI* wmm;
|
1998-11-24 18:30:37 +01:00
|
|
|
switch (wMsg) {
|
|
|
|
case DRV_LOAD: return 1;
|
|
|
|
case DRV_FREE: return 1;
|
|
|
|
case DRV_ENABLE: return 1;
|
|
|
|
case DRV_DISABLE: return 1;
|
|
|
|
case DRV_QUERYCONFIGURE: return 1;
|
1999-05-02 12:21:49 +02:00
|
|
|
case DRV_CONFIGURE: MessageBoxA(0, "Sample Midi Driver !", "OSS Driver", MB_OK); return 1;
|
1998-11-24 18:30:37 +01:00
|
|
|
case DRV_INSTALL: return DRVCNF_RESTART;
|
|
|
|
case DRV_REMOVE: return DRVCNF_RESTART;
|
2005-02-09 23:26:25 +01:00
|
|
|
case DRV_OPEN: return MIDI_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
|
1999-07-04 13:05:57 +02:00
|
|
|
case DRV_CLOSE: return MIDI_drvClose(dwDevID);
|
2002-05-12 01:02:55 +02:00
|
|
|
}
|
2010-12-15 21:49:58 +01:00
|
|
|
if ((wMsg < DRV_MCI_FIRST) || (wMsg > DRV_MCI_LAST)) {
|
|
|
|
TRACE("Sending msg %04x to default driver proc\n", wMsg);
|
|
|
|
return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
|
|
|
|
}
|
2010-12-15 22:36:01 +01:00
|
|
|
|
2010-12-15 22:47:45 +01:00
|
|
|
wmm = MIDI_mciGetOpenDev(dwDevID, wMsg);
|
2010-12-15 22:36:01 +01:00
|
|
|
if (wmm == NULL) return MCIERR_INVALID_DEVICE_ID;
|
|
|
|
|
2002-05-12 01:02:55 +02:00
|
|
|
switch (wMsg) {
|
2010-12-15 22:36:01 +01:00
|
|
|
case MCI_OPEN_DRIVER: return MIDI_mciOpen (wmm, dwParam1, (LPMCI_OPEN_PARMSW) dwParam2);
|
|
|
|
case MCI_CLOSE_DRIVER: return MIDI_mciClose (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
|
|
|
|
case MCI_PLAY: return MIDI_mciPlay (wmm, dwParam1, (LPMCI_PLAY_PARMS) dwParam2);
|
|
|
|
case MCI_STOP: return MIDI_mciStop (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
|
|
|
|
case MCI_SET: return MIDI_mciSet (wmm, dwParam1, (LPMCI_SEQ_SET_PARMS) dwParam2);
|
|
|
|
case MCI_PAUSE: return MIDI_mciPause (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
|
|
|
|
case MCI_RESUME: return MIDI_mciResume (wmm, dwParam1, (LPMCI_GENERIC_PARMS) dwParam2);
|
|
|
|
case MCI_STATUS: return MIDI_mciStatus (wmm, dwParam1, (LPMCI_STATUS_PARMS) dwParam2);
|
|
|
|
case MCI_GETDEVCAPS: return MIDI_mciGetDevCaps(wmm, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2);
|
|
|
|
case MCI_INFO: return MIDI_mciInfo (wmm, dwParam1, (LPMCI_INFO_PARMSW) dwParam2);
|
|
|
|
case MCI_SEEK: return MIDI_mciSeek (wmm, dwParam1, (LPMCI_SEEK_PARMS) dwParam2);
|
1998-11-24 18:30:37 +01:00
|
|
|
case MCI_OPEN:
|
|
|
|
case MCI_CLOSE:
|
1999-05-24 10:17:54 +02:00
|
|
|
FIXME("Shouldn't receive a MCI_OPEN or CLOSE message\n");
|
2010-12-15 21:49:58 +01:00
|
|
|
/* fall through */
|
2002-06-01 01:06:46 +02:00
|
|
|
default:
|
2010-12-15 21:49:58 +01:00
|
|
|
TRACE("Unsupported command [0x%x]\n", wMsg);
|
|
|
|
return MCIERR_UNSUPPORTED_FUNCTION; /* Win9x: MCIERR_UNRECOGNIZED_COMMAND */
|
1998-11-24 18:30:37 +01:00
|
|
|
}
|
|
|
|
}
|