2.5 Bars


2.5.1 Bar lines

Bar lines are used to delimit measures and sections, and to indicate repetition. Normally, simple bar lines are automatically inserted into the printed output at places according to the current time signature. Various commands insert other kinds of bar lines automatically as part of their effect (see Automatic bar lines).

A bar line inserted automatically can be changed to another type with the \bar command:

\relative { e'4 d c2 \bar "!" }
[image of music]

The final note of a measure is not required to end on the automatically inserted bar line: the note is assumed to carry over into the next measure. But if a long sequence of such carry-over measures appears, the music can appear compressed or even flowing off the page. This is because automatic line breaks happen only at the end of complete measures, i.e., where all notes end before the end of a measure.

Note: An incorrect duration can inhibit line breaks, leading to a line of highly compressed music or music that flows off the page.

Line breaks are also permitted at manually inserted bar lines even within incomplete measures. To allow a line break without printing a bar line, use \allowBreak; see Line breaking.

This and other special bar lines may be inserted manually at any point. When they coincide with the end of a measure they replace the simple bar line which would have been inserted there automatically. When they do not coincide with the end of a measure the specified bar line is inserted at that point in the printed output.

Manual bar lines are purely visual. They do not affect any of the properties that a normal bar line would affect, such as measure numbers and accidentals. They do not affect the calculation and placement of subsequent automatic bar lines. When a manual bar line is placed where a normal bar line already exists, the effects of the original bar line are not altered.

Various single and double bar lines are available for manual insertion:

\relative {
  f'1 \bar "|"
  f1 \bar "."
  g1 \bar "||"     % see \section
  a1 \bar ".|"
  b1 \bar ".."
  c1 \bar "|.|"
  d1 \bar "|."     % see \fine
  e1
}
[image of music]

together with dotted and dashed bar lines:

\relative {
  f'1 \bar ";"
  g1 \bar "!"
  a1
}
[image of music]

and various repeat bar lines:

\relative {
  f'1 \bar ".|:"
  g1 \bar ":..:"
  a1 \bar ":|.|:"
  b1 \bar ":|.:"
  c1 \bar ":.|.:"
  d1 \bar "[|:"
  e1 \bar ":|][|:"
  f1 \bar ":|]"
  g1 \bar ":|."
  a1
}
[image of music]

Ticks and short bar lines are also available; however, in the context of Gregorian chant, using \divisioMinima and \divisioMaior is preferable (see Divisiones).

f'1 \bar "'"
g1 \bar ","
a1
[image of music]

LilyPond supports Kievan notation and provides a special Kievan bar line:

f'1 \bar "k"
[image of music]

Further details of this notation are explained in Typesetting Kievan square notation.

There are various in-staff segno signs which differ in their behavior at line breaks:

\fixed c' {
  c4 4 4 4
  \bar "S"
  d4 4 4 4 \break
  \bar "S"
  e4 4 4 4
  \bar "S-|"
  f4 4 4 4 \break
  \bar "S-|"
  g4 4 4 4
  \bar "S-||"
  a4 4 4 4 \break
  \bar "S-||"
  b4 4 4 4
  \bar "S-S"
  c'4 4 4 4 \break
  \bar "S-S"
  d'1
}
[image of music]

Although the bar line types signifying repeats may be inserted manually they do not in themselves cause LilyPond to recognize a repeated section. Such repeated sections are better entered using the various repeat commands (see Repeats), which automatically print the appropriate bar lines, which can be customized (see Automatic bar lines).

In addition, you can specify ".|:-||", which is equivalent to ".|:" except at line breaks, where it gives a double bar line at the end of the line and a start repeat at the beginning of the next line.

\fixed c' {
  c4 4 4 4
  \bar ".|:"
  d4 4 4 4 \break
  \bar ".|:"
  e4 4 4 4
  \bar ".|:-|"
  f4 4 4 4 \break
  \bar ".|:-|"
  g4 4 4 4
  \bar ".|:-||"
  a4 4 4 4 \break
  \bar ".|:-||"
  b4 4 4 4
  \bar ".|:-|."
  c'4 4 4 4 \break
  \bar ".|:-|."
  d'4 4 4 4
}
[image of music]

There are various combinations of repeats with the segno sign:

\fixed c' {
  g,4 4 4 4
  \bar ":|.S"
  a,4 4 4 4 \break
  \bar ":|.S"
  b,4 4 4 4
  \bar ":|.S-S"
  c4 4 4 4 \break
  \bar ":|.S-S"
  d4 4 4 4
  \bar "S.|:-S"
  e4 4 4 4 \break
  \bar "S.|:-S"
  f4 4 4 4
  \bar "S.|:"
  g4 4 4 4 \break
  \bar "S.|:"
  a4 4 4 4
  \bar "S.|:-|"
  b4 4 4 4 \break
  \bar "S.|:-|"
  c'4 4 4 4
  \bar "S.|:-||"
  d'4 4 4 4 \break
  \bar "S.|:-||"
  e'4 4 4 4
  \bar ":|.S.|:"
  f'4 4 4 4 \break
  \bar ":|.S.|:"
  g'4 4 4 4
  \bar ":|.S.|:-S"
  a'4 4 4 4 \break
  \bar ":|.S.|:-S"
  b'1
}
[image of music]

Many of the repeat and segno bar lines above can be inserted automatically by \repeat commands (see Repeats).

New bar line types can be defined with \defineBarLine:

\defineBarLine bar-type #'(eol-bar bol-bar span-bar)

Briefly, the bar-type argument specifies the bar line glyph to use in the middle of a staff line, and also serves as the name by which this bar line type is referenced. The other arguments specify the bar line glyph to use at the end or beginning of a line, or in the span between multiple staves. Setting any of eol-bar, bol-bar, or span-bar to #t means to use the same bar line type specified by bar-type for the corresponding position. Setting them to #f means to print no bar line in the corresponding position.

In more detail, the bar-type argument is a string that serves a dual purpose: It specifies the bar line glyph to be printed when it occurs in the middle of a staff line; and it identifies the bar line object that can be invoked with \bar bar-type. It must have the form midglyph or midglyph-annotation (with a literal hyphen), where annotation is an arbitrary string, and midglyph is a string each of whose characters is the name of one of the predefined bar line elements listed below. The resulting bar line glyph to be used in the middle of a line is the concatenation of these elements. For example, a bar-type of either ";|" or ";|-other" specifies a compound bar line consisting of a dotted line (‘;’) paired with a solid line (‘|’):

\defineBarLine ";|" #'(#t #t #t)
\defineBarLine ";|-other" #'(#f #f #f)
\fixed c' {
   \bar ";|" a1 \bar ";|" b1 \bar ";|-other" c'1 \bar ";|-other"
}
[image of music]

The annotation (‘other’ in the second example above) is used to distinguish this bar type from others with the same midglyph but different line break or multi-staff behavior. (By convention, the string specified in eol-bar is often used as the annotation, so we might have named the second example ‘";|-f"’.)

The arguments eol-bar and bol-bar specify the bar line to be printed at the end of the line and beginning of the next line, when \bar bar-type occurs at a line break. bol-bar also applies when \bar bar-type is used at the beginning of a score. The format of these arguments is the same as that of bar-type. The string of bar line elements specifies the bar line glyph to print at the corresponding line position. In addition, either of these arguments can be #t as a shorthand for copying the value of bar-type; or #f to print no bar line. For example, all of the bar line types in this example print a dotted-solid line pair in the middle of a staff line, but have different behavior at ends or beginnings of lines:

%   dotted-solid everywhere
\defineBarLine  ";|"  #'( #t #t #t)
%   solid-bold at EOL, solid-solid at BOL
\defineBarLine  ";|-A" #'( "|."  "||"  #f )
%   dotted-solid at EOL, nothing at BOL
\defineBarLine  ";|-B" #'( #t  #f  #f )
%   nothing at EOL, dotted-solid at BOL
\defineBarLine  ";|-C" #'( #f  #t  #f )
\relative c'' {
  \bar ";|"  \textMark "\";|\""
  a1  \bar ";|-A"
  a1  \bar ";|-A"  \textEndMark "\";|-A\""  \break
  b1  \bar ";|-B" b \bar ";|-B"  \textEndMark "\";|-B\""  \break
  c1  \bar ";|-C" c \bar ";|-C"  \textEndMark "\";|-C\""   \break
  d1  \bar ";|" \textEndMark "\";|\""
}
[image of music]

Note: The eol-bar or bol-bar strings may be names of previously defined bar line types. In a single staff context, it does not matter: the bar line elements in the given string are used regardless of any features of the defined bar line named by the string. In particular, any annotation is ignored in this context. However, in a multi-staff system it is important that eol-bar and bol-bar refer to previously defined bar line types (including bar-type itself), or be #t or #f. This is explained in more detail below.

The argument span-bar has an effect only in multi-staff systems (see Grouping staves), where it specifies what to print between grouped staves. This argument should be a string of bar line elements, of the same length as bar-type or shorter. (Extra elements are ignored.) Each element will be printed in line with the corresponding element of bar-type. A space character (‘ ’) can be used to omit a bar line element but leave space for it. Setting span-bar to #t makes it the same as the mid-line glyph. Setting it to #f omits the span bar, and setting it to "" (an empty string) makes a zero-width span bar. Here are some examples:

\defineBarLine  ";|!-A"  #'(#t #t "!|")
\defineBarLine  ";|!-B"  #'(#t #t " !|")
\defineBarLine  ";|!-C"  #'(#t #t #t)
\defineBarLine  ";|!-D"  #'(#t #t #f)
\fixed c' {
  \new StaffGroup <<
    \new Staff {
      a1 \bar ";|!-A"
      b  \bar ";|!-B"
      c' \bar ";|!-C"
      d' \bar ";|!-D"
      e'
    }
    \new Staff {
      a1 b c' d' e'
    }
  >>
}
[image of music]

At line breaks, instead of using span-bar, the bar line types referenced by eol-bar and bol-bar are used to determine the span bar to print. In the context of a staff group, if eol-bar and bol-bar do not refer to defined bar line types, LilyPond issues a warning, and no span bar is printed at line breaks. It is allowed for eol-bar or bol-bar to be #f, in which case no span bar is printed at the corresponding line position. These arguments can also be #t, or equivalently, equal to bar-type, in which case the current span-bar does determine the span bar to print at the corresponding line position:

\defineBarLine  "!|-t"  #'(#t #t #t)
\defineBarLine  "|!-t"  #'(#t #t #t)
\defineBarLine  ";|!-bad"  #'("|!" "!|" #t)  % fails at line breaks
\defineBarLine  ";|!-good" #'("!|-t" "|!-t" #t)
\relative c'' {
  \new StaffGroup <<
    \new Staff {
      \bar ";|!-good"
      a1 \bar ";|!-good"
      % \bar ";|!-bad"     % "WARNING: No span bar glyph defined..."
      b1 \bar ";|!-good"
    }
    \new Staff {
      a1 b1
    }
  >>
}
[image of music]

Note: If span-bar is a string, it should contain only bar line elements, or space (‘ ’), and not an annotation such as allowed in the other arguments. If span-bar contains an annotation, LilyPond issues a warning. The one exception is that it may be equal to bar-type, in which case no warning is issued even if bar-type includes an annotation.

All the available bar line elements are shown below. Most also have predefined bar types (for arguments to \bar) that reference them individually. Some elements are primarily intended to be combined with others and so do not have predefined individual bar types.

\defineBarLine ":" #'(#f #t #f)
\defineBarLine "=" #'(#t #f #t)
\defineBarLine "[" #'(#f #t #f)
\defineBarLine "]" #'(#t #f #f)

\new Staff {
  s1 \bar "'"
  s1 \bar ","
  s1 \bar "|"
  s1 \bar "."
  s1 \bar "!"
  s1 \bar ";"
  s1 \bar ":"
  s1 \bar "k"
  s1 \bar "S"
  s1 \bar "="
  s1 \bar "["
  s1 \bar "]"
  s1 \bar ""
}
[image of music]

The "=" bar line provides a double span bar line for use in combination with the segno sign. Using it as a stand-alone double thin bar line is not recommended; \bar "||" is preferred.

If additional elements are needed, LilyPond provides a simple way to define them. For more information on modifying or adding bar lines, see file scm/bar-line.scm.

In scores with many staves, a \bar command in one staff is automatically applied to all staves. The resulting bar lines are connected between different staves of a StaffGroup, PianoStaff, or GrandStaff.

<<
  \new StaffGroup <<
    \new Staff \relative {
      e'4 d
      \bar "||"
      f4 e
    }
    \new Staff \relative { \clef bass c'4 g e g }
  >>
  \new Staff \relative { \clef bass c'2 c2 }
>>
[image of music]

The bar type used for automatically inserted measure bar lines is "|". This may be changed at any time with ‘\set Timing.measureBarType = bartype’.

It is also possible to set different types of bar lines in a score with multiple staves, using one of the possible commands or properties explained below (see Automatic bar lines). Of course this may lead to a mismatch of bar lines and span bars, due to their different width.

Usually bar lines are left-aligned (disregarding colon signs as in repeat bar lines). To get them right-aligned the command

[\once] \override Context.BarLine.right-justified = ##t

needs to be applied, where Context is a context suitable for multiple staves, like Score, StaffGroup, Grandstaff, etc.

\new StaffGroup
  <<
    \new Staff = "a" {
      b1  b b
      <<
        { \textMark "BarLines right-justified" b b }
        \new Staff \with { alignAboveContext = "b" }
        {
          \override StaffGroup.BarLine.right-justified = ##t
          b
          \section
        }
      >>
    }
    \new Staff = "b" { b \section }
    \new Staff = "c" { b b \section b b b \section }
  >>
[image of music]

After a line-break bar lines are never right-aligned. For mid-line and right-aligned bar lines the anchor-point (used to align BarNumber, RehearsalMark, etc.) moves acordingly.

See also

Notation Reference: Line breaking, Repeats, Grouping staves.

Installed Files: scm/bar-line.scm.

Snippets: Rhythms.

Internals Reference: BarLine (created at Staff level), SpanBar (across staves), Timing_translator (for Timing properties).


2.5.2 Automatic bar lines

Various commands other than \bar can also create bar lines as part of their effect. The bar lines created in these cases can be changed by setting context properties. If a property is set to '() or is unset, it is ignored; otherwise, the value must be a predefined bar type or one previously defined with the \defineBarLine command (see Bar lines).

Multiple reasons for creating different automatic bar lines may apply at the same time. Conflicts are resolved in part by providing properties for predetermined combinations and in part by a priority scheme. The table below presents the available properties in order of increasing priority.

underlyingRepeatBarType

Used at points of repetition or departure where no bar line would otherwise appear. This is expected when repeated sections are not aligned to measures. Several commands employ this bar type: \codaMark, \inStaffSegno, \repeat segno, \repeat volta, and \segnoMark.

caesuraType underlying-bar-line

Used at \caesura; see Phrase bar lines in hymn tunes.

measureBarType

Used at a measure boundary.

caesuraType bar-line

Used at \caesura; see Phrase bar lines in hymn tunes.

sectionBarType

Used at a section break created by \section.

fineBarType

Used at \fine.

doubleRepeatBarType
doubleRepeatSegnoBarType
endRepeatBarType
endRepeatSegnoBarType
fineSegnoBarType
fineStartRepeatSegnoBarType
segnoBarType
startRepeatBarType
startRepeatSegnoBarType

Only one of these bar types is used at a time; which one is used depends on the structure of the piece.

Properties with startRepeat or endRepeat in the name are used at the start or end of a repeated section created by \repeat volta, and properties with doubleRepeat in the name are used where the end of one repeated section and the start of another coincide.

Properties with segno in the name are used at an in-staff segno, which can be created by \repeat segno or \segnoMark when the segnoStyle property is set to bar-line, or created by \inStaffSegno.

Properties with fine in the name are used at \fine.

Priority applies independently to beginning-, middle-, and end-of-line bar lines, allowing a lower-priority bar line to appear where higher-priority bar types have no glyphs defined (see Bar lines).

\fixed c' {
  c1 \section \break
  \repeat volta 2 d1
}
[image of music]

Selected Snippets

Setting the double repeat default for volte

There are three different styles of double repeats for volte, that can be set using doubleRepeatBarType.

\relative c'' {
  \repeat volta 2 { c1 }
  \set Score.doubleRepeatBarType = ":..:"
  \repeat volta 2 { c1 }
  \set Score.doubleRepeatBarType = ":|.|:"
  \repeat volta 2 { c1 }
  \set Score.doubleRepeatBarType = ":|.:"
  \repeat volta 2 { c1 }
}
[image of music]

See also

Notation Reference: Bar lines, Repeats.

Snippets: Rhythms.

Internals Reference: Repeat_acknowledge_engraver.


2.5.3 Bar numbers

Bar numbers are typeset by default at the start of every line except the first line. The number itself is stored in the currentBarNumber property, which is normally updated automatically for every measure. It may also be set manually:

\relative c' {
  c1 c c c
  \break
  \set Score.currentBarNumber = 50
  c1 c c c
}
[image of music]

The default behavior of only printing bar numbers at the start of every line can be changed through the break-visibility property of BarNumber. This takes three values which may be set to #t or #f to specify whether the corresponding bar number is visible or not. The order of the three values is end of line visible, middle of line visible, beginning of line visible. In the following example bar numbers are printed at all possible places:

\relative c' {
  \override Score.BarNumber.break-visibility = ##(#t #t #t)
  \set Score.currentBarNumber = 11
  c1 | c | c | c |
  \break
  c1 | c | c | c |
}
[image of music]

Selected Snippets

Printing the bar number for the first measure

By default, the first bar number in a score is suppressed if it is less than or equal to 1. By setting barNumberVisibility to all-bar-numbers-visible, any bar number can be printed for the first measure and all subsequent measures.

\layout {
  indent = 0
  ragged-right = ##t
}

\relative c' {
  \set Score.barNumberVisibility = #all-bar-numbers-visible
  c1 | d | e | f \break
  g1 | e | d | c
}
[image of music]

Printing bar numbers at regular intervals

By setting the barNumberVisibility property, bar numbers can be printed at regular intervals. Here the bar numbers are printed every two measures except at the end of the line.

\relative c' {
  \override Score.BarNumber.break-visibility = #end-of-line-invisible
  \set Score.currentBarNumber = 11
  % Print a bar number every second measure
  \set Score.barNumberVisibility = #(every-nth-bar-number-visible 2)
  c1 | c | c | c | c
  \break
  c1 | c | c | c | c
}

\paper { tagline = ##f }
[image of music]

Printing bar numbers with changing regular intervals

Using the set-bar-number-visibility context function, bar number intervals can be changed.

\relative c' {
  \override Score.BarNumber.break-visibility = #end-of-line-invisible
  \context Score \applyContext #(set-bar-number-visibility 4)
  \repeat unfold 10 c'1
  \context Score \applyContext #(set-bar-number-visibility 2)
  \repeat unfold 10 c
}

\paper { tagline = ##f }
[image of music]

Printing bar numbers for broken measures

By default a BarNumber of a broken measure is not repeated at the beginning of the new line. Use first-bar-number-invisible-save-broken-bars for barNumberVisibility to get a parenthesized BarNumber there.

\layout {
  \context {
    \Score
    barNumberVisibility = #first-bar-number-invisible-save-broken-bars
    \override BarNumber.break-visibility = ##(#f #t #t)
  }
}

\relative c' {
  c1 | d | e | f2 \bar "" \break
  fis | g1 | e2 \bar "" \break
  <>^"reenabled default"
  % back to default -
  % \unset Score.barNumberVisibility would do so as well
  \set Score.barNumberVisibility =
    #first-bar-number-invisible-and-no-parenthesized-bar-numbers
  es | d1 | c
}

\paper { tagline = ##f }
[image of music]

Printing bar numbers using modulo-bar-number-visible

If the remainder of the division of the current BarNumber by the first argument of modulo-bar-number-visible equals its second argument print the BarNumber.

Useful to print the BarNumber at certain distances, p.e.:

  • (modulo-bar-number-visible 3 2) -> prints 2,5,8
  • (modulo-bar-number-visible 4 2) -> prints 2,6,10
  • (modulo-bar-number-visible 3 1) -> prints 3,5,7
  • (modulo-bar-number-visible 5 2) -> prints 2,7,12
\layout {
  \context {
    \Score
    \override BarNumber.break-visibility = ##(#f #t #t)
    barNumberVisibility = #(modulo-bar-number-visible 3 2)
  }
}

\relative c' {
  c1 | d | e | f \break
  g1 | e | d | c
}

\paper { tagline = ##f }
[image of music]

Printing bar numbers inside boxes or circles

Bar numbers can also be printed inside boxes or circles.

\relative c' {
  % Prevent bar numbers at the end of a line and permit them elsewhere
  \override Score.BarNumber.break-visibility = #end-of-line-invisible
  \set Score.barNumberVisibility = #(every-nth-bar-number-visible 4)

  % Increase the size of the bar number by 2
  \override Score.BarNumber.font-size = 2

  % Draw a box round the following bar number(s)
  \override Score.BarNumber.stencil
    = #(make-stencil-boxer 0.1 0.25 ly:text-interface::print)
  \repeat unfold 5 { c1 }

  % Draw a circle round the following bar number(s)
  \override Score.BarNumber.stencil
    = #(make-stencil-circler 0.1 0.25 ly:text-interface::print)
  \repeat unfold 4 { c1 } \bar "|."
}
[image of music]

Alternative bar numbering

Two alternative methods for bar numbering can be set, especially for when using repeated music.

music = \relative c' {
  \repeat volta 3 {
    c4 d e f |
    \alternative {
      \volta 1 { c4 d e f | c2 d \break }
      \volta 2 { f4 g a b | f4 g a b | f2 a | \break }
      \volta 3 { c4 d e f | c2 d } } }
  c1 \bar "|."
}

\markup "default"
{
  \music
}

\markup \typewriter "'numbers"
{
  \set Score.alternativeNumberingStyle = #'numbers
  \music
}

\markup \typewriter "'numbers-with-letters"
{
  \set Score.alternativeNumberingStyle = #'numbers-with-letters
  \music
}

\paper { tagline = ##f }
[image of music]

Aligning bar numbers

Bar numbers by default are right-aligned to their parent object. This is usually the left edge of a line or, if numbers are printed within a line, the left hand side of a bar line. The numbers may also be positioned directly over the bar line or left-aligned to the bar line.

\relative c' {
  \set Score.currentBarNumber = 111
  \override Score.BarNumber.break-visibility = #all-visible
  % Increase the size of the bar number by 2
  \override Score.BarNumber.font-size = 2
  % Print a bar number every second measure
  \set Score.barNumberVisibility = #(every-nth-bar-number-visible 2)
  c1 | c1
  % Center-align bar numbers
  \override Score.BarNumber.self-alignment-X = #CENTER
  c1 | c1
  % Left-align bar numbers
  \override Score.BarNumber.self-alignment-X = #LEFT
  c1 | c1
}
[image of music]

Removing bar numbers from a score

Bar numbers can be removed entirely by removing the Bar_number_engraver from the Score context.

\layout {
  \context {
    \Score
    \omit BarNumber
    % or:
    %\remove "Bar_number_engraver"
  }
}

\relative c'' {
  c4 c c c \break
  c4 c c c
}

\paper { tagline = ##f }
[image of music]

Measure-centered bar numbers

For film scores, a common convention is to center bar numbers within their measure. This is achieved through setting the centerBarNumbers context property to true. When this is used, the type of the bar number grobs is CenteredBarNumber rather than BarNumber.

This example demonstrates a number of settings: the centered bar numbers are boxed and placed below the staves.

\layout {
  \context {
    \Score
    centerBarNumbers = ##t
    barNumberVisibility = #all-bar-numbers-visible
    \override CenteredBarNumber.stencil
      = #(make-stencil-boxer 0.1 0.25 ly:text-interface::print)
    \override CenteredBarNumberLineSpanner.direction = #DOWN
  }
}

\new StaffGroup <<
  \new Staff \relative c' {
    d4-. f8( e d4) bes'-> |
    d,-. f8( e d4) cis'-> |
    g-. f8( d e4) g-> |
    a,1-> |
  }
  \new Staff \relative c {
    \clef bass
    d4 f8 e d2~ |
    4 f8 e d2~ |
    4 4 2 |
    a1 |
  }
>>
[image of music]

See also

Snippets: Rhythms.

Internals Reference: BarNumber, CenteredBarNumber, CenteredBarNumberLineSpanner, Bar_number_engraver, Centered_bar_number_align_engraver.

Known issues and warnings

Bar numbers may collide with the top of the StaffGroup bracket, if there is one. To solve this, the padding property of BarNumber can be used to position the number correctly. See StaffGroup and BarNumber for more.


2.5.4 Bar and bar number checks

Bar checks help detect errors in the entered durations. A bar check may be entered using the bar symbol, |, at any place where a bar line is expected to fall. If bar check lines are encountered at other places, a list of warnings is printed in the log file, showing the line numbers and lines in which the bar checks failed. In the next example, the second bar check will signal an error.

\time 3/4 c2 e4 | g2 |

An incorrect duration can result in a completely garbled score, especially if the score is polyphonic, so a good place to start correcting input is by scanning for failed bar checks and incorrect durations.

If successive bar checks are off by the same musical interval, only the first warning message is displayed. This allows the warning to focus on the source of the timing error.

Bar checks can also be inserted in lyrics:

\lyricmode {
  \time 2/4
  Twin -- kle | Twin -- kle |
}

Note that bar check marks in lyrics are evaluated at the musical moment when the syllable following the check mark is processed. If the lyrics are associated with the notes of a voice which has a rest at the beginning of a bar, then no syllable can be located at the start of that bar and a warning will be issued if a bar check mark is placed in the lyrics at that position.

It is also possible to redefine the action taken when a bar check or pipe symbol, |, is encountered in the input, so that it does something other than a bar check. This is done by assigning a music expression to "|". In the following example | is set to insert a double bar line wherever it appears in the input, rather than checking for end of bar.

"|" = \bar "||"
{
  c'2 c' |
  c'2 c'
  c'2 | c'
  c'2 c'
}
[image of music]

When copying large pieces of music, it can be helpful to check that the LilyPond bar number corresponds to the original that you are entering from. This can be checked with \barNumberCheck, for example,

\barNumberCheck 123

will print a warning if the currentBarNumber is not 123 when it is processed.

See also

Snippets: Rhythms.


2.5.5 Rehearsal marks

To print a rehearsal mark, use the \mark command.

\relative c'' {
  c1 \mark \default
  c1 \mark \default
  c1 \mark \default
  c1 \mark \default
}
[image of music]

The mark is incremented automatically if you use \mark \default, but you can also use an integer argument to set the mark manually. The value to use is stored in the property rehearsalMark.

\relative c'' {
  c1 \mark \default
  c1 \mark \default
  c1 \mark 8
  c1 \mark \default
  c1 \mark \default
}
[image of music]

The letter ‘I’ is skipped in accordance with engraving traditions. If you wish to include the letter ‘I’, then use one of the following commands, depending on which style of rehearsal mark you want (letters only, letters in a hollow box, or letters in a hollow circle).

\set Score.rehearsalMarkFormatter = #format-mark-alphabet
\set Score.rehearsalMarkFormatter = #format-mark-box-alphabet
\set Score.rehearsalMarkFormatter = #format-mark-circle-alphabet
\relative c'' {
  \set Score.rehearsalMarkFormatter = #format-mark-box-alphabet
  c1 \mark \default
  c1 \mark \default
  c1 \mark 8
  c1 \mark \default
  c1 \mark \default
}
[image of music]

The style is defined by the property rehearsalMarkFormatter. It is a function taking the current mark (an integer) and the current context as argument. It should return a markup object. In the following example, rehearsalMarkFormatter is set to a predefined procedure. After a few measures, it is set to a procedure that produces a boxed number.

\relative c'' {
  \set Score.rehearsalMarkFormatter = #format-mark-numbers
  c1 \mark \default
  c1 \mark \default
  \set Score.rehearsalMarkFormatter = #format-mark-box-numbers
  c1 \mark \default
  \set Score.rehearsalMarkFormatter = #format-mark-circle-numbers
  c1 \mark \default
  \set Score.rehearsalMarkFormatter = #format-mark-circle-letters
  c1
}
[image of music]

The file scm/translation-functions.scm contains the definitions of format-mark-letters (the default format), format-mark-box-letters, format-mark-numbers, and format-mark-box-numbers. These can be used as inspiration for other formatting functions.

You may use format-mark-barnumbers, format-mark-box-barnumbers, and format-mark-circle-barnumbers to get bar numbers instead of incremented numbers or letters.

For common tweaks to the positioning of rehearsal marks, see Formatting text. For more precise control, consider break-alignable-interface (see Aligning objects).

The file scm/translation-functions.scm contains the definitions of format-mark-numbers and format-mark-letters. They can be used as inspiration for other formatting functions.

Selected Snippets

Printing marks on every staff

Although rehearsal and text marks are normally only printed above the topmost staff, they may also be printed on every staff.

\score {
  <<
    \new Staff { \mark \default c''1 \textMark "molto" c'' }
    \new Staff { \mark \default c'1 \textMark "molto" c' }
  >>
  \layout {
    \context {
      \Score
      \remove Mark_engraver
      \remove Text_mark_engraver
      \remove Staff_collecting_engraver
    }
    \context {
      \Staff
      \consists Mark_engraver
      \consists Text_mark_engraver
      \consists Staff_collecting_engraver
    }
  }
}
[image of music]

See also

Notation Reference: The Emmentaler font, Formatting text, Aligning objects, Music notation inside markup, Metronome marks, Section labels.

Installed Files: scm/translation-functions.scm.

Snippets: Rhythms.

Internals Reference: AdHocMarkEvent, RehearsalMark, RehearsalMarkEvent.


2.5.6 Measure counts

Measure counts are a way to number consecutive measures, for example as an aid for musicians to count measures in written-out repeats. Using this feature requires adding the Measure_counter_engraver to a context type, usually Staff or Score.

\layout {
  \context {
    \Staff
    \consists Measure_counter_engraver
  }
}

\relative c' {
  \time 6/8
  \key e \minor
  r4 a8 b c dis
  \startMeasureCount
  \repeat unfold 3 {
    e8 b e g8. fis32 e dis8
  }
  \stopMeasureCount
  b'4. r
}
[image of music]

Broken measures are numbered in parentheses.

\layout {
  \context {
    \Staff
    \consists Measure_counter_engraver
  }
}

\relative c' {
  \time 6/8
  \key e \minor
  r4 a8 b c dis
  \startMeasureCount
  e8 b e g8. fis32 e dis8
  e8 b e \break g8. fis32 e dis8
  e8 b e g8. fis32 e dis8
  \stopMeasureCount
  b'4. r
}
[image of music]

Compressed multi-measure rests receive special treatment: the full measure range is shown.

\layout {
  \context {
    \Staff
    \consists Measure_counter_engraver
  }
  \context {
    \Voice
    \override MultiMeasureRestNumber.direction = #DOWN
  }
}

\compressMMRests {
  \key e \minor
  \startMeasureCount
  \new CueVoice {
    b4.( e'8) b8 r e' r
  }
  R1*2
  \stopMeasureCount
  g'2\> fis'2\!
}
[image of music]

Measure counters honor alternative numbering styles. If the style is numbers-with-letters, they render best with a textual font.

\layout {
  \context {
    \Score
    alternativeNumberingStyle = #'numbers-with-letters
  }
  \context {
    \Staff
    \consists Measure_counter_engraver
    \override MeasureCounter.Y-offset = 6
    \override MeasureCounter.font-encoding = #'latin1
    \override MeasureCounter.font-size = 1
  }
}

\relative c' {
  \startMeasureCount
  \repeat volta 2 {
    c8 d e f c d e f
  }
  \alternative {
    { e4 d c b }
    { g'4 g c2 }
  }
  \bar "|."
  \stopMeasureCount
}
[image of music]

Predefined commands

\startMeasureCount, \stopMeasureCount.

See also

Notation Reference: Modifying context plug-ins, Compressing empty measures, Breaks, Bar numbers.

Internals Reference: Measure_counter_engraver, MeasureCounter, measure-counter-interface.


2.5.7 Section divisions

The \section command marks a point where one section of music ends and another begins. It does not have to be followed by more music: it may also be used to emphasize that the written end of the music is not the end of the piece, such as at a D.C. instruction or where one movement continues into the next without a break. \section normally creates a double bar line, but its effect can depend on other notation, e.g., repeat bar lines.

The \fine command ends the piece, normally with a final bar line. It is not limited to use at the written end of the music: it may also appear inside \repeat (see Al-fine repeats).

A section can optionally be named with \sectionLabel (see Section labels).

\fixed c' {
  f1
  \section
  \sectionLabel "Refrain"
  g1
  a1
  \fine
}
[image of music]

For details on interactions of \fine and \section bar lines with other types of bar lines, and options for changing their appearance, see Automatic bar lines.

See also

Music Glossary: fine.

Notation Reference: Automatic bar lines, Divisiones, Al-fine repeats, Section labels.

Internals Reference: FineEvent, SectionEvent.


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