lilypond-1.3.65
[lilypond.git] / lily / note-head.cc
blob4452ce905a9e5fad0e42da131457154410f86bb3
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->extent (Y_AXIS).length();
33 Real len = e->extent (X_AXIS).length () - thick;
35 Molecule total;
36 Direction d = LEFT;
37 do {
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);
48 xpos += len;
51 return total;
55 GLUE_SCORE_ELEMENT(Note_head,before_line_breaking);
56 SCM
57 Note_head::member_before_line_breaking ()
59 // 8 ball looks the same as 4 ball:
61 if (balltype_i () > 2)
62 set_elt_property ("duration-log", gh_int2scm (2));
64 if (Dots *d = dots_l ())
65 { // move into Rhythmic_head?
66 Staff_symbol_referencer_interface si (d);
67 Staff_symbol_referencer_interface me (this);
69 si.set_position(int (me.position_f ()));
72 return SCM_UNDEFINED;
77 GLUE_SCORE_ELEMENT(Note_head,brew_molecule);
79 SCM
80 Note_head::member_brew_molecule () const
82 Staff_symbol_referencer_interface si (this);
84 Real inter_f = si.staff_space ()/2;
85 int sz = si.line_count ()-1;
86 Real p = si.position_f ();
87 int streepjes_i = abs (p) < sz
88 ? 0
89 : (abs((int)p) - sz) /2;
91 SCM style = get_elt_property ("style");
92 if (style == SCM_UNDEFINED)
94 style = ly_symbol2scm("default");
97 Molecule out = lookup_l()->afm_find (String ("noteheads-") +
98 ly_scm2string (scm_eval (gh_list (ly_symbol2scm("find-notehead-symbol"),
99 gh_int2scm(balltype_i ()),
100 ly_quote_scm(style),
101 SCM_UNDEFINED))));
103 if (streepjes_i)
105 Direction dir = (Direction)sign (p);
106 Interval hd = out.extent (X_AXIS);
107 Real hw = hd.length ()/4;
108 Molecule ledger (ledger_line (Interval (hd[LEFT] - hw,
109 hd[RIGHT] + hw)));
112 ledger.set_empty (true);
113 int parity = abs(int (p)) % 2;
115 for (int i=0; i < streepjes_i; i++)
117 Molecule s (ledger);
118 s.translate_axis (-dir * inter_f * (i*2 + parity),
119 Y_AXIS);
120 out.add_molecule (s);
123 return out.create_scheme();
127 Note_head::Note_head (SCM s)
128 : Rhythmic_head (s)