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

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

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

[ad_1]

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 subsequently are fairly lengthy (e.g. 1.5-2.0 seconds). If I set the Length to the size of the pattern the next occurs: Pattern one performs, Pattern two performs and can be reduce off early by the observe off of the primary pattern.

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

import SwiftUI
import AudioKit
import AVFoundation

class DrumsConductor: ObservableObject {
    
    let engine = AudioEngine()
    let sequencer = AppleSequencer()
    personal 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: Length(beats: Double(index)), length: Length(beats: 1.2))
        }
        
        sequencer.rewind()
        sequencer.play()
    }
    
    func stopSequence() {
        guard sequencer.isPlaying else { return }
        sequencer.cease()
        sequencer.preroll()
    }
    
    func begin() {
        do {
            strive engine.begin()
        } catch let err {
            Log(err)
        }
        setupSound()
    }
    
    func cease() {
        engine.cease()
    }
    
    func setupSound() {
        let path = "Sounds/Sampler Devices/Drums"
        
        do {
            strive drums.loadSoundFont(path, preset: 0, financial institution: 0)
        } catch {
            fatalError(error.localizedDescription)
        }
    }
}

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

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here