LilyPond Tie Crusade

As we all know, LilyPond is valuable software but it’s not perfect.  Some people find text input inconvenient, others would like to have more realistic MIDI playback or advanced contemporary notation enhancements – there’ll always be features to implement and bugs to fix, and that’s normal.

Nevertheless, some things are more important than others – and I suggest to focus on the fundamental ones.  After all, LilyPond’s goal is to provide automatic music engraving for everyone, with the highest quality possible, so let’s ensure that the most basic elements, which are common to all scores, are handled perfectly.

What are these?  Noteheads, stems, flags, beams and rests – we have them covered.  As well as augmentation dots, ledger lines, barlines, clefs, key and time signatures.  There is one more element that is necessary for basic notation, something that appears in virtually every score: ties, which connect two notes of the same pitch to indicate that they should be played as one sound.  Ties in LilyPond are quite far from being perfect – a couple examples is enough to demonstrate this:


Now, neither of the above two ties is wrong or horribly ugly – but why are they different at all?  There is no reason for this inconsistency; both ties connect noteheads that stick out of the staff (i.e. there are no stafflines that could interfere with the ties) and the notes are spaced identically in each case – therefore both ties should look identical or at least very similar.

Another example:


Here the tie is too flat and it’s ends are too far away from the noteheads.  The first thing is bad because there is not enough clearance between the tie’s belly and the staffline, which results in unpleasant, obscure black clump instead of a clearly curved shape.  As for the placement of the tips, I personally think that it’s better when they point directly into the noteheads, instead of “embracing” them.  If the ends point into the noteheads, it’s harder to mistake a tie for a slur.

Now, you may think that fixing this is just a matter of adjusting some parameters that govern tie formatting, but I’m pretty sure this is not enough.  Over the last two years I’ve collected scores of bad tie examples, and seen much more of them in various LilyPond-made scores – some were actually much worse than the above ones.  I’ve also had the opportunity to see how LilyPond behaviour changes when some of the parameters are altered (thanks to Karol Majewski) – sometimes the results were better but still unsatisfactory.  This evidence makes me sure that a major redesign of tie formatting code is necessary.

Therefore I announce the Tie Crusade (or, less poetically, the Tie Project): let’s improve tie formatting together!

The task is fairly big, so there’s plenty of space for many people to join.  We need to look through tracker issues about ties, search for more examples in real-life scores, find patterns and thoroughly discuss what exactly the desired behaviour should be, before finally implementing it.  A lot of work has already been done by me, so there is a solid starting point; together with my cousin Franek we recently begun reading through the current code.  It would be very helpful to have more people analyse it (it’s written mostly in C++) and think about the task, so that we’ll have a good understanding of the current situation and a solid specification before we start changing things.

There are also purely engraving issues – sometimes I’m not sure what the desired formatting should be, so I welcome all experienced engravers with a keen eye for details to share their opinions with me.

Anyone interested in learning more is invited to contact me (through the contact form or personally) or the LilyPond developers mailing list; I’ll share my research with you so that you can see what problems we’re facing as well as my ideas for solving them.  Currently I have all this stuff in a folder on Dropbox – I don’t think it would make sense to create a tracker issue for this, as the materials keep changing; as for now I’ll just share it with people who are interested.

I expect that with the help of several people we can do this in a few weeks and about 2000 lines of code.

Of course, LilyPond users providing examples of badly formatted ties are welcome as well!  We don’t want to miss anything here 🙂

14 thoughts on “LilyPond Tie Crusade

    1. Janek Warchoł Post author

      Do you mean situations like the ones described in issue 570? If so, I believe that the placement of the tie tips is simply wrong in these cases, and i intend to change it so that collisions will be smaller or disappear altogether.

      1. Alex D.

        Yes! I always end up going back and changing the ties to slurs to avoid this. Why aren’t ties and slurs the same thing internally? They usually end up looking the same.

  1. Carl Peterson

    Janek, in general terms, how does the tie engraver go about plotting a tie today?

    The process I was thinking of is:
    1. Plot the tie as a bezier curve originating in the center of the two noteheads (using the process demonstrated in the animations at
    2. Given a sufficiently dense set of points plotted (perhaps determined by the distance between the two noteheads), trim any plotted points within a certain distance of the noteheads (to provide a clear space)
    3. Plot the outline of the actual tie curve using the points as the center and the slope of the line used to plot the points in (1) with a thickness parameter to determine where the outline points should be placed.

    The question would be how to determine the parameters for the bezier curve. One factor (to determine the height of the curve) would be a distance function, but there’s also a matter of collision avoidance (to avoid slurs or other voices), which is well beyond what I know about the internal workings (which is basically nothing).

    1. Janek Warchoł Post author


      i haven’t read all the tie formatting code yet, but as far as i can see firstly the vertical position of the tie ends and its direction is determined, and then the height and curvature is a function of the length.

      I don’t think that this “trimming” approach would be effective. I’d rather determine the position of the ends of the tie directly, and then set the position of the middle bezier control points so that the slope of the tie will be “pointing into” the notehead.
      And besides, there are many additional factors that make the optimum slope often unavailable. So, i don’t think that a slope-centric approach (like the one you suggest, if i understand it correctly) would work well.

      I’ll send you a link to my resources, including my notes on the algorithm.

      As for avoiding ties connecting other notes, i think that the current algorithm is doing that fine – we can leave that part of the code mostly unchanged.

    1. Janek Warchoł Post author

      Yes, i’ve read that section of “Behind Bars”. It was quite some time ago (i don’t have my own copy), but as far as i remember it wasn’t detailed enough to be of much help. Just some general guidelines, without lots of analyzed examples – it more or less said what the effect should be (for example that a tie shouldn’t be easy to mistake for a slur), without saying how to achieve that. At least that was my impression.

      1. Phil H

        I think it’s of a sufficient ly detailed nature in many areas of tie layout that it would be worth re-reading it prior to a wholesale activity on tie design.

        1. Janek Warchoł Post author

          Ok, i’ll try to find someone near me who has one (but that will probably prove dificult).

        2. Janek Warchoł Post author

          I got a scan and i have to admit i was wrong – there are many useful examples there. Fortunately, Elaine’s conclusions are usually similar to mine 🙂

          1. simon

            glad to see it’s of use, janek. 😀 i think you may have been confusing gould’s textbook with gardner-read’s. iirc, from browsing through the other day, he doesn’t have much to say about ties. 😉

  2. Pingback: Honestly: Is LilyPond Good Enough? | Scores of Beauty

  3. Pingback: Tie Crusade, round 2 | Scores of Beauty

Leave a Reply

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