]> git.donarmstrong.com Git - lilypond.git/blob - input/regression/molecule-hacking.ly
09f5c958fbbc83a7ce5f19cbe5fc6fecf7493823
[lilypond.git] / input / regression / molecule-hacking.ly
1
2 \version "2.3.17"
3
4 \header { texidoc=" You can write stencil callbacks in Scheme, thus
5 providing custom glyphs for notation elements.  A simple example is
6 adding parentheses to existing stencil callbacks.
7
8 The parenthesized beam is less successful due to implementation of the
9 Beam. The note head is also rather naive, since the extent of the
10 parens are also not seen by accidentals.
11 "
12         
13 }
14
15 #(define (parenthesize-callback callback)
16    "Construct a function that will do CALLBACK and add parentheses.
17 Example usage:
18
19   \\property NoteHead \\override #'print-function
20                    =
21                       #(parenthesize-callback Note_head::print)
22                     
23 "
24
25    
26    (define (parenthesize-stencil grob)
27      "This function adds parentheses to the original callback for
28 GROB.  The dimensions of the stencil is not affected.
29 "
30      
31      (let* ((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))
35
36             ; remember old size
37             (subject-dim-x (ly:stencil-extent subject 0))
38             (subject-dim-y (ly:stencil-extent subject 1)))
39
40         ; add parens
41         (set! subject
42              (ly:stencil-combine-at-edge 
43               (ly:stencil-combine-at-edge subject 0 1 pclose 0.2)
44               0 -1 popen  0.2))
45
46         ; revert old size.
47        (ly:stencil-set-extent! subject 0 subject-dim-x)
48        (ly:stencil-set-extent! subject 1 subject-dim-y)
49        subject))
50    parenthesize-stencil)
51     
52
53 \paper { raggedright = ##t }
54 \relative c' {
55     c4 e
56
57     \override NoteHead  #'print-function
58     =
59     #(parenthesize-callback Note_head::print)
60     g bes
61     \revert NoteHead #'print-function
62     \override Beam  #'print-function
63     =
64     #(parenthesize-callback Beam::print)
65
66     a8 gis8 a2.
67     
68 }
69
70
71