LilyPond Notation Reference: 1.2.6 Special rhythmic concerns

### 1.2.6 Special rhythmic concerns

#### Grace notes

Grace notes are ornaments that are written out. Grace notes are printed in a smaller font and take up no logical time in a measure.

>     c4 \grace c16 c4
>     \grace { c16[ d16] } c2

LilyPond also supports two special types of grace notes, the acciaccatura – an unmeasured grace note indicated by a slurred small note with a slashed stem – and the appoggiatura, which takes a fixed fraction of the main note and appears in small print without a slash.

>     \grace c8 b4
>     \acciaccatura d8 c4
>     \appoggiatura e8 d4
>     \acciaccatura { g16[ f] } e4

The placement of grace notes is synchronized between different staves. In the following example, there are two sixteenth grace notes for every eighth grace note

>     <<
>       \new Staff { e2 \grace { c16[ d e f] } e2 }
>       \new Staff { c2 \grace { g8[ b] } c2 }
>     >>

If you want to end a note with a grace, use the `\afterGrace` command. It takes two arguments: the main note, and the grace notes following the main note.

>     c1 \afterGrace d1 { c16[ d] } c1

This will put the grace notes after a space lasting 3/4 of the length of the main note. The default fraction 3/4 can be changed by setting `afterGraceFraction`. The following example shows the results from setting the space at the default, at 15/16, and finally at 1/2 of the main note.

>     <<
>       \new Staff {
>         c1 \afterGrace d1 { c16[ d] } c1
>       }
>       \new Staff {
>         #(define afterGraceFraction (cons 15 16))
>         c1 \afterGrace d1 { c16[ d] } c1
>       }
>       \new Staff {
>         #(define afterGraceFraction (cons 1 2))
>         c1 \afterGrace d1 { c16[ d] } c1
>       }
>     >>

The space between the main note and the grace note may also be specified using spacers. The following example places the grace note after a space lasting 7/8 of the main note.

>     \new Voice {
>       <<
>         { d1^\trill_( }
>         { s2 s4. \grace { c16[ d] } }
>       >>
>       c1)
>     }

A `\grace` music expression will introduce special typesetting settings, for example, to produce smaller type, and set directions. Hence, when introducing layout tweaks to override the special settings, they should be placed inside the grace expression. The overrides should also be reverted inside the grace expression. Here, the grace note’s default stem direction is overridden and then reverted.

>     \new Voice {
>       \acciaccatura {
>         \stemDown
>         f16->
>         \stemNeutral
>       }
>       g4 e c2
>     }

#### Selected Snippets

Using grace note slashes with normal heads

The slash through the stem found in acciaccaturas can be applied in other situations.

>     \relative c'' {
>       \override Stem #'stroke-style = #"grace"
>       c8( d2) e8( f4)
>     }

Tweaking grace layout within music

The layout of grace expressions can be changed throughout the music using the functions `add-grace-property` and `remove-grace-property`. The following example undefines the `Stem` direction for this grace, so that stems do not always point up, and changes the default note heads to crosses.

>     \relative c'' {
>       \new Staff {
>         #(remove-grace-property 'Voice 'Stem 'direction)
>         #(add-grace-property 'Voice 'NoteHead 'style 'cross)
>         \new Voice {
>            \acciaccatura { f16 } g4
>            \grace { d16[ e] } f4
>            \appoggiatura { f,32[ g a] } e2
>         }
>       }
>     }

Redefining grace note global defaults

The global defaults for grace notes are stored in the identifiers `startGraceMusic`, `stopGraceMusic`, `startAcciaccaturaMusic`, `stopAcciaccaturaMusic`, `startAppoggiaturaMusic` and `stopAppoggiaturaMusic`, which are defined in the file `ly/grace-init.ly`. By redefining them other effects may be obtained.

>     startAcciaccaturaMusic = {
>       s1*0(
>       \override Stem #'stroke-style = #"grace"
>       \slurDashed
>     }

>     stopAcciaccaturaMusic = {
>       \revert Stem #'stroke-style
>       \slurSolid
>       s1*0)
>     }

>     \relative c'' {
>       \acciaccatura d8 c1
>     }

Positioning grace notes with floating space

Setting the property `'strict-grace-spacing` makes the musical columns for grace notes ’floating’, i.e., decoupled from the non-grace notes: first the normal notes are spaced, then the (musical columns of the) graces are put left of the musical columns for the main notes.

>     \relative c'' {
>       <<
>         \override Score.SpacingSpanner #'strict-grace-spacing = ##t
>         \new Staff \new Voice {
>           \afterGrace c4 { c16[ c8 c16] }
>           c8[ \grace { b16[ d] } c8]
>           c4 r
>         }
>         \new Staff {
>           c16 c c c c c c c c4 r
>         }
>       >>
>     }

#### See also

Music Glossary: grace notes, acciaccatura, appoggiatura.

Notation Reference: Manual beams.

Installed Files: ‘`ly/grace-init.ly`’.

Snippets: Rhythms.

Internals Reference: GraceMusic, Grace_beam_engraver, Grace_engraver, Grace_spacing_engraver.

#### Known issues and warnings

A multi-note beamed acciaccatura is printed without a slash, and looks exactly the same as a multi-note beamed appoggiatura.

Grace note synchronization can also lead to surprises. Staff notation, such as key signatures, bar lines, etc., are also synchronized. Take care when you mix staves with grace notes and staves without, for example,

>     <<
>       \new Staff { e4 \bar "|:" \grace c16 d2. }
>       \new Staff { c4 \bar "|:" d2. }
>     >>

This can be remedied by inserting grace skips of the corresponding durations in the other staves. For the above example

>     <<
>       \new Staff { e4 \bar "|:" \grace c16 d2. }
>       \new Staff { c4 \bar "|:" \grace s16 d2. }
>     >>

The use of grace notes within voice contexts confuses the way the voice is typeset. This can be overcome by inserting a rest or note between the voice command and the grace note.

>     accMusic = {
>       \acciaccatura { f8 } e8 r8 \acciaccatura { f8 } e8 r4
>     }

>     \new Staff {
>       <<
>         \new Voice {
>           \relative c'' {
>             r8 r8 \voiceOne \accMusic \oneVoice r8 |
>             r8 \voiceOne r8 \accMusic \oneVoice r8 |
>           }
>         }
>         \new Voice {
>           \relative c' {
>             s8 s8 \voiceTwo \accMusic \oneVoice s8 |
>             s8 \voiceTwo r8 \accMusic \oneVoice s8 |
>           }
>         }
>       >>
>     }

Grace sections should only be used within sequential music expressions. Nesting or juxtaposing grace sections is not supported, and might produce crashes or other errors.

Each grace note in MIDI output has a length of 1/4 of its actual duration. If the combined length of the grace notes is greater than the length of the preceding note a “`Going back in MIDI time`” error will be generated. Either make the grace notes shorter in duration, for example:

>     \acciaccatura { c'8[ d' e' f' g'] }

becomes:

>     \acciaccatura { c'16[ d' e' f' g'] }

Or explicitly change the musical duration:

>     \acciaccatura { \scaleDurations #' (1 . 2) { c'8[ d' e' f' g'] } }

See Scaling durations.

#### Aligning to cadenzas

In an orchestral context, cadenzas present a special problem: when constructing a score that includes a measured cadenza or other solo passage, all other instruments should skip just as many notes as the length of the cadenza, otherwise they will start too soon or too late.

One solution to this problem is to use the functions `mmrest-of-length` and `skip-of-length`. These Scheme functions take a defined piece of music as an argument and generate a multi-measure rest or `\skip` exactly as long as the piece.

>     MyCadenza = \relative c' {
>       c4 d8 e f g g4
>       f2 g4 g
>     }

>     \new GrandStaff <<
>       \new Staff {
>         \MyCadenza c'1
>         \MyCadenza c'1
>       }
>       \new Staff {
>         #(ly:export (mmrest-of-length MyCadenza))
>         c'1
>         #(ly:export (skip-of-length MyCadenza))
>         c'1
>       }
>     >>

#### See also

Music Glossary: cadenza.

Snippets: Rhythms.

#### Time administration

Time is administered by the `Timing_translator`, which by default is to be found in the `Score` context. An alias, `Timing`, is added to the context in which the `Timing_translator` is placed. To ensure that the `Timing` alias is available, you may need to explicitly instantiate the containing context (such as `Voice` or `Staff`).

The following properties of `Timing` are used to keep track of timing within the score.

`currentBarNumber`

  The current measure number. For an example showing the use of this property see Bar numbers.

`measureLength`

  The length of the measures in the current time signature. For a 4/4 time this is 1, and for 6/8 it is 3/4. Its value determines when bar lines are inserted and how automatic beams should be generated.

`measurePosition`

  The point within the measure where we currently are. This quantity is reset by subtracting `measureLength` whenever `measureLength` is reached or exceeded. When that happens, `currentBarNumber` is incremented.

`timing`

  If set to true, the above variables are updated for every time step. When set to false, the engraver stays in the current measure indefinitely.

Timing can be changed by setting any of these variables explicitly. In the next example, the default 4/4 time signature is printed, but `measureLength` is set to 5/4. At 4/8 through the third measure, the `measurePosition` is advanced by 1/8 to 5/8, shortening that bar by 1/8. The next bar line then falls at 9/8 rather than 5/4.

>     \new Voice \relative c' {
>       \set Timing.measureLength = #(ly:make-moment 5 4)
>       c1 c4 |
>       c1 c4 |
>       c4 c
>       \set Timing.measurePosition = #(ly:make-moment 5 8)
>       b4 b b8 |
>       c4 c1 |
>     }

As the example illustrates, `ly:make-moment n m` constructs a duration of n/m of a whole note. For example, `ly:make-moment 1 8` is an eighth note duration and `ly:make-moment 7 16` is the duration of seven sixteenths notes.

#### See also

Notation Reference: Bar numbers, Unmetered music.

Snippets: Rhythms.

Internals Reference: Timing_translator, Score.

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

#### LilyPond — Notation Reference