preparation for MIDI controller audio fader level support

This commit is contained in:
Volker Fischer 2019-01-12 14:32:41 +00:00
parent 91642b0c2e
commit d36cd17815
4 changed files with 69 additions and 4 deletions

View file

@ -29,7 +29,8 @@
CSound::CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ),
void* arg,
const int iCtrlMIDIChannel ) :
CSoundBase ( "CoreAudio", true, fpNewProcessCallback, arg, iCtrlMIDIChannel )
CSoundBase ( "CoreAudio", true, fpNewProcessCallback, arg, iCtrlMIDIChannel ),
midiInPortRef ( static_cast<MIDIPortRef> ( 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<short>& psData, voi
iSelInputRightChannel = 0;
iSelOutputLeftChannel = 0;
iSelOutputRightChannel = 0;
// Optional MIDI initialization --------------------------------------------
if ( iCtrlMIDIChannel != INVALID_MIDI_CH )
{
// create client and ports
MIDIClientRef midiClient = static_cast<MIDIClientRef> ( 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<CSound*> ( refCon );
if ( pSound->midiInPortRef != static_cast<MIDIPortRef> ( NULL ) )
{
MIDIPacket* midiPacket = const_cast<MIDIPacket*> ( pktlist->packet );
for ( unsigned int j = 0; j < pktlist->numPackets; j++ )
{
CVector<uint8_t> vMIDIPaketBytes ( midiPacket->length );
// copy packet and send it to the MIDI parser
for ( int i = 0; i < midiPacket->length; i++ )
{
vMIDIPaketBytes[i] = static_cast<uint8_t> ( midiPacket->data[i] );
}
pSound->ParseMIDIMessage ( vMIDIPaketBytes );
midiPacket = MIDIPacketNext ( midiPacket );
}
}
}
bool CSound::ConvertCFStringToQString ( const CFStringRef stringRef,
QString& sOut )
{

View file

@ -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];

View file

@ -97,11 +97,24 @@ void CSoundBase::run()
}
}
void CSoundBase::ParseMIDIMessage ( const CVector<int8_t>& vMIDIPaketBytes )
void CSoundBase::ParseMIDIMessage ( const CVector<uint8_t>& 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 );
}

View file

@ -116,7 +116,7 @@ protected:
void run();
bool bRun;
void ParseMIDIMessage ( const CVector<int8_t>& vMIDIPaketBytes );
void ParseMIDIMessage ( const CVector<uint8_t>& vMIDIPaketBytes );
bool bIsCallbackAudioInterface;
QString strSystemDriverTechniqueName;