AKSequencer

open class AKSequencer

Sequencer based on tried-and-true CoreAudio/MIDI Sequencing

  • Music sequence

    Declaration

    Swift

    open var sequence: MusicSequence?
  • Pointer to Music Sequence

    Declaration

    Swift

    open var sequencePointer: UnsafeMutablePointer<MusicSequence>?
  • Array of AudioKit Music Tracks

    Declaration

    Swift

    open var tracks: [AKMusicTrack]
  • Loop control

    Declaration

    Swift

    open private(set) var loopEnabled: Bool
  • Sequencer Initialization

    Declaration

    Swift

    @objc
    public init()
  • Initialize the sequence with a MIDI file

    Declaration

    Swift

    public convenience init(filename: String)

    Parameters

    filename

    Location of the MIDI File

  • Initialize the sequence with a MIDI file

    Declaration

    Swift

    public convenience init(fromURL fileURL: URL)

    Parameters

    fromURL

    URL of MIDI File

  • Preroll the music player. Call this function in advance of playback to reduce the sequencers startup latency. If you call play without first calling this function, the sequencer will call this function before beginning playback.

    Declaration

    Swift

    open func preroll()
  • Set loop functionality of entire sequence

    Declaration

    Swift

    open func toggleLoop()
  • Enable looping for all tracks - loops entire sequence

    Declaration

    Swift

    open func enableLooping()
  • Enable looping for all tracks with specified length

    Declaration

    Swift

    open func enableLooping(_ loopLength: AKDuration)

    Parameters

    loopLength

    Loop length in beats

  • Disable looping for all tracks

    Declaration

    Swift

    open func disableLooping()
  • Set looping duration and count for all tracks

    Declaration

    Swift

    open func setLoopInfo(_ duration: AKDuration, numberOfLoops: Int)

    Parameters

    duration

    Duration of the loop in beats

    numberOfLoops

    The number of time to repeat

  • Set length of all tracks

    Declaration

    Swift

    open func setLength(_ length: AKDuration)

    Parameters

    length

    Length of tracks in beats

  • Length of longest track in the sequence

    Declaration

    Swift

    open var length: AKDuration { get }
  • Set the rate of the sequencer

    Declaration

    Swift

    open func setRate(_ rate: Double)

    Parameters

    rate

    Set the rate relative to the tempo of the track

  • Rate relative to the default tempo (BPM) of the track

    Declaration

    Swift

    open var rate: Double { get }
  • Set the tempo of the sequencer

    Declaration

    Swift

    open func setTempo(_ bpm: Double)
  • Add a tempo change to the score

    Declaration

    Swift

    open func addTempoEventAt(tempo bpm: Double, position: AKDuration)

    Parameters

    bpm

    Tempo in beats per minute

    position

    Point in time in beats

  • Tempo retrieved from the sequencer

    Declaration

    Swift

    open var tempo: Double { get }
  • Possible values for the time signature lower value

    See more

    Declaration

    Swift

    public enum TimeSignatureBottomValue : UInt8
  • Add a time signature event to start of tempo track NB: will affect MIDI file layout but NOT sequencer playback

    Declaration

    Swift

    open func addTimeSignatureEvent(timeSignatureTop: UInt8,
                                    timeSignatureBottom: TimeSignatureBottomValue,
                                    ticksPerMetronomeClick: UInt8 = 24,
                                    thirtySecondNotesPerQuarter: UInt8 = 8)

    Parameters

    timeSignatureTop

    Number of beats per measure

    timeSignatureBottom

    Unit of beat

    ticksPerMetronomeClick

    MIDI clocks between metronome clicks (not PPQN), typically 24

    thirtySecondNotesPerQuarter

    Number of 32nd notes making a quarter, typically 8

  • Convert seconds into AKDuration

    Declaration

    Swift

    open func duration(seconds: Double) -> AKDuration

    Parameters

    seconds

    time in seconds

  • Convert beats into seconds

    Declaration

    Swift

    open func seconds(duration: AKDuration) -> Double

    Parameters

    duration

    AKDuration

  • Play the sequence

    Declaration

    Swift

    open func play()
  • Stop the sequence

    Declaration

    Swift

    @objc
    open func stop()
  • Rewind the sequence

    Declaration

    Swift

    open func rewind()
  • Wheter or not the sequencer is currently playing

    Declaration

    Swift

    open var isPlaying: Bool { get }
  • Current Time

    Declaration

    Swift

    open var currentPosition: AKDuration { get }
  • Current Time relative to sequencer length

    Declaration

    Swift

    open var currentRelativePosition: AKDuration { get }
  • Track count

    Declaration

    Swift

    open var trackCount: Int { get }
  • Time Resolution, i.e., Pulses per quarter note

    Declaration

    Swift

    open var timeResolution: UInt32 { get }
  • Load a MIDI file from the bundle (removes old tracks, if present)

    Declaration

    Swift

    open func loadMIDIFile(_ filename: String)
  • Load a MIDI file given a URL (removes old tracks, if present)

    Declaration

    Swift

    open func loadMIDIFile(fromURL fileURL: URL)
  • Add tracks from MIDI file to existing sequencer

    Will copy only MIDINoteMessage events

    Declaration

    Swift

    open func addMIDIFileTracks(_ filename: String, useExistingSequencerLength: Bool = true)

    Parameters

    filename

    Location of the MIDI File

    useExistingSequencerLength

    flag for automatically setting length of new track to current sequence length

  • Add tracks from MIDI file to existing sequencer

    Will copy only MIDINoteMessage events

    Declaration

    Swift

    open func addMIDIFileTracks(_ url: URL, useExistingSequencerLength: Bool = true)

    Parameters

    filename

    fromURL: URL of MIDI File

    useExistingSequencerLength

    flag for automatically setting length of new track to current sequence length

  • Get a new track

    Declaration

    Swift

    open func newTrack(_ name: String = "Unnamed") -> AKMusicTrack?
  • Delete track and remove it from the sequence Not to be used during playback

    Declaration

    Swift

    open func deleteTrack(trackIndex: Int)
  • Declaration

    Swift

    open func clearRange(start: AKDuration, duration: AKDuration)

    Parameters

    start

    Start of the range to clear, in beats (inclusive)

    duration

    Length of time after the start position to clear, in beats (exclusive)

  • Set the music player time directly

    Declaration

    Swift

    open func setTime(_ time: MusicTimeStamp)

    Parameters

    time

    Music time stamp to set

  • Generate NSData from the sequence

    Declaration

    Swift

    open func genData() -> Data?
  • Print sequence to console

    Declaration

    Swift

    open func debug()
  • Set the midi output for all tracks

    Declaration

    Swift

    open func setGlobalMIDIOutput(_ midiEndpoint: MIDIEndpointRef)
  • Nearest time of quantized beat

    Declaration

    Swift

    open func nearestQuantizedPosition(quantizationInBeats: Double) -> AKDuration
  • The last quantized beat

    Declaration

    Swift

    open func previousQuantizedPosition(quantizationInBeats: Double) -> AKDuration
  • Next quantized beat

    Declaration

    Swift

    open func nextQuantizedPosition(quantizationInBeats: Double) -> AKDuration