lilypond-1.3.19
[lilypond.git] / lily / note-head.cc
blobfa911e7ca4b19cea11dc752cdf16ad240ad28cde
1 /*
2 notehead.cc -- implement Note_head
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "misc.hh"
10 #include "dots.hh"
11 #include "note-head.hh"
12 #include "debug.hh"
13 #include "lookup.hh"
14 #include "molecule.hh"
15 #include "musical-request.hh"
16 #include "dimension-cache.hh"
17 #include "staff-symbol-referencer.hh"
22 void
23 Note_head::do_pre_processing ()
25 // 8 ball looks the same as 4 ball:
26 String type;
27 SCM style = get_elt_property ("style");
28 if (gh_string_p (style))
30 type = ly_scm2string (style);
34 if (balltype_i () > 2 || type == "harmonic" || type == "cross")
35 set_elt_property ("duration-log", gh_int2scm (2));
37 if (Dots *d = dots_l ())
38 { // move into Rhythmic_head?
39 Staff_symbol_referencer_interface si (d);
40 Staff_symbol_referencer_interface me (this);
42 si.set_position(int (me.position_f ()));
49 Molecule*
50 Note_head::do_brew_molecule_p() const
52 Staff_symbol_referencer_interface si (this);
54 Real inter_f = si.staff_space ()/2;
55 int sz = si.line_count ()-1;
56 Real p = si.position_f ();
57 int streepjes_i = abs (p) < sz
58 ? 0
59 : (abs((int)p) - sz) /2;
61 String type;
62 SCM style = get_elt_property ("style");
63 if (gh_string_p (style))
65 type = ly_scm2string (style);
68 Molecule* out =
69 new Molecule (lookup_l()->afm_find (String ("noteheads-") + to_str (balltype_i ()) + type));
71 Box ledgerless = out->dim_;
73 if (streepjes_i)
75 Direction dir = (Direction)sign (p);
76 Interval hd = out->dim_[X_AXIS];
77 Real hw = hd.length ()/4;
79 Molecule ledger
80 = lookup_l ()->ledger_line (Interval (hd[LEFT] - hw,
81 hd[RIGHT] + hw));
83 int parity = abs(int (p)) % 2;
85 for (int i=0; i < streepjes_i; i++)
87 Molecule s (ledger);
88 s.translate_axis (-dir * inter_f * (i*2 + parity),
89 Y_AXIS);
90 out->add_molecule (s);
94 out->dim_ = ledgerless;
95 return out;