]> git.donarmstrong.com Git - lilypond.git/blob - input/regression/molecule-hacking.ly
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[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-dim-x (ly-get-molecule-extent subject 0))
38             (subject-dim-y (ly-get-molecule-extent subject 1))
39         )
40
41         ; add parens
42         (set! subject
43              (ly-combine-molecule-at-edge 
44               (ly-combine-molecule-at-edge subject 0 1 pclose 0.2)
45               0 -1 popen  0.2))
46
47         ; revert old size.
48        (ly-set-molecule-extent! subject 0 subject-dim-x)
49        (ly-set-molecule-extent! subject 1 subject-dim-y)
50        subject
51     )
52      )
53    parenthesize-molecule
54    )
55     
56
57
58 \score {
59         \notes \relative c' { c4 e
60
61                     \property Voice.NoteHead \override #'molecule-callback
62                       =
63                       #(parenthesize-callback Note_head::brew_molecule)
64                     g bes
65                     \property Voice.NoteHead \revert #'molecule-callback
66                     \property Voice.Beam \override #'molecule-callback
67                       =
68                       #(parenthesize-callback Beam::brew_molecule)
69
70                     a8 gis8 a2.
71                     
72                     }
73
74         \paper { linewidth = -1. }
75         }
76