[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fixes heights and pure heights of stems. (issue 4898044)

From: mtsolo
Subject: Fixes heights and pure heights of stems. (issue 4898044)
Date: Sun, 14 Aug 2011 16:25:28 +0000

Reviewers: ,

Hey all,

This patch fixes a bug in LilyPond that has nagged me for some time:
incorrect heights and pure heights for stems.


With this patch, heights for stems are correct (they weren't before) and
pure heights are better approximations.  There is one new regtest that
shows it in action, and the code works favorably in several other
regtests.  To wit: : leads to the lesser of two evils in a beam
collision actually works now (before the
spacing was off) the heights between systems corresponds to the
actual system skyline (lengths of stems in this context used to be set
to zero)

Also, the Stem grob's property list is cleaned up.  It looses three
confusing properties: length, stem-begin-position, and
stem-end-position.  It also leads to cleaner overrides: if the user
wants to do some work with stem ends but does not want to trigger beam
calculations, she can work with the pure callback.  Idem for stem

To see this patch do its thing, add:

\override Stem #'stencil =
#(lambda (grob)
  (let ((y-ext (ly:stem::pure-height grob 0 1000))
         (stem (ly:stem::print grob)))
  (if (null? stem) (ly:make-stencil '() '(0 . 0) '(0 . 0))
(ly:stencil-add stem
    (stencil-with-color (ly:stencil-translate-axis
(ly:stencil-translate-axis (make-line-stencil 0.2 0 (car y-ext) 0 (cdr
y-ext)) 0 Y) -0.3 X) red)))))


\override Stem #'stencil =
#(lambda (grob)
  (let ((y-ext (ly:stem::height grob))
         (stem (ly:stem::print grob)))
  (if (null? stem) (ly:make-stencil '() '(0 . 0) '(0 . 0))
(ly:stencil-add stem
    (stencil-with-color (ly:stencil-translate-axis
(ly:stencil-translate-axis (make-line-stencil 0.2 0 (car y-ext) 0 (cdr
y-ext)) 0 Y) -0.3 X) red)))))

depending on if you want to see the height or pure height.  You'll see
that the results of this patch compared to current master are much


The pure height calculation for beamed stems is more computationally
intensive, which increases compile time for pieces with lots of beams,
especially if those beams hold lots of stems.  A separate patch to cache
pure heights would speed this (and many other things) up a great deal.
At a certain point, gave me periodic errors of
infinite stencil offset for the tuplet bracket.  It no longer does this,
but I'm not sure if this is because I actually fixed it or because I'm
lucky.  The problem originally came from the change in


Because this patch effects stem extents across the board, the regtest
comparisons are nightmarish to check.  The layout probably does not
change at all in most regtests (at least not to the naked eye), but
because of the change in Y-extent, almost every regtest with stems comes
back as having changed.  So, spotting regressions is very difficult.
The files I list above are the only ones where I see a noteworthy
change, and I believe all of these are for the better.


This is a labor of love that will pave the way for non-buggy glissando
stems in LilyPond as well as (probably) no more stem-accidental
collisions in extreme beaming situations.  It may also fix other
collision-related issues in the tracker (I'll have to do some snooping).
 The existing code logic does not change at all save the stem
pure_height function. is, however, significantly rearranged in
order to consolidate properties and standardize height/pure-height

Thanks for your time looking at this, and I'm looking forward to any and
all comments!


Fixes heights and pure heights of stems.

Please review this at

Affected files:
  M input/regression/
  A input/regression/
  M lily/
  M lily/
  M lily/include/stem.hh
  M lily/
  M lily/
  M lily/
  M lily/
  M lily/
  M lily/
  M ly/
  M scm/define-grob-properties.scm
  M scm/define-grobs.scm
  M scm/flag-styles.scm

reply via email to

[Prev in Thread] Current Thread [Next in Thread]