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


Multiple repeats with 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, }
}


The \inStaffSegno command can be used to generate a composite bar line incorporating the segno symbol with the appropriate repeat bar line when used with the \repeat volta command. The correct type of repeat bar line, viz. start repeat, end repeat or double repeat, is selected automatically. Note that the corresponding “D.S.” mark must be added manually.

Away from a repeat:

e1
\inStaffSegno
f2 g a b
c1_"D.S." \bar "|."


At the start of a repeat:

e1
\repeat volta 2 {
\inStaffSegno  % start repeat
f2 g a b
}
c1_"D.S." \bar "|."


At the end of a repeat:

e1
\repeat volta 2 {
f2 g a b
\inStaffSegno  % end repeat
}
f2 g a b
c1_"D.S." \bar "|."


Between two repeats:

e1
\repeat volta 2 {
f2 g a b
}
\inStaffSegno  % double repeat
\repeat volta 2 {
f2 g a b
}
c1_"D.S." \bar "|."


Alternative bar line symbols can be obtained by setting (in the Score context) the properties segnoType, startRepeatSegnoType, endRepeatSegnoType or doubleRepeatSegnoType to the required bar line type. The alternative bar line types must be selected from the pre-defined types or types previously defined with the \defineBarLine command (see Bar lines).

\defineBarLine ":|.S[" #'(":|." "S[" "")
\defineBarLine "]" #'("]" "" "")
e1
\repeat volta 2 {
f2 g a b
\once \set Score.endRepeatSegnoType = ":|.S["
\inStaffSegno
}
f2 g \bar "]" a b
c1_"D.S." \bar "|."


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


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


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
}


Music Glossary: repeat, volta.

Notation Reference: Bar lines, Modifying context plug-ins, Modifying ties and slurs, 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 alternative ending. The visual appearance of a continuing slur in other alternative blocks may be simulated with \repeatTie if the slur extends into only one note in the alternative block, although this method does not work in TabStaff. Other methods which may be tailored to indicate continuing slurs over several notes in alternative blocks, and which also work in TabStaff contexts, are shown in Modifying ties and slurs.

Also, slurs cannot wrap around from the end of one alternative back to the beginning of the repeat.

Glissandi that span from a \repeat block into an \alternative block will only work for the first alternative ending. The visual appearance of a continuing glissando in other alternative blocks may be indicated by coding a glissando starting on a hidden grace note. For an example, see “Extending glissandi across repeats” under Selected Snippets in Glissando.

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
}


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


In some cases, especially in a \relative context, the \repeat unfold function is not the same as writing out the music expression multiple times. E.g,

\repeat unfold 2 { a'4 b c }


is not equivalent to

a'4 b c | a'4 b c


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 only the first alternatives are applied. The remaining alternatives will be ignored and not 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


Chord constructs can be repeated by the chord repetition symbol q. See Chord repetition.

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