]> git.donarmstrong.com Git - lilypond.git/blob - lily/easy-notation.cc
* flower/include/axis.hh: rename from axes.hh
[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-interface.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 #include <cctype>
21
22 MAKE_SCHEME_CALLBACK (Note_head, brew_ez_stencil, 1);
23 SCM
24 Note_head::brew_ez_stencil (SCM smob)
25 {
26   Grob *me = unsmob_grob (smob);
27   int log = Note_head::get_balltype (me);
28
29   SCM cause = me->get_property ("cause");
30   SCM spitch = unsmob_music (cause)->get_property ("pitch");
31   Pitch *pit = unsmob_pitch (spitch);
32
33   SCM idx = scm_int2num (pit->get_notename ());
34   SCM names = me->get_property ("note-names");
35   SCM charstr = SCM_EOL;
36   if (scm_is_vector (names))
37     charstr = scm_vector_ref (names, idx);
38   else
39     {
40       char s[2] = "a";
41       s[0] = (pit->get_notename () + 2) % 7 + 'a';
42       s[0] = toupper (s[0]);
43       charstr = scm_makfrom0str (s);
44     }
45
46   
47   SCM letter
48     = Text_interface::interpret_string (me->get_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   
57   l = Stencil (Box (), l.expr ()); 
58   Real ss = Staff_symbol_referencer::staff_space (me);
59   Real lt = Staff_symbol_referencer::line_thickness (me);
60
61   Real radius = (ss + lt) / 2.0;
62   Real stem_thick = 1.3 * lt; 
63   if (Grob *stem = unsmob_grob (me->get_property ("stem")))
64     {
65       stem_thick = Stem::thickness (stem);
66     }
67
68   int black = (log >= 2);
69
70   Stencil head;
71   Box extent (Interval (-radius, radius),
72               Interval (-radius, radius));
73               
74   Stencil black_head (extent,
75                       scm_list_4 (ly_symbol2scm ("circle"),
76                                   scm_from_double (radius),
77                                   scm_from_double (0.0),
78                                   SCM_BOOL_T));
79   Stencil white_head;
80   if (black)
81     {
82       l = l.in_color (1, 1, 1); 
83     }
84   else
85     {
86       white_head = Stencil (extent,
87                             scm_list_4 (ly_symbol2scm ("circle"),
88                                scm_from_double (radius - stem_thick),
89                                scm_from_double (0.0),
90                                SCM_BOOL_T));
91
92       white_head = white_head.in_color (1, 1, 1);
93     }
94     
95
96   Stencil total;
97   total.add_stencil (l);
98   total.add_stencil (white_head);
99   total.add_stencil (black_head);
100   total.translate_axis (radius, X_AXIS);
101
102   return total.smobbed_copy ();
103 }
104