我试图用AudioKits传统音序器AKAppleSequencer来播放一个基本的MIDI文件。我已经让它播放了文件的第一个音符,但之后就没有了。(我无法从新的AKKSequencer中得到任何输出。)以下是我的代码,它与AudioKits Playgrounds的MIDI播放代码基本相同。
class MIDIPlayer {
var piano: AKMIDISampler?
var sequencer: AKAppleSequencer?
var mixer: AKMixer?
var reverb: AKCostelloReverb?
var dryWetMixer: AKDryWetMixer?
func playMidiFile() {
piano = AKMIDISampler()
try? piano!.loadWav("FM Piano")
mixer = AKMixer(piano)
reverb = AKCostelloReverb(mixer)
dryWetMixer = AKDryWetMixer(mixer!, reverb!, balance: 0.2)
AudioKit.output = dryWetMixer
sequencer = AKAppleSequencer(filename: "Score")
sequencer!.setGlobalMIDIOutput(piano!.midiIn)
sequencer!.setLength(AKDuration(beats: 16))
try? AudioKit.start()
sequencer!.play()
print("MIDIPlayer playing...")
}
}
我听到MIDI文件的第一个音符,得到以下错误警告。
2020-04-24 16:30:19.653852-0400 TauMusicTest[20668:3188919] [seq] SequenceTrack.cpp:918:Clear: Invalid beat range or track is empty
2020-04-24 16:30:19.654171-0400 TauMusicTest[20668:3188919] [seq] SequenceTrack.cpp:1028:Merge: Invalid beat range
2020-04-24 16:30:20.349048-0400 TauMusicTest[20668:3189067] HALC_ProxyIOContext::IOWorkLoop: failed to send the final message to the server, Error: 0x10000003
2020-04-24 16:30:20.450640-0400 TauMusicTest[20668:3189034] [ddagg] AggregateDevice.mm:331 Output: index 1 >= allChannelDescs size 1
2020-04-24 16:30:20.532394-0400 TauMusicTest[20668:3189251] [aqme] AQMEIO_HAL.cpp:1526:IOProc: AQDefaultDevice: Abandoning I/O cycle because reconfig pending (1).
MDIDPlayer playing...
2020-04-24 16:30:20.542721-0400 TauMusicTest[20668:3188919] [general] AKAppleSequencer.swift:deinit:41:deinit: (AKAppleSequencer.swift:deinit:41)
2020-04-24 16:30:20.542882-0400 TauMusicTest[20668:3188919] [general] AKAppleSequencer.swift:deinit:41:deinit: (AKAppleSequencer.swift:deinit:41)
2020-04-24 16:30:20.543023-0400 TauMusicTest[20668:3188919] [general] AKAppleSequencer.swift:deinit:41:deinit: (AKAppleSequencer.swift:deinit:41)
2020-04-24 16:30:20.543149-0400 TauMusicTest[20668:3188919] [general] AKAppleSequencer.swift:deinit:41:deinit: (AKAppleSequencer.swift:deinit:41)
2020-04-24 16:30:20.543264-0400 TauMusicTest[20668:3188919] [general] AKAppleSequencer.swift:deinit:41:deinit: (AKAppleSequencer.swift:deinit:41)
2020-04-24 16:30:20.698072-0400 TauMusicTest[20668:3188919] [general] AKAppleSequencer.swift:deinit:41:deinit: (AKAppleSequencer.swift:deinit:41)
2020-04-24 16:30:20.698443-0400 TauMusicTest[20668:3188919] [general] AKAppleSequencer.swift:deinit:41:deinit: (AKAppleSequencer.swift:deinit:41)
2020-04-24 16:30:20.698718-0400 TauMusicTest[20668:3188919] [general] AKAppleSequencer.swift:deinit:41:deinit: (AKAppleSequencer.swift:deinit:41)```
你已经在一个函数的范围内声明了你的采样器、混音器、音序器等。当函数完成时,操作系统认为你已经完成了对它们的处理,并会尝试释放它们使用的内存。
这个函数实际上是一个类中的方法。 试着在类的层次上声明这些变量,这样它们就可以在方法完成后持久存在。例如:。
class MySequencer {
var piano: AKMIDISampler?
var sequencer: AKAppleSequencer?
// etc. . .
func playMIDIFile() {
piano = AKMIDISampler()
try? piano!.loadWav("FM Piano")
// etc . . .
}
}