]> git.donarmstrong.com Git - lilypond.git/blob - input/regression/molecule-hacking.ly
19f94d9380cc1d616db050f4221c5b65a7386239
[lilypond.git] / input / regression / molecule-hacking.ly
1 \version "1.5.68"
2
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.
6
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.
10 "
11         
12          }
13
14 #(define (parenthesize-callback callback)
15    "Construct a function that will do CALLBACK and add parentheses.
16 Example usage:
17
18   \property Voice.NoteHead \\override #'molecule-callback
19                       =
20                       #(parenthesize-callback Note_head::brew_molecule)
21                     
22 "
23
24    
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.
28 "
29      
30      (let* (
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))
35
36             ; remember old size
37             (subject-dims (ly-get-molecule-extent subject 0))
38             )
39
40         ; add parens
41         (set! subject
42              (ly-combine-molecule-at-edge 
43               (ly-combine-molecule-at-edge subject 0 1 pclose 0.2)
44               0 -1 popen  0.2))
45
46         ; revert old size.
47        (ly-set-molecule-extent! subject 0 subject-dims)
48        subject
49     )
50      )
51    parenthesize-molecule
52    )
53     
54
55
56 \score {
57         \notes \relative c' { c4 e
58
59                     \property Voice.NoteHead \override #'molecule-callback
60                       =
61                       #(parenthesize-callback Note_head::brew_molecule)
62                     g bes
63                     \property Voice.NoteHead \revert #'molecule-callback
64                     \property Voice.Beam \override #'molecule-callback
65                       =
66                       #(parenthesize-callback Beam::brew_molecule)
67
68                     a8 gis8 a2.
69                     
70                     }
71
72         \paper { linewidth = -1. }
73         }
74