2 notehead.cc -- implement Note_head
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 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"
20 Note_head contains the code for printing note heads and the ledger lines.
22 TODO: maybe it's worthwhile to split away the Ledger lines into a
25 #include "staff-symbol-referencer.hh"
28 build a ledger line for small pieces.
31 Note_head::ledger_line (Interval xwid, Grob *me)
33 Drul_array<Molecule> endings;
34 endings[LEFT] = Font_interface::get_default_font (me)->find_by_name ("noteheads-ledgerending");
35 Molecule *e = &endings[LEFT];
38 Real thick = e->extent (Y_AXIS).length ();
39 Real len = e->extent (X_AXIS).length () - thick;
44 endings[d].translate_axis (xwid[d] - endings[d].extent (X_AXIS)[d], X_AXIS);
45 total.add_molecule (endings[d]);
46 } while ((flip (&d)) != LEFT);
48 Real xpos = xwid [LEFT] + len;
50 while (xpos + len + thick /2 <= xwid[RIGHT])
52 e->translate_axis (len, X_AXIS);
53 total.add_molecule (*e);
62 Note_head::ledger_lines (Grob*me,
64 int count, Direction dir, Interval idw)
66 Real inter_f = Staff_symbol_referencer::staff_space (me)/2;
76 Molecule ledger (ledger_line (idw, me));
79 ledger.set_empty (true);
81 Real offs = (Staff_symbol_referencer::on_staffline (me))
86 for (int i=0; i < count; i++)
89 s.translate_axis (-dir * inter_f * i*2 + offs,
91 legs.add_molecule (s);
98 internal_brew_molecule (Grob *me, bool ledger_take_space)
100 int sz = Staff_symbol_referencer::line_count (me)-1;
101 int p = (int) rint (Staff_symbol_referencer::position_f (me));
102 int streepjes_i = abs (p) < sz
106 SCM style = me->get_grob_property ("style");
107 if (!gh_symbol_p (style))
113 ugh: use gh_call () / scm_apply ().
115 UGH: use grob-property.
117 SCM log = gh_int2scm (Rhythmic_head::balltype_i (me));
118 SCM exp = scm_list_n (ly_symbol2scm ("find-notehead-symbol"), log,
119 ly_quote_scm (style),
121 String name = "noteheads-" + ly_scm2string (scm_primitive_eval (exp));
122 Molecule out = Font_interface::get_default_font (me)->find_by_name (name);
126 Direction dir = (Direction)sign (p);
127 Interval hd = out.extent (X_AXIS);
128 Real hw = hd.length ()/4;
129 out.add_molecule (Note_head::ledger_lines (me, ledger_take_space, streepjes_i, dir,
130 Interval (hd[LEFT] - hw,
136 MAKE_SCHEME_CALLBACK (Note_head,brew_molecule,1);
139 Note_head::brew_molecule (SCM smob)
141 Grob *me = unsmob_grob (smob);
142 return internal_brew_molecule (me, true).smobbed_copy ();
146 Compute the width the head without ledgers.
149 Note_head::head_extent (Grob *me, Axis a)
151 return internal_brew_molecule (me, false).extent (a);
155 Note_head::has_interface (Grob*m)
157 return m&& m->has_interface (ly_symbol2scm ("note-head-interface"));
161 MAKE_SCHEME_CALLBACK (Note_head,brew_ez_molecule,1);
164 TODO: ledger lines are causing a mess again, now with accidentals and
168 Note_head::brew_ez_molecule (SCM smob)
170 Grob *me = unsmob_grob (smob);
171 int l = Rhythmic_head::balltype_i (me);
174 SCM at = scm_list_n (ly_symbol2scm ("ez-ball"),
175 me->get_grob_property ("note-character"),
179 Box bx (Interval (0, 1.0), Interval (-0.5, 0.5));
181 int p = (int) rint (Staff_symbol_referencer::position_f (me));
183 int sz = Staff_symbol_referencer::line_count (me)-1;
184 int streepjes_i = abs (p) < sz
190 Direction dir = (Direction)sign (p);
191 Interval hd = m.extent (X_AXIS);
192 Real hw = hd.length ()/4;
193 m.add_molecule (ledger_lines (me, false, streepjes_i, dir,
194 Interval (hd[LEFT] - hw,
198 return m.smobbed_copy ();
203 Note_head::stem_attachment_coordinate (Grob *me, Axis a)
205 SCM v = me->get_grob_property ("stem-attachment-function");
207 if (!gh_procedure_p (v))
210 SCM st = me->get_grob_property ("style");
211 SCM result = gh_apply (v, scm_list_n (st, SCM_UNDEFINED));
213 if (!gh_pair_p (result))
216 result = (a == X_AXIS) ? ly_car (result) : ly_cdr (result);
218 return gh_number_p (result) ? gh_scm2double (result) : 0.0;