diff --git a/stepmania/src/RageInputDevice.cpp b/stepmania/src/RageInputDevice.cpp index 690059d8cd..2470fea3f8 100644 --- a/stepmania/src/RageInputDevice.cpp +++ b/stepmania/src/RageInputDevice.cpp @@ -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; diff --git a/stepmania/src/RageInputDevice.h b/stepmania/src/RageInputDevice.h index fe6cc57dc9..670f9a4fd9 100644 --- a/stepmania/src/RageInputDevice.h +++ b/stepmania/src/RageInputDevice.h @@ -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; } diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index bc6f5cf342..8da83805cd 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -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" diff --git a/stepmania/src/arch/InputHandler/InputHandler_Win32_MIDI.cpp b/stepmania/src/arch/InputHandler/InputHandler_Win32_MIDI.cpp new file mode 100644 index 0000000000..bfbb912075 --- /dev/null +++ b/stepmania/src/arch/InputHandler/InputHandler_Win32_MIDI.cpp @@ -0,0 +1,128 @@ +#include "global.h" +#include "RageUtil.h" +#include "InputHandler_Win32_MIDI.h" +#include "RageLog.h" + +#include +#include + +#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& vDevicesOut, vector& 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. + */ diff --git a/stepmania/src/arch/InputHandler/InputHandler_Win32_MIDI.h b/stepmania/src/arch/InputHandler/InputHandler_Win32_MIDI.h new file mode 100644 index 0000000000..d3b803908d --- /dev/null +++ b/stepmania/src/arch/InputHandler/InputHandler_Win32_MIDI.h @@ -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& vDevicesOut, vector& 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. + */ + diff --git a/stepmania/src/arch/InputHandler/Selector_InputHandler.h b/stepmania/src/arch/InputHandler/Selector_InputHandler.h index 81ac6daee8..19064e7d85 100644 --- a/stepmania/src/arch/InputHandler/Selector_InputHandler.h +++ b/stepmania/src/arch/InputHandler/Selector_InputHandler.h @@ -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 diff --git a/stepmania/src/arch/arch.cpp b/stepmania/src/arch/arch.cpp index 23b87321e4..5fdaf3376b 100644 --- a/stepmania/src/arch/arch.cpp +++ b/stepmania/src/arch/arch.cpp @@ -42,6 +42,9 @@ void MakeInputHandlers(CString drivers, vector &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