Search code examples
lilypond

Lilypond grace note affects formatting


When I start this piece with a grace note, it messes up formatting: bad formatting

Code:

\version "2.18.2"

\header {
    title = "Sonata in D Major"
    composer = "Joseph Haydn"
    opus = "Hob. XVI/37"
}

\language "english"

upper = \relative c'' {
    \clef treble
    \key d \major
    \time 4/4

    r4 r8 <cs a'> <d gs>( <cs a'>) <d gs>( <cs a'>) %m1
}

lower = \relative c {
    \clef treble
    \key d \major
    \time 4/4

    \grace gs''8( a-!) a,-! a-! a-! b(\trill a) b(\trill a)
}

\score {
    \new PianoStaff <<
        \set PianoStaff.instrumentName = #"Piano  "
        \new Staff = "upper" \upper
        \new Staff = "lower" \lower
    >>
    \layout { }
    \midi { }
}

If I remove the \grace indication, it works (but of course, without the grace note):

good format

How can I use this grace note while keeping the correct formatting? Is this a bug with Lilypond?


Solution

  • This is a knnown problem but there is a workaround: just add a spacer grace note ( \grace s8 ) at the upper staff, before the r4 rest.

    \grace s8 r4 r8 <cs a'> % etc
    

    lilypond output sample

    A fix for the problem is proposed to be investigated this summer during Google GSoC, see http://lilypond.org/google-summer-of-code.html