]> git.donarmstrong.com Git - lilypond.git/blob - lily/easy-notation.cc
bd24ffbab2f699a4646bc8c04b7776f1100ca881
[lilypond.git] / lily / easy-notation.cc
1 /*
2   easy-notation.cc --  implement easy notation heads
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "note-head.hh"
10
11 #include "text-interface.hh"
12 #include "grob.hh"
13 #include "output-def.hh"
14 #include "music.hh"
15 #include "pitch.hh"
16 #include "font-interface.hh"
17 #include "staff-symbol-referencer.hh"
18 #include "stem.hh"
19 #include <cctype>
20
21 MAKE_SCHEME_CALLBACK (Note_head, brew_ez_stencil, 1);
22 SCM
23 Note_head::brew_ez_stencil (SCM smob)
24 {
25   Grob *me = unsmob_grob (smob);
26   int log = Note_head::get_balltype (me);
27
28   SCM cause = me->get_property ("cause");
29   SCM spitch = unsmob_music (cause)->get_property ("pitch");
30   Pitch *pit = unsmob_pitch (spitch);
31
32   SCM idx = scm_from_int (pit->get_notename ());
33   SCM names = me->get_property ("note-names");
34   SCM charstr = SCM_EOL;
35   if (scm_is_vector (names))
36     charstr = scm_vector_ref (names, idx);
37   else
38     {
39       char s[2] = "a";
40       s[0] = (pit->get_notename () + 2) % 7 + 'a';
41       s[0] = toupper (s[0]);
42       charstr = scm_makfrom0str (s);
43     }
44
45   SCM letter
46     = Text_interface::interpret_string (me->get_layout ()->self_scm (),
47                                         Font_interface::text_font_alist_chain (me),
48                                         charstr);
49
50   Stencil l (*unsmob_stencil (letter));
51   l.align_to (X_AXIS, CENTER);
52   l.align_to (Y_AXIS, CENTER);
53
54   l = Stencil (Box (), l.expr ());
55   Real ss = Staff_symbol_referencer::staff_space (me);
56   Real lt = Staff_symbol_referencer::line_thickness (me);
57
58   Real radius = (ss + lt) / 2.0;
59   Real stem_thick = 1.3 * lt;
60   if (Grob *stem = unsmob_grob (me->get_object ("stem")))
61     stem_thick = Stem::thickness (stem);
62
63   int black = (log >= 2);
64
65   Stencil head;
66   Box extent (Interval (-radius, radius),
67               Interval (-radius, radius));
68
69   Stencil black_head (extent,
70                       scm_list_4 (ly_symbol2scm ("circle"),
71                                   scm_from_double (radius),
72                                   scm_from_double (0.0),
73                                   SCM_BOOL_T));
74   Stencil white_head;
75   if (black)
76     l = l.in_color (1, 1, 1);
77   else
78     {
79       white_head = Stencil (extent,
80                             scm_list_4 (ly_symbol2scm ("circle"),
81                                         scm_from_double (radius - stem_thick),
82                                         scm_from_double (0.0),
83                                         SCM_BOOL_T));
84
85       white_head = white_head.in_color (1, 1, 1);
86     }
87
88   Stencil total;
89   total.add_stencil (l);
90   total.add_stencil (white_head);
91   total.add_stencil (black_head);
92   total.translate_axis (radius, X_AXIS);
93
94   return total.smobbed_copy ();
95 }
96