Jump to content

Changing MIDI output to one channel per voice: Difference between revisions

From LilyPond wiki
m New category
Tags: Mobile edit Mobile web edit
mNo edit summary
 
Line 40: Line 40:
</lilypond>
</lilypond>


[[Category:Contexts and engravers]]
[[Category:Midi]]
[[Category:Midi]]
[[Category:Contexts and engravers]]
[[Category:Real music]]
[[Category:Real music]]
[[Category:Included in the official documentation]]
[[Category:Included in the official documentation]]
[[Category:Snippet]]
[[Category:Snippet]]

Latest revision as of 19:15, 16 December 2025

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 track.

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.

\version "2.24"

\score {
  \new Staff <<
    \new Voice \relative c''' {
      \set midiInstrument = "flute"
      \voiceOne
      \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"
      \voiceTwo
      b1-"Clarinet"
      a2. b8 a
      g2. fis8 e
      fis2 r
    }
  >>
  \layout { }
  \midi {
    \context {
      \Staff
      \remove "Staff_performer"
    }
    \context {
      \Voice
      \consists "Staff_performer"      
    }
    \tempo 2 = 72
  }
}