ios - 在 IOS 上使用 AudioKit 将声音文件作为 MIDI 音符发送

标签 ios swift midi audiokit

我有一个 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/

相关文章:

ios - 是否可以向没有来源的现有枚举添加案例?

ios - 带有左右标签的 UITableViewCell。如何让它们正确显示?

xcode - Swift 自定义框架 - 合并模块命令失败,退出代码为 1

ios - Estimote iOS SDK Examples 找不到要选择的信标

ios - 如何在 UITableViewCell (Swift) 中暂停 AVPlayer?

ios - 找不到有效的 GoogleService-info.plist

ios - 使用 "self"的未解析标识符

loops - iOS9 Beta 和 MusicTrackLoopInfo

java - 如何向 jMusic 添加 "Arabian"或 "Microtone"或 "Quarter-tone"支持?

java - 输出简单 MIDI 文件的最简单方法?