Music Sequence Reference

30
MusicSequence Reference Audio & Video: Audio 2009-11-25

Transcript of Music Sequence Reference

Page 1: Music Sequence Reference

MusicSequence ReferenceAudio & Video: Audio

2009-11-25

Page 2: Music Sequence Reference

Apple Inc.© 2009 Apple Inc.All rights reserved.

No part of this publication may be reproduced,stored in a retrieval system, or transmitted, inany form or by any means, mechanical,electronic, photocopying, recording, orotherwise, without prior written permission ofApple Inc., with the following exceptions: Anyperson is hereby authorized to storedocumentation on a single computer forpersonal use only and to print copies ofdocumentation for personal use provided thatthe documentation contains Apple’s copyrightnotice.

The Apple logo is a trademark of Apple Inc.

No licenses, express or implied, are grantedwith respect to any of the technology describedin this document. Apple retains all intellectualproperty rights associated with the technologydescribed in this document. This document isintended to assist application developers todevelop applications only for Apple-labeledcomputers.

Apple Inc.1 Infinite LoopCupertino, CA 95014408-996-1010

Apple, the Apple logo, Mac, and Mac OS aretrademarks of Apple Inc., registered in theUnited States and other countries.

Even though Apple has reviewed this document,APPLE MAKES NO WARRANTY OR REPRESENTATION,EITHER EXPRESS OR IMPLIED, WITH RESPECT TOTHIS DOCUMENT, ITS QUALITY, ACCURACY,MERCHANTABILITY, OR FITNESS FOR A PARTICULARPURPOSE. AS A RESULT, THIS DOCUMENT ISPROVIDED “AS IS,” AND YOU, THE READER, AREASSUMING THE ENTIRE RISK AS TO ITS QUALITYAND ACCURACY.

IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,INDIRECT, SPECIAL, INCIDENTAL, ORCONSEQUENTIAL DAMAGES RESULTING FROM ANYDEFECT OR INACCURACY IN THIS DOCUMENT, evenif advised of the possibility of such damages.

THE WARRANTY AND REMEDIES SET FORTH ABOVEARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORALOR WRITTEN, EXPRESS OR IMPLIED. No Appledealer, agent, or employee is authorized to makeany modification, extension, or addition to thiswarranty.

Some states do not allow the exclusion or limitationof implied warranties or liability for incidental orconsequential damages, so the above limitation orexclusion may not apply to you. This warranty givesyou specific legal rights, and you may also haveother rights which vary from state to state.

Page 3: Music Sequence Reference

Contents

MusicSequence Reference 5

Overview 5Functions by Task 5

Creating and Configuring Music Sequences 5Working with Music Tracks 6Working With Audio Processing Graphs and MIDI Endpoints 6Working With Time 6Working With Files 7

Functions 7DisposeMusicSequence 7MusicSequenceBarBeatTimeToBeats 8MusicSequenceBeatsToBarBeatTime 8MusicSequenceDisposeTrack 9MusicSequenceFileCreate 10MusicSequenceFileCreateData 11MusicSequenceFileLoad 12MusicSequenceFileLoadData 12MusicSequenceGetAUGraph 13MusicSequenceGetBeatsForSeconds 14MusicSequenceGetIndTrack 15MusicSequenceGetInfoDictionary 15MusicSequenceGetSecondsForBeats 16MusicSequenceGetSequenceType 16MusicSequenceGetSMPTEResolution 17MusicSequenceGetTempoTrack 17MusicSequenceGetTrackCount 18MusicSequenceGetTrackIndex 19MusicSequenceNewTrack 19MusicSequenceReverse 20MusicSequenceSetAUGraph 20MusicSequenceSetMIDIEndpoint 21MusicSequenceSetSequenceType 21MusicSequenceSetSMPTEResolution 22MusicSequenceSetUserCallback 23NewMusicSequence 23

Callbacks 24MusicSequenceUserCallback 24

Data Types 25MusicSequence 25MusicTimeStamp 25

Constants 25

32009-11-25 | © 2009 Apple Inc. All Rights Reserved.

Page 4: Music Sequence Reference

Music Sequence Load Flags 25Music Sequence Types 26Music Sequence File Type Identifiers 26Music Sequence File Flags 27

Document Revision History 29

42009-11-25 | © 2009 Apple Inc. All Rights Reserved.

CONTENTS

Page 5: Music Sequence Reference

Framework: AudioToolbox/MusicPlayer.h

Declared in MusicPlayer.h

Overview

A music sequence contains one or more music tracks, and can be played using a music player. Music tracks,in turn, can contain MIDI data and audio unit parameter automation data. A music sequence is an opaqueMusicSequence data type.

The opaque types used with a music sequence are described in the following documents:

● MusicEventIterator Reference

● MusicPlayer Reference

● MusicTrack Reference

Result codes for this opaque type are described in MusicPlayer Reference.

Functions by Task

Creating and Configuring Music Sequences

NewMusicSequence (page 23)Creates a new empty music sequence.

DisposeMusicSequence (page 7)Disposes of a music sequence.

MusicSequenceSetSequenceType (page 21)Sets the sequence type for a music sequence.

MusicSequenceGetSequenceType (page 16)Gets the sequence type for a music sequence.

MusicSequenceSetSMPTEResolution (page 22)Calculates the SMPTE resolution for a specified frame rate and number of ticks per quarter note.

Overview 52009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 6: Music Sequence Reference

MusicSequenceGetSMPTEResolution (page 17)Calculates the frame rate and number of ticks per quarter note for a specified SMPTE resolution.

MusicSequenceSetUserCallback (page 23)Registers a user callback function with a music sequence.

MusicSequenceGetInfoDictionary (page 15)Returns a dictionary containing music sequence information.

Working with Music Tracks

MusicSequenceNewTrack (page 19)Add a new, empty music track to a music sequence.

MusicSequenceDisposeTrack (page 9)Removes a music track from a music sequence, and disposes of the track.

MusicSequenceGetTrackCount (page 18)Gets the number of music tracks owned by a music sequence.

MusicSequenceGetIndTrack (page 15)Gets the music track at the specified track index.

MusicSequenceGetTrackIndex (page 19)Gets the index number for a specified music track.

MusicSequenceGetTempoTrack (page 17)Gets the tempo track for a music sequence.

Working With Audio Processing Graphs and MIDI Endpoints

MusicSequenceSetAUGraph (page 20)Associates an audio processing graph with a music sequence.

MusicSequenceGetAUGraph (page 13)Gets the audio processing graph associated with a music sequence.

MusicSequenceSetMIDIEndpoint (page 21)Associates a specified MIDI endpoint with all music tracks in a music sequence.

Working With Time

MusicSequenceGetSecondsForBeats (page 16)Calculates the number of seconds that correspond to a number of beats.

MusicSequenceGetBeatsForSeconds (page 14)Calculates the number of beats that correspond to a number of seconds.

6 Functions by Task2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 7: Music Sequence Reference

MusicSequenceBeatsToBarBeatTime (page 8)Formats a music sequence’s beat time to its bar-beat time.

MusicSequenceBarBeatTimeToBeats (page 8)Formats a music sequence’s bar-beat time to its beat time.

MusicSequenceReverse (page 20)Reverses the MIDI and tempo events in a music sequence, so the start becomes the end.

Working With Files

MusicSequenceFileLoad (page 12)Loads data into a music sequence from a URL reference.

MusicSequenceFileLoadData (page 12)Load data into a music sequence from a data reference.

MusicSequenceFileCreate (page 10)Creates a MIDI file from the events in a music sequence.

MusicSequenceFileCreateData (page 11)Creates a data object containing the events from a music sequence.

Functions

DisposeMusicSequenceDisposes of a music sequence.

OSStatus DisposeMusicSequence ( MusicSequence inSequence);

ParametersinSequence

The music sequence to dispose of.

Return ValueA result code.

DiscussionYou cannot dispose of a music sequence while it is associated with a music player.

AvailabilityAvailable in Mac OS X v10.0 and later.

See AlsoNewMusicSequence (page 23)

Related Sample CodePlaySequence

Functions 72009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 8: Music Sequence Reference

Declared InMusicPlayer.h

MusicSequenceBarBeatTimeToBeatsFormats a music sequence’s bar-beat time to its beat time.

OSStatus MusicSequenceBarBeatTimeToBeats( MusicSequence inSequence, const CABarBeatTime *inBarBeatTime, MusicTimeStamp *outBeats);

ParametersinSequence

The music sequence that you want the beat count for.

inBarBeatTimeThe bar-beat time to be represented as beats.

outBeatsOn output, the music sequence’s beat time.

Return ValueA result code.

DiscussionThe sequence's tempo track time signature events are used to to calculate the bar-beat representation. Ifthere are no Time Sig events added to the sequence 4/4 is assumed. A time signature event is a MIDI MetaEvent as specified for MIDI files.

Refer to AudioToolbox/CAClock.h for more information.

AvailabilityAvailable in Mac OS X v10.5 and later.

See AlsoMusicSequenceBeatsToBarBeatTime (page 8)

Declared InMusicPlayer.h

MusicSequenceBeatsToBarBeatTimeFormats a music sequence’s beat time to its bar-beat time.

8 Functions2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 9: Music Sequence Reference

OSStatus MusicSequenceBeatsToBarBeatTime( MusicSequence inSequence, MusicTimeStamp inBeats, UInt32 inSubbeatDivisor, CABarBeatTime *outBarBeatTime);

ParametersinSequence

The music sequence that you want bar-beat time for.

inBeatsThe beats to be represented as bar-beats.

inSubbeatDivisorThe denominator of the fractional number of beats.

outBarBeatTimeOn output, the music sequence’s bar-beat time.

Return ValueA result code.

DiscussionThe sequence's tempo track time signature events are used to to calculate the bar-beat representation. Ifthere are no Time Sig events added to the sequence 4/4 is assumed. A time signature event is a MIDI MetaEvent as specified for MIDI files.

Refer to AudioToolbox/CAClock.h for more information.

AvailabilityAvailable in Mac OS X v10.5 and later.

See AlsoMusicSequenceBarBeatTimeToBeats (page 8)

Declared InMusicPlayer.h

MusicSequenceDisposeTrackRemoves a music track from a music sequence, and disposes of the track.

OSStatus MusicSequenceDisposeTrack ( MusicSequence inSequence, MusicTrack inTrack);

ParametersinSequence

The music sequence to remove the music track from.

inTrackThe music track to remove and dispose of.

Return ValueA result code.

Functions 92009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 10: Music Sequence Reference

AvailabilityAvailable in Mac OS X v10.0 and later.

See AlsoMusicSequenceNewTrack (page 19)

Declared InMusicPlayer.h

MusicSequenceFileCreateCreates a MIDI file from the events in a music sequence.

OSStatus MusicSequenceFileCreate ( MusicSequence inSequence, CFURLRef inFileRef, MusicSequenceFileTypeID inFileType, MusicSequenceFileFlags inFlags, SInt16 inResolution);

ParametersinSequence

The music sequence that you want to create a MIDI file from.

inFileRefThe URL to the MIDI file to be created.

inFileTypeThe type of file to create.

inFlagsFlags that configure the file creation process.

inResolutionThe resolution, which depends on the file type and the music sequence type.

Return ValueA result code.

DiscussionThis function can be (and is most commonly) used to create a MIDI file from the events in a sequence. OnlyMIDI based events are used when creating the MIDI file. MIDI files are normally beat based, but can also havea SMPTE (or real-time rather than beat time) representation.

The inResolution parameter specifies the relationship between "tick" and quarter note for saving to a standardMIDI file. Pass 0 to this parameter to use the default value; namely, the value that is currently set on thetempo track.

The various sequence types determine the kinds of files that can be created, as follows:

● Beats—When saving a MIDI file, it saves a beats (PPQ) based axis.

● Seconds—When saving a MIDI file, it will save it as a SMPTE resolution - so you should specify thisresolution when creating the MIDI file. If zero is specified, 25 fps and 40 ticks/frame is used (a time scaleof a millisecond)

10 Functions2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 11: Music Sequence Reference

● Samples—You cannot save to a MIDI file with this sequence type.

The complete meaning of the 16-bit "division" field in a MIDI File's MThd chunk. If it is positive, then a tickrepresents 1/D quarter notes. If it negative, the following pertains:

● Bits 14-8 are a signed 7-bit number representing the SMPTE format: 24, -25, -29 (drop), -30.

● Bits 7-0 represents the number of ticks per SMPTE frame. Typical values are 4, 10, 80, 100. You can obtainmillisecond resolution by specifying 25 frames/sec and 40 divisions/frame:

30 fps with 80 bits (ticks) per frame: 0xE250 ((char)0xE2 == -30)

AvailabilityAvailable in Mac OS X v10.5 and later.

See AlsoMusicSequenceFileCreateData (page 11)MusicSequenceSetSMPTEResolution (page 22)

Declared InMusicPlayer.h

MusicSequenceFileCreateDataCreates a data object containing the events from a music sequence.

OSStatus MusicSequenceFileCreateData ( MusicSequence inSequence, MusicSequenceFileTypeID inFileType, MusicSequenceFileFlags inFlags, SInt16 inResolution, CFDataRef *outData);

ParametersinSequence

The music sequence that you want to create a MIDI data object from.

inFileTypeThe type of file format for the data in the data object.

inFlagsFlags that configure the data object creation process.

inResolutionThe resolution, which depends on the file type and the music sequence type.

outDataOn output, the data object containing MIDI data in the specified format.

Return ValueA result code.

DiscussionThe CFData object should be released by the caller.

Functions 112009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 12: Music Sequence Reference

AvailabilityAvailable in Mac OS X v10.5 and later.

See AlsoMusicSequenceFileCreate (page 10)

Declared InMusicPlayer.h

MusicSequenceFileLoadLoads data into a music sequence from a URL reference.

OSStatus MusicSequenceFileLoad ( MusicSequence inSequence, CFURLRef inFileRef, MusicSequenceFileTypeID inFileTypeHint, // can be zero in many cases MusicSequenceLoadFlags inFlags);

ParametersinSequence

The music sequence to load the data into.

inFileRefA file:// URL pointing to a file that contains the data to load.

inFileTypeHintProvides a hint to the system about the file type referenced by the inFileRef parameter.

inFlagsFlags that specify how the data should be parsed, and how it should be assigned to tracks. See “MusicSequence Load Flags” (page 25).

Return ValueA result code.

AvailabilityAvailable in Mac OS X v10.5 and later.

See AlsoMusicSequenceFileLoadData (page 12)

Related Sample CodePlaySequence

Declared InMusicPlayer.h

MusicSequenceFileLoadDataLoad data into a music sequence from a data reference.

12 Functions2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 13: Music Sequence Reference

OSStatus MusicSequenceFileLoadData ( MusicSequence inSequence, CFDataRef inData, MusicSequenceFileTypeID inFileTypeHint, // can be zero in many cases MusicSequenceLoadFlags inFlags);

ParametersinSequence

The music sequence to load the data into.

inDataThe contents of a valid file loaded into a CFData object.

inFileTypeHintProvides a hint to the system about the file type referenced by the inFileRef parameter.

inFlagsFlags that specify how the data should be parsed, and how it should be assigned to tracks. See “MusicSequence Load Flags” (page 25).

Return ValueA result code.

DiscussionThe data to be loaded must conform to the file type indicated by the inFileTypeHint parameter.

AvailabilityAvailable in Mac OS X v10.5 and later.

See AlsoMusicSequenceFileLoad (page 12)

Declared InMusicPlayer.h

MusicSequenceGetAUGraphGets the audio processing graph associated with a music sequence.

OSStatus MusicSequenceGetAUGraph ( MusicSequence inSequence, AUGraph *outGraph);

ParametersinSequence

The music sequence whose associated audio processing graph you want to get.

outGraphOn output, the audio processing graph associated with the music sequence.

Return ValueA result code.

Functions 132009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 14: Music Sequence Reference

DiscussionIf no audio processing graph is already associated with the music sequence, this function creates a defaultgraph. The default graph contains an Instrument unit (of type DLSMusicDevice) and a dynamic compressorunit (of type DynamicCompressor). In this case, all music tracks in the music sequence have their outputsdirected to the Instrument unit.

AvailabilityAvailable in Mac OS X v10.0 and later.

See AlsoMusicSequenceSetAUGraph (page 20)

Related Sample CodePlaySequence

Declared InMusicPlayer.h

MusicSequenceGetBeatsForSecondsCalculates the number of beats that correspond to a number of seconds.

OSStatus MusicSequenceGetBeatsForSeconds ( MusicSequence inSequence, Float64 inSeconds, MusicTimeStamp *outBeats);

ParametersinSequence

The sequence that you want to get a count of beats for.

inSecondsThe number of seconds that you want the corresponding number of beats for.

outBeatsOn output, the number of beats that corresponds to the number of seconds in the inSecondsparameter.

Return ValueA result code.

DiscussionThis function makes use of the music sequence’s tempo track.

AvailabilityAvailable in Mac OS X v10.2 and later.

See AlsoMusicSequenceGetSecondsForBeats (page 16)

Declared InMusicPlayer.h

14 Functions2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 15: Music Sequence Reference

MusicSequenceGetIndTrackGets the music track at the specified track index.

OSStatus MusicSequenceGetIndTrack ( MusicSequence inSequence, UInt32 inTrackIndex, MusicTrack *outTrack);

ParametersinSequence

The music sequence to obtain the music track from.

inTrackIndexThe whole-number index for the music track you want to obtain. This function returns an error if thevalue for this parameter is not greater than 0 and less than the number of music tracks.

outTrackOn output, the music track specified by the inTrackIndex parameter.

Return ValueA result code.

DiscussionThis function is for accessing only music tracks, not the tempo track.

AvailabilityAvailable in Mac OS X v10.0 and later.

See AlsoMusicSequenceGetTrackIndex (page 19)

Related Sample CodePlaySequence

Declared InMusicPlayer.h

MusicSequenceGetInfoDictionaryReturns a dictionary containing music sequence information.

CFDictionaryRef MusicSequenceGetInfoDictionary ( MusicSequence inSequence);

ParametersinSequence

The music sequence that you want the information dictionary from.

Return ValueA dictionary object containing information about a music sequence.

Functions 152009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 16: Music Sequence Reference

DiscussionThe dictionary can contain one or more of the kAFInfoDictionary_* keys specified inAudioToolbox/AudioFile.h. The caller should release the returned dictionary. If the call fails it will returnNULL

AvailabilityAvailable in Mac OS X v10.5 and later.

Declared InMusicPlayer.h

MusicSequenceGetSecondsForBeatsCalculates the number of seconds that correspond to a number of beats.

OSStatus MusicSequenceGetSecondsForBeats ( MusicSequence inSequence, MusicTimeStamp inBeats, Float64 *outSeconds);

ParametersinSequence

The sequence that you want to get a count of seconds for.

inBeatsThe number of beats that you want the corresponding number of seconds for.

outSecondsOn output, the number of seconds that corresponds to the number of beats in the inBeats parameter.

Return ValueA result code.

DiscussionThis function makes use of the music sequence’s tempo track.

AvailabilityAvailable in Mac OS X v10.2 and later.

See AlsoMusicSequenceGetBeatsForSeconds (page 14)

Declared InMusicPlayer.h

MusicSequenceGetSequenceTypeGets the sequence type for a music sequence.

16 Functions2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 17: Music Sequence Reference

OSStatus MusicSequenceGetSequenceType ( MusicSequence inSequence, MusicSequenceType *outType);

ParametersinSequence

The music sequence whose sequence type you want to get.

outTypeOn output, the sequence type for the music sequence.

Return ValueA result code.

AvailabilityAvailable in Mac OS X v10.5 and later.

See AlsoMusicSequenceSetSequenceType (page 21)

Declared InMusicPlayer.h

MusicSequenceGetSMPTEResolutionCalculates the frame rate and number of ticks per quarter note for a specified SMPTE resolution.

MusicSequenceGetSMPTEResolution ( SInt16 inRes, SignedByte *fps, Byte *ticks);

ParametersinRes

The SMPTE resolution of a MIDI file.

fpsFrames per second.

ticksTicks per quarter note.

See AlsoMusicSequenceFileCreate (page 10)MusicSequenceSetSMPTEResolution (page 22)

MusicSequenceGetTempoTrackGets the tempo track for a music sequence.

Functions 172009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 18: Music Sequence Reference

OSStatus MusicSequenceGetTempoTrack ( MusicSequence inSequence, MusicTrack *outTrack);

ParametersinSequence

The music sequence whose tempo track you want to obtain.

outTrackOn output, the tempo track.

Return ValueA result code.

DiscussionEach music sequence has a single tempo track. All tempo events are placed into this track, as well as someother events—such as the time signature from a MIDI file. The tempo track, once retrieved, can be editedand iterated over as can a music track. Most non-tempo events in a tempo track are ignored.

AvailabilityAvailable in Mac OS X v10.1 and later.

Declared InMusicPlayer.h

MusicSequenceGetTrackCountGets the number of music tracks owned by a music sequence.

OSStatus MusicSequenceGetTrackCount ( MusicSequence inSequence, UInt32 *outNumberOfTracks);

ParametersinSequence

The music sequence whose track count you want.

outNumberOfTracksOn output, the number of music tracks in the music sequence.

Return ValueA result code.

DiscussionThe track count provided by this function excludes the tempo track.

AvailabilityAvailable in Mac OS X v10.0 and later.

Related Sample CodePlaySequence

Declared InMusicPlayer.h

18 Functions2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 19: Music Sequence Reference

MusicSequenceGetTrackIndexGets the index number for a specified music track.

OSStatus MusicSequenceGetTrackIndex ( MusicSequence inSequence, MusicTrack inTrack, UInt32 *outTrackIndex);

ParametersinSequence

The music sequence to obtain the track index number from.

inTrackThe music track whose index you want to obtain. This function returns an error if the music track isnot part of the music sequence specified in the inSequence parameter.

outTrackIndexOn output, the zero-based index of the music track that you provided in the inTrack parameter.

Return ValueA result code.

DiscussionThis function is for accessing only indexes for music tracks, not the tempo track.

AvailabilityAvailable in Mac OS X v10.0 and later.

See AlsoMusicSequenceGetIndTrack (page 15)

Declared InMusicPlayer.h

MusicSequenceNewTrackAdd a new, empty music track to a music sequence.

OSStatus MusicSequenceNewTrack ( MusicSequence inSequence, MusicTrack *outTrack);

ParametersinSequence

The music sequence to add the new music track to.

outTrackOn output, the new music track that was appended to the list of tracks for the music sequence.

Return ValueA result code.

AvailabilityAvailable in Mac OS X v10.0 and later.

Functions 192009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 20: Music Sequence Reference

See AlsoMusicSequenceDisposeTrack (page 9)

Declared InMusicPlayer.h

MusicSequenceReverseReverses the MIDI and tempo events in a music sequence, so the start becomes the end.

OSStatus MusicSequenceReverse ( MusicSequence inSequence);

ParametersinSequence

The music sequence that you want to time-reverse.

Return ValueA result code.

AvailabilityAvailable in Mac OS X v10.0 and later.

Declared InMusicPlayer.h

MusicSequenceSetAUGraphAssociates an audio processing graph with a music sequence.

OSStatus MusicSequenceSetAUGraph ( MusicSequence inSequence, AUGraph inGraph);

ParametersinSequence

The music sequence to associate with an audio processing graph.

inGraphThe audio processing graph to associate with the music sequence.

Return ValueA result code.

DiscussionAfter you call this function, the system directs a played music sequence’s output to the associated audioprocessing graph. By default, all music tracks in the sequence are directed to the first node in the graph thatis an Instrument unit (of type DLSMusicDevice).

AvailabilityAvailable in Mac OS X v10.0 and later.

20 Functions2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 21: Music Sequence Reference

See AlsoMusicSequenceGetAUGraph (page 13)

Declared InMusicPlayer.h

MusicSequenceSetMIDIEndpointAssociates a specified MIDI endpoint with all music tracks in a music sequence.

OSStatus MusicSequenceSetMIDIEndpoint ( MusicSequence inSequence, MIDIEndpointRef inEndpoint);

ParametersinSequence

The music sequence that you want to associate with a MIDI endpoint.

inEndpointThe MIDI endpoint to associate with the music sequence.

Return ValueA result code.

DiscussionThis is a convenience function, equivalent to iterating through the music tracks in a music sequence andtargeting each to the MIDI endpoint.

AvailabilityAvailable in Mac OS X v10.1 and later.

Related Sample CodePlaySequence

Declared InMusicPlayer.h

MusicSequenceSetSequenceTypeSets the sequence type for a music sequence.

OSStatus MusicSequenceSetSequenceType ( MusicSequence inSequence, MusicSequenceType inType);

ParametersinSequence

The music sequence whose sequence type you want to set.

inTypeThe type of sequence to assign to the music sequence. For the list of available sequence types, see“Music Sequence Types” (page 26). The default sequence type is kMusicSequenceType_Beats.

Functions 212009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 22: Music Sequence Reference

Return ValueA result code.

DiscussionThe sequence type can be set to kMusicSequenceType_Beats at any time. The sequence type can onlybe set to kMusicSequenceType_Seconds or kMusicSequenceType_Samples if there are no tempo eventsalready in the sequence.

The following considerations pertain to the various sequence types:

● kMusicSequenceType_Beats—Tempo is specified as beats-per-minute. A music sequence of this typecan contain any number of tempo events.

● kMusicSequenceType_Samples—Tempo is specified as a sample rate, in terms of samples-per-second.If you set the tempo to 44,100 using a sequence of this type, then 44,100 beats corresponds to a durationof one second.

● kMusicSequenceType_Seconds—The tempo should be set to 60; a beat is a second.

After setting a music sequence to the kMusicSequenceType_Samples or kMusicSequenceType_Secondstype, add a single tempo event to specify the tempo.

A meta event of interest for the kMusicSequenceType_Seconds sequence type is the SMPTE Offset metaevent, which is stored in the tempo track. The sequence doesn't do anything with this event.

AvailabilityAvailable in Mac OS X v10.5 and later.

See AlsoMusicSequenceGetSequenceType (page 16)

Declared InMusicPlayer.h

MusicSequenceSetSMPTEResolutionCalculates the SMPTE resolution for a specified frame rate and number of ticks per quarter note.

SInt16 MusicSequenceSetSMPTEResolution ( SignedByte fps, Byte ticks);

Parametersfps

Frames per second.

ticksTicks per quarter note.

Return ValueA SMPTE resolution.

See AlsoMusicSequenceFileCreate (page 10)

22 Functions2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 23: Music Sequence Reference

MusicSequenceGetSMPTEResolution (page 17)

MusicSequenceSetUserCallbackRegisters a user callback function with a music sequence.

OSStatus MusicSequenceSetUserCallback ( MusicSequence inSequence, MusicSequenceUserCallback inCallback, void *inClientData);

ParametersinSequence

The music sequence that you want to add a user callback function to.

inCallbackA reference to your callback function. Use NULL to remove a registered callback function.

inClientDataYour data that the music sequence provides back to your callback function when it is invoked.

Return ValueA result code.

DiscussionThe music sequence invokes your callback for each user event added to any music track owned by thesequence. If there is a callback registered, then UserEvents will be chased when MusicPlayerSetTime is called.In that case the inStartSliceBeat and inEndSliceBeat will both be the same value and will be the beat that theplayer is chasing to.

Usually, where the sequence data is being scheduled for playback, the following applies:

inStartSliceBeat <= inEventTime < inEndSliceBeat

The only exception to this is if the track that owns the MusicEvent is looping. In this case the start beat willstill be less than the end beat (so your callback can still determine that it is playing, and what beats arecurrently being scheduled), however, the inEventTime will be the original time-stamped time of the userevent.

AvailabilityAvailable in Mac OS X v10.3 and later.

Declared InMusicPlayer.h

NewMusicSequenceCreates a new empty music sequence.

Functions 232009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 24: Music Sequence Reference

OSStatus NewMusicSequence ( MusicSequence *outSequence);

ParametersoutSequence

On output, the new, empty music sequence.

Return ValueA result code.

DiscussionA new music sequence has only a tempo track, with a default tempo of 120 beats-per-minute. The defaultsequence type is beat-based. For the various sequence types, see “Music Sequence Types” (page 26).

To direct the output of a music sequence to an audio processing graph, use theMusicSequenceSetAUGraph (page 20) function. To direct the output instead to a MIDI endpoint, use theMusicSequenceSetMIDIEndpoint (page 21) function.

To direct the output of a specific music track, use the MusicTrackSetDestNode andMusicTrackSetDestMIDIEndpoint functions, described in MusicTrack Reference.

AvailabilityAvailable in Mac OS X v10.0 and later.

See AlsoDisposeMusicSequence (page 7)

Related Sample CodePlaySequence

Declared InMusicPlayer.h

Callbacks

MusicSequenceUserCallback

typedef void (*MusicSequenceUserCallback) ( void *inClientData, MusicSequence inSequence, MusicTrack inTrack, MusicTimeStamp inEventTime, const MusicEventUserData *inEventData, MusicTimeStamp inStartSliceBeat, MusicTimeStamp inEndSliceBeat);

If you named your callback MyMusicSequenceUserCallback, you would declare it like this:

void MyMusicSequenceUserCallback ( void *inClientData, MusicSequence inSequence,

24 Callbacks2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 25: Music Sequence Reference

MusicTrack inTrack, MusicTimeStamp inEventTime, const MusicEventUserData *inEventData, MusicTimeStamp inStartSliceBeat, MusicTimeStamp inEndSliceBeat);

AvailabilityAvailable in Mac OS X v10.3 and later.

Declared InMusicPlayer.h

Data Types

MusicSequenceA music sequence.

typedef struct OpaqueMusicSequence *MusicSequence;

AvailabilityAvailable in Mac OS X v10.0 and later.

Declared InMusicPlayer.h

MusicTimeStampA timestamp for use by a music sequence.

typedef Float64 MusicTimeStamp;

AvailabilityAvailable in Mac OS X v10.0 and later.

Declared InMusicPlayer.h

Constants

Music Sequence Load FlagsFlags used to configure the behavior of the MusicSequenceFileLoad (page 12) andMusicSequenceFileLoadData (page 12) functions.

Data Types 252009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 26: Music Sequence Reference

enum { kMusicSequenceLoadSMF_ChannelsToTracks = (1 << 0)};typedef UInt32 MusicSequenceLoadFlags;

ConstantskMusicSequenceLoadSMF_ChannelsToTracks

If this flag is set the resultant Sequence will contain a tempo track, 1 track for each MIDI Channel thatis found in the SMF, 1 track for SysEx or MetaEvents - and this will be the last track in the sequenceafter the LoadSMFWithFlags calls.

Available in Mac OS X v10.3 and later.

Declared in MusicPlayer.h.

Music Sequence TypesThe various types of music sequences.

enum { kMusicSequenceType_Beats = 'beat', kMusicSequenceType_Seconds = 'secs', kMusicSequenceType_Samples = 'samp'};typedef UInt32 MusicSequenceType;

ConstantskMusicSequenceType_Beats

Used for a music sequence that corresponds to a normal MIDI file. The tempo track defines the numberof beats per second and can have multiple tempo events.

Available in Mac OS X v10.5 and later.

Declared in MusicPlayer.h.

kMusicSequenceType_SecondsUsed for a music sequence that corresponds to a MIDI file, but employs SMPTE timecode. The tempotrack contains a single tempo event that specifies 60 beat-per-minute.

Available in Mac OS X v10.5 and later.

Declared in MusicPlayer.h.

kMusicSequenceType_SamplesUsed for audio samples; a music sequence of this type cannot be saved to a MIDI file. The tempo trackcontains a single tempo event that specifies an audio sample rate in samples-per-second.

Available in Mac OS X v10.5 and later.

Declared in MusicPlayer.h.

Music Sequence File Type IdentifiersThe various types of files that can be parsed by a music sequence.

26 Constants2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 27: Music Sequence Reference

enum { kMusicSequenceFile_MIDIType = 'midi', kMusicSequenceFile_iMelodyType = 'imel'};typedef UInt32 MusicSequenceFileTypeID;

ConstantskMusicSequenceFile_MIDIType

A MIDI file type

Available in Mac OS X v10.5 and later.

Declared in MusicPlayer.h.

kMusicSequenceFile_iMelodyTypeAn iMelody file type.

Available in Mac OS X v10.5 and later.

Declared in MusicPlayer.h.

Music Sequence File FlagsFlags that configure the behavior of the MusicSequenceFileCreate (page 10) andMusicSequenceFileCreateData (page 11) functions.

enum { kMusicSequenceFileFlags_EraseFile = 1};typedef UInt32 MusicSequenceFileFlags;

ConstantskMusicSequenceFileFlags_EraseFile

Specifies that an existing file should be erased when creating a new file.

Available in Mac OS X v10.5 and later.

Declared in MusicPlayer.h.

Constants 272009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 28: Music Sequence Reference

28 Constants2009-11-25 | © 2009 Apple Inc. All Rights Reserved.

MusicSequence Reference

Page 29: Music Sequence Reference

This table describes the changes to MusicSequence Reference.

NotesDate

Added descriptions for the MusicSequenceSetSMPTEResolution (page 22)and MusicSequenceGetSMPTEResolution (page 17) inline functions.

2009-11-25

Other minor improvements.

New document that describes a playable collection of MIDI music tracks.2009-11-17

292009-11-25 | © 2009 Apple Inc. All Rights Reserved.

REVISION HISTORY

Document Revision History

Page 30: Music Sequence Reference

302009-11-25 | © 2009 Apple Inc. All Rights Reserved.

REVISION HISTORY

Document Revision History