我有一个 IOS 应用程序,它使用 AudioKit 播放与 Pad 相关的声音的 AudioFiles。所以,我希望应用程序支持 MIDI 文件。我想知道如何使用 MIDI 导出这些声音文件以在 Garage band 等应用程序上播放它们
最佳答案
发送 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)
要接收 MIDI,您需要有一个实现 AKMIDIListener
协议(protocol)的类(它甚至可以是您的 ViewController,但可能不应该是)。此类允许您实现诸如 receivedMIDINoteOn
之类的方法来处理传入的事件。
class ClassThatImplementsMIDIListener: AKMIDIListener {
func receivedMIDINoteOn(noteNumber: MIDINoteNumber,
velocity: MIDIVelocity,
channel: MIDIChannel) {
// handle the MIDI event in your app, e.g., trigger you sound file
}
}
设置起来很简单:
// 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)
关于ios - 在 IOS 上使用 AudioKit 将声音文件作为 MIDI 音符发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53033484/