使用AudioKit从MIDI文件中读取音符 [英] Read note from MIDI file using AudioKit
问题描述
我正在尝试构建一个音序器,以从midi文件中呈现音符.
I am trying to build a sequencer that render the note from midi file.
当前,我正在使用AudioKit进行音乐数据处理.想知道如何使用AudioKit从midi文件中获取音符数据/事件.
Currently I am using AudioKit for the music data processing. Would like to know how can I get the note data / event from the midi file with AudioKit.
我尝试使用AKSequencer并输出到AKMIDINode来监听MIDI事件,但似乎无法从中获取任何信息.
I have tried to use AKSequencer and output to AKMIDINode to listen the MIDI event, but seems cannot get anything from it.
class CustomMIDINode: AKMIDINode {
override init(node: AKPolyphonicNode) {
print("Node create") // OK
super.init(node: node)
}
func receivedMIDINoteOff(noteNumber: MIDINoteNumber, velocity: MIDIVelocity, channel: MIDIChannel) {
print("midi note off") // Not printed
}
func receivedMIDISetupChange() {
print("midi setup changed") // Not printed
}
override func receivedMIDINoteOn(_ noteNumber: MIDINoteNumber, velocity: MIDIVelocity, channel: MIDIChannel) {
print("receivedMIDINoteOn") // Not printed
}
}
func setupSynth() {
oscBank.attackDuration = 0.05
oscBank.decayDuration = 0.1
oscBank.sustainLevel = 0.1
oscBank.releaseDuration = 0.1
}
let seq = AKSequencer(filename: "music")
let oscBank = AKOscillatorBank()
var midi = AKMIDI()
let midiNode = CustomMIDINode(node: oscBank)
setupSynth()
midi.openInput()
midi.addListener(midiNode)
seq.tracks.forEach { (track) in
track.setMIDIOutput(midiNode.midiIn)
}
AudioKit.output = midiNode
AudioKit.start()
seq.play()
推荐答案
您是否看过可供下载的示例音频工具包项目?它们对于AK故障排除非常有用.实际上,与示例文档相比,我发现这些示例更好(因为对实现的解释不是很好).
Have you looked at any of the example Audio Kit projects available for download? they are very useful for troubleshooting AK. I actually find the examples better than the documentation (as implementation isn't explained very well).
对于您的问题,您可以将Midi侦听器添加到事件中,在 Analog Synth X 项目在此处可用.
As for your question you can add a midi listener to an event, there is an example of this code in the Analog Synth X Project available here.
let midi = AKMIDI()
midi.createVirtualPorts()
midi.openInput("Session 1")
midi.addListener(self)
要获取更多工作代码,您可以参阅此尽管部分代码可能已经过时.
For a more worked bit of code you can refer to this although the code is likely out of date in parts.
这篇关于使用AudioKit从MIDI文件中读取音符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!