iosswiftaudioaudiokitaksequencer

How to sequence raw values instead of midi notes with Audiokit


I am new to Audiokit. I want to sequence a set of Double raw values to be used like attenuators in eurorack modules. Using the AKSequencer seems not to be possible as they are meant to be used with tracks (AudioKit.AKMusicTrack), sending MIDI data to AKMidi-Insrument instances. How is it then possible to sequence f.e. raw oscillator or table attribute values? Thnx!


Solution

  • Using an AKCallbackInstrument and some values in an array with the length of the sequence it is possible

    let sequenceLength = AKDuration(beats: 8.0)
    let sequencerCallbackInst = AKCallbackInstrument()
    var seq1Values = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    
    ...
    
    sequencer.setLength(sequenceLength)
    let stepSize: Float = 1 //1/8
    let numberOfSteps = Int(Float(sequenceLength.beats) / stepSize)
    
    ...
    
    let seqPositioncallbackTrack = sequencer.newTrack()
    seqPositioncallbackTrack?.setMIDIOutput(sequencerCallbackInst.midiIn)
            sequencerCallbackInst.callback = { status, noteNumber, velocity in
                self.onSequencerStepChange(status: status, noteNumber: noteNumber, velocity: velocity)
            }
    
    ...
    
    for i in 0 ..< numberOfSteps {
                seqPositioncallbackTrack?.add(noteNumber: MIDINoteNumber(i), velocity: 100, position: AKDuration(beats: Double(i)), duration: AKDuration(beats: 0.5))
    
    ...
    
        private func onSequencerStepChange(status: AKMIDIStatus, noteNumber: MIDINoteNumber, velocity: MIDIVelocity) {
    
            guard status == .noteOn
            else { return }
    
            let stepValue = Int(noteNumber)
            // do something
    
    ...