2 notehead.cc -- implement Note_head
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "note-head.hh"
13 #include <algorithm> // min, max
16 #include "directional-element-interface.hh"
17 #include "staff-symbol.hh"
21 #include "font-interface.hh"
23 #include "rhythmic-head.hh"
24 #include "staff-symbol-referencer.hh"
26 #include "output-def.hh"
29 clean up the mess left by ledger line handling.
32 internal_print (Grob *me, String *font_char)
34 SCM style = me->get_property ("style");
35 if (!scm_is_symbol (style))
36 style = ly_symbol2scm ("default");
38 SCM log = scm_from_int (Note_head::get_balltype (me));
39 String suffix = to_string (min (robust_scm2int (me->get_property ("duration-log"), 2), 2));
40 if (style != ly_symbol2scm ("default"))
42 SCM proc = me->get_property ("glyph-name-procedure");
43 if (ly_is_procedure (proc))
44 suffix = ly_scm2string (scm_call_2 (proc, log, style));
46 Font_metric *fm = Font_interface::get_default_font (me);
48 String idx = "noteheads.s" + suffix;
50 Stencil out = fm->find_by_name (idx);
53 String prefix = "noteheads.";
54 Grob *stem = unsmob_grob (me->get_object ("stem"));
55 Direction stem_dir = stem ? get_grob_direction (stem) : CENTER;
57 if (stem_dir == CENTER)
58 programming_error ("must have stem dir for note head");
60 idx = prefix + ((stem_dir == UP) ? "u" : "d") + suffix;
61 out = fm->find_by_name (idx);
66 me->warning (_f ("note head `%s' not found", idx.to_str0 ()));
67 out = Stencil (Box (Interval (0, 0), Interval (0, 0)), SCM_EOL);
76 TODO: make stem X-parent of notehead.
78 MAKE_SCHEME_CALLBACK (Note_head, stem_x_shift, 2);
80 Note_head::stem_x_shift (SCM smob, SCM axis)
84 Grob *me = unsmob_grob (smob);
85 Grob *stem = unsmob_grob (me->get_object ("stem"));
87 (void) stem->get_property ("positioning-done");
89 return scm_from_int (0);
92 MAKE_SCHEME_CALLBACK (Note_head, print, 1);
94 Note_head::print (SCM smob)
96 Grob *me = unsmob_grob (smob);
99 return internal_print (me, &idx).smobbed_copy ();
103 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
105 SCM brewer = me->get_property ("print-function");
106 Font_metric *fm = Font_interface::get_default_font (me);
108 if (brewer == Note_head::print_proc)
111 internal_print (me, &key);
113 int k = fm->name_to_index (key);
116 Box b = fm->get_indexed_char (k);
117 Offset wxwy = fm->attachment_point (key);
120 return 2 * (wxwy[a] - v.center ()) / v.length ();
127 SCM v = me->get_property ("stem-attachment-function");
128 if (!ly_is_procedure (v))
131 SCM result = scm_call_2 (v, me->self_scm (), scm_from_int (a));
132 if (!scm_is_pair (result))
135 result = (a == X_AXIS) ? scm_car (result) : scm_cdr (result);
137 return robust_scm2double (result, 0);
141 Note_head::get_balltype (Grob *me)
143 SCM s = me->get_property ("duration-log");
144 return scm_is_number (s) ? min (scm_to_int (s), 2) : 0;
147 ADD_INTERFACE (Note_head, "note-head-interface",
152 "glyph-name-procedure "
155 "stem-attachment-function");