Hi Carl,

2016-12-18 8:26 GMT+01:00 Carl Williams <carl.j.willia...@gmail.com>:
> One more little adjustment, for anyone who will benefit from it.
> The previous version only overrode Beam.positions on the first line. After a
> line break they go back to how they were if by default.
> I don't quite understand why, but the solution was to move that section
> under a before-line-breaking section rather than after-line-breaking.

Then remove it there.

I missed to take 'beam-thickness into account. Good catch.
Your code can be shortened to the below, probably even more (depending
on your final goal)

beam-stem-height =
#(define-music-function (parser location start-in length-in)(number? number?)
  "Takes a list containing values for:
  - the stem-start in Y-direction
  - the stem-length
  Values can be positive or negative, depending on direction
  but may produce a warning if only one value is negative:
    'warning: weird stem size, check for narrow beams'
  "
  #{
    \override Stem.direction = #(if (positive? length-in) UP DOWN)
    \override Stem.stem-begin-position = #start-in
    \override Stem.length = #(abs length-in)
    \override Beam.after-line-breaking =
      #(lambda (grob)
        (let ((stems (ly:grob-array->list (ly:grob-object grob 'stems))))
          (for-each
            (lambda (stem)
              (ly:stem::calc-stem-begin-position stem)
              (ly:grob-set-property! stem 'length (abs length-in))
              (ly:grob-set-property! stem 'stem-begin-position start-in))
            stems)))
    \override Beam.before-line-breaking =
      #(lambda (grob)
        (let*
      ;; TODO returns 'direction always correctly?
          ((dir (ly:grob-property grob 'direction))
           (position
             (/ (+ (abs start-in)
                   (- (abs length-in)
                      (ly:grob-property grob 'beam-thickness)))
                (* dir 2))))
          (ly:grob-set-property! grob 'positions (cons position position))))
#})

Cheers,
  Harm

P.S.
Your code doesn't follow the recommended style, makes it harder to follow.
Please read
http://community.schemewiki.org/?scheme-style

_______________________________________________
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond

Reply via email to