【发布时间】:2022-07-03 05:35:48
【问题描述】:
我试图让一个天真的案例工作,其中从文件中读取 Midi 并让 AppleSequencer 通过打印将事件信息中继到控制台:
let path = "FullPath/To/MIDI_sample.mid"
let sequencer = AppleSequencer(fromURL: URL(fileURLWithPath: path))
let callbackInstr = MIDICallbackInstrument()
func initializeSession() {
sequencer.setGlobalMIDIOutput(callbackInstr.midiIn)
callbackInstr.callback = myCallBack
sequencer.enableLooping()
sequencer.setTempo(85.0)
sequencer.addTimeSignatureEvent(timeSignature: TimeSignature(topValue: 4, bottomValue: .four))
sequencer.setLength(Duration(beats: 4.0))
sequencer.play()
print(sequencer.isPlaying)
usleep(UInt32(5000000))
print(sequencer.isPlaying)
}
func myCallBack(a: UInt8, b:MIDINoteNumber, c:MIDIVelocity) -> () {
print(a,b,c);
}
initializeSession()
现在的控制台输出是:
2022-01-07 11:33:36.507401-0600 audioKitCommandLine[84619:12905225] [seq] SequenceTrack.cpp:927 Clear: Invalid beat range or track is empty
2022-01-07 11:33:36.507711-0600 audioKitCommandLine[84619:12905225] [seq] SequenceTrack.cpp:1037 Merge: Invalid beat range
2022-01-07 11:33:36.507940-0600 audioKitCommandLine[84619:12905225] [midi] MIDI.swift:init():52:Initializing MIDI (MIDI.swift:init():52)
true
true
Program ended with exit code: 0
我在其他地方看到Clear: Invalid beat range or track is empty 是一个警告,但我希望调用myCallBack 函数并产生输出。
【问题讨论】: