2 notehead.cc -- implement Note_head
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "note-head.hh"
14 #include "font-interface.hh"
15 #include "molecule.hh"
16 #include "musical-request.hh"
17 #include "rhythmic-head.hh"
19 #include "staff-symbol-referencer.hh"
22 build a ledger line for small pieces.
25 Note_head::ledger_line (Interval xwid, Grob *me)
27 Drul_array<Molecule> endings;
28 endings[LEFT] = Font_interface::get_default_font (me)->find_by_name ("noteheads-ledgerending");
29 Molecule *e = &endings[LEFT];
32 Real thick = e->extent (Y_AXIS).length ();
33 Real len = e->extent (X_AXIS).length () - thick;
38 endings[d].translate_axis (xwid[d] - endings[d].extent (X_AXIS)[d], X_AXIS);
39 total.add_molecule (endings[d]);
40 } while ((flip (&d)) != LEFT);
42 Real xpos = xwid [LEFT] + len;
44 while (xpos + len + thick /2 <= xwid[RIGHT])
46 e->translate_axis (len, X_AXIS);
47 total.add_molecule (*e);
56 Note_head::ledger_lines (Grob*me, int count, Direction dir, Interval idw)
58 Real inter_f = Staff_symbol_referencer::staff_space (me)/2;
59 Molecule ledger (ledger_line (idw, me));
61 ledger.set_empty (true);
62 Real offs = (Staff_symbol_referencer::on_staffline (me))
67 for (int i=0; i < count; i++)
70 s.translate_axis (-dir * inter_f * i*2 + offs,
72 legs.add_molecule (s);
78 MAKE_SCHEME_CALLBACK (Note_head,brew_molecule,1);
81 Note_head::brew_molecule (SCM smob)
83 Grob *me = unsmob_grob (smob);
85 int sz = Staff_symbol_referencer::line_count (me)-1;
86 int p = (int) rint (Staff_symbol_referencer::position_f (me));
87 int streepjes_i = abs (p) < sz
91 SCM style = me->get_grob_property ("style");
92 if (!gh_symbol_p (style))
98 ugh: use gh_call () / scm_apply ().
100 UGH: use grob-property.
102 SCM log = gh_int2scm (Rhythmic_head::balltype_i (me));
103 SCM exp = scm_list_n (ly_symbol2scm ("find-notehead-symbol"), log,
104 ly_quote_scm (style),
106 String name = "noteheads-" + ly_scm2string (scm_primitive_eval (exp));
107 Molecule out = Font_interface::get_default_font (me)->find_by_name (name);
112 Direction dir = (Direction)sign (p);
113 Interval hd = out.extent (X_AXIS);
114 Real hw = hd.length ()/4;
115 out.add_molecule (ledger_lines (me, streepjes_i, dir,
116 Interval (hd[LEFT] - hw,
120 return out.smobbed_copy ();
124 Note_head::has_interface (Grob*m)
126 return m&& m->has_interface (ly_symbol2scm ("note-head-interface"));
130 MAKE_SCHEME_CALLBACK (Note_head,brew_ez_molecule,1);
133 Note_head::brew_ez_molecule (SCM smob)
135 Grob *me = unsmob_grob (smob);
136 int l = Rhythmic_head::balltype_i (me);
139 SCM at = scm_list_n (ly_symbol2scm ("ez-ball"),
140 me->get_grob_property ("note-character"),
144 Box bx (Interval (0, 1.0), Interval (-0.5, 0.5));
146 int p = (int) rint (Staff_symbol_referencer::position_f (me));
148 int sz = Staff_symbol_referencer::line_count (me)-1;
149 int streepjes_i = abs (p) < sz
155 Direction dir = (Direction)sign (p);
156 Interval hd = m.extent (X_AXIS);
157 Real hw = hd.length ()/4;
158 m.add_molecule (ledger_lines (me, streepjes_i, dir,
159 Interval (hd[LEFT] - hw,
163 return m.smobbed_copy ();
168 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
170 SCM v = me->get_grob_property ("stem-attachment-function");
172 if (!gh_procedure_p (v))
175 SCM st = me->get_grob_property ("style");
176 SCM result = gh_apply (v, scm_list_n (st, SCM_UNDEFINED));
178 if (!gh_pair_p (result))
181 result = (a == X_AXIS) ? ly_car (result) : ly_cdr (result);
183 return gh_number_p (result) ? gh_scm2double (result) : 0.0;