Class

AVAudioSequencer

A collection of MIDI events organized into multiple music tracks, plus a player to play back the events.

Declaration

class AVAudioSequencer : NSObject

Topics

Creating an Audio Sequencer

init()

Initializes a new sequencer that's not connected to an audio engine.

init(audioEngine: AVAudioEngine)

Initializes a new sequencer, handing it the audio engine.

func write(to: URL, smpteResolution: Int, replaceExisting: Bool)

Creates and writes a MIDI file from the events in the sequence.

Handling Music Tracks

class AVMusicTrack

A collection of music events sent to a given destination, and which can be offset, muted, and manipulated independently from other track events.

enum AVMusicTrackLoopCount

Constants that define the number of times a track will loop.

Operating an Audio Sequencer

func prepareToPlay()

Gets ready to play the sequence by prerolling all events.

func start()

Start the sequencer's player.

func stop()

Stops the sequencer's player.

Managing Sequence Load Options

func load(from: Data, options: AVMusicSequenceLoadOptions)

Parses the data and adds its events to the sequence.

func load(from: URL, options: AVMusicSequenceLoadOptions)

Loads the file referenced by the URL and adds the events to the sequence.

struct AVMusicSequenceLoadOptions

A structure that defines whether data on different MIDI channels is mapped to multiple tracks, or if the tracks are preserved as they are.

Managing Time Stamps

typealias AVMusicTimeStamp

A fractional number of beats.

func hostTime(forBeats: AVMusicTimeStamp, error: NSErrorPointer) -> UInt64

Returns the host time that will be (or was) played at the specified beat.

func seconds(forBeats: AVMusicTimeStamp) -> TimeInterval

Gets the time, in seconds, for the given beat position (timestamp) in the track.

Handling Beat Range

func beats(forHostTime: UInt64, error: NSErrorPointer) -> AVMusicTimeStamp

Returns the beat that will be (or was) played at the specified host time.

func beats(forSeconds: TimeInterval) -> AVMusicTimeStamp

Gets the beat position (timestamp) for the given time in the track.

typealias AVBeatRange

A specific time range within a music track.

Getting Sequence Properties

func data(withSMPTEResolution: Int, error: NSErrorPointer) -> Data

Returns a data object containing the events from the sequence.

var currentPositionInBeats: TimeInterval

The current playback position in beats.

var currentPositionInSeconds: TimeInterval

The current playback position, in seconds.

var isPlaying: Bool

A Boolean value that indicates whether or not the sequencer's player is playing.

var rate: Float

The playback rate of the sequencer's player.

var tracks: [AVMusicTrack]

An array containing all the tracks in the sequence.

var userInfo: [String : Any]

A dictionary containing metadata derived from a sequence.

Relationships

Inherits From

Conforms To

See Also

Source Node Types

class AVAudioInputNode

A node that connects to the system's audio input.

class AVAudioIONode

The base class for nodes that connect to the system's audio input or output.

typealias AVAudioIONodeInputBlock

A block to get input data when called by a render operation in the manual rendering mode.

typealias AVAudioNodeCompletionHandler

A general callback handler.

typealias AVAudioPlayerNodeCompletionHandler

The callback handler for buffer or file completion.

class AVAudioPlayerNode

A class that plays buffers or segments of audio files.

class AVAudioUnitGenerator

An audio unit subclass that generates audio output.

class AVAudioUnitMIDIInstrument

An abstract class representing music devices or remote instruments.

class AVAudioUnitSampler

A class that encapsulates Apple's Sampler Audio Unit.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software