lilypond-user
[Top][All Lists]
Advanced

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

Re: How to restore default-stem-attachment with note-head-stencil-overri


From: Thomas Morley
Subject: Re: How to restore default-stem-attachment with note-head-stencil-override?
Date: Sat, 21 Jul 2012 00:25:53 +0200

2012/7/19 Keith OHara <address@hidden>:
> On Wed, 18 Jul 2012 13:56:09 -0700, Thomas Morley
> <address@hidden> wrote:
>
>> But reading out x- and y-length of the NoteHead-stencil, and comparing
>> their quotient with the quotient build from the values I got via
>> 'stem-attachment, different results are returned.
>
>
>> x-length 1.316178
>> y-length 1.100012
>> [stem-attachment]  (1.0 . 0.341476274804275)
>
>
> The stem attaches at 1.0 times the width of the head, 0.34 times the height,
> so for the default note-head it attaches at (1.32 staff-space, 0.37
> staff-space)
> ... or possibly the origin is in the middle of the head, so stem might
> attache
> at half what I figured, (0.66 0.18) relative to the center.
>
> When you make a bigger stencil by putting a box around, it will be about
> 2.0 high and 2.0 wide, so the desired stem-attachment will be around (0.50,
> 0.17)
>
> Maybe you can figure the new stem-attachment coordinates based on the new
> height
> and width, but it looks easier to choose them by hand, as part of designing
> a
> new note-head.
>

Hi Keith,

thanks for all your hints.
I'm coming up now with the code below.

Testing it with different note-head-styles returns weird output or
log-warnings while using 'mensural, 'neomensural and 'petrucci.
A bug?

Best,
  Harm

\version "2.15.42"

#(set-global-staff-size 40)

restoreStemAttachment =
\override NoteHead #'stencil =
  #(lambda (grob)
    (let* ((stencil (ly:note-head::print grob))
           (new-stil (grob-interpret-markup grob (markup #:box
#:stencil stencil)))
           (stem-attach (ly:grob-property grob 'stem-attachment))
           (x-length-stil (interval-length (ly:stencil-extent stencil X)))
           (x-length-new-stil (interval-length (ly:stencil-extent new-stil X)))
           (x-coord (/ x-length-stil x-length-new-stil))

           (y-length-stil (interval-length (ly:stencil-extent stencil Y)))
           (y-length-new-stil (interval-length (ly:stencil-extent new-stil Y)))
           (y-factor (/ y-length-stil y-length-new-stil))
           (ratio (/ (car stem-attach) (cdr stem-attach)))
           (y-coord (/ y-factor ratio)))
  (ly:grob-set-property! grob 'stem-attachment (cons x-coord y-coord))
  new-stil))

%--- test ---

\new Staff
\transpose c cis
\relative c'' {
        \accidentalStyle "forget"
        \override Stem #'color = #red
        \override Stem #'layer = #10

        % weird output with:
        % \override NoteHead #'style = #'mensural
        % \override NoteHead #'style = #'neomensural

        % log: warning: Found infinity or nan in output. Substituting 0.0
        % and no stem printed with:
        % \override NoteHead #'style = #'petrucci

        g4
        \once \restoreStemAttachment
        g
        g'
        \once \restoreStemAttachment
        g
}



reply via email to

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