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
17 #include "directional-element-interface.hh"
18 #include "font-interface.hh"
19 #include "international.hh"
23 internal_print (Grob *me, string *font_char)
25 SCM style = me->get_property ("style");
26 if (!scm_is_symbol (style))
27 style = ly_symbol2scm ("default");
29 string suffix = to_string (min (robust_scm2int (me->get_property ("duration-log"), 2), 2));
30 if (style != ly_symbol2scm ("default"))
32 SCM gn = me->get_property ("glyph-name");
33 if (scm_is_string (gn))
34 suffix = ly_scm2string (gn);
37 Font_metric *fm = Font_interface::get_default_font (me);
42 idx_symmetric = idx_either = "noteheads.s" + suffix;
43 Stencil out = fm->find_by_name (idx_symmetric);
46 string prefix = "noteheads.";
48 Grob *stem = unsmob_grob (me->get_object ("stem"));
49 Direction stem_dir = stem ? get_grob_direction (stem) : CENTER;
51 if (stem_dir == CENTER)
52 programming_error ("must have stem dir for note head");
54 idx_directed = idx_either =
55 prefix + ((stem_dir == UP) ? "u" : "d") + suffix;
56 out = fm->find_by_name (idx_directed);
62 me->warning (_f ("none of note heads `%s' or `%s' found",
63 idx_symmetric.c_str (), idx_directed.c_str ()));
64 out = Stencil (Box (Interval (0, 0), Interval (0, 0)), SCM_EOL);
67 *font_char = idx_either;
73 TODO: make stem X-parent of notehead.
75 MAKE_SCHEME_CALLBACK (Note_head, stem_x_shift, 1);
77 Note_head::stem_x_shift (SCM smob)
79 Grob *me = unsmob_grob (smob);
80 Grob *stem = unsmob_grob (me->get_object ("stem"));
82 (void) stem->get_property ("positioning-done");
84 return scm_from_int (0);
87 MAKE_SCHEME_CALLBACK (Note_head, print, 1);
89 Note_head::print (SCM smob)
91 Grob *me = unsmob_grob (smob);
94 return internal_print (me, &idx).smobbed_copy ();
98 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
100 Offset off = robust_scm2offset (me->get_property ("stem-attachment"),
107 Note_head::get_stem_attachment (Font_metric *fm, string key)
111 int k = fm->name_to_index (key);
114 Box b = fm->get_indexed_char (k);
115 Offset wxwy = fm->attachment_point (key);
116 for (int i = X_AXIS ; i < NO_AXES; i++)
123 att[a] = (2 * (wxwy[a] - v.center ()) / v.length ());
131 MAKE_SCHEME_CALLBACK(Note_head, calc_stem_attachment, 1);
133 Note_head::calc_stem_attachment (SCM smob)
135 Grob *me = unsmob_grob (smob);
136 Font_metric *fm = Font_interface::get_default_font (me);
138 internal_print (me, &key);
140 return ly_offset2scm (get_stem_attachment (fm, key));
144 ADD_INTERFACE (Note_head, "note-head-interface",