Creates a MIDI file from the events in a music sequence.
- iOS 5.0+
- macOS 10.5+
- Mac Catalyst 13.0+
- tvOS 9.0+
The music sequence that you want to create a MIDI file from.
The URL to the MIDI file to be created.
The type of file to create.
Flags that configure the file creation process.
The resolution, which depends on the file type and the music sequence type.
A result code.
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: