I\'m looking for a way to mix 2 or more midi files, each with their own sound font files. I\'ve found the following code for one file and tried to do multiple music players
Multiple MusicPlayer instances sounds a bit awkward (to keep in sync) and I have doubts that multiple AUGraphs would work. I haven't tried it myself.
One approach using a sole instance of MusicPlayer
would be to load the tracks from each midi file into a 'master' sequence. You can assign an AUSampler node (with unique soundFont) to each track (MusicTrackSetDestNode
) and connect them all through an AUMixer
. You would need to manage the tempos from each midi file (using MusicTrackNewExtendedTempoEvent
) to assign file tempos to the relevant tracks. Muting tracks + track volume is easily handled at the track or mixer level.
I guess much depends on the nature of the midi files you are working with. Fwiw - I did lots of research on midi file playback on iOS and there is nothing out there that is as easy to use as MusicPlayer. However, the Bass lib might be worth looking at if MusicPlayer turns out not to work for you.
Specifying the number of mixer inputs:
// set the bus count
UInt32 numBuses = BUS_COUNT; // a constant defined elsewhere
result = AudioUnitSetProperty(mixerUnit,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0,
&numBuses,
sizeof(numBuses));
if (noErr != result) {[self printErrorMessage: @"Error setting Bus Count" withStatus: result]; return;}