2 notehead.cc -- implement Note_head
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 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 ()));
79 MAKE_SCHEME_CALLBACK (Note_head,print,1);
81 Note_head::print (SCM smob)
83 Grob *me = unsmob_grob (smob);
86 return internal_print (me, &idx).smobbed_copy ();
90 MAKE_SCHEME_CALLBACK (Note_head,brew_ez_stencil,1);
92 Note_head::brew_ez_stencil (SCM smob)
94 Grob *me = unsmob_grob (smob);
95 int l = Note_head::get_balltype (me);
99 SCM cause = me->get_property ("cause");
100 SCM spitch = unsmob_music (cause)->get_property ("pitch");
101 Pitch* pit = unsmob_pitch (spitch);
103 SCM idx = scm_int2num (pit->get_notename ());
104 SCM names = me->get_property ("note-names");
105 SCM charstr = SCM_EOL;
106 if (ly_c_vector_p (names))
107 charstr = scm_vector_ref (names, idx);
111 s[0] = (pit->get_notename () + 2)%7 + 'a';
112 s[0] = toupper (s[0]);
113 charstr = scm_makfrom0str (s);
116 SCM at = scm_list_n (ly_symbol2scm ("ez-ball"),
121 Box bx (Interval (0, 1.0), Interval (-0.5, 0.5));
124 return m.smobbed_copy ();
129 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
131 SCM brewer = me->get_property ("print-function");
132 Font_metric * fm = Font_interface::get_default_font (me);
134 if (brewer == Note_head::print_proc)
137 internal_print (me, &key);
139 int k = fm->name_to_index (key) ;
142 Box b = fm->get_indexed_char (k);
143 Offset wxwy = fm->attachment_point (key);
146 return 2 * (wxwy[a] - v.center ()) / v.length ();
153 SCM v = me->get_property ("stem-attachment-function");
154 if (!ly_c_procedure_p (v))
157 SCM result = scm_call_2 (v, me->self_scm (), scm_int2num (a));
158 if (!scm_is_pair (result))
161 result = (a == X_AXIS) ? scm_car (result) : scm_cdr (result);
163 return robust_scm2double (result,0);
167 Note_head::get_balltype (Grob*me)
169 SCM s = me->get_property ("duration-log");
170 return scm_is_number (s) ? scm_to_int (s) <? 2 : 0;
173 ADD_INTERFACE (Note_head,"note-head-interface",
175 "note-names glyph-name-procedure accidental-grob style stem-attachment-function");