]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head.cc
release: 1.1.67
[lilypond.git] / lily / note-head.cc
1 /*
2   notehead.cc -- implement Note_head
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
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 "stem.hh"
17
18 void
19 Note_head::flip_around_stem (Direction d)
20 {
21   translate_axis (do_width ().length () * d, X_AXIS);
22 }
23
24 Note_head::Note_head ()
25 {
26 }
27
28 void
29 Note_head::do_pre_processing ()
30 {
31   // 8 ball looks the same as 4 ball:
32   if (balltype_i_ > 2)
33     balltype_i_ = 2;
34   if (dots_l_)                  // move into Rhythmic_head?
35     dots_l_->position_i_ = position_i_;
36 }
37
38
39
40 int
41 Note_head::compare (Note_head *const  &a, Note_head * const &b)
42 {
43   return a->position_i_ - b->position_i_;
44 }
45
46 /**
47  Don't account for ledgerlines in the width.
48  */
49 Interval
50 Note_head::do_width () const
51 {
52   Molecule a =  lookup_l ()->notehead (balltype_i_, ""); // UGH
53   Interval i = a.dim_[X_AXIS];
54   return i;
55 }
56
57 Molecule*
58 Note_head::do_brew_molecule_p() const 
59 {
60   Real inter_f = staff_line_leading_f ()/2;
61   int sz = lines_i ()-1;
62
63   int streepjes_i = abs (position_i_) < sz 
64     ? 0
65     : (abs(position_i_) - sz) /2;
66
67
68   String type; 
69   SCM style  =get_elt_property (style_scm_sym);
70   if (style != SCM_BOOL_F)
71     {
72       type = ly_scm2string (SCM_CDR(style));
73     }
74   
75   Molecule*  out = new Molecule (lookup_l()->notehead (balltype_i_, type));
76
77   Box b = out->dim_;
78
79   if (streepjes_i) 
80     {
81       Direction dir = sign (position_i_);
82       Interval hd = out->dim_[X_AXIS];
83       Real hw = hd.length ()/4;
84       
85       Molecule ledger
86         = lookup_l ()->ledger_line  (Interval (hd[LEFT] - hw,
87                                                hd[RIGHT] + hw));
88       
89       int parity =  abs(position_i_) % 2;
90       
91       for (int i=0; i < streepjes_i; i++)
92         {
93           Molecule s (ledger);
94           s.translate_axis (-dir * inter_f * (i*2 + parity),
95                            Y_AXIS);
96           out->add_molecule (s);
97         }
98     }
99
100   out->dim_ = b;
101   out->translate_axis (inter_f*position_i_, Y_AXIS);
102   return out;
103 }