3.6.3 The MIDI block

To create a MIDI output file from a LilyPond input file, insert a \midi block, which can be empty, within the \score block;

\score {
  … music …
  \layout { }
  \midi { }

Note: A \score block that contains music and a \midi block but no \layout block produces a MIDI output file only. No notation gets printed.

A \midi block at the top level can be used to change MIDI settings globally; however, the generation of an actual MIDI file only happens when a \midi block is part of a \score block.

Similarly, a \layout block at the top level affects layout settings globally but does not influence whether printed output is produced or not.

The default output file extension (.midi) can be changed by using the -dmidi-extension option with the lilypond command:

lilypond -dmidi-extension=mid MyFile.ly

Alternatively, add the following Scheme expression before the start of either the \book, \bookpart or \score blocks. See File structure.

#(ly:set-option 'midi-extension "mid")

See also

Notation Reference: File structure, Creating output file metadata.

Installed Files: scm/midi.scm.

Known issues and warnings

There are fifteen MIDI channels available and one additional channel (#10) for drums. Staves are assigned to channels in sequence, so a score that contains more than fifteen staves will result in the extra staves sharing (but not overwriting) the same MIDI channel. This may be a problem if the sharing staves have conflicting, channel-based, MIDI properties – such as different MIDI instruments – set.

LilyPond Notation Reference v2.25.16 (development-branch).