2 notehead.cc -- implement Note_head
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "note-head.hh"
13 #include <algorithm> // min, max
16 #include "directional-element-interface.hh"
18 #include "font-interface.hh"
19 #include "international.hh"
23 #include "output-def.hh"
24 #include "rhythmic-head.hh"
25 #include "staff-symbol-referencer.hh"
26 #include "staff-symbol.hh"
30 internal_print (Grob *me, string *font_char)
32 SCM style = me->get_property ("style");
33 if (!scm_is_symbol (style))
34 style = ly_symbol2scm ("default");
36 string suffix = to_string (min (robust_scm2int (me->get_property ("duration-log"), 2), 2));
37 if (style != ly_symbol2scm ("default"))
39 SCM gn = me->get_property ("glyph-name");
40 if (scm_is_string (gn))
41 suffix = ly_scm2string (gn);
44 Font_metric *fm = Font_interface::get_default_font (me);
46 string idx = "noteheads.s" + suffix;
47 Stencil out = fm->find_by_name (idx);
50 string prefix = "noteheads.";
52 Grob *stem = unsmob_grob (me->get_object ("stem"));
53 Direction stem_dir = stem ? get_grob_direction (stem) : CENTER;
55 if (stem_dir == CENTER)
56 programming_error ("must have stem dir for note head");
58 idx = prefix + ((stem_dir == UP) ? "u" : "d") + suffix;
59 out = fm->find_by_name (idx);
65 me->warning (_f ("note head `%s' not found", idx.c_str ()));
66 out = Stencil (Box (Interval (0, 0), Interval (0, 0)), SCM_EOL);
75 TODO: make stem X-parent of notehead.
77 MAKE_SCHEME_CALLBACK (Note_head, stem_x_shift, 1);
79 Note_head::stem_x_shift (SCM smob)
81 Grob *me = unsmob_grob (smob);
82 Grob *stem = unsmob_grob (me->get_object ("stem"));
84 (void) stem->get_property ("positioning-done");
86 return scm_from_int (0);
89 MAKE_SCHEME_CALLBACK (Note_head, print, 1);
91 Note_head::print (SCM smob)
93 Grob *me = unsmob_grob (smob);
96 return internal_print (me, &idx).smobbed_copy ();
100 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
102 Offset off = robust_scm2offset (me->get_property ("stem-attachment"),
109 Note_head::get_stem_attachment (Font_metric *fm, string key)
113 int k = fm->name_to_index (key);
116 Box b = fm->get_indexed_char (k);
117 Offset wxwy = fm->attachment_point (key);
118 for (int i = X_AXIS ; i < NO_AXES; i++)
125 att[a] = (2 * (wxwy[a] - v.center ()) / v.length ());
133 MAKE_SCHEME_CALLBACK(Note_head, calc_stem_attachment, 1);
135 Note_head::calc_stem_attachment (SCM smob)
137 Grob *me = unsmob_grob (smob);
138 Font_metric *fm = Font_interface::get_default_font (me);
140 internal_print (me, &key);
142 return ly_offset2scm (get_stem_attachment (fm, key));
146 Note_head::get_balltype (Grob *me)
148 SCM s = me->get_property ("duration-log");
149 return scm_is_number (s) ? min (int (scm_to_int (s)), 2) : 0;
152 ADD_INTERFACE (Note_head, "note-head-interface",