From f7c62d29c802288f6ddec1b6183b2be160b389b9 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Mon, 8 Sep 2008 22:24:00 +0000 Subject: [PATCH] finally made WinMM MIDI driver work properly by fixing internal data structures git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1591 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 5 +++ include/midi_winmm.h | 11 +----- src/core/midi/midi_winmm.cpp | 76 +++++++++++++----------------------- 3 files changed, 34 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3892f9262..ace602b94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2008-09-08 Tobias Doerffel + * include/midi_winmm.h: + * src/core/midi/midi_winmm.cpp: + finally made WinMM MIDI driver work properly by fixing internal data + structures + * buildtools/bin2res.cpp: * plugins/bit_invader/logo.png: * plugins/bit_invader/bit_invader.cpp: diff --git a/include/midi_winmm.h b/include/midi_winmm.h index 3c8fdd70c..8d1836d3b 100644 --- a/include/midi_winmm.h +++ b/include/midi_winmm.h @@ -118,7 +118,7 @@ public: } ; -private slots: +private:// slots: void updateDeviceList( void ); @@ -127,19 +127,12 @@ private: void closeDevices( void ); #ifdef LMMS_BUILD_WIN32 - static DWORD WINAPI midiThreadProc( midiWinMM * _midi ); - DWORD threadProc( void ); - - static void CALLBACK inputCallback( HMIDIIN _hm, UINT _msg, + static void WINAPI CALLBACK inputCallback( HMIDIIN _hm, UINT _msg, DWORD_PTR _inst, DWORD_PTR _param1, DWORD_PTR _param2 ); void handleInputEvent( HMIDIIN _hm, DWORD _ev ); - HANDLE m_threadHandle; - DWORD m_threadId; - volatile bool m_isRunning; - QMap m_inputDevices; QMap m_outputDevices; #endif diff --git a/src/core/midi/midi_winmm.cpp b/src/core/midi/midi_winmm.cpp index 6cd5368b7..13f713964 100644 --- a/src/core/midi/midi_winmm.cpp +++ b/src/core/midi/midi_winmm.cpp @@ -40,19 +40,12 @@ midiWinMM::midiWinMM( void ) : midiClient(), - m_threadHandle( 0 ), - m_threadId( 0 ), - m_isRunning( false ), m_inputDevices(), m_outputDevices(), m_inputSubs(), m_outputSubs() { - m_threadHandle = CreateThread( NULL, 0, - (LPTHREAD_START_ROUTINE) midiThreadProc, - this, 0, &m_threadId ); - - m_isRunning = true; + openDevices(); } @@ -60,9 +53,7 @@ midiWinMM::midiWinMM( void ) : midiWinMM::~midiWinMM() { - m_isRunning = false; - WaitForSingleObject( m_threadHandle, INFINITE ); - CloseHandle( m_threadHandle ); + closeDevices(); } @@ -90,7 +81,7 @@ void midiWinMM::applyPortMode( midiPort * _port ) } } - if( _port->outputEnabled() ) + if( !_port->outputEnabled() ) { for( subMap::iterator it = m_outputSubs.begin(); it != m_outputSubs.end(); ++it ) @@ -132,13 +123,10 @@ void midiWinMM::subscribeReadablePort( midiPort * _port, return; } - if( m_inputSubs.contains( _dest ) ) + m_inputSubs[_dest].removeAll( _port ); + if( _subscribe ) { - m_inputSubs[_dest].removeAll( _port ); - if( _subscribe ) - { - m_inputSubs[_dest].push_back( _port ); - } + m_inputSubs[_dest].push_back( _port ); } } @@ -169,28 +157,7 @@ void midiWinMM::subscribeWriteablePort( midiPort * _port, -DWORD WINAPI midiWinMM::midiThreadProc( midiWinMM * _midi ) -{ - return _midi->threadProc(); -} - - - - -DWORD midiWinMM::threadProc( void ) -{ - openDevices(); - while( m_isRunning ) - { - Sleep( 100 ); - } - closeDevices(); -} - - - - -void midiWinMM::inputCallback( HMIDIIN _hm, UINT _msg, DWORD_PTR _inst, +void WINAPI CALLBACK midiWinMM::inputCallback( HMIDIIN _hm, UINT _msg, DWORD_PTR _inst, DWORD_PTR _param1, DWORD_PTR _param2 ) { if( _msg == MIM_DATA ) @@ -216,7 +183,7 @@ void midiWinMM::handleInputEvent( HMIDIIN _hm, DWORD _ev ) const int chan = cmd & 0x0f; const QString d = m_inputDevices.value( _hm ); - if( d.isEmpty() ) + if( d.isEmpty() || !m_inputSubs.contains( d ) ) { return; } @@ -283,19 +250,30 @@ void midiWinMM::updateDeviceList( void ) void midiWinMM::closeDevices( void ) { - for( QList::const_iterator it = m_inputDevices.keys().begin(); - it != m_inputDevices.keys().end(); ++it ) + m_inputSubs.clear(); + m_outputSubs.clear(); + QMapIterator i( m_inputDevices ); + while( i.hasNext() ) { - midiInReset( *it ); - midiInClose( *it ); +// i.next(); + midiInClose( i.next().key() ); } + QMapIterator o( m_outputDevices ); + while( o.hasNext() ) + { +// o.next(); + midiOutClose( o.next().key() ); + } +/* } for( QList::const_iterator it = m_outputDevices.keys().begin(); it != m_outputDevices.keys().end(); ++it ) { //midiOutStop( *it ); midiOutClose( *it ); - } + }*/ + m_inputDevices.clear(); + m_outputDevices.clear(); } @@ -306,15 +284,15 @@ void midiWinMM::openDevices( void ) m_inputDevices.clear(); for( int i = 0; i < midiInGetNumDevs(); ++i ) { + MIDIINCAPS c; + midiInGetDevCaps( i, &c, sizeof( c ) ); HMIDIIN hm = 0; MMRESULT res = midiInOpen( &hm, i, (DWORD) &inputCallback, (DWORD_PTR) this, CALLBACK_FUNCTION ); if( res == MMSYSERR_NOERROR ) { - MIDIINCAPS c; - midiInGetDevCaps( (UINT) hm, &c, sizeof( c ) ); - m_inputDevices[hm] = c.szPname; + m_inputDevices[hm] = qstrdup( c.szPname ); midiInStart( hm ); } }