]> git.donarmstrong.com Git - lilypond.git/blob - lily/easy-notation.cc
* lily/stencil-scheme.cc (LY_DEFINE): ly:stencil-in-color
[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
10 #include "note-head.hh"
11
12 #include "text-item.hh"
13 #include "grob.hh"
14 #include "output-def.hh"
15 #include "music.hh"
16 #include "pitch.hh"
17 #include "font-interface.hh"
18 #include "staff-symbol-referencer.hh"
19 #include "stem.hh"
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_int2num (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   
46   SCM letter
47     = Text_interface::interpret_string (me->get_layout()->self_scm (),
48                                         Font_interface::text_font_alist_chain (me),
49                                         charstr);
50   
51   Stencil l (*unsmob_stencil (letter));
52   l.align_to (X_AXIS, CENTER);
53   l.align_to (Y_AXIS, CENTER);
54
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_property ("stem")))
63     {
64       stem_thick = Stem::thickness (stem);
65     }
66
67   int black = (log >= 2);
68
69   Stencil head;
70   Box extent (Interval (-radius, radius),
71               Interval (-radius, radius));
72               
73   Stencil black_head (extent,
74                       scm_list_4 (ly_symbol2scm ("circle"),
75                                   scm_from_double (radius),
76                                   scm_from_double (0.0),
77                                   SCM_BOOL_T));
78   Stencil white_head;
79   if (black)
80     {
81       l = l.in_color (1, 1, 1); 
82     }
83   else
84     {
85       white_head = Stencil (extent,
86                             scm_list_4 (ly_symbol2scm ("circle"),
87                                scm_from_double (radius - stem_thick),
88                                scm_from_double (0.0),
89                                SCM_BOOL_T));
90
91       white_head = white_head.in_color (1, 1, 1);
92     }
93     
94
95   Stencil total;
96   total.add_stencil (l);
97   total.add_stencil (white_head);
98   total.add_stencil (black_head);
99   total.translate_axis (radius, X_AXIS);
100
101   return total.smobbed_copy ();
102 }
103