This topic has been covered Numerous Times, and I have successfully used a AKMIDICallbackInstrument
with the old AKAppleSequencer
in my previous ap
To get AKCallbackInstrument
working with the new AKSequencer
, try connecting your callback instrument to your output, e.g.,
metroCallback >>> mixer
Not obvious, but has worked for me.
Edit: including a minimal working version of the new AKSequencer
with AKCallbackInstrument
class SequencerWrapper {
var seq: AKSequencer!
var cbInst: AKCallbackInstrument!
var mixer: AKMixer!
init() {
mixer = AKMixer()
AudioKit.output = mixer
seq = AKSequencer()
cbInst = AKCallbackInstrument()
// set up a track
let track = seq.addTrack(for: cbInst)
for i in 0 ..< 4 {
track.add(noteNumber: 60, position: Double(i), duration: 0.5)
}
track.length = 4.0
track.loopEnabled = true
track >>> mixer // must send track to mixer
// set up the callback instrument
cbInst.callback = { status, note, vel in
guard let status = AKMIDIStatus(byte: status),
let type = status.type,
type == .noteOn else { return }
print("note on: \(note)")
// trigger sampler etc from here
}
cbInst >>> mixer // must send callbackInst to mixer
}
func play() {
seq.playFromStart()
}
}
Thanks for the working example @c_booth! Just wanted to add for any dummies like me that couldn't figure out why the above example wasn't working, you will still need to call AudioKit.start().