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 "staff-symbol.hh"
18 #include "font-interface.hh"
20 #include "rhythmic-head.hh"
21 #include "staff-symbol-referencer.hh"
23 #include "output-def.hh"
26 clean up the mess left by ledger line handling.
29 internal_print (Grob *me)
31 SCM style = me->get_property ("style");
32 if (!scm_is_symbol (style))
37 SCM log = scm_int2num (Note_head::get_balltype (me));
38 SCM proc = me->get_property ("glyph-name-procedure");
39 SCM scm_font_char = scm_call_2 (proc, log, style);
40 String font_char = "noteheads-" + ly_scm2string (scm_font_char);
42 Font_metric * fm = Font_interface::get_default_font (me);
43 Stencil out = fm->find_by_name (font_char);
46 me->warning (_f ("note head `%s' not found", font_char.to_str0 ()));
53 MAKE_SCHEME_CALLBACK (Note_head,print,1);
55 Note_head::print (SCM smob)
57 Grob *me = unsmob_grob (smob);
59 return internal_print (me).smobbed_copy ();
63 MAKE_SCHEME_CALLBACK (Note_head,brew_ez_stencil,1);
65 Note_head::brew_ez_stencil (SCM smob)
67 Grob *me = unsmob_grob (smob);
68 int l = Note_head::get_balltype (me);
72 SCM cause = me->get_property ("cause");
73 SCM spitch = unsmob_music (cause)->get_property ("pitch");
74 Pitch* pit = unsmob_pitch (spitch);
76 SCM idx = scm_int2num (pit->get_notename ());
77 SCM names = me->get_property ("note-names");
78 SCM charstr = SCM_EOL;
79 if (ly_c_vector_p (names))
80 charstr = scm_vector_ref (names, idx);
84 s[0] = (pit->get_notename () + 2)%7 + 'a';
85 s[0] = toupper (s[0]);
86 charstr = scm_makfrom0str (s);
89 SCM at = scm_list_n (ly_symbol2scm ("ez-ball"),
94 Box bx (Interval (0, 1.0), Interval (-0.5, 0.5));
97 return m.smobbed_copy ();
102 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
104 SCM brewer = me->get_property ("print-function");
105 Font_metric * fm = Font_interface::get_default_font (me);
107 if (brewer == Note_head::print_proc)
109 SCM style = me->get_property ("style");
110 if (!scm_is_symbol (style))
115 SCM log = scm_int2num (Note_head::get_balltype (me));
116 SCM proc = me->get_property ("glyph-name-procedure");
117 SCM scm_font_char = scm_call_2 (proc, log, style);
118 String font_char = "noteheads-" + ly_scm2string (scm_font_char);
120 int k = fm->name_to_index (font_char) ;
124 Box b = fm->get_indexed_char (k);
125 Offset wxwy = fm->get_indexed_wxwy (k);
128 return 2 * (wxwy[a] - v.center ()) / v.length ();
135 SCM v = me->get_property ("stem-attachment-function");
136 if (!ly_c_procedure_p (v))
139 SCM result = scm_call_2 (v, me->self_scm (), scm_int2num (a));
140 if (!scm_is_pair (result))
143 result = (a == X_AXIS) ? scm_car (result) : scm_cdr (result);
145 return robust_scm2double (result,0);
149 Note_head::get_balltype (Grob*me)
151 SCM s = me->get_property ("duration-log");
152 return scm_is_number (s) ? scm_to_int (s) <? 2 : 0;
155 ADD_INTERFACE (Note_head,"note-head-interface",
157 "note-names glyph-name-procedure accidental-grob style stem-attachment-function");