Contents

MusicSequenceFileCreate(_:_:_:_:_:)

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

Declaration

func MusicSequenceFileCreate(_ inSequence: MusicSequence, _ inFileRef: CFURL, _ inFileType: MusicSequenceFileTypeID, _ inFlags: MusicSequenceFileFlags, _ inResolution: Int16) -> OSStatus

Parameters

  • inSequence:

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

  • inFileRef:

    The URL to the MIDI file to be created.

  • inFileType:

    The type of file to create.

  • inFlags:

    Flags that configure the file creation process.

  • inResolution:

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

Return Value

A result code.

Discussion

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

The inResolution parameter specifies the relationship between “tick” and quarter note for saving to a standard MIDI file. Pass 0 to this parameter to use the default value; namely, the value that is currently set on the tempo 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 this resolution when creating the MIDI file. If zero is specified, 25 fps and 40 ticks/frame is used (a time scale of a millisecond)

  • 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 tick represents 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 obtain millisecond resolution by specifying 25 frames/sec and 40 divisions/frame:

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

See Also

Managing Music Sequences