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


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