lilypond-1.3.28
[lilypond.git] / lily / note-head.cc
blobd7da247660a90f0b37a419021e636ae9bbe7b97f
1 /*
2 notehead.cc -- implement Note_head
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 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 build a ledger line for small pieces.
24 Molecule
25 Note_head::ledger_line (Interval xwid) const
27 Drul_array<Molecule> endings;
28 endings[LEFT] = lookup_l()->afm_find ("noteheads-ledgerending");
29 Molecule * e = &endings[LEFT];
30 endings[RIGHT] = *e;
32 Real thick = e->dim_[Y_AXIS].length();
33 Real len = e->dim_[X_AXIS].length () - thick;
35 Molecule total;
36 Direction d = LEFT;
37 do {
38 endings[d].translate_axis (xwid[d] - endings[d].dim_[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);
48 xpos += len;
51 return total;
55 void
56 Note_head::do_pre_processing ()
58 // 8 ball looks the same as 4 ball:
59 String type;
60 SCM style = get_elt_property ("style");
61 if (gh_string_p (style))
63 type = ly_scm2string (style);
67 if (balltype_i () > 2 || type == "harmonic" || type == "cross")
68 set_elt_property ("duration-log", gh_int2scm (2));
70 if (Dots *d = dots_l ())
71 { // move into Rhythmic_head?
72 Staff_symbol_referencer_interface si (d);
73 Staff_symbol_referencer_interface me (this);
75 si.set_position(int (me.position_f ()));
82 Molecule*
83 Note_head::do_brew_molecule_p() const
85 Staff_symbol_referencer_interface si (this);
87 Real inter_f = si.staff_space ()/2;
88 int sz = si.line_count ()-1;
89 Real p = si.position_f ();
90 int streepjes_i = abs (p) < sz
91 ? 0
92 : (abs((int)p) - sz) /2;
94 String type;
95 SCM style = get_elt_property ("style");
96 if (gh_string_p (style))
98 type = ly_scm2string (style);
101 Molecule* out =
102 new Molecule (lookup_l()->afm_find (String ("noteheads-") + to_str (balltype_i ()) + type));
104 Box ledgerless = out->dim_;
106 if (streepjes_i)
108 Direction dir = (Direction)sign (p);
109 Interval hd = out->dim_[X_AXIS];
110 Real hw = hd.length ()/4;
112 Molecule ledger (ledger_line (Interval (hd[LEFT] - hw,
113 hd[RIGHT] + hw)));
115 int parity = abs(int (p)) % 2;
117 for (int i=0; i < streepjes_i; i++)
119 Molecule s (ledger);
120 s.translate_axis (-dir * inter_f * (i*2 + parity),
121 Y_AXIS);
122 out->add_molecule (s);
126 out->dim_ = ledgerless;
127 return out;