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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
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"
|
2004-12-06 21:55:25 +01:00
|
|
|
#include "wine/unicode.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.
|
|
|
|
*
|
|
|
|
* Full form (in HKU) is:
|
|
|
|
*
|
|
|
|
* [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).
|
|
|
|
*/
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msacm);
|
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];
|
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));
|
|
|
|
if (strcmpW(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 */
|
2002-06-01 01:06:46 +02:00
|
|
|
if (*name == '#' && isdigit(name[1]))
|
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';
|
|
|
|
} while (isdigit(*++ptr));
|
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
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
for (idx = 0; !RegEnumKeyW(hKey, idx, buffer, sizeof(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;
|
2004-12-06 21:55:25 +01:00
|
|
|
WCHAR buffer[256];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
ret = 2;
|
|
|
|
size = sizeof(out);
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!RegQueryValueExA(hKey, "UseScheme", 0, &type, (void*)&out, &size) && out)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
static const WCHAR cs[] = {'C','u','r','r','e','n','t','S','c','h','e','m','e',0};
|
2001-05-22 21:20:53 +02:00
|
|
|
size = sizeof(buffer);
|
2004-12-06 21:55:25 +01:00
|
|
|
if (!RegQueryValueExW(hKey, cs, 0, &type, (void*)buffer, &size))
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
if (!(ret = MIDIMAP_LoadSettingsScheme(mom, buffer)))
|
|
|
|
ret = MIDIMAP_LoadSettingsDefault(mom, NULL);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
ERR("Wrong registry: UseScheme is active, but no CurrentScheme found\n");
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
if (ret == 2)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
static const WCHAR ci[] = {'C','u','r','r','e','n','t','I','n','s','t','r','u','m','e','n','t',0};
|
2001-05-22 21:20:53 +02:00
|
|
|
size = sizeof(buffer);
|
2004-12-06 21:55:25 +01:00
|
|
|
if (!RegQueryValueExW(hKey, ci, 0, &type, (void*)buffer, &size) && *buffer)
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
ret = MIDIMAP_LoadSettingsDefault(mom, buffer);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
ret = MIDIMAP_LoadSettingsDefault(mom, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
1999-10-31 03:23:49 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (ret && TRACE_ON(msacm))
|
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
|
|
|
}
|
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
static DWORD modOpen(LPDWORD 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
|
|
|
|
2002-12-02 19:57:00 +01:00
|
|
|
TRACE("(%p %p %08lx)\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;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (MIDIMAP_LoadSettings(mom))
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
*lpdwUser = (DWORD)mom;
|
|
|
|
mom->self = mom;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
1999-10-31 03:23:49 +01:00
|
|
|
if (ret == MMSYSERR_NOERROR)
|
2001-05-22 21:20:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mom);
|
1999-10-31 03:23:49 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
static DWORD modLongData(MIDIMAPDATA* mom, LPMIDIHDR lpMidiHdr, DWORD 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;
|
|
|
|
|
|
|
|
mh = *lpMidiHdr;
|
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));
|
|
|
|
midiOutUnprepareHeader(mom->ChannelMap[chn]->hMidi, &mh, sizeof(mh));
|
|
|
|
if (ret != MMSYSERR_NOERROR) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
static DWORD modData(MIDIMAPDATA* mom, DWORD 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
|
|
|
{
|
|
|
|
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
|
2002-06-01 01:06:46 +02:00
|
|
|
* patch mappings
|
2001-05-22 21:20:53 +02:00
|
|
|
*/
|
|
|
|
}
|
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:
|
|
|
|
FIXME("ooch %lu\n", dwParam);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
static DWORD modPrepare(MIDIMAPDATA* mom, LPMIDIHDR lpMidiHdr, DWORD dwParam2)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
if (MIDIMAP_IsBadData(mom)) return MMSYSERR_ERROR;
|
|
|
|
if (lpMidiHdr->dwFlags & (MHDR_ISSTRM|MHDR_PREPARED))
|
|
|
|
return MMSYSERR_INVALPARAM;
|
1999-11-21 01:51:05 +01:00
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
lpMidiHdr->dwFlags |= MHDR_PREPARED;
|
|
|
|
return MMSYSERR_NOERROR;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
static DWORD modUnprepare(MIDIMAPDATA* mom, LPMIDIHDR lpMidiHdr, DWORD dwParam2)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2001-05-22 21:20:53 +02:00
|
|
|
if (MIDIMAP_IsBadData(mom)) return MMSYSERR_ERROR;
|
|
|
|
if ((lpMidiHdr->dwFlags & MHDR_ISSTRM) || !(lpMidiHdr->dwFlags & MHDR_PREPARED))
|
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
|
|
|
|
lpMidiHdr->dwFlags &= ~MHDR_PREPARED;
|
|
|
|
return MMSYSERR_NOERROR;
|
1999-10-31 03:23:49 +01:00
|
|
|
}
|
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
static DWORD modGetDevCaps(UINT wDevID, MIDIMAPDATA* mom, LPMIDIOUTCAPSW lpMidiCaps, DWORD size)
|
1999-10-31 03:23:49 +01:00
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
static const WCHAR name[] = {'W','i','n','e',' ','m','i','d','i',' ','m','a','p','p','e','r',0};
|
2001-05-22 21:20:53 +02:00
|
|
|
lpMidiCaps->wMid = 0x00FF;
|
|
|
|
lpMidiCaps->wPid = 0x0001;
|
|
|
|
lpMidiCaps->vDriverVersion = 0x0100;
|
2004-12-06 21:55:25 +01:00
|
|
|
lstrcpyW(lpMidiCaps->szPname, name);
|
2001-05-22 21:20:53 +02:00
|
|
|
lpMidiCaps->wTechnology = MOD_MAPPER;
|
|
|
|
lpMidiCaps->wVoices = 0;
|
|
|
|
lpMidiCaps->wNotes = 0;
|
|
|
|
lpMidiCaps->wChannelMask = 0xFFFF;
|
|
|
|
lpMidiCaps->dwSupport = 0L;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* modMessage (MIDIMAP.@)
|
1999-10-31 03:23:49 +01:00
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
DWORD WINAPI MIDIMAP_modMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
|
1999-10-31 03:23:49 +01:00
|
|
|
DWORD dwParam1, DWORD dwParam2)
|
|
|
|
{
|
|
|
|
TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
|
|
|
|
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:
|
|
|
|
case DRVM_EXIT:
|
|
|
|
case DRVM_ENABLE:
|
|
|
|
case DRVM_DISABLE:
|
|
|
|
/* FIXME: Pretend this is supported */
|
|
|
|
return 0;
|
|
|
|
|
2001-05-22 21:20:53 +02:00
|
|
|
case MODM_OPEN: return modOpen ((LPDWORD)dwUser, (LPMIDIOPENDESC)dwParam1,dwParam2);
|
|
|
|
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;
|
|
|
|
case MODM_GETVOLUME: return MMSYSERR_NOTSUPPORTED;
|
|
|
|
case MODM_SETVOLUME: return MMSYSERR_NOTSUPPORTED;
|
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
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
static LRESULT MIDIMAP_drvOpen(LPSTR str)
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2004-12-06 21:55:25 +01:00
|
|
|
strcpyW(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;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else
|
2001-05-22 21:20:53 +02:00
|
|
|
{
|
|
|
|
midiOutPorts[dev].loaded = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2005-11-28 20:53:22 +01:00
|
|
|
static LRESULT MIDIMAP_drvClose(DWORD_PTR dwDevID)
|
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;
|
|
|
|
case DRV_OPEN: return MIDIMAP_drvOpen((LPSTR)dwParam1);
|
|
|
|
case DRV_CLOSE: return MIDIMAP_drvClose(dwDevID);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|