LilyPond Notation Reference: 1.4.1 Long repeats

### 1.4.1 Long repeats

This section discusses how to input long (usually multi-measure) repeats. The repeats can take two forms: repeats enclosed between repeat signs; or written out repeats, used to input repetitious music. Repeat signs can also be controlled manually.

#### Normal repeats

The syntax for a normal repeat is

>     \repeat volta repeatcount musicexpr

where `musicexpr` is a music expression.

A single repeat without an alternate ending:

>     \repeat volta 2 { c4 d e f }
>     c2 d
>     \repeat volta 2 { d4 e f g }

Alternative endings can be produced using `\alternative`. Each group of alternatives must be themselves, enclosed in a set of braces.

>     \repeat volta repeatcount musicexpr
>     \alternative {
>       { musicexpr }
>     }

where `musicexpr` is a music expression.

If there are more repeats than there are alternate endings, the earliest repeats are given the first alternative.

A single repeat with one alternate ending:

>     \repeat volta 2 { c4 d e f | }
>     \alternative {
>       { c2 e | }
>       { f2 g | }
>     }
>     c1

A single repeat with more than one alternate ending:

>     \repeat volta 4 { c4 d e f | }
>     \alternative {
>       { c2 e | }
>       { f2 g | }
>     }
>     c1

Multiple repeats with more than one alternate ending:

>     \repeat volta 3 { c4 d e f | }
>     \alternative {
>       { c2 e | }
>       { f2 g | }
>       { a2 g | }
>     }
>     c1

Note: If there are two or more alternatives, nothing should appear between the closing brace of one and the opening brace of the next in an `\alternative` block, otherwise you will not get the expected number of endings.

Note: If you include `\relative` inside a `\repeat` without explicitly instantiating the `Voice` context, extra (unwanted) staves will appear. See An extra staff appears.

If a repeat starts in the middle of a measure and has no alternate endings, normally the end of the repeat will also fall in the middle of a measure, so that the two ends add up to one complete measure. In such cases, the repeat signs do not constitute true bar lines. Do not use `\partial` commands or bar checks where these repeat signs are printed:

>     % no \partial here
>     c4 e g  % no bar check here
>     % no \partial here
>     \repeat volta 4 {
>       e4 |
>       c2 e |
>       % no \partial here
>       g4 g g  % no bar check here
>     }
>     % no \partial here
>     g4 |
>     a2 a |
>     g1 |

Similarly, if a repeat begins with the initial partial measure of a score and has no alternate endings, the same conditions apply as in the above example, except that in this case the `\partial` command is required at the beginning of the score:

>     \partial 4  % required
>     \repeat volta 4 {
>       e4 |
>       c2 e |
>       % no \partial here
>       g4 g g  % no bar check here
>     }
>     % no \partial here
>     g4 |
>     a2 a |
>     g1 |

When alternate endings are added to a repeat that begins with an incomplete measure, it becomes necessary to set the `Timing.measureLength` context property manually, in the following specific places:

- at the start of any incomplete measures in the `\alternative` block, which normally occur at the end of each alternative, except (in most cases) the last.
- at the start of each alternative, except the first.

>     \partial 4
>     \repeat volta 2 { e4 | c2 e | }
>     \alternative {
>       {
>         f2 d |
>         \set Timing.measureLength = #(ly:make-moment 3 4)
>         g4 g g  % optional bar check is allowed here
>       }
>       {
>         \set Timing.measureLength = #(ly:make-moment 4 4)
>         a2 a |
>       }
>     }
>     g1 |

The `measureLength` property is described in Time administration.

Ties may be added to a second ending:

>     c1
>     \repeat volta 2 { c4 d e f~ }
>     \alternative {
>       { f2 d }
>       { f2\repeatTie f, }
>     }

#### Selected Snippets

Shortening volta brackets

By default, the volta brackets will be drawn over all of the alternative music, but it is possible to shorten them by setting `voltaSpannerDuration`. In the next example, the bracket only lasts one measure, which is a duration of 3/4.

>     \relative c'' {
>       \time 3/4
>       c4 c c
>       \set Score.voltaSpannerDuration = #(ly:make-moment 3 4)
>       \repeat volta 5 { d4 d d }
>       \alternative {
>         {
>           e4 e e
>           f4 f f
>         }
>         { g4 g g }
>       }
>     }

Adding volta brackets to additional staves

The `Volta_engraver` by default resides in the `Score` context, and brackets for the repeat are thus normally only printed over the topmost staff. This can be adjusted by adding the `Volta_engraver` to the `Staff` context where the brackets should appear; see also the “Volta multi staff” snippet.

>     <<
>       \new Staff { \repeat volta 2 { c'1 } \alternative { c' } }
>       \new Staff { \repeat volta 2 { c'1 } \alternative { c' } }
>       \new Staff \with { \consists "Volta_engraver" } { c'2 g' e' a' }
>       \new Staff { \repeat volta 2 { c'1 } \alternative { c' } }
>     >>

Setting the double repeat default for volte

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

>     \relative c'' {
>       \repeat volta 1 { c1 }
>       \set Score.doubleRepeatType = #":|:"
>       \repeat volta 1 { c1 }
>       \set Score.doubleRepeatType = #":|.|:"
>       \repeat volta 1 { c1 }
>       \set Score.doubleRepeatType = #":|.:"
>       \repeat volta 1 { c1 }
>     }

#### See also

Music Glossary: repeat, volta.

Notation Reference: Bar lines, Modifying context plug-ins, Time administration.

Snippets: Repeats.

Internals Reference: VoltaBracket, RepeatedMusic, VoltaRepeatedMusic, UnfoldedRepeatedMusic.

#### Known issues and warnings

Slurs that span from a `\repeat` block into an `\alternative` block will only work for the first alternate ending. Also, slurs cannot wrap around from the end of one alternative back to the beginning of the repeat.

If a repeat that begins with an incomplete measure has an `\alternative` block that contains modifications to the `measureLength` property, using `\unfoldRepeats` will result in wrongly-placed bar lines and bar check warnings.

A nested repeat like

>     \repeat …
>     \repeat …
>     \alternative

is ambiguous, since it is not clear to which `\repeat` the `\alternative` belongs. This ambiguity is resolved by always having the `\alternative` belong to the inner `\repeat`. For clarity, it is advisable to use braces in such situations.

#### Manual repeat marks

Note: These methods are only used for displaying unusual repeat constructs, and may produce unexpected behavior. In most cases, repeats should be created using the standard `\repeat` command or by printing the relevant bar lines. For more information, see Bar lines.

The property `repeatCommands` can be used to control the layout of repeats. Its value is a Scheme list of repeat commands.

`start-repeat`

  Print a `|:` bar line.

  >     c1
  >     \set Score.repeatCommands = #'(start-repeat)
  >     d4 e f g
  >     c1

  As per standard engraving practice, repeat signs are not printed at the beginning of a piece.

`end-repeat`

  Print a `:|` bar line:

  >     c1
  >     d4 e f g
  >     \set Score.repeatCommands = #'(end-repeat)
  >     c1

`(volta number) ... (volta #f)`

  Create a new volta with the specified number. The volta bracket must be explicitly terminated, or it will not be printed.

  >     f4 g a b
  >     \set Score.repeatCommands = #'((volta "2"))
  >     g4 a g a
  >     \set Score.repeatCommands = #'((volta #f))
  >     c1

Multiple repeat commands may occur at the same point:

>     f4 g a b
>     \set Score.repeatCommands = #'((volta "2, 5") end-repeat)
>     g4 a g a
>     c1
>     \set Score.repeatCommands = #'((volta #f) (volta "95") end-repeat)
>     b1
>     \set Score.repeatCommands = #'((volta #f))

Text can be included with the volta bracket. The text can be a number or numbers or markup text, see Formatting text. The simplest way to use markup text is to define the markup first, then include the markup in a Scheme list.

>     voltaAdLib = \markup { 1. 2. 3... \text \italic { ad lib. } }
>     \relative c'' {
>       c1
>       \set Score.repeatCommands = #(list(list 'volta voltaAdLib) 'start-repeat)
>       c4 b d e
>       \set Score.repeatCommands = #'((volta #f) (volta "4.") end-repeat)
>       f1
>       \set Score.repeatCommands = #'((volta #f))
>     }

#### Selected Snippets

Printing a repeat sign at the beginning of a piece

A `|:` bar line can be printed at the beginning of a piece, by overriding the relevant property:

>     \relative c'' {
>       \once \override Score.BreakAlignment #'break-align-orders =
>         #(make-vector 3 '(instrument-name
>                           left-edge
>                           ambitus
>                           breathing-sign
>                           clef
>                           key-signature
>                           time-signature
>                           staff-bar
>                           custos))
>       \once \override Staff.TimeSignature #'space-alist =
>         #'((first-note . (fixed-space . 2.0))
>            (right-edge . (extra-space . 0.5))
>            ;; free up some space between time signature
>            ;; and repeat bar line
>            (staff-bar . (extra-space . 1)))
>       \bar "|:"
>       c1
>       d1
>       d4 e f g
>     }

#### See also

Notation Reference: Bar lines, Formatting text.

Snippets: Repeats.

Internals Reference: VoltaBracket, RepeatedMusic, VoltaRepeatedMusic.

#### Written-out repeats

By using the `unfold` command, repeats can be used to simplify the writing out of repetitious music. The syntax is

>     \repeat unfold repeatcount musicexpr

where `musicexpr` is a music expression and `repeatcount` is the number of times `musicexpr` is repeated.

>     \repeat unfold 2 { c4 d e f }
>     c1

Unfold repeats can be made with alternate endings.

>     \repeat unfold 2 { c4 d e f }
>     \alternative {
>       { c2 g' }
>       { c,2 b }
>     }
>     c1

If there are more repeats than there are alternate endings, the first alternative is applied multiple times until the remaining alternatives make up the total number of repeats.

>     \repeat unfold 4 { c4 d e f }
>     \alternative {
>       { c2 g' }
>       { c,2 b }
>       { e2 d }
>      }
>     c1

If there are more alternate endings than repeats then the first alternatives are applied, LilyPond will ignore the remaining alternatives which will not be printed.

>     \repeat unfold 2 { c4 d e f }
>     \alternative {
>       { c2 g' }
>       { c,2 b }
>       { e2 d }
>     }
>     c1

It is also possible to nest multiple `unfold` functions (with or without alternate endings).

>     \repeat unfold 2 {
>       \repeat unfold 2 { c4 d e f }
>       \alternative {
>         { c2 g' }
>         { c,2 b }
>       }
>     }
>     c1

Note: If you include `\relative` inside a `\repeat` without explicitly instantiating the `Voice` context, extra (unwanted) staves will appear. See An extra staff appears.

#### See also

Snippets: Repeats.

Internals Reference: RepeatedMusic, UnfoldedRepeatedMusic.

其它语言：deutsch, español, français, 日本語。

#### LilyPond — Notation Reference