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