Massive improvement in LilyPond’s horizontal spacing!

In the post about horizontal spacing in Fried Songs edition I have complained about a nasty bug in LilyPond horizontal spacing (issue 3304), which was causing us a lot of trouble in pieces that contained a lot of triplets. I am extremely happy to announce that the bug has been fixed by Keith OHara!

A little background

When calculating distances between notes, LilyPond uses a metaphor of springs and “compressing force”. First, virtual spring objects are inserted between consecutive notes in the score; the stiffness of these springs (as well as their minimal and optimal lengths) is related to the duration of the notes. After the line-breaking is decided (i.e. after it’s known what measures will be in which system), LilyPond stretches the music until all springs are fully extended and then loosens them until the desired line width is reached.
Now, when different voices contain unequal subdivisions (for example one instrument plays quavers, and another plays quaver triplets) some springs are split (i.e. one longer spring is replaced with two shorter ones). The problem was that these smaller springs didn’t behave the same during compressing as the bigger springs they replaced, which resulted in uneven spacing of some notes (it was especially visible when the music was compressed or stretched a lot):

spacing-multi-tuplet-before

It was possible to noticeably improve the results by enabling uniform-stretching option, but it had some unwanted side-effects (so it couldn’t be enabled by default).

The results

Fortunately, Keith managed to change this behaviour, so now this example is rendered as follows (by default!):

spacing-multi-tuplet-after

Also, the triplet-intense opus 7-1 from Fried Edition, which was giving me some headaches before, has improved dramatically:

That's how it used to look - ugh!

That’s how it used to look – ugh!

This is how it looks by default now!

This is how it looks by default now!

Keith’s fix not only makes the spacing more pleasing to the eye – it also significantly improves legibility of polyphonic rhythms in situations like this:

Before: quarter notes in alto are too much to the left, which makes it hard to see that they should be sung exactly in the middle of soprano half note

After: now the spacing makes it clear when alto quarters are relative to soprano half note.

After: now the spacing makes it more clear when alto quarters should be sung relative to soprano half note.

And an extreme example – the music here is compressed so much that before Keith’s adjustments the spacing was completely wrong (notes that aren’t simultaneous had the same horizontal position, ugh!):

really-tight-before

Now note placement is quite acceptable (given how extremely limited the available space is):

really-tight-after

I have to say that I am very happy to see this change – this was probably the most serious horizontal spacing bug LilyPond had. There are a few other things that should still be improved, but generally speaking horizontal spacing in LilyPond is now in a quite good condition 🙂

Since the fix was applied already after we released stable 2.18 version, it is now available only in the development branch (2.19) – however, it is possible that it will be backported to the 2.18.2 stable version, which should be released in the next few weeks.

I’d like to end this post with a big THANK YOU to Keith 🙂 This is really awesome!

6 thoughts on “Massive improvement in LilyPond’s horizontal spacing!

  1. vvillenave

    Indeed it is. I haven’t given it a go yet but I suspect it will be a big help in complex polyphonic piano scores (involving simultaneous asynchronous 5-plets, 7-plets and the like). The pianist who performer my first Piano Sonata a couple of years ago, kept complaining about the edition and if I had listened to him I would have had to recompile the whole thing under a ‘uniform-stretching paradigm (which is, at least in my case, way worse than the default output, no matter how bad it may look).

    Big up to Keith, and to the whole community who keeps (unlike me) finding the courage of contributing to LilyPond!

    Reply
    1. Janek Warchoł Post author

      Indeed, i have your piano sonata in my “lilypond inspiration” collection. There’s a LOT of stuff that should be fixed there (i mean lilypond bugs) – but if i see correctly, some problems were already fixed, so you may consider recompiling it with latest dev version and comparing the results.

      Reply
  2. Joshua Nichols

    My face lit up when I saw this. It was also bittersweet because of the memory this wonderful achievement/improvement has brought to mind: the fact that I paid untold monies for programs that can not touch the strength and versatility of LilyPond.

    Now, on to getting a graphical integration! 🙂

    Reply
    1. Urs Liska

      We see it at other things too: Many of the issues we’ll have when updating our Fried edition to current LilyPond versions are eliminating workarounds that aren’t necessary anymore. And I’m looking explicitly at you, David 😉

      Reply
  3. Abraham Lee

    Oddly enough, I have experienced the example of “extreme example” when the eighth note in the top staff and the dotted quarter note in the bottom staff shouldn’t appear at the same musical moment, but actually do.

    Bad timing example

    At first, I thought, “Huh? That certainly doesn’t look right.” I then proceeded to display the grid line timing marks to see if my eyes were just playing tricks on me. Unfortunately, it was still true, even when zooming in REALLY close. Very sad to see.

    Part of the problem, I think, was that I was also including lyrics, which tends to push notes to unwanted horizontal positions. Funny thing is, when I put

    \context {
      \Lyrics
      \override LyricText #'font-size = #0
    }

    in the layout block, which I think isn’t really supposed to do anything to the font size (though I could be mistaken), it magically adjusted the notes!

    Timing fixed!

    I was thrilled, but puzzled. So, seeing a more permanent fix for this is WONDERFUL news! The full score (and others) can be found on my github site.

    Thanks so much for everything you do! (You, meaning, EVERYONE developing this marvelous piece of software 🙂

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *