3 \header { texidoc=" You can write molecule callbacks in Scheme, thus
4 providing custom glyphs for notation elements. A simple example is
5 adding parentheses to existing molecule callbacks.
7 The parenthesized beam is less successful due to implementation of the
8 Beam. The note head is also rather naive, since the extent of the
9 parens are also not seen by accidentals.
14 #(define (parenthesize-callback callback)
15 "Construct a function that will do CALLBACK and add parentheses.
18 \property Voice.NoteHead \\override #'molecule-callback
20 #(parenthesize-callback Note_head::brew_molecule)
25 (define (parenthesize-molecule grob)
26 "This function adds parentheses to the original callback for
27 GROB. The dimensions of the molecule is not affected.
31 (fn (ly:get-default-font grob))
32 (pclose (ly:find-glyph-by-name fn "accidentals-rightparen"))
33 (popen (ly:find-glyph-by-name fn "accidentals-leftparen"))
34 (subject (callback grob))
37 (subject-dim-x (ly:get-molecule-extent subject 0))
38 (subject-dim-y (ly:get-molecule-extent subject 1))
43 (ly:combine-molecule-at-edge
44 (ly:combine-molecule-at-edge subject 0 1 pclose 0.2)
48 (ly:set-molecule-extent! subject 0 subject-dim-x)
49 (ly:set-molecule-extent! subject 1 subject-dim-y)
59 \notes \relative c' { c4 e
61 \property Voice.NoteHead \override #'molecule-callback
63 #(parenthesize-callback Note_head::brew_molecule)
65 \property Voice.NoteHead \revert #'molecule-callback
66 \property Voice.Beam \override #'molecule-callback
68 #(parenthesize-callback Beam::brew_molecule)
74 \paper { linewidth = -1. }