iOS Development

ios – How can I arrange AppleSequencer and MIDISampler to disregard noteOffs?

I am utilizing AudioKit 5.6.2 to create a easy Drum Sequencer. I am utilizing some Samples that have already got reverb on them and due to this fact are fairly lengthy (e.g. 1.5-2.0 seconds). If I set the Period to the size of the pattern the next occurs: Pattern one performs, Pattern two performs and can be minimize off early by the observe off of the primary pattern.

I obtained the next code for making a easy Drum Sequencer, much like the one within the AudioKit CookBook:

import SwiftUI
import AudioKit
import AVFoundation

class DrumsConductor: ObservableObject {
    
    let engine = AudioEngine()
    let sequencer = AppleSequencer()
    non-public var drums = MIDISampler(identify: "Drums")
    
    var tempo: Double = 60.0 {
        didSet {
            sequencer.setTempo(tempo)
        }
    }
    
    init() {
        engine.output = drums
    }
    
    func destroy() {
        drums.destroyEndpoint()
    }
    
    func playSequence() {
        sequencer.cease()
        sequencer.setTempo(tempo)
        if sequencer.trackCount < 1 {
            let _ = sequencer.newTrack()
        }
        sequencer.setGlobalMIDIOutput(drums.midiIn)
        
        for index in 0..<8 {
            sequencer.tracks[0].add(noteNumber: 48, velocity: 60, place: Period(beats: Double(index)), period: Period(beats: 1.2))
        }
        
        sequencer.rewind()
        sequencer.play()
    }
    
    func stopSequence() {
        guard sequencer.isPlaying else { return }
        sequencer.cease()
        sequencer.preroll()
    }
    
    func begin() {
        do {
            attempt engine.begin()
        } catch let err {
            Log(err)
        }
        setupSound()
    }
    
    func cease() {
        engine.cease()
    }
    
    func setupSound() {
        let path = "Sounds/Sampler Devices/Drums"
        
        do {
            attempt drums.loadSoundFont(path, preset: 0, financial institution: 0)
        } catch {
            fatalError(error.localizedDescription)
        }
    }
}

I attempted to discover a approach to make the AppleSequencer or MIDISampler ignore noteOffs however could not discover something. I would have the ability to calculate the period of every pattern by measuring its distance to the subsequent hit or I would use a number of tracks which are used alternating. However clearly I might want an answer the place the samples simply are usually not minimize off. Is there Something I might do about it inside current AudioKit options?

Credit: www.ismmailgsm.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button