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