1.2.5 Bars


Bar lines

Bar lines delimit measures, and are also used to indicate repeats. Normally, simple bar lines are automatically inserted into the printed output at places based on the current time signature.

The simple bar lines inserted automatically can be changed to other types with the \bar command. For example, a closing double bar line is usually placed at the end of a piece:

e4 d c2 \bar "|."

[image of music]

It is not invalid if the final note in a measure does not end on the automatically entered 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 cause line breaks to be inhibited, leading to a line of highly compressed music or music which 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 the following:

\bar ""

This will insert an invisible bar line and allow (but not force) a line break to occur at this point. The bar number counter is not increased. To force a line break 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.

Note that 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, accidentals, line breaks, etc. 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.

Two types of simple bar lines and five types of double bar lines are available for manual insertion:

f1 \bar "|"
f1 \bar "."
g1 \bar "||"
a1 \bar ".|"
b1 \bar ".."
c1 \bar "|.|"
d1 \bar "|."
e1

[image of music]

together with dotted and dashed bar lines:

f1 \bar ";"
g1 \bar "!"
a1

[image of music]

and nine types of repeat bar lines:

f1 \bar ".|:"
g1 \bar ":..:"
a1 \bar ":|.|:"
b1 \bar ":|.:"
c1 \bar ":.|.:"
d1 \bar "[|:"
e1 \bar ":|][|:"
f1 \bar ":|]"
g1 \bar ":|."
a1

[image of music]

Additionally, a bar line can be printed as a simple tick:

f1 \bar "'" g1

[image of music]

However, as such ticks are typically used in Gregorian chant, it is preferable to use \divisioMinima there instead, described in the section Divisiones in Gregorian chant.

Lilypond supports kievan notation and provides a special kievan bar line:

f1 \bar "k"

[image of music]

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

For in-line segno signs, there are three types of bar lines which differ in their behavior at line breaks:

c4 c c c
\bar "S"
c4 c c c \break
\bar "S"
c4 c c c
\bar "S-|"
c4 c c c \break
\bar "S-|"
c4 c c c
\bar "S-S"
c4 c c c \break
\bar "S-S"
c1

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

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.

c4 c c c
\bar ".|:-||"
c4 c c c \break
\bar ".|:-||"
c4 c c c

[image of music]

For combinations of repeats with the segno sign, there are six different variations:

c4 c c c
\bar ":|.S"
c4 c c c \break
\bar ":|.S"
c4 c c c
\bar ":|.S-S"
c4 c c c \break
\bar ":|.S-S"
c4 c c c
\bar "S.|:-S"
c4 c c c \break
\bar "S.|:-S"
c4 c c c
\bar "S.|:"
c4 c c c \break
\bar "S.|:"
c4 c c c
\bar ":|.S.|:"
c4 c c c \break
\bar ":|.S.|:"
c4 c c c
\bar ":|.S.|:-S"
c4 c c c \break
\bar ":|.S.|:-S"
c1

[image of music]

Additionally there is an \inStaffSegno command which creates a segno bar line in conjunction with an appropriate repeat bar line when used with a \repeat volta command, see Normal repeats.

New bar line types can be defined with \defineBarLine:

\defineBarLine bartype #'(end begin span)

The \defineBarline variables can include the ‘empty’ string "", which is equivalent to an invisible bar line being printed. Or they can be set to #f which prints no bar line at all.

After the definiton, the new bar line can be used by \bar bartype.

There are currently ten bar line elements available:

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

\new Staff {
  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 the double span bar line, used in combination with the segno sign. Do not use it as a standalone double thin bar line; here, \bar "||" is preferred.

The "-" sign starts annotations to bar lines which are useful to distinguish those with identical appearance but different behavior at line breaks and/or different span bars. The part following the "-" sign is not used for building up the bar line.

\defineBarLine "||-dashedSpan" #'("||" "" "!!")

\new StaffGroup <<
  \new Staff {
    c1 \bar "||"
    c1 \bar "||-dashedSpan"
    c1
  }
  \new Staff {
    c1
    c1
    c1
  }
>>

[image of music]

Furthermore, the space character " " serves as a placeholder for defining span bars correctly aligned to the main bar lines:

\defineBarLine ":|.-wrong" #'(":|." "" "|.")
\defineBarLine ":|.-right" #'(":|." "" " |.")

\new StaffGroup <<
  \new Staff {
    c1 \bar ":|.-wrong"
    c1 \bar ":|.-right"
    c1
  }
  \new Staff {
    c1
    c1
    c1
  }
>>

[image of music]

If additional elements are needed, LilyPond provides a simple way to define them. For more informations 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 {
      e4 d
      \bar "||"
      f4 e
    }
    \new Staff { \clef bass c4 g e g }
  >>
  \new Staff { \clef bass c2 c2 }
>>

[image of music]

The command ‘\bar bartype’ is a shortcut for ‘\set Timing.whichBar = bartype’. A bar line is created whenever the whichBar property is set.

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

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


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:

c1 c c c
\break
\set Score.currentBarNumber = #50
c1 c c c

[image of music]

Bar numbers can be typeset at regular intervals instead of just at the beginning of every line. To do this the default behavior must be overridden to permit bar numbers to be printed at places other than the start of a line. This is controlled by 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:

\override Score.BarNumber.break-visibility = ##(#t #t #t)
\set Score.currentBarNumber = #11
% Permit first bar number to be printed
\bar ""
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. Note that an empty bar line must be inserted before the first note for this to work.

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

[image of music]

Printing bar numbers at regular intervals

Bar numbers can be printed at regular intervals by setting the property barNumberVisibility. 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
  % Permit first bar number to be printed
  \bar ""
  % 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
}

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

\relative c'{
  \set Score.alternativeNumberingStyle = #'numbers
  \repeat volta 3 { c4 d e f | }
    \alternative {
      { c4 d e f | c2 d \break }
      { f4 g a b | f4 g a b | f2 a | \break }
      { c4 d e f | c2 d }
    }
  c1 \break
  \set Score.alternativeNumberingStyle = #'numbers-with-letters
  \repeat volta 3 { c,4 d e f | }
    \alternative {
      { c4 d e f | c2 d \break }
      { f4 g a b | f4 g a b | f2 a | \break }
      { c4 d e f | c2 d }
    }
  c1
}

[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
    \remove "Bar_number_engraver"
  }
}

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

[image of music]

See also

Snippets: Rhythms.

Internals Reference: BarNumber, Bar_number_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.


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 |

Bar checks can also be used in lyrics:

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

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.

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.


Rehearsal marks

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

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.

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.markFormatter = #format-mark-alphabet
\set Score.markFormatter = #format-mark-box-alphabet
\set Score.markFormatter = #format-mark-circle-alphabet
\set Score.markFormatter = #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 markFormatter. 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, markFormatter is set to a pre-defined procedure. After a few measures, it is set to a procedure that produces a boxed number.

\set Score.markFormatter = #format-mark-numbers
c1 \mark \default
c1 \mark \default
\set Score.markFormatter = #format-mark-box-numbers
c1 \mark \default
\set Score.markFormatter = #format-mark-circle-numbers
c1 \mark \default
\set Score.markFormatter = #format-mark-circle-letters
c1

[image of music]

The file ‘scm/translation-functions.scm’ contains the definitions of format-mark-numbers (the default format), format-mark-box-numbers, format-mark-letters and format-mark-box-letters. 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.

Other styles of rehearsal mark can be specified manually:

\mark "A1"

Note that Score.markFormatter does not affect marks specified in this manner. However, it is possible to apply a \markup to the string.

\mark \markup{ \box A1 }

Music glyphs (such as the segno sign) may be printed inside a \mark

c1 \mark \markup { \musicglyph #"scripts.segno" }
c1 \mark \markup { \musicglyph #"scripts.coda" }
c1 \mark \markup { \musicglyph #"scripts.ufermata" }
c1

[image of music]

See The Feta font, for a list of symbols which may be printed with \musicglyph.

For common tweaks to the positioning of rehearsal marks, see Formatting text. For more precise control, see break-alignable-interface in 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.

See also

Notation Reference: The Feta font, Formatting text, Aligning objects.

Installed Files: ‘scm/translation-functions.scm’.

Snippets: Rhythms.

Internals Reference: MarkEvent, Mark_engraver, RehearsalMark.


Other languages: deutsch, español, français, italiano, 日本語.
About automatic language selection.

LilyPond — Notation Reference v2.18.2 (stable-branch).