I have a MIDI Synth Unit
AudioComponentDescription midiSynthDesc;
midiSynthDesc.componentType = kAudioUnitType_MusicDevice;
midiSynthDesc.componentSubType = kAudioUnitSubType_MIDISynth;
midiSynthDesc.componentManufacturer = kAudioUnitManufacturer_Apple;
midiSynthDesc.componentFlags = 0;
midiSynthDesc.componentFlagsMask = 0;
which used to be in an AUGraph. But since AUGraph is deprecated, I used AudioComponentInstanceNew to create it without using AUNode and AUGraph
AudioComponent foundMIDISynthReference = AudioComponentFindNext ( NULL, &midiSynthDesc);
AudioComponentInstanceNew(foundMIDISynthReference, &midiSynthUnit);
I was using it to play Sequence by attaching the Sequence to AUGraph
NSString *presetURLPath = [[NSBundle mainBundle] pathForResource:@"GortsMiniPianoJ1" ofType:@"SF2"];
NSURL * presetURL = [NSURL fileURLWithPath:presetURLPath];
[self loadFromDLSOrSoundFont: (NSURL *)presetURL withPatch: (int)3];
NSString *midiFilePath = [[NSBundle mainBundle] pathForResource:name ofType:@"mid"];
NSURL * midiFileURL = [NSURL fileURLWithPath:midiFilePath];
NewMusicPlayer(&musicPlayer);
MusicPlayerSetSequence(musicPlayer, musicSequence);
MusicSequenceSetAUGraph(musicSequence, _processingGraph);
MusicPlayerPreroll(musicPlayer);
MusicPlayerStart(musicPlayer);
But now that AUGraph is deprecated, using AudioUnit only, how can I use Play MIDI Files in Core Audio?
MusicSequence accepts a reference to a MIDIEndPointRef instead of an AUGraph. A possible workaround would be to create an internal virtual port to receive the events sent by the MusicPlayer and redispatch them to your audio unit(s). Here is a simplified example :
Creates a MIDI client :
Creates a virtual input port :
MIDI events sent by the MusicPlayer are received through the callback referenced when creating the port :
Creates a very simple MusicPlayer containing a single note :
References the EndPoint and starts playing : the played note is received by the callback where it can be redirected to an audio unit of type music device.