1\version "2.19.21" 2 3\header { texidoc=" You can write stencil callbacks in Scheme, thus 4providing custom glyphs for notation elements. A simple example is 5adding parentheses to existing stencil callbacks. 6 7The parenthesized beam is less successful due to implementation of the 8Beam. The note head is also rather naive, since the extent of the 9parens are also not seen by accidentals. 10" 11 12} 13 14%% Silence a warning about missing font-property, if compiled with the 15%% check-internal-types option. 16#(if (ly:get-option 'check-internal-types) 17 (ly:expect-warning "Grob `Beam' has no interface for property")) 18 19#(define (parenthesize-callback callback) 20 "Construct a function that will do CALLBACK and add parentheses. 21Example usage: 22 23 \\override NoteHead.stencil 24 = 25 #(parenthesize-callback ly:note-head::print)" 26 27 (define (parenthesize-stencil grob) 28 "This function adds parentheses to the original callback for 29GROB. It does not affect the dimensions of the stencil. 30" 31 32 (let* ((fn (ly:grob-default-font grob)) 33 (pclose (ly:font-get-glyph fn "accidentals.rightparen")) 34 (popen (ly:font-get-glyph fn "accidentals.leftparen")) 35 (subject (callback grob)) 36 37 ; remember old size 38 (subject-dim-x (ly:stencil-extent subject X)) 39 (subject-dim-y (ly:stencil-extent subject Y))) 40 41 ;; add parens 42 (set! subject 43 (ly:stencil-combine-at-edge 44 (ly:stencil-combine-at-edge subject X RIGHT pclose 0.2) 45 X LEFT popen 0.2)) 46 47 ; revert old size. 48 (ly:make-stencil 49 (ly:stencil-expr subject) subject-dim-x subject-dim-y))) 50 parenthesize-stencil) 51 52 53\layout { ragged-right = ##t } 54\relative { 55 c'4 e 56 57 \override NoteHead.stencil 58 = 59 #(parenthesize-callback ly:note-head::print) 60 g bes 61 \revert NoteHead.stencil 62 63 \override Beam.stencil 64 = 65 #(parenthesize-callback ly:beam::print) 66 67 a8 gis8 a2. 68 69} 70 71 72 73