3

I am trying to make something like this in LilyPond, where the note in the upper stave is aligned with the grace notes in the lower staff:

enter image description here

Any solution should also work after a time signature change, hence the example.

It's to be played similarly as when notated with a guide line (like this). A guide line wouldn't be very fitting in this case, though, so I'm trying to indicate it spatially. Using a new spacing section like here does not solve the problem.

The best I've managed so far is to just move the upper note with X-offsets. An unpleasant but manageable disadvantage of this is that you have to manually check how far you have to move it. If you for example uncomment the new spacing section in the code, the notes in the third bar are not aligned anymore. Also the overall spacing in the third bar is pretty bad, but this can be fixed by simply moving the last quarter note the same space to the right as the other was moved to the left.

enter image description here

Is there any better, more consistent and elegant way to do this? (Could one for example have LilyPond treat the note and grace note I want vertically aligned as a sort of unit, so that they're always aligned like normal notes usually are? Or are there other ideas?)

My code:

\version "2.22.2"
NotesLeft = {
  \override NoteHead.X-offset = -3.5
  \override Stem.X-offset = -3.5
  \override Beam.X-offset = -3.5
}
NotesRestore = {
  \revert NoteHead.X-offset
  \revert Stem.X-offset
  \revert Beam.X-offset
}

\score {
  \new PianoStaff <<
    \new Staff \relative c'' {
      \numericTimeSignature \time 4/4
      \grace{s16} a1                                | \time 5/4
      \grace{s8} \NotesLeft c1~ \NotesRestore c4    |
      c2 \NotesLeft c2 \NotesRestore g4             |
    }
    \new Staff \relative c {\clef bass \numericTimeSignature
      \grace{e16} f1            | %\time 5/4
      \grace{c16 g'} e'2~ e2.   |
      %\newSpacingSection
      %\override Score.SpacingSpanner.strict-grace-spacing = ##t
      e2 \grace{c,8 g'} e'2.    |
    }
  >>
}

0

1 Answer 1

3

The problem you’re facing is that grace notes are placed into a prior Paper Column. But you can nicely hack around this by inserting a minimal skip before the grace notes, forcing them into a later Paper Column like this:

\new PianoStaff
<<
  \new Staff { a'1 \time 5/4 c''2~ 2. }
  \new Staff { \clef bass \grace {e16 } f1 |
               \time 5/4 s1024 \grace { c16 d } e2*511/512~ 2. }
>>
4
  • This is much nicer, thank you! Just to clarify the logic behind it: The grace notes' usual spot is filled by the invisible rest and the grace notes end up in the upper principal note's column. And the lower principal note is moved to the next paper column. Is that correct? And regarding the note lengths: The grace notes take up no space in the measure. The principal note following our hack needs to be shortened so that together with our invisible space it has the length it usually has. So if we had a whole note it would be e1*1023/1024?
    – MrBubbles
    Commented Jun 14, 2022 at 17:04
  • @MrBubbles Lilypond puts things that happen at the same time into Columns. Each point in "score time", which Lilypond calls "Moment" might have a grace part that get’s put into grace columns that are strictly prior to the main part. So the default would be something like grace note | note rh/lh. We circumvent this here by putting the left hand note into a column that is slightly later (in this case a 1/1024th later). Thus we get something like rh note | grace note | lh note.
    – Lazy
    Commented Jun 14, 2022 at 19:38
  • @MrBubbles If you were to use a larger value for this skip you’d actually see that the grace notes come slightly after the right hand note, which is the reason why this uses a very small skip (we could of course also use a 1/2048th or a 1/4096th or even smaller skip, but the effect would not really be noticeable anymore.
    – Lazy
    Commented Jun 14, 2022 at 19:39
  • Thank you for the explanation, very helpful. That sort of stuff is not something I had found in the documentation so far. I only saw paper columns in the internals section, where the concept isn't explained. (If anybody has a link to an "official" explanation, I'd appreciate that.) So the notes are not really coupled, but I guess there's no case where that would really matter. and everything after is also aligned. Works for me :)
    – MrBubbles
    Commented Jun 14, 2022 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.