1

我在 Swift 中成功完成了以下操作:

  • 创建了一个 MIKMIDI 音序器
  • 将轨道添加到音序器
  • 将声音字体加载到该轨道的内置合成器
  • 将 MIDI 事件添加到轨道
  • 在音序器上触发播放

是否可以在多音色声音字体中选择预设?检查音序器轨道引用的 MIKMIDISynthesizer 实例的 availableInstruments 属性会向日志控制台报告一个空数组。这是代码:

let _ = try sequence.addTrack()
let track = sequence.tracks[0]
let trackSynth = sequencer.builtinSynthesizerForTrack(track)

if let soundfont = NSBundle.mainBundle().URLForResource("fluid_gm", withExtension: "sf2") {
    do {
        try  trackSynth?.loadSoundfontFromFileAtURL(soundfont)
          print(trackSynth!.availableInstruments)
        } catch {

        }
    }


   let note1 = MIKMIDINoteEvent(timeStamp:0.0,note:60,velocity:100,duration:5,channel:0)
   let note2 = MIKMIDINoteEvent(timeStamp:0.0,note:63,velocity:100,duration:5,channel:0)
   let note3 = MIKMIDINoteEvent(timeStamp:1.0,note:60,velocity:0,duration:5,channel:0)
   let note4 = MIKMIDINoteEvent(timeStamp:1.0,note:63,velocity:0,duration:5,channel:0)
   track.addEvents([note1!,note2!,note3!,note4!])
   sequencer.sequence = sequence
   sequencer.startPlayback()
4

0 回答 0