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>
11 #include "staff-symbol.hh"
14 #include "note-head.hh"
16 #include "font-interface.hh"
19 #include "rhythmic-head.hh"
20 #include "staff-symbol-referencer.hh"
22 #include "output-def.hh"
25 clean up the mess left by ledger line handling.
28 internal_print (Grob *me)
30 SCM style = me->get_property ("style");
31 if (!scm_is_symbol (style))
36 SCM log = scm_int2num (Note_head::get_balltype (me));
37 SCM proc = me->get_property ("glyph-name-procedure");
38 SCM scm_font_char = scm_call_2 (proc, log, style);
39 String font_char = "noteheads-" + ly_scm2string (scm_font_char);
41 Font_metric * fm = Font_interface::get_default_font (me);
42 Stencil out = fm->find_by_name (font_char);
45 me->warning (_f ("note head `%s' not found", font_char.to_str0 ()));
52 MAKE_SCHEME_CALLBACK (Note_head,print,1);
54 Note_head::print (SCM smob)
56 Grob *me = unsmob_grob (smob);
58 return internal_print (me).smobbed_copy ();
62 Compute the width the head without ledgers.
64 -- there used to be some code from the time that ledgers
65 did take space. Nowadays, we can simply take the standard extent.
68 Note_head::head_extent (Grob *me, Axis a)
70 SCM brewer = me->get_property ("print-function");
71 if (brewer == Note_head::print_proc)
73 Stencil mol = internal_print (me);
76 return mol.extent (a);
80 Stencil * mol = me->get_stencil ();
82 return mol->extent (a) ;
85 return Interval (0,0);
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 (ly_c_vector_p (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 ();
127 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
129 SCM brewer = me->get_property ("print-function");
130 Font_metric * fm = Font_interface::get_default_font (me);
132 if (brewer == Note_head::print_proc)
134 SCM style = me->get_property ("style");
135 if (!scm_is_symbol (style))
140 SCM log = scm_int2num (Note_head::get_balltype (me));
141 SCM proc = me->get_property ("glyph-name-procedure");
142 SCM scm_font_char = scm_call_2 (proc, log, style);
143 String font_char = "noteheads-" + ly_scm2string (scm_font_char);
145 int k = fm->name_to_index (font_char) ;
149 Box b = fm->get_indexed_char (k);
150 Offset wxwy = fm->get_indexed_wxwy (k);
153 return 2 * (wxwy[a] - v.center ()) / v.length ();
160 SCM v = me->get_property ("stem-attachment-function");
161 if (!ly_c_procedure_p (v))
164 SCM result = scm_call_2 (v, me->self_scm (), scm_int2num (a));
165 if (!ly_c_pair_p (result))
168 result = (a == X_AXIS) ? ly_car (result) : ly_cdr (result);
170 return robust_scm2double (result,0);
174 Note_head::get_balltype (Grob*me)
176 SCM s = me->get_property ("duration-log");
177 return scm_is_number (s) ? scm_to_int (s) <? 2 : 0;
180 ADD_INTERFACE (Note_head,"note-head-interface",
182 "note-names glyph-name-procedure accidental-grob style stem-attachment-function");