Jump to content

Metric modulation (proportional tempi)

From LilyPond wiki
Revision as of 22:03, 11 June 2026 by Gabriel Ellsworth (talk | contribs) (Created page with "This snippet shows how you can typeset a metric modulation as a rehearsal mark. (See [https://lists.gnu.org/archive/html/lilypond-user/2026-05/msg00194.html this thread on the mailing list].) Compare Metric modulation with tuplet. In the code below, the following commands enable you to to center the = glyph above the bar line. # <code>\general-align</code> commands set the center of the <code>myMetricModulation</code> markup to be the center of the equals sign (=)....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This snippet shows how you can typeset a metric modulation as a rehearsal mark. (See this thread on the mailing list.) Compare Metric modulation with tuplet.

In the code below, the following commands enable you to to center the = glyph above the bar line.

  1. \general-align commands set the center of the myMetricModulation markup to be the center of the equals sign (=). For more information, see A.1.2 Markup for text alignment in the Notation Reference.
  2. \put-adjacent commands add elements to the sides of the equals sign without shifting it. See A.1.2 Markup for text alignment.
  3. Switching off self-alignment-X means that the 0 coordinate of the stencil gets used for alignment with the bar line, without any shifting. Without \tweak self-alignment-X ##f, self-alignment-X = 0 would calculate a shift in order to align the center of the markup (rather than the equals sign) to its anchor point.

The music is from Tomás Luis de Victoria, “O magnum mysterium,” Tenor part (PDF of source).

\version "2.26"

% Optional: Define markup commands
% to contain shortcuts for the notes
% to typeset in your metric modulation markup.
simpleBreve = \markup {
  \override #'(style . baroque)
  \note { \breve }
  #UP % (stem direction)
}

dottedBreve = \markup {
  \override #'(style . baroque)
  \note { \breve. }
  #UP % (stem direction)
}

thickSpace = \markup \char ##x2004
% Unicode codepoint U+2004 is a
% Three-per-Em space
% (also known as a “thick space”); see
% https://en.wikipedia.org/wiki/Whitespace_character#Unicode

% Define a custom markup command
% to typeset an equals sign (=)
% with a thick space on each side.
equals = \markup {
  \put-adjacent #X #RIGHT
  \put-adjacent #X #LEFT
  \general-align #Y #DOWN \char ##x003D
  % https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode
  \thickSpace
  \thickSpace
}

% Define a markup that says
% “breve = dotted breve”
% with the = glyph at the
% center of this markup.
myMetricModulation = \markup {
  \put-adjacent #X #RIGHT
  \put-adjacent #X #LEFT
  
  \general-align #X #CENTER
  \general-align #Y #CENTER
  \equals
  
  \simpleBreve
  \dottedBreve
}

words = \lyricmode {
  Ie -- sum Chris -- tum
  al -- le -- lu -- ia
  al
}

music = \relative {
  \key g \dorian
  \clef "petrucci-c4"
  \override NoteHead.style = #'baroque
  \tag #'metronome { \tempo 1 = 60 }
  \time 2/1
  f\breve | g1 a1 |
  \tweak self-alignment-X ##f
  \mark \myMetricModulation
  \tag #'metronome {
    \once \override Score.MetronomeMark.X-offset = #7
    \tempo "" 1 = 90
  }
  \time 3/1
  g\breve g1 | d'\breve d1 |
  c\breve c1 |
}

\markup { \circle 1 Metric modulation: }
\markup \vspace #0.2
\score {
  <<
    \new Voice = "tenor"
      \removeWithTag #'metronome \music
    \new Lyrics \lyricsto "tenor" \words
  >>
}

\markup { \circle 2 With metronome marks added: }
\markup \vspace #0.2
\score {
  <<
    \new Voice = "tenor"
      \keepWithTag #'metronome \music
    \new Lyrics \lyricsto "tenor" \words
  >>
}