]> git.donarmstrong.com Git - lilypond.git/blob - input/regression/molecule-hacking.ly
* lily/beam-engraver.cc: move new-beam-event to beam-event
[lilypond.git] / input / regression / molecule-hacking.ly
1
2 \version "1.9.1"
3
4 \header { texidoc=" You can write molecule callbacks in Scheme, thus
5 providing custom glyphs for notation elements.  A simple example is
6 adding parentheses to existing molecule 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 Voice.NoteHead \\override #'molecule-callback
20                       =
21                       #(parenthesize-callback Note_head::brew_molecule)
22                     
23 "
24
25    
26    (define (parenthesize-molecule grob)
27      "This function adds parentheses to the original callback for
28 GROB.  The dimensions of the molecule is not affected.
29 "
30      
31      (let* (
32             (fn (ly:get-default-font grob))
33             (pclose (ly:find-glyph-by-name fn "accidentals-rightparen"))
34             (popen (ly:find-glyph-by-name fn "accidentals-leftparen"))
35             (subject (callback grob))
36
37             ; remember old size
38             (subject-dim-x (ly:molecule-get-extent subject 0))
39             (subject-dim-y (ly:molecule-get-extent subject 1))
40         )
41
42         ; add parens
43         (set! subject
44              (ly:molecule-combine-at-edge 
45               (ly:molecule-combine-at-edge subject 0 1 pclose 0.2)
46               0 -1 popen  0.2))
47
48         ; revert old size.
49        (ly:molecule-set-extent! subject 0 subject-dim-x)
50        (ly:molecule-set-extent! subject 1 subject-dim-y)
51        subject
52     )
53      )
54    parenthesize-molecule
55    )
56     
57
58
59 \score {
60         \notes \relative c' { c4 e
61
62                     \property Voice.NoteHead \override #'molecule-callback
63                       =
64                       #(parenthesize-callback Note_head::brew_molecule)
65                     g bes
66                     \property Voice.NoteHead \revert #'molecule-callback
67                     \property Voice.Beam \override #'molecule-callback
68                       =
69                       #(parenthesize-callback Beam::brew_molecule)
70
71                     a8 gis8 a2.
72                     
73                     }
74
75         \paper { raggedright = ##t}
76         }
77
78