lilypond-user
[Top][All Lists]
Advanced

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

Parenthesized notehead


From: Jonatan Liljedahl
Subject: Parenthesized notehead
Date: Tue, 22 Nov 2005 20:25:20 -0200

People often asks how to get parenthesized noteheads. There is an
example: stencil-hacking.ly but that doesn't adjust the stencil extents
properly, so the parenthesis collides with accidentals and stuff like
that. I have made a version that does take care of this:

Perhaps this functionality should be included in lilypond, it's not so
uncommon to want parenthesis around noteheads... There could be a
\startParenthesizeNoteHeads and \stopParenthesizeNoteHeads command...
(or maybe some shorter names? ;) Or even something like "\override
NoteHead #'parenthesized = ##t" (merge the code below with the default
stencil proc for noteheads)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\version "2.7.15"

#(define (parenthesize-callback callback)
   (define (parenthesize-stencil grob)
     (let* ((fn (ly:grob-default-font grob))
            (pclose (ly:font-get-glyph fn "accidentals.rightparen"))
            (popen (ly:font-get-glyph fn "accidentals.leftparen"))
            (subject (callback grob))

                ; get position of stem
                (stem-pos (ly:grob-property grob 'stem-attachment))
                
            ; remember old size
            (subject-dim-x (ly:stencil-extent subject 0))
            (subject-dim-y (ly:stencil-extent subject 1)))

        ;; add parens
        (set! subject
             (ly:stencil-combine-at-edge 
              (ly:stencil-combine-at-edge subject 0 1 pclose 0)
              0 -1 popen  0))
                  
                ; adjust stem position
                (ly:grob-set-property! grob 'stem-attachment
                        (cons (- (car stem-pos) 0.43) (cdr stem-pos)))

        ; adjust size
       (ly:make-stencil
        (ly:stencil-expr subject)
                  (cons (- (car subject-dim-x) 0.5) (+ (cdr
subject-dim-x) 0.5)) subject-dim-y)))
   parenthesize-stencil)
    

\layout { raggedright = ##t }
\relative c' {

    c4 e
    \override NoteHead  #'stencil = #(parenthesize-callback
Note_head::print) g bes a1
    \revert NoteHead #'stencil

    a8 gis8 a2.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/Jonatan    -=( http://kymatica.com )=-




reply via email to

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