3.5.1 Creating MIDI files

To create a MIDI output file from a LilyPond input file, add a \midi block to a score, for example,

\score {
  \midi { }

If there is a \midi block in a \score with no \layout block, only MIDI output will be produced. When notation is needed too, a \layout block must also be present.

\score {
  \midi { }
  \layout { }

Pitches, rhythms, ties, dynamics, and tempo changes are interpreted and translated correctly to the MIDI output. Dynamic marks, crescendi and decrescendi translate into MIDI volume levels. Dynamic marks translate to a fixed fraction of the available MIDI volume range. Crescendi and decrescendi make the volume vary linearly between their two extremes. The effect of dynamic markings on the MIDI output can be removed completely, see MIDI block.

The initial tempo and later tempo changes can be specified with the \tempo command within the music notation. These are reflected in tempo changes in the MIDI output. This command will normally result in the metronome mark being printed, but this can be suppressed, see Indicazioni metronomiche. An alternative way of specifying the initial or overall MIDI tempo is described below, see MIDI block.

Due to some limitations on Windows, the default extension for MIDI files on Windows is .mid. Other operating systems still use the extension .midi. If a different extension is preferred, insert the following line at the top-level of the input file, before the start of any \book, \bookpart or \score blocks:

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

The line above will set the default extension for MIDI files to .midi.

Alternatively, this option can also be supplied on the command line:

lilypond … -dmidi-extension=midi lilyFile.ly

Frammenti di codice selezionati

Changing MIDI output to one channel per voice

When outputting MIDI, the default behavior is for each staff to represent one MIDI channel, with all the voices on a staff amalgamated. This minimizes the risk of running out of MIDI channels, since there are only 16 available per MIDI port, and most devices support only one port.

However, by moving the Staff_performer to the Voice context, each voice on a staff can have its own MIDI channel, as is demonstrated by the following example: despite being on the same staff, two MIDI channels are created, each with a different midiInstrument.

\score {
  \new Staff <<
    \new Voice \relative c''' {
      \set midiInstrument = #"flute"
      \key g \major
      \time 2/2
      r2 g-"Flute" ~
      g fis ~
      fis4 g8 fis e2 ~
      e4 d8 cis d2
    \new Voice \relative c'' {
      \set midiInstrument = #"clarinet"
      a2. b8 a
      g2. fis8 e
      fis2 r
  \layout { }
  \midi {
    \context {
      \remove "Staff_performer"
    \context {
      \consists "Staff_performer"
    \tempo 2 = 72

[image of music]

Problemi noti e avvertimenti

Changes in the MIDI volume take place only on starting a note, so crescendi and decrescendi cannot affect the volume of a single note.

Not all midi players correctly handle tempo changes in the midi output. Players that are known to work include MS Windows Media Player and timidity.

Altre lingue: English, deutsch, español, français, 日本語.
About automatic language selection.

LilyPond — Guida alla Notazione v2.17.97 (ramo di sviluppo).