2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2003-04-02 03:23:43 +02:00
|
|
|
* Wine MIDI mapper driver
|
1999-10-31 03:23:49 +01:00
|
|
|
*
|
2001-05-22 21:20:53 +02:00
|
|
|
* Copyright 1999, 2000, 2001 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
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2001-05-22 21:20:53 +02:00
|
|
|
* TODO:
|
|
|
|
* notification has to be implemented
|
|
|
|
* IDF file loading
|
1999-10-31 03:23:49 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2001-05-22 21:20:53 +02:00
|
|
|
#include <stdlib.h>
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "windef.h"
|
2000-12-19 05:53:20 +01:00
|
|
|
#include "winbase.h"
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "wingdi.h"
|
1999-10-31 03:23:49 +01:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "mmddk.h"
|
2001-05-22 21:20:53 +02:00
|
|
|
#include "winreg.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
/*
|
|
|
|
* Here's how Windows stores the midiOut mapping information.
|
|
|
|
*
|
2021-07-24 14:45:24 +02:00
|
|
|
* Windows XP form (in HKU) is:
|
|
|
|
*
|
|
|
|
* [Software\\Microsoft\\Windows\\CurrentVersion\\Multimedia\\MIDIMap]
|
|
|
|
* "szPname"="TiMidity port 0"
|
|
|
|
* (incomplete)
|
|
|
|
*
|
|
|
|
* szPname: name of midiOut device to use.
|
|
|
|
*
|
|
|
|
* If szPname isn't defined, we use Windows 2000 form (also in HKU):
|
2001-05-22 21:20:53 +02:00
|
|
|
*
|
|
|
|
* [Software\\Microsoft\\Windows\\CurrentVersion\\Multimedia\\MIDIMap] 988836060
|
|
|
|
* "AutoScheme"=dword:00000000
|
|
|
|
* "ConfigureCount"=dword:00000004
|
|
|
|
* "CurrentInstrument"="Wine OSS midi"
|
|
|
|
* "CurrentScheme"="epp"
|
|
|
|
* "DriverList"=""
|
|
|
|
* "UseScheme"=dword:00000000
|
|
|
|
*
|
|
|
|
* AutoScheme: ?
|
|
|
|
* CurrentInstrument: name of midiOut device to use when UseScheme is 0. Wine uses an extension
|
|
|
|
* of the form #n to link to n'th midiOut device of the system
|
|
|
|
* CurrentScheme: when UseScheme is non null, it's the scheme to use (see below)
|
|
|
|
* DriverList: ?
|
|
|
|
* UseScheme: trigger for simple/complex mapping
|
|
|
|
*
|
|
|
|
* A scheme is defined (in HKLM) as:
|
|
|
|
*
|
|
|
|
* [System\\CurrentControlSet\\Control\\MediaProperties\\PrivateProperties\\Midi\\Schemes\\<nameScheme>]
|
|
|
|
* <nameScheme>: one key for each defined scheme (system wide)
|
|
|
|
* under each one of these <nameScheme> keys, there's:
|
|
|
|
* [...\\<nameScheme>\\<idxDevice>]
|
|
|
|
* "Channels"="<bitMask>"
|
|
|
|
* (the default value of this key also refers to the name of the device).
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* this defines, for each midiOut device (identified by its index in <idxDevice>), which
|
2001-05-22 21:20:53 +02:00
|
|
|
* channels have to be mapped onto it. The <bitMask> defines the channels (from 0 to 15)
|
|
|
|
* will be mapped (mapping occurs for channel <ch> if bit <ch> is set in <bitMask>
|
|
|
|
*
|
|
|
|
* Further mapping information can also be defined in:
|
|
|
|
* [System\\CurrentControlSet\\Control\\MediaProperties\\PrivateProperties\\Midi\\Ports\\<nameDevice>\\Instruments\\<idx>]
|
|
|
|
* "Definition"="<.idf file>"
|
|
|
|
* "FriendlyName"="#for .idx file#"
|
|
|
|
* "Port"="<idxPort>"
|
|
|
|
*
|
|
|
|
* This last part isn't implemented (.idf file support).
|
|
|
|
*/
|
|
|
|
|
2021-07-24 14:45:22 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(midi);
|
2017-09-30 22:07:08 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(winediag);
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
typedef struct tagMIDIOUTPORT
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
WCHAR name[MAXPNAMELEN];
|
2001-05-22 21:20:53 +02:00
|
|
|
int loaded;
|
2002-08-01 20:17:51 +02:00
|
|
|
HMIDIOUT hMidi;
|
2001-05-22 21:20:53 +02:00
|
|
|
unsigned short uDevID;
|
|
|
|
LPBYTE lpbPatch;
|
|
|
|
unsigned int aChn[16];
|
|
|
|
} MIDIOUTPORT;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
typedef struct tagMIDIMAPDATA
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
1999-11-21 01:51:05 +01:00
|
|
|
struct tagMIDIMAPDATA* self;
|
2001-05-22 21:20:53 +02:00
|
|
|
MIDIOUTPORT* ChannelMap[16];
|
2010-02-10 19:42:15 +01:00
|
|
|
MIDIOPENDESC midiDesc;
|
|
|
|
WORD wCbFlags;
|
1999-10-31 03:23:49 +01:00
|
|
|
} MIDIMAPDATA;
|
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
static MIDIOUTPORT* midiOutPorts;
|
|
|
|
static unsigned numMidiOutPorts;
|
|
|
|
|
|
|
|
static BOOL MIDIMAP_IsBadData(MIDIMAPDATA* mm)
|
1999-11-21 01:51:05 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
if (!IsBadReadPtr(mm, sizeof(MIDIMAPDATA)) && mm->self == mm)
|
|
|
|
return FALSE;
|
|
|
|
TRACE("Bad midimap data (%p)\n", mm);
|
|
|
|
return TRUE;
|
1999-11-21 01:51:05 +01:00
|
|
|
}
|
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
static BOOL MIDIMAP_FindPort(const WCHAR* name, unsigned* dev)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
for (*dev = 0; *dev < numMidiOutPorts; (*dev)++)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
TRACE("%s\n", wine_dbgstr_w(midiOutPorts[*dev].name));
|
2019-06-11 08:26:30 +02:00
|
|
|
if (lstrcmpW(midiOutPorts[*dev].name, name) == 0)
|
2001-05-22 21:20:53 +02:00
|
|
|
return TRUE;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
2001-05-22 21:20:53 +02:00
|
|
|
/* try the form #nnn */
|
2017-05-16 17:00:10 +02:00
|
|
|
if (*name == '#' && name[1] >= '0' && name[1] <= '9')
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
const WCHAR* ptr = name + 1;
|
|
|
|
*dev = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*dev = *dev * 10 + *ptr - '0';
|
2017-05-16 17:00:10 +02:00
|
|
|
ptr++;
|
|
|
|
} while (*ptr >= '0' && *ptr <= '9');
|
2001-05-22 21:20:53 +02:00
|
|
|
if (*dev < numMidiOutPorts)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
static BOOL MIDIMAP_LoadSettingsDefault(MIDIMAPDATA* mom, const WCHAR* port)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
unsigned i, dev = 0;
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (port != NULL && !MIDIMAP_FindPort(port, &dev))
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
ERR("Registry glitch: couldn't find midi out (%s)\n", wine_dbgstr_w(port));
|
2001-05-22 21:20:53 +02:00
|
|
|
dev = 0;
|
|
|
|
}
|
2001-06-19 20:15:53 +02:00
|
|
|
|
|
|
|
/* this is necessary when no midi out ports are present */
|
|
|
|
if (dev >= numMidiOutPorts)
|
|
|
|
return FALSE;
|
2001-05-22 21:20:53 +02:00
|
|
|
/* sets default */
|
|
|
|
for (i = 0; i < 16; i++) mom->ChannelMap[i] = &midiOutPorts[dev];
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
return TRUE;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
static BOOL MIDIMAP_LoadSettingsScheme(MIDIMAPDATA* mom, const WCHAR* scheme)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
HKEY hSchemesKey, hKey, hPortKey;
|
|
|
|
unsigned i, idx, dev;
|
2004-12-06 21:55:25 +01:00
|
|
|
WCHAR buffer[256], port[256];
|
2001-05-22 21:20:53 +02:00
|
|
|
DWORD type, size, mask;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) mom->ChannelMap[i] = NULL;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (RegOpenKeyA(HKEY_LOCAL_MACHINE,
|
|
|
|
"System\\CurrentControlSet\\Control\\MediaProperties\\PrivateProperties\\Midi\\Schemes",
|
|
|
|
&hSchemesKey))
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-06 21:55:25 +01:00
|
|
|
if (RegOpenKeyW(hSchemesKey, scheme, &hKey))
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
RegCloseKey(hSchemesKey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2018-07-30 21:18:11 +02:00
|
|
|
for (idx = 0; !RegEnumKeyW(hKey, idx, buffer, ARRAY_SIZE(buffer)); idx++)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
if (RegOpenKeyW(hKey, buffer, &hPortKey)) continue;
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
size = sizeof(port);
|
2004-12-06 21:55:25 +01:00
|
|
|
if (RegQueryValueExW(hPortKey, NULL, 0, &type, (void*)port, &size)) continue;
|
1999-11-21 01:51:05 +01:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
if (!MIDIMAP_FindPort(port, &dev)) continue;
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
size = sizeof(mask);
|
|
|
|
if (RegQueryValueExA(hPortKey, "Channels", 0, &type, (void*)&mask, &size))
|
|
|
|
continue;
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
for (i = 0; i < 16; i++)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if (mask & (1 << i))
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if (mom->ChannelMap[i])
|
2001-05-22 21:20:53 +02:00
|
|
|
ERR("Quirks in registry, channel %u is mapped twice\n", i);
|
|
|
|
mom->ChannelMap[i] = &midiOutPorts[dev];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
RegCloseKey(hSchemesKey);
|
|
|
|
RegCloseKey(hKey);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
return TRUE;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
static BOOL MIDIMAP_LoadSettings(MIDIMAPDATA* mom)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
HKEY hKey;
|
|
|
|
BOOL ret;
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (RegOpenKeyA(HKEY_CURRENT_USER,
|
|
|
|
"Software\\Microsoft\\Windows\\CurrentVersion\\Multimedia\\MIDIMap", &hKey))
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
ret = MIDIMAP_LoadSettingsDefault(mom, NULL);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
DWORD type, size, out;
|
2021-07-24 14:45:24 +02:00
|
|
|
WCHAR buffer[256];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2021-07-24 14:45:24 +02:00
|
|
|
size = sizeof(buffer);
|
|
|
|
if (!RegQueryValueExW(hKey, L"szPname", 0, &type, (void*)buffer, &size))
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2021-07-24 14:45:24 +02:00
|
|
|
ret = MIDIMAP_LoadSettingsDefault(mom, buffer);
|
2001-05-22 21:20:53 +02:00
|
|
|
}
|
2021-07-24 14:45:24 +02:00
|
|
|
else
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2021-07-24 14:45:24 +02:00
|
|
|
ret = 2;
|
|
|
|
size = sizeof(out);
|
|
|
|
if (!RegQueryValueExA(hKey, "UseScheme", 0, &type, (void*)&out, &size) && out)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2021-07-24 14:45:24 +02:00
|
|
|
size = sizeof(buffer);
|
|
|
|
if (!RegQueryValueExW(hKey, L"CurrentScheme", 0, &type, (void*)buffer, &size))
|
|
|
|
{
|
|
|
|
if (!(ret = MIDIMAP_LoadSettingsScheme(mom, buffer)))
|
|
|
|
ret = MIDIMAP_LoadSettingsDefault(mom, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Wrong registry: UseScheme is active, but no CurrentScheme found\n");
|
|
|
|
}
|
2001-05-22 21:20:53 +02:00
|
|
|
}
|
2021-07-24 14:45:24 +02:00
|
|
|
if (ret == 2)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2021-07-24 14:45:24 +02:00
|
|
|
size = sizeof(buffer);
|
|
|
|
if (!RegQueryValueExW(hKey, L"CurrentInstrument", 0, &type, (void*)buffer, &size) && *buffer)
|
|
|
|
{
|
|
|
|
ret = MIDIMAP_LoadSettingsDefault(mom, buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = MIDIMAP_LoadSettingsDefault(mom, NULL);
|
|
|
|
}
|
2001-05-22 21:20:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2021-07-24 14:45:22 +02:00
|
|
|
if (ret && TRACE_ON(midi))
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
for (i = 0; i < 16; i++)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2002-12-02 19:57:00 +01:00
|
|
|
TRACE("chnMap[%2d] => %d\n",
|
2001-05-22 21:20:53 +02:00
|
|
|
i, mom->ChannelMap[i] ? mom->ChannelMap[i]->uDevID : -1);
|
|
|
|
}
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
2001-05-22 21:20:53 +02:00
|
|
|
return ret;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2010-02-10 19:42:15 +01:00
|
|
|
static void MIDIMAP_NotifyClient(MIDIMAPDATA* mom, WORD wMsg,
|
|
|
|
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
|
|
|
{
|
|
|
|
DriverCallback(mom->midiDesc.dwCallback, mom->wCbFlags, (HDRVR)mom->midiDesc.hMidi,
|
|
|
|
wMsg, mom->midiDesc.dwInstance, dwParam1, dwParam2);
|
|
|
|
}
|
|
|
|
|
2007-05-31 16:01:53 +02:00
|
|
|
static DWORD modOpen(DWORD_PTR *lpdwUser, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
MIDIMAPDATA* mom = HeapAlloc(GetProcessHeap(), 0, sizeof(MIDIMAPDATA));
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2006-10-05 00:59:49 +02:00
|
|
|
TRACE("(%p %p %08x)\n", lpdwUser, lpDesc, dwFlags);
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
if (!mom) return MMSYSERR_NOMEM;
|
2010-02-10 19:42:15 +01:00
|
|
|
if (!lpDesc) {
|
2010-01-27 17:18:14 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, mom);
|
2010-02-10 19:42:15 +01:00
|
|
|
return MMSYSERR_INVALPARAM;
|
2010-01-27 17:18:14 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (MIDIMAP_LoadSettings(mom))
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2018-04-04 17:40:44 +02:00
|
|
|
UINT chn;
|
2007-05-31 16:01:53 +02:00
|
|
|
*lpdwUser = (DWORD_PTR)mom;
|
2001-05-22 21:20:53 +02:00
|
|
|
mom->self = mom;
|
2010-02-10 19:42:15 +01:00
|
|
|
mom->wCbFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
|
|
|
|
mom->midiDesc = *lpDesc;
|
|
|
|
|
2018-04-04 17:40:44 +02:00
|
|
|
for (chn = 0; chn < 16; chn++)
|
|
|
|
{
|
|
|
|
if (mom->ChannelMap[chn]->loaded) continue;
|
|
|
|
if (midiOutOpen(&mom->ChannelMap[chn]->hMidi, mom->ChannelMap[chn]->uDevID,
|
|
|
|
0L, 0L, CALLBACK_NULL) == MMSYSERR_NOERROR)
|
|
|
|
mom->ChannelMap[chn]->loaded = 1;
|
|
|
|
else
|
|
|
|
mom->ChannelMap[chn]->loaded = -1;
|
|
|
|
/* FIXME: should load here the IDF midi data... and allow channel and
|
|
|
|
* patch mappings
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
MIDIMAP_NotifyClient(mom, MOM_OPEN, 0L, 0L);
|
2001-05-22 21:20:53 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
2001-05-22 21:20:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mom);
|
|
|
|
return MIDIERR_INVALIDSETUP;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
static DWORD modClose(MIDIMAPDATA* mom)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
UINT i;
|
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
|
|
|
|
if (MIDIMAP_IsBadData(mom)) return MMSYSERR_ERROR;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
for (i = 0; i < 16; i++)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
DWORD t;
|
2002-06-01 01:06:46 +02:00
|
|
|
if (mom->ChannelMap[i] && mom->ChannelMap[i]->loaded > 0)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
t = midiOutClose(mom->ChannelMap[i]->hMidi);
|
2002-06-01 01:06:46 +02:00
|
|
|
if (t == MMSYSERR_NOERROR)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
mom->ChannelMap[i]->loaded = 0;
|
|
|
|
mom->ChannelMap[i]->hMidi = 0;
|
|
|
|
}
|
|
|
|
else if (ret == MMSYSERR_NOERROR)
|
|
|
|
ret = t;
|
|
|
|
}
|
|
|
|
}
|
2010-02-10 19:42:15 +01:00
|
|
|
if (ret == MMSYSERR_NOERROR) {
|
|
|
|
MIDIMAP_NotifyClient(mom, MOM_CLOSE, 0L, 0L);
|
2001-05-22 21:20:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mom);
|
2010-02-10 19:42:15 +01:00
|
|
|
}
|
1999-10-31 03:23:49 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-05-31 16:01:53 +02:00
|
|
|
static DWORD modLongData(MIDIMAPDATA* mom, LPMIDIHDR lpMidiHdr, DWORD_PTR dwParam2)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
WORD chn;
|
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
MIDIHDR mh;
|
|
|
|
|
|
|
|
if (MIDIMAP_IsBadData(mom))
|
|
|
|
return MMSYSERR_ERROR;
|
2010-01-27 18:08:04 +01:00
|
|
|
if (!(lpMidiHdr->dwFlags & MHDR_PREPARED))
|
|
|
|
return MIDIERR_UNPREPARED;
|
|
|
|
if (lpMidiHdr->dwFlags & MHDR_INQUEUE)
|
|
|
|
return MIDIERR_STILLPLAYING;
|
2001-05-22 21:20:53 +02:00
|
|
|
|
|
|
|
mh = *lpMidiHdr;
|
2010-01-27 18:08:04 +01:00
|
|
|
lpMidiHdr->dwFlags &= ~MHDR_DONE;
|
|
|
|
lpMidiHdr->dwFlags |= MHDR_INQUEUE;
|
2002-06-01 01:06:46 +02:00
|
|
|
for (chn = 0; chn < 16; chn++)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if (mom->ChannelMap[chn] && mom->ChannelMap[chn]->loaded > 0)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
mh.dwFlags = 0;
|
|
|
|
midiOutPrepareHeader(mom->ChannelMap[chn]->hMidi, &mh, sizeof(mh));
|
|
|
|
ret = midiOutLongMsg(mom->ChannelMap[chn]->hMidi, &mh, sizeof(mh));
|
2010-01-27 18:08:04 +01:00
|
|
|
/* As of 2009, wineXYZ.drv's LongData handlers are synchronous */
|
|
|
|
if (!ret && !(mh.dwFlags & MHDR_DONE))
|
|
|
|
FIXME("wait until MHDR_DONE\n");
|
2001-05-22 21:20:53 +02:00
|
|
|
midiOutUnprepareHeader(mom->ChannelMap[chn]->hMidi, &mh, sizeof(mh));
|
|
|
|
if (ret != MMSYSERR_NOERROR) break;
|
|
|
|
}
|
|
|
|
}
|
2010-01-27 18:08:04 +01:00
|
|
|
lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
|
|
|
|
lpMidiHdr->dwFlags |= MHDR_DONE;
|
2010-02-10 19:42:15 +01:00
|
|
|
MIDIMAP_NotifyClient(mom, MOM_DONE, (DWORD_PTR)lpMidiHdr, 0L);
|
2001-05-22 21:20:53 +02:00
|
|
|
return ret;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2007-05-31 16:01:53 +02:00
|
|
|
static DWORD modData(MIDIMAPDATA* mom, DWORD_PTR dwParam)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
BYTE lb = LOBYTE(LOWORD(dwParam));
|
|
|
|
WORD chn = lb & 0x0F;
|
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
|
|
|
|
if (MIDIMAP_IsBadData(mom))
|
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
|
|
|
|
if (!mom->ChannelMap[chn]) return MMSYSERR_NOERROR;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
switch (lb & 0xF0)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
case 0x80:
|
|
|
|
case 0x90:
|
|
|
|
case 0xA0:
|
|
|
|
case 0xB0:
|
|
|
|
case 0xC0:
|
|
|
|
case 0xD0:
|
|
|
|
case 0xE0:
|
2002-06-01 01:06:46 +02:00
|
|
|
if (mom->ChannelMap[chn]->loaded > 0)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
/* change channel */
|
|
|
|
dwParam &= ~0x0F;
|
|
|
|
dwParam |= mom->ChannelMap[chn]->aChn[chn];
|
|
|
|
|
|
|
|
if ((LOBYTE(LOWORD(dwParam)) & 0xF0) == 0xC0 /* program change */ &&
|
2002-06-01 01:06:46 +02:00
|
|
|
mom->ChannelMap[chn]->lpbPatch)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
BYTE patch = HIBYTE(LOWORD(dwParam));
|
|
|
|
|
|
|
|
/* change patch */
|
|
|
|
dwParam &= ~0x0000FF00;
|
|
|
|
dwParam |= mom->ChannelMap[chn]->lpbPatch[patch];
|
|
|
|
}
|
|
|
|
ret = midiOutShortMsg(mom->ChannelMap[chn]->hMidi, dwParam);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xF0:
|
2002-06-01 01:06:46 +02:00
|
|
|
for (chn = 0; chn < 16; chn++)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
if (mom->ChannelMap[chn]->loaded > 0)
|
|
|
|
ret = midiOutShortMsg(mom->ChannelMap[chn]->hMidi, dwParam);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2007-05-31 16:01:53 +02:00
|
|
|
FIXME("ooch %lx\n", dwParam);
|
2001-05-22 21:20:53 +02:00
|
|
|
}
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
return ret;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2010-01-27 18:08:04 +01:00
|
|
|
static DWORD modPrepare(MIDIMAPDATA* mom, LPMIDIHDR lpMidiHdr, DWORD_PTR dwSize)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
if (MIDIMAP_IsBadData(mom)) return MMSYSERR_ERROR;
|
2013-01-26 23:29:31 +01:00
|
|
|
if (dwSize < offsetof(MIDIHDR,dwOffset) || lpMidiHdr == 0 || lpMidiHdr->lpData == 0)
|
2001-05-22 21:20:53 +02:00
|
|
|
return MMSYSERR_INVALPARAM;
|
2013-01-26 23:29:31 +01:00
|
|
|
if (lpMidiHdr->dwFlags & MHDR_PREPARED)
|
|
|
|
return MMSYSERR_NOERROR;
|
1999-11-21 01:51:05 +01:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
lpMidiHdr->dwFlags |= MHDR_PREPARED;
|
2013-01-26 23:29:31 +01:00
|
|
|
lpMidiHdr->dwFlags &= ~(MHDR_DONE|MHDR_INQUEUE); /* flags cleared since w2k */
|
2001-05-22 21:20:53 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:31 +01:00
|
|
|
static DWORD modUnprepare(MIDIMAPDATA* mom, LPMIDIHDR lpMidiHdr, DWORD_PTR dwSize)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
if (MIDIMAP_IsBadData(mom)) return MMSYSERR_ERROR;
|
2013-01-26 23:29:31 +01:00
|
|
|
if (dwSize < offsetof(MIDIHDR,dwOffset) || lpMidiHdr == 0 || lpMidiHdr->lpData == 0)
|
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
if (!(lpMidiHdr->dwFlags & MHDR_PREPARED))
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
if (lpMidiHdr->dwFlags & MHDR_INQUEUE)
|
|
|
|
return MIDIERR_STILLPLAYING;
|
2001-05-22 21:20:53 +02:00
|
|
|
|
|
|
|
lpMidiHdr->dwFlags &= ~MHDR_PREPARED;
|
|
|
|
return MMSYSERR_NOERROR;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2010-01-28 16:39:52 +01:00
|
|
|
static DWORD modGetVolume(MIDIMAPDATA* mom, DWORD* lpdwVolume)
|
|
|
|
{
|
|
|
|
if (!lpdwVolume) return MMSYSERR_INVALPARAM;
|
|
|
|
*lpdwVolume = 0xFFFFFFFF; /* tests show this initial value */
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD modSetVolume(MIDIMAPDATA* mom, DWORD dwVolume)
|
|
|
|
{
|
|
|
|
/* Native forwards it to some underlying device
|
|
|
|
* GetVolume returns what was last set here. */
|
|
|
|
FIXME("stub\n");
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2007-05-31 16:01:53 +02:00
|
|
|
static DWORD modGetDevCaps(UINT wDevID, MIDIMAPDATA* mom, LPMIDIOUTCAPSW lpMidiCaps, DWORD_PTR size)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2010-02-10 08:55:00 +01:00
|
|
|
static const MIDIOUTCAPSW mappercaps = {
|
|
|
|
0x00FF, 0x0001, 0x0100, /* Manufacturer and Product ID */
|
2020-10-03 20:28:18 +02:00
|
|
|
L"Wine midi mapper", MOD_MAPPER, 0, 0, 0xFFFF,
|
2010-02-10 08:55:00 +01:00
|
|
|
/* Native returns volume caps of underlying device + MIDICAPS_STREAM */
|
|
|
|
MIDICAPS_VOLUME|MIDICAPS_LRVOLUME
|
|
|
|
};
|
|
|
|
if (lpMidiCaps == NULL) return MMSYSERR_INVALPARAM;
|
2010-02-18 17:37:25 +01:00
|
|
|
if (!numMidiOutPorts) return MMSYSERR_BADDEVICEID;
|
2010-02-10 08:55:00 +01:00
|
|
|
|
|
|
|
memcpy(lpMidiCaps, &mappercaps, min(size, sizeof(*lpMidiCaps)));
|
2001-05-22 21:20:53 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
static DWORD modReset(MIDIMAPDATA* mom)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
WORD chn;
|
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
|
|
|
|
if (MIDIMAP_IsBadData(mom))
|
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
for (chn = 0; chn < 16; chn++)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if (mom->ChannelMap[chn] && mom->ChannelMap[chn]->loaded > 0)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
ret = midiOutReset(mom->ChannelMap[chn]->hMidi);
|
|
|
|
if (ret != MMSYSERR_NOERROR) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2010-03-17 10:50:24 +01:00
|
|
|
static LRESULT MIDIMAP_drvOpen(void);
|
|
|
|
static LRESULT MIDIMAP_drvClose(void);
|
|
|
|
|
1999-10-31 03:23:49 +01:00
|
|
|
/**************************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* modMessage (MIDIMAP.@)
|
1999-10-31 03:23:49 +01:00
|
|
|
*/
|
2007-05-31 16:01:53 +02:00
|
|
|
DWORD WINAPI MIDIMAP_modMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
|
|
|
|
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2007-05-31 16:01:53 +02:00
|
|
|
TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
|
1999-10-31 03:23:49 +01:00
|
|
|
wDevID, wMsg, dwUser, dwParam1, dwParam2);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
switch (wMsg)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
1999-10-31 03:23:49 +01:00
|
|
|
case DRVM_INIT:
|
2010-03-17 10:50:24 +01:00
|
|
|
return MIDIMAP_drvOpen();
|
1999-10-31 03:23:49 +01:00
|
|
|
case DRVM_EXIT:
|
2010-03-17 10:50:24 +01:00
|
|
|
return MIDIMAP_drvClose();
|
1999-10-31 03:23:49 +01:00
|
|
|
case DRVM_ENABLE:
|
|
|
|
case DRVM_DISABLE:
|
|
|
|
/* FIXME: Pretend this is supported */
|
|
|
|
return 0;
|
|
|
|
|
2007-05-31 16:01:53 +02:00
|
|
|
case MODM_OPEN: return modOpen((DWORD_PTR *)dwUser, (LPMIDIOPENDESC)dwParam1, dwParam2);
|
2001-05-22 21:20:53 +02:00
|
|
|
case MODM_CLOSE: return modClose ((MIDIMAPDATA*)dwUser);
|
|
|
|
|
|
|
|
case MODM_DATA: return modData ((MIDIMAPDATA*)dwUser, dwParam1);
|
|
|
|
case MODM_LONGDATA: return modLongData ((MIDIMAPDATA*)dwUser, (LPMIDIHDR)dwParam1, dwParam2);
|
|
|
|
case MODM_PREPARE: return modPrepare ((MIDIMAPDATA*)dwUser, (LPMIDIHDR)dwParam1, dwParam2);
|
|
|
|
case MODM_UNPREPARE: return modUnprepare ((MIDIMAPDATA*)dwUser, (LPMIDIHDR)dwParam1, dwParam2);
|
|
|
|
case MODM_RESET: return modReset ((MIDIMAPDATA*)dwUser);
|
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
case MODM_GETDEVCAPS: return modGetDevCaps (wDevID, (MIDIMAPDATA*)dwUser, (LPMIDIOUTCAPSW)dwParam1,dwParam2);
|
2001-05-22 21:20:53 +02:00
|
|
|
case MODM_GETNUMDEVS: return 1;
|
2010-01-28 16:39:52 +01:00
|
|
|
case MODM_GETVOLUME: return modGetVolume ((MIDIMAPDATA*)dwUser, (DWORD*)dwParam1);
|
|
|
|
case MODM_SETVOLUME: return modSetVolume ((MIDIMAPDATA*)dwUser, dwParam1);
|
1999-10-31 03:23:49 +01:00
|
|
|
default:
|
2001-05-22 21:20:53 +02:00
|
|
|
FIXME("unknown message %d!\n", wMsg);
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*======================================================================*
|
|
|
|
* Driver part *
|
|
|
|
*======================================================================*/
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDIMAP_drvOpen [internal]
|
1999-10-31 03:23:49 +01:00
|
|
|
*/
|
2010-03-17 10:50:24 +01:00
|
|
|
static LRESULT MIDIMAP_drvOpen(void)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
MIDIOUTCAPSW moc;
|
2001-05-22 21:20:53 +02:00
|
|
|
unsigned dev, i;
|
2017-09-30 22:07:08 +02:00
|
|
|
BOOL found_valid_port = FALSE;
|
2001-05-22 21:20:53 +02:00
|
|
|
|
|
|
|
if (midiOutPorts)
|
1999-10-31 03:23:49 +01:00
|
|
|
return 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
numMidiOutPorts = midiOutGetNumDevs();
|
2002-06-01 01:06:46 +02:00
|
|
|
midiOutPorts = HeapAlloc(GetProcessHeap(), 0,
|
2001-05-22 21:20:53 +02:00
|
|
|
numMidiOutPorts * sizeof(MIDIOUTPORT));
|
2002-06-01 01:06:46 +02:00
|
|
|
for (dev = 0; dev < numMidiOutPorts; dev++)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
if (midiOutGetDevCapsW(dev, &moc, sizeof(moc)) == 0L)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2019-06-11 08:26:30 +02:00
|
|
|
lstrcpyW(midiOutPorts[dev].name, moc.szPname);
|
2001-05-22 21:20:53 +02:00
|
|
|
midiOutPorts[dev].loaded = 0;
|
|
|
|
midiOutPorts[dev].hMidi = 0;
|
2002-12-02 19:57:00 +01:00
|
|
|
midiOutPorts[dev].uDevID = dev;
|
2001-05-22 21:20:53 +02:00
|
|
|
midiOutPorts[dev].lpbPatch = NULL;
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
midiOutPorts[dev].aChn[i] = i;
|
2020-10-03 20:28:18 +02:00
|
|
|
if (wcsncmp(midiOutPorts[dev].name, L"Midi Through", lstrlenW(L"Midi Through")) != 0)
|
2017-09-30 22:07:08 +02:00
|
|
|
found_valid_port = TRUE;
|
2001-05-22 21:20:53 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
midiOutPorts[dev].loaded = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 22:07:08 +02:00
|
|
|
if (!found_valid_port)
|
|
|
|
ERR_(winediag)("No software synthesizer midi port found, Midi sound output probably won't work.\n");
|
|
|
|
|
1999-10-31 03:23:49 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* MIDIMAP_drvClose [internal]
|
1999-10-31 03:23:49 +01:00
|
|
|
*/
|
2010-03-17 10:50:24 +01:00
|
|
|
static LRESULT MIDIMAP_drvClose(void)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if (midiOutPorts)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, midiOutPorts);
|
|
|
|
midiOutPorts = NULL;
|
1999-10-31 03:23:49 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* DriverProc (MIDIMAP.@)
|
1999-10-31 03:23:49 +01:00
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
LRESULT CALLBACK MIDIMAP_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
|
|
|
|
LPARAM dwParam1, LPARAM dwParam2)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
|
|
|
/* EPP TRACE("(%08lX, %04X, %08lX, %08lX, %08lX)\n", */
|
|
|
|
/* EPP dwDevID, hDriv, wMsg, dwParam1, dwParam2); */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
switch (wMsg)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
1999-10-31 03:23:49 +01:00
|
|
|
case DRV_LOAD: return 1;
|
|
|
|
case DRV_FREE: return 1;
|
2010-03-17 10:50:24 +01:00
|
|
|
case DRV_OPEN: return 1;
|
|
|
|
case DRV_CLOSE: return 1;
|
1999-10-31 03:23:49 +01:00
|
|
|
case DRV_ENABLE: return 1;
|
|
|
|
case DRV_DISABLE: return 1;
|
|
|
|
case DRV_QUERYCONFIGURE: return 1;
|
|
|
|
case DRV_CONFIGURE: MessageBoxA(0, "MIDIMAP MultiMedia Driver !", "OSS Driver", MB_OK); return 1;
|
|
|
|
case DRV_INSTALL: return DRVCNF_RESTART;
|
|
|
|
case DRV_REMOVE: return DRVCNF_RESTART;
|
|
|
|
default:
|
|
|
|
return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
|
|
|
|
}
|
|
|
|
}
|