Reputation: 11
i have an IOS app that use AudioKit to play AudioFiles for the sound related to the Pad. So, I want the app to support MIDI files. I want to know how to export these sound files using MIDI to play them on apps like Garage band
Upvotes: 1
Views: 786
Reputation: 2225
To send MIDI:
// to send between app, create a virtual port:
AudioKit.midi.createVirtualOutputPort()
// you can specify which outputs you want to open, or open all by default:
AudioKit.midi.openOutput()
// to send a noteOn message:
AudioKit.midi.sendNoteOnMessage(noteNumber: aNoteNumber, velocity: aVelocity)
// to send a noteOff message:
AudioKit.midi.sendNoteOffMessage(noteNumber: aNoteNumber, velocity: 0)
To receive MIDI, you need to have a class which implements the AKMIDIListener
protocol (it could even be your ViewController, but probably shouldn't be). This class lets you implements methods such as receivedMIDINoteOn
to handle incoming events.
class ClassThatImplementsMIDIListener: AKMIDIListener {
func receivedMIDINoteOn(noteNumber: MIDINoteNumber,
velocity: MIDIVelocity,
channel: MIDIChannel) {
// handle the MIDI event in your app, e.g., trigger you sound file
}
}
Setting it up is easy:
// if you want to receive midi from other apps, create a virtual in
AudioKit.midi.createVirtualInputPort()
// you can specify which inputs you want to open, or open them all by default
AudioKit.midi.openInput()
// add your listener
AudioKit.midi.addListener(classImplementingMIDIListener)
Upvotes: 2