diff --git a/mac/sound.cpp b/mac/sound.cpp index 2698fc36..2dd41260 100755 --- a/mac/sound.cpp +++ b/mac/sound.cpp @@ -29,7 +29,8 @@ CSound::CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), void* arg, const int iCtrlMIDIChannel ) : - CSoundBase ( "CoreAudio", true, fpNewProcessCallback, arg, iCtrlMIDIChannel ) + CSoundBase ( "CoreAudio", true, fpNewProcessCallback, arg, iCtrlMIDIChannel ), + midiInPortRef ( static_cast ( NULL ) ) { // Apple Mailing Lists: Subject: GUI Apps should set kAudioHardwarePropertyRunLoop // in the HAL, From: Jeff Moore, Date: Fri, 6 Dec 2002 @@ -169,6 +170,25 @@ CSound::CSound ( void (*fpNewProcessCallback) ( CVector& psData, voi iSelInputRightChannel = 0; iSelOutputLeftChannel = 0; iSelOutputRightChannel = 0; + + + // Optional MIDI initialization -------------------------------------------- + if ( iCtrlMIDIChannel != INVALID_MIDI_CH ) + { + // create client and ports + MIDIClientRef midiClient = static_cast ( NULL ); + MIDIClientCreate ( CFSTR ( APP_NAME ), NULL, NULL, &midiClient ); + MIDIInputPortCreate ( midiClient, CFSTR ( "Input port" ), callbackMIDI, this, &midiInPortRef ); + + // open connections from all sources + const int iNMIDISources = MIDIGetNumberOfSources(); + + for ( int i = 0; i < iNMIDISources; i++ ) + { + MIDIEndpointRef src = MIDIGetSource ( i ); + MIDIPortConnectSource ( midiInPortRef, src, NULL) ; + } + } } void CSound::GetAudioDeviceInfos ( const AudioDeviceID DeviceID, @@ -832,6 +852,32 @@ if ( iNumInChan == 4 ) return kAudioHardwareNoError; } +void CSound::callbackMIDI ( const MIDIPacketList* pktlist, + void* refCon, + void* ) +{ + CSound* pSound = static_cast ( refCon ); + + if ( pSound->midiInPortRef != static_cast ( NULL ) ) + { + MIDIPacket* midiPacket = const_cast ( pktlist->packet ); + + for ( unsigned int j = 0; j < pktlist->numPackets; j++ ) + { + CVector vMIDIPaketBytes ( midiPacket->length ); + + // copy packet and send it to the MIDI parser + for ( int i = 0; i < midiPacket->length; i++ ) + { + vMIDIPaketBytes[i] = static_cast ( midiPacket->data[i] ); + } + pSound->ParseMIDIMessage ( vMIDIPaketBytes ); + + midiPacket = MIDIPacketNext ( midiPacket ); + } + } +} + bool CSound::ConvertCFStringToQString ( const CFStringRef stringRef, QString& sOut ) { diff --git a/mac/sound.h b/mac/sound.h index 8c73eada..7952625b 100755 --- a/mac/sound.h +++ b/mac/sound.h @@ -103,11 +103,17 @@ protected: const AudioTimeStamp*, void* inRefCon ); + static void callbackMIDI ( const MIDIPacketList* pktlist, + void* refCon, + void* ); + AudioDeviceID audioInputDevice[MAX_NUMBER_SOUND_CARDS]; AudioDeviceID audioOutputDevice[MAX_NUMBER_SOUND_CARDS]; AudioDeviceIOProcID audioInputProcID; AudioDeviceIOProcID audioOutputProcID; + MIDIPortRef midiInPortRef; + QString sChannelNamesInput[MAX_NUM_IN_OUT_CHANNELS]; QString sChannelNamesOutput[MAX_NUM_IN_OUT_CHANNELS]; diff --git a/src/soundbase.cpp b/src/soundbase.cpp index b9c24e8c..f7678f24 100755 --- a/src/soundbase.cpp +++ b/src/soundbase.cpp @@ -97,11 +97,24 @@ void CSoundBase::run() } } -void CSoundBase::ParseMIDIMessage ( const CVector& vMIDIPaketBytes ) +void CSoundBase::ParseMIDIMessage ( const CVector& vMIDIPaketBytes ) { + for ( int i = 0; i < vMIDIPaketBytes.Size(); i++ ) + { + +// TEST debugging +printf ( "%02X ", vMIDIPaketBytes[i] ); + + } + +// TEST +static int cnt = 0; +cnt++; +if ( cnt >= 10 * AUD_MIX_FADER_MAX ) cnt = 0; + // TODO int iChannelIdx = 0; -int iFaderLevel = 0; +int iFaderLevel = cnt / 10; EmitControllerInFaderLevel ( iChannelIdx, iFaderLevel ); } diff --git a/src/soundbase.h b/src/soundbase.h index b51a091b..c38ef741 100755 --- a/src/soundbase.h +++ b/src/soundbase.h @@ -116,7 +116,7 @@ protected: void run(); bool bRun; - void ParseMIDIMessage ( const CVector& vMIDIPaketBytes ); + void ParseMIDIMessage ( const CVector& vMIDIPaketBytes ); bool bIsCallbackAudioInterface; QString strSystemDriverTechniqueName;