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 }
  • Clears all existing tempo events and adds single tempo event at start Will also adjust the tempo immediately if sequence is playing when called

    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. Defaults to 120 NB: It looks at the currentPosition back in time for the last tempo event. If the sequence is not started, it returns default 120 A sequence may contain several tempo events.

    Declaration

    Swift

    open var tempo: Double { get }
  • returns an array of (MusicTimeStamp, bpm) tuples for all tempo events on the tempo track

    Declaration

    Swift

    open var allTempoEvents: [(MusicTimeStamp, Double)] { get }
  • returns the tempo at a given position in beats

    if there is more than one event precisely at the requested position it will return the most recently added Will return default 120 if there is no tempo event at or before position

    Declaration

    Swift

    open func getTempo(at position: MusicTimeStamp) -> Double

    Parameters

    at

    Position at which the tempo is desired

  • Return and array of (MusicTimeStamp, AKTimeSignature) tuples

    Declaration

    Swift

    open var allTimeSignatureEvents: [(MusicTimeStamp, AKTimeSignature)] { get }
  • returns the time signature at a given position in beats

    If there is more than one event precisely at the requested position it will return the most recently added. Will return 4/4 if there is no Time Signature event at or before position

    Declaration

    Swift

    open func getTimeSignature(at position: MusicTimeStamp) -> AKTimeSignature

    Parameters

    at

    Position at which the time signature is desired

  • 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(at timeStamp: MusicTimeStamp = 0.0,
                                    timeSignature: AKTimeSignature,
                                    ticksPerMetronomeClick: UInt8 = 24,
                                    thirtySecondNotesPerQuarter: UInt8 = 8,
                                    clearExistingEvents: Bool = true)

    Parameters

    at

    MusicTimeStamp where time signature event will be placed

    timeSignature

    Time signature for added event

    ticksPerMetronomeClick

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

    thirtySecondNotesPerQuarter

    Number of 32nd notes making a quarter, typically 8

    clearExistingEvents

    Flag that will clear other Time Signature Events from tempo track

  • 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?