I'm trying to record MIDI tracks with one sampler, but in the same time. For every new recording, it's creating new track on sequencer, callback instrument using different channel.
When tracks don't intersect, everything works fine. But when I add notes for new track, which intersect with already recorded track, just recordered track on playback will not call callback function for sound and it will be standard 'beep'.
Here's the code of setting track and callback function:
func startRecord() {
guard let newTrack = sequencer.newTrack() else { return }
recordingTrack = newTrack
recordingChannel = MIDIChannel(sequencer.tracks.count)
let midiInstrument = AKMIDICallbackInstrument()
let channel = recordingChannel
let sampler = currentSampler
midiInstrument.callback = { (status, note, velocity) in
let status = AKMIDIStatus(byte: status)!.type!
switch status {
case .noteOn:
try! sampler.play(noteNumber: note, velocity: velocity, channel: channel!)
case .noteOff:
try! sampler.stop(noteNumber: note, channel: channel!)
default:
break
}
}
newTrack.setMIDIOutput(midiInstrument.midiIn)
sequencer.rewind()
sequencer.preroll()
sequencer.play()
}