Add: Win32 MIDI Support

This commit is contained in:
Charles Lohr
2005-05-25 21:58:56 +00:00
parent b05d0c29ed
commit 8e74fab0c1
7 changed files with 205 additions and 10 deletions
+4 -1
View File
@@ -132,6 +132,7 @@ static const CString InputDeviceNames[] = {
"Joy16",
"Pump1",
"Pump2",
"Midi",
"Para1",
};
XToString( InputDevice, NUM_INPUT_DEVICES );
@@ -253,8 +254,9 @@ CString DeviceButtonToString( InputDevice device, DeviceButton i )
case DEVICE_JOY14:
case DEVICE_JOY15:
case DEVICE_JOY16: return JoystickButtonToString( (JoystickButton)i );
case DEVICE_PUMP1:
case DEVICE_PUMP1: return PumpPadButtonToString( (PumpPadButton)i );
case DEVICE_PUMP2: return PumpPadButtonToString( (PumpPadButton)i );
case DEVICE_MIDI: return ssprintf("Midi %d", (int)i);
case DEVICE_PARA1: return ParaPadButtonToString( (ParaPadButton)i );
case DEVICE_NONE: return "";
default: ASSERT(0); return "";
@@ -284,6 +286,7 @@ DeviceButton StringToDeviceButton( InputDevice device, const CString& s )
case DEVICE_JOY16: return (DeviceButton)StringToJoystickButton( s );
case DEVICE_PUMP1:
case DEVICE_PUMP2: return (DeviceButton)StringToPumpPadButton( s );
case DEVICE_MIDI: { int i=0; sscanf( "Midi %d", s, i ); return (DeviceButton)i; }
case DEVICE_PARA1: return (DeviceButton)StringToParaPadButton( s );
case DEVICE_NONE: return DEVICE_BUTTON_INVALID;
default: ASSERT(0); return DEVICE_BUTTON_INVALID;
+3
View File
@@ -29,6 +29,7 @@ enum InputDevice {
DEVICE_JOY16,
DEVICE_PUMP1,
DEVICE_PUMP2,
DEVICE_MIDI,
DEVICE_PARA1,
NUM_INPUT_DEVICES, // leave this at the end
DEVICE_NONE // means this is NULL
@@ -275,6 +276,7 @@ enum PumpPadButton {
const CString& PumpPadButtonToString( PumpPadButton i );
PumpPadButton StringToPumpPadButton( const CString& s );
#define NUM_MIDI_CHANNELS 100
enum ParaPadButton {
PARA_L,
@@ -321,6 +323,7 @@ inline int GetNumDeviceButtons( InputDevice device )
case DEVICE_JOY16: return NUM_JOYSTICK_BUTTONS;
case DEVICE_PUMP1:
case DEVICE_PUMP2: return NUM_PUMP_PAD_BUTTONS;
case DEVICE_MIDI: return NUM_MIDI_CHANNELS;
case DEVICE_PARA1: return NUM_PARA_PAD_BUTTONS;
default: ASSERT(0); return 0;
}
+17 -9
View File
@@ -59,10 +59,10 @@ LINK32=link.exe
# SUBTRACT LINK32 /verbose /profile /pdb:none /incremental:no /nodefaultlib
# Begin Special Build Tool
IntDir=.\../Debug6
TargetDir=\stepmania\Program
TargetDir=\StepMania\Program
TargetName=StepMania-debug
SOURCE="$(InputPath)"
PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
PostBuild_Cmds=archutils\Win32\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi
# End Special Build Tool
@@ -96,10 +96,10 @@ LINK32=link.exe
# SUBTRACT LINK32 /pdb:none
# Begin Special Build Tool
IntDir=.\../Release6
TargetDir=\stepmania\Program
TargetDir=\StepMania\Program
TargetName=StepMania
SOURCE="$(InputPath)"
PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
PostBuild_Cmds=archutils\Win32\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi
# End Special Build Tool
@@ -1362,6 +1362,14 @@ SOURCE=.\arch\InputHandler\InputHandler_MonkeyKeyboard.h
# End Source File
# Begin Source File
SOURCE=.\arch\InputHandler\InputHandler_Win32_MIDI.cpp
# End Source File
# Begin Source File
SOURCE=.\arch\InputHandler\InputHandler_Win32_MIDI.h
# End Source File
# Begin Source File
SOURCE=.\arch\InputHandler\InputHandler_Win32_Para.cpp
# End Source File
# Begin Source File
@@ -1376,6 +1384,10 @@ SOURCE=.\arch\InputHandler\InputHandler_Win32_Pump.cpp
SOURCE=.\arch\InputHandler\InputHandler_Win32_Pump.h
# End Source File
# Begin Source File
SOURCE=.\arch\InputHandler\Selector_InputHandler.h
# End Source File
# End Group
# Begin Group "MovieTexture"
@@ -1547,11 +1559,7 @@ SOURCE=.\arch\arch_default.h
# End Source File
# Begin Source File
SOURCE=.\arch\arch_Win32.h
# End Source File
# Begin Source File
SOURCE=.\arch\arch_xbox.h
SOURCE=.\arch\arch_platform.h
# End Source File
# End Group
# Begin Group "system"
@@ -0,0 +1,128 @@
#include "global.h"
#include "RageUtil.h"
#include "InputHandler_Win32_MIDI.h"
#include "RageLog.h"
#include <windows.h>
#include <mmsystem.h>
#include "ScreenManager.h"
#pragma comment (lib,"winmm.lib")
HMIDIIN g_device;
void CALLBACK midiCallback(HMIDIIN g_device, UINT status, DWORD instancePtr, DWORD data, DWORD timestamp);
InputHandler_Win32_MIDI::InputHandler_Win32_MIDI()
{
int device_id = 0;
MMRESULT result;
g_device = NULL;
if (device_id >= midiInGetNumDevs()) {
m_bFoundDevice = false;
return;
} else
m_bFoundDevice = true;
result = midiInOpen(&g_device, device_id, (DWORD)&(midiCallback), (DWORD)this, CALLBACK_FUNCTION);
if (result != MMSYSERR_NOERROR) {
char strError[256];
midiOutGetErrorText( result, strError, 256 );
LOG->Warn( "Error with MIDI Opening: %s", strError );
return;
}
result = midiInStart(g_device);
if (result != MMSYSERR_NOERROR) {
char strError[256];
midiOutGetErrorText( result, strError, 256 );
LOG->Warn( "Error with MIDI Starting: %s", strError );
return;
}
}
InputHandler_Win32_MIDI::~InputHandler_Win32_MIDI()
{
MMRESULT result;
result = midiInReset(g_device);
if (result != MMSYSERR_NOERROR) {
char strError[256];
midiOutGetErrorText( result, strError, 256 );
LOG->Warn( "Error with MIDI Reset: %s", strError );
return;
}
result = midiInClose(g_device);
if (result != MMSYSERR_NOERROR) {
char strError[256];
midiOutGetErrorText( result, strError, 256 );
LOG->Warn( "Error with MIDI Close: %s", strError );
return;
}
}
void InputHandler_Win32_MIDI::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
{
if ( m_bFoundDevice )
{
vDevicesOut.push_back( InputDevice(DEVICE_MIDI) );
vDescriptionsOut.push_back( "Win32_MIDI" );
}
}
void CALLBACK midiCallback(HMIDIIN g_device, UINT status, DWORD instancePtr, DWORD data, DWORD timestamp)
{
if (status == MIM_DATA) {
int type = data & 0x00ff;
int channel = (data & 0xff00) >> 8;
int value = ( data & 0x00ff0000) >> 16;
//Channel 0 in midi is a special channel that generally will get triggerd when too many channels are pressed
if ( channel == 0 ) return;
if ( type == 144 )
{
DeviceInput di = DeviceInput(DEVICE_MIDI,channel);
di.ts.Touch();
if ( value > 0 )
((InputHandler_Win32_MIDI *)instancePtr)->SetDev( di, true );
else
((InputHandler_Win32_MIDI *)instancePtr)->SetDev( di, false );
}
}
}
void InputHandler_Win32_MIDI::Update( float fDeltaTime )
{
}
/*
* Copyright (c) 2005 Charles Lohr
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
@@ -0,0 +1,49 @@
#ifndef INPUT_HANDLER_WIN32_MIDI
#define INPUT_HANDLER_WIN32_MIDI
#include "InputHandler.h"
#include "RageInputDevice.h"
class InputHandler_Win32_MIDI: public InputHandler
{
public:
InputHandler_Win32_MIDI();
~InputHandler_Win32_MIDI();
void Update(float fDeltaTime);
void GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut);
void SetDev( DeviceInput key, bool pressed ) { ButtonPressed( key, pressed ); }
private:
bool m_bFoundDevice;
};
#endif
/*
* (c) 2002-2005 Charles Lohr, Glenn Maynard
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
@@ -26,6 +26,7 @@
#ifdef HAVE_WIN32
#include "InputHandler_Win32_Pump.h"
#include "InputHandler_Win32_Para.h"
#include "InputHandler_Win32_MIDI.h"
#endif
#ifdef HAVE_XBOX
+3
View File
@@ -42,6 +42,9 @@ void MakeInputHandlers(CString drivers, vector<InputHandler *> &Add)
#ifdef USE_INPUT_HANDLER_WIN32_PUMP
if(!s->CompareNoCase("Pump") ) ret = new InputHandler_Win32_Pump;
#endif
#ifdef USE_INPUT_HANDLER_WIN32_PARA
if(!s->CompareNoCase("MIDI") ) ret = new InputHandler_Win32_MIDI;
#endif
#ifdef USE_INPUT_HANDLER_X11
if(!s->CompareNoCase("X11") ) ret = new InputHandler_X11;
#endif