Files
itgmania212121/stepmania/src/arch/InputHandler/InputHandler_Win32_MIDI.cpp
T

125 lines
3.6 KiB
C++
Raw Normal View History

2005-05-25 21:58:56 +00:00
#include "global.h"
#include "RageUtil.h"
#include "InputHandler_Win32_MIDI.h"
#include "RageLog.h"
#include <windows.h>
#include <mmsystem.h>
#pragma comment (lib,"winmm.lib")
2005-05-25 22:16:43 +00:00
static HMIDIIN g_device;
static void CALLBACK midiCallback(HMIDIIN g_device, UINT status, DWORD instancePtr, DWORD data, DWORD timestamp);
2005-05-25 21:58:56 +00:00
2005-05-25 22:25:41 +00:00
static CString GetMidiError( MMRESULT result )
{
char szError[256];
midiOutGetErrorText( result, szError, 256 );
return szError;
}
2005-05-25 21:58:56 +00:00
InputHandler_Win32_MIDI::InputHandler_Win32_MIDI()
{
int device_id = 0;
g_device = NULL;
2005-05-31 06:25:28 +00:00
if( device_id >= (int) midiInGetNumDevs() )
2005-05-25 22:21:35 +00:00
{
2005-05-25 21:58:56 +00:00
m_bFoundDevice = false;
return;
2005-12-18 22:57:23 +00:00
}
2005-05-25 22:21:35 +00:00
m_bFoundDevice = true;
2005-05-25 21:58:56 +00:00
2005-05-25 22:25:41 +00:00
MMRESULT result = midiInOpen( &g_device, device_id, (DWORD) &midiCallback, (DWORD) this, CALLBACK_FUNCTION );
2005-12-18 22:57:23 +00:00
if( result != MMSYSERR_NOERROR )
2005-05-25 22:21:35 +00:00
{
2005-05-25 22:25:41 +00:00
LOG->Warn( "Error with MIDI Opening: %s", GetMidiError(result).c_str() );
2005-12-18 22:57:23 +00:00
return;
}
2005-05-25 21:58:56 +00:00
2005-12-18 22:57:23 +00:00
result = midiInStart(g_device);
2005-05-25 22:21:35 +00:00
if( result != MMSYSERR_NOERROR )
{
2005-05-25 22:25:41 +00:00
LOG->Warn( "Error with MIDI Starting: %s", GetMidiError(result).c_str() );
2005-12-18 22:57:23 +00:00
return;
}
2005-05-25 21:58:56 +00:00
}
InputHandler_Win32_MIDI::~InputHandler_Win32_MIDI()
{
MMRESULT result;
2005-05-25 22:21:35 +00:00
result = midiInReset( g_device );
if( result != MMSYSERR_NOERROR )
{
2005-05-25 22:25:41 +00:00
LOG->Warn( "Error with MIDI Reset: %s", GetMidiError(result).c_str() );
2005-12-18 22:57:23 +00:00
return;
}
2005-05-25 21:58:56 +00:00
2005-05-25 22:21:35 +00:00
result = midiInClose( g_device );
if( result != MMSYSERR_NOERROR )
{
2005-05-25 22:25:41 +00:00
LOG->Warn( "Error with MIDI Close: %s", GetMidiError(result).c_str() );
2005-12-18 22:57:23 +00:00
return;
}
2005-05-25 21:58:56 +00:00
}
2005-05-25 22:21:35 +00:00
void InputHandler_Win32_MIDI::GetDevicesAndDescriptions( vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut )
2005-05-25 21:58:56 +00:00
{
2005-05-25 22:21:35 +00:00
if( m_bFoundDevice )
2005-05-25 21:58:56 +00:00
{
vDevicesOut.push_back( InputDevice(DEVICE_MIDI) );
vDescriptionsOut.push_back( "Win32_MIDI" );
}
}
2005-05-25 22:21:35 +00:00
static void CALLBACK midiCallback( HMIDIIN device, UINT status, DWORD instancePtr, DWORD data, DWORD timestamp )
2005-05-25 21:58:56 +00:00
{
2005-05-25 22:21:35 +00:00
if( status == MIM_DATA )
{
int iType = data & 0xff;
int iChannel = (data & 0xff00) >> 8;
int iValue = (data & 0xff0000) >> 16;
2005-05-25 21:58:56 +00:00
2005-05-25 22:25:41 +00:00
// Channel 0 in midi is a special channel that generally will get triggered when too many channels are pressed.
2005-05-25 22:21:35 +00:00
if( iChannel == 0 )
return;
2005-05-25 21:58:56 +00:00
2005-05-25 22:21:35 +00:00
if( iType == 144 )
2005-05-25 21:58:56 +00:00
{
2005-05-25 22:21:35 +00:00
DeviceInput di = DeviceInput( DEVICE_MIDI, iChannel );
2005-05-25 21:58:56 +00:00
di.ts.Touch();
2005-05-25 22:21:35 +00:00
if( iValue > 0 )
2005-05-25 21:58:56 +00:00
((InputHandler_Win32_MIDI *)instancePtr)->SetDev( di, true );
else
((InputHandler_Win32_MIDI *)instancePtr)->SetDev( di, false );
}
2005-12-18 22:57:23 +00:00
}
2005-05-25 21:58:56 +00:00
}
/*
* 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.
*/