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"
14 #include "directional-element-interface.hh"
15 #include "staff-symbol.hh"
19 #include "font-interface.hh"
21 #include "rhythmic-head.hh"
22 #include "staff-symbol-referencer.hh"
24 #include "output-def.hh"
27 clean up the mess left by ledger line handling.
30 internal_print (Grob *me, String *font_char)
32 SCM style = me->get_property ("style");
33 if (!scm_is_symbol (style))
38 SCM log = scm_int2num (Note_head::get_balltype (me));
39 SCM proc = me->get_property ("glyph-name-procedure");
40 SCM scm_font_char = scm_call_2 (proc, log, style);
42 Font_metric *fm = Font_interface::get_default_font (me);
44 Direction stem_dir = CENTER;
45 if (Grob *stem = unsmob_grob (me->get_property ("stem")))
47 stem_dir = get_grob_direction (stem);
48 if (stem_dir == CENTER)
50 programming_error ("Must have stem dir for note head");
56 String prefix = "noteheads.";
58 = prefix + ((stem_dir == UP) ? "u" : "d") + ly_scm2string (scm_font_char);
59 out = fm->find_by_name (idx);
62 idx = prefix + "s" + ly_scm2string (scm_font_char);
63 out = fm->find_by_name (idx);
68 me->warning (_f ("note head `%s' not found", idx.to_str0 ()));
78 MAKE_SCHEME_CALLBACK (Note_head, print, 1);
80 Note_head::print (SCM smob)
82 Grob *me = unsmob_grob (smob);
85 return internal_print (me, &idx).smobbed_copy ();
88 MAKE_SCHEME_CALLBACK (Note_head, brew_ez_stencil, 1);
90 Note_head::brew_ez_stencil (SCM smob)
92 Grob *me = unsmob_grob (smob);
93 int l = Note_head::get_balltype (me);
97 SCM cause = me->get_property ("cause");
98 SCM spitch = unsmob_music (cause)->get_property ("pitch");
99 Pitch *pit = unsmob_pitch (spitch);
101 SCM idx = scm_int2num (pit->get_notename ());
102 SCM names = me->get_property ("note-names");
103 SCM charstr = SCM_EOL;
104 if (scm_is_vector (names))
105 charstr = scm_vector_ref (names, idx);
109 s[0] = (pit->get_notename () + 2)%7 + 'a';
110 s[0] = toupper (s[0]);
111 charstr = scm_makfrom0str (s);
114 SCM at = scm_list_n (ly_symbol2scm ("ez-ball"),
119 Box bx (Interval (0, 1.0), Interval (-0.5, 0.5));
122 return m.smobbed_copy ();
126 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
128 SCM brewer = me->get_property ("print-function");
129 Font_metric *fm = Font_interface::get_default_font (me);
131 if (brewer == Note_head::print_proc)
134 internal_print (me, &key);
136 int k = fm->name_to_index (key);
139 Box b = fm->get_indexed_char (k);
140 Offset wxwy = fm->attachment_point (key);
143 return 2 * (wxwy[a] - v.center ()) / v.length ();
150 SCM v = me->get_property ("stem-attachment-function");
151 if (!ly_c_procedure_p (v))
154 SCM result = scm_call_2 (v, me->self_scm (), scm_int2num (a));
155 if (!scm_is_pair (result))
158 result = (a == X_AXIS) ? scm_car (result) : scm_cdr (result);
160 return robust_scm2double (result, 0);
164 Note_head::get_balltype (Grob *me)
166 SCM s = me->get_property ("duration-log");
167 return scm_is_number (s) ? scm_to_int (s) <? 2 : 0;
170 ADD_INTERFACE (Note_head, "note-head-interface",
172 "note-names glyph-name-procedure accidental-grob style stem-attachment-function");