]> git.donarmstrong.com Git - lilypond.git/blob - lily/easy-notation.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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 /*
24
25 TODO: move to scheme
26
27 */
28 MAKE_SCHEME_CALLBACK (Note_head, brew_ez_stencil, 1);
29 SCM
30 Note_head::brew_ez_stencil (SCM smob)
31 {
32   Grob *me = unsmob_grob (smob);
33   int log = Note_head::get_balltype (me);
34
35   SCM cause = me->get_property ("cause");
36   SCM spitch = unsmob_music (cause)->get_property ("pitch");
37   Pitch *pit = unsmob_pitch (spitch);
38
39   SCM idx = scm_from_int (pit->get_notename ());
40   SCM names = me->get_property ("note-names");
41   SCM charstr = SCM_EOL;
42   if (scm_is_vector (names))
43     charstr = scm_vector_ref (names, idx);
44   else
45     {
46       char s[2] = "a";
47       s[0] = (pit->get_notename () + 2) % 7 + 'a';
48       s[0] = toupper (s[0]);
49       charstr = scm_makfrom0str (s);
50     }
51
52   SCM letter
53     = Text_interface::interpret_string (me->layout ()->self_scm (),
54                                         Font_interface::text_font_alist_chain (me),
55                                         charstr);
56
57   Stencil l (*unsmob_stencil (letter));
58   l.align_to (X_AXIS, CENTER);
59   l.align_to (Y_AXIS, CENTER);
60
61   l = Stencil (Box (), l.expr ());
62   Real ss = Staff_symbol_referencer::staff_space (me);
63   Real lt = Staff_symbol_referencer::line_thickness (me);
64
65   Real radius = (ss + lt) / 2.0;
66   Real stem_thick = 1.3 * lt;
67   if (Grob *stem = unsmob_grob (me->get_object ("stem")))
68     stem_thick = Stem::thickness (stem);
69
70   int black = (log >= 2);
71
72   Stencil head;
73   Box extent (Interval (-radius, radius),
74               Interval (-radius, radius));
75
76   Stencil black_head (extent,
77                       scm_list_4 (ly_symbol2scm ("circle"),
78                                   scm_from_double (radius),
79                                   scm_from_double (0.0),
80                                   SCM_BOOL_T));
81   Stencil white_head;
82   if (black)
83     l = l.in_color (1, 1, 1);
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   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