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
17 #include "directional-element-interface.hh"
18 #include "staff-symbol.hh"
22 #include "font-interface.hh"
24 #include "rhythmic-head.hh"
25 #include "staff-symbol-referencer.hh"
27 #include "output-def.hh"
30 clean up the mess left by ledger line handling.
33 internal_print (Grob *me, String *font_char)
35 SCM style = me->get_property ("style");
36 if (!scm_is_symbol (style))
38 style = ly_symbol2scm ("default");
41 SCM log = scm_int2num (Note_head::get_balltype (me));
42 SCM proc = me->get_property ("glyph-name-procedure");
44 String suffix = to_string (robust_scm2int (me->get_property ("duration-log"), 2));
45 if (scm_procedure_p (proc) == SCM_BOOL_T)
46 suffix = ly_scm2string (scm_call_2 (proc, log, style));
48 Font_metric *fm = Font_interface::get_default_font (me);
50 Direction stem_dir = CENTER;
51 if (Grob *stem = unsmob_grob (me->get_property ("stem")))
53 stem_dir = get_grob_direction (stem);
54 if (stem_dir == CENTER)
55 programming_error ("must have stem dir for note head");
60 String prefix = "noteheads.";
62 = prefix + ((stem_dir == UP) ? "u" : "d") + suffix;
63 out = fm->find_by_name (idx);
66 idx = prefix + "s" + suffix;
67 out = fm->find_by_name (idx);
72 me->warning (_f ("note head `%s' not found", idx.to_str0 ()));
82 MAKE_SCHEME_CALLBACK (Note_head, print, 1);
84 Note_head::print (SCM smob)
86 Grob *me = unsmob_grob (smob);
89 return internal_print (me, &idx).smobbed_copy ();
93 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
95 SCM brewer = me->get_property ("print-function");
96 Font_metric *fm = Font_interface::get_default_font (me);
98 if (brewer == Note_head::print_proc)
101 internal_print (me, &key);
103 int k = fm->name_to_index (key);
106 Box b = fm->get_indexed_char (k);
107 Offset wxwy = fm->attachment_point (key);
110 return 2 * (wxwy[a] - v.center ()) / v.length ();
117 SCM v = me->get_property ("stem-attachment-function");
118 if (!ly_c_procedure_p (v))
121 SCM result = scm_call_2 (v, me->self_scm (), scm_int2num (a));
122 if (!scm_is_pair (result))
125 result = (a == X_AXIS) ? scm_car (result) : scm_cdr (result);
127 return robust_scm2double (result, 0);
131 Note_head::get_balltype (Grob *me)
133 SCM s = me->get_property ("duration-log");
134 return scm_is_number (s) ? min (scm_to_int (s), 2) : 0;
137 ADD_INTERFACE (Note_head, "note-head-interface",
139 "note-names glyph-name-procedure accidental-grob style stem-attachment-function");