GNU LilyPond Notation Reference: 1.2.5 Bars

### 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 "|."

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

>     \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. Such insertions do not affect the calculation and placement of subsequent automatic bar lines.

The simple bar line and five types of double bar line are available for manual insertion:

>     f1 \bar "|" g \bar "||" a \bar ".|" b \bar ".|." c \bar "|.|" d \bar "|." e

together with dotted and dashed bar lines:

>     f1 \bar ":" g \bar "dashed" a

and five types of repeat bar line:

>     f1 \bar "|:" g \bar ":|:" a \bar ":|.|:" b \bar ":|.:" c \bar ":|" d

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.

>     \override Score.RehearsalMark #'padding = #3
>     c c c c
>     \bar "||:"
>     c c c c \break
>     \bar "||:"
>     c c c c

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 {
>           e'4 d'
>           \bar "||"
>           f' e'
>         }
>         \new Staff { \clef bass c4 g e g }
>       >>
>       \new Staff { \clef bass c2 c2 }
>     >>

#### Selected Snippets

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.

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

#### Selected Snippets

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
>     \bar ""  % Permit first bar number to be printed
>     c1 c c c
>     \break
>     c c c c

and here the bar numbers are printed every two measures except at the end of the line:

>     \override Score.BarNumber #'break-visibility = #'#(#f #t #t)
>     \set Score.currentBarNumber = #11
>     \bar ""  % Permit first bar number to be printed
>     % Print a bar number every second measure
>     \set Score.barNumberVisibility = #(every-nth-bar-number-visible 2)
>     c1 c c c c
>     \break
>     c c c c c

The size of the bar number may be changed. This is illustrated in the following example, which also shows how to enclose bar numbers in boxes and circles, and shows an alternative way of specifying `#(#f #t #t)` for `break-visibility`.

>     % Prevent bar numbers at the end of a line and permit them elsewhere
>     \override Score.BarNumber #'break-visibility
>       = #end-of-line-invisible

>     % Increase the size of the bar number by 2
>     \override Score.BarNumber #'font-size = #2
>     \repeat unfold 3 { c1 } \bar "|"

>     % 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 3 { c1 } \bar "|"

>     % 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 "|."

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

>     \set Score.currentBarNumber = #111
>     \override Score.BarNumber #'break-visibility = #'#(#t #t #t)
>     % 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 = #0
>     c1 c1
>     % Right-align bar numbers
>     \override Score.BarNumber #'self-alignment-X = #-1
>     c1 c1

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
>     }

#### See also

Snippets: Rhythms.

Internals Reference: BarNumber.

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

#### 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, for example

>     \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 `pipeSymbol`. 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.

>     pipeSymbol = \bar "||"
>     {
>       c'2 c'2 |
>       c'2 c'2
>       c'2 | c'2
>       c'2 c'2
>     }

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 #8
>     c1 \mark \default
>     c1 \mark \default

The letter ‘I’ is skipped in accordance with engraving traditions. If you wish to include the letter ‘I’, then use

>     \set Score.markFormatter = #format-mark-alphabet

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

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

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"

`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

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.

#### See also

Notation Reference: The Feta font, Formatting text.

Installed Files: ‘`scm/translation-functions.scm`’ contains the definition of `format-mark-numbers` and `format-mark-letters`. They can be used as inspiration for other formatting functions.

Snippets: Rhythms.

Internals Reference: RehearsalMark.

Other languages: français, español, deutsch.

#### Notation Reference