]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head.cc
f881c6134c9a4d58553a6dbd63f0e0edb9ff968d
[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
17 void
18 Note_head::flip_around_stem (Direction d)
19 {
20   translate_axis (do_width ().length () * d, X_AXIS);
21 }
22
23 Note_head::Note_head ()
24 {
25   position_i_ = 0;
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 int
39 Note_head::compare (Note_head *const  &a, Note_head * const &b)
40 {
41   return a->position_i_ - b->position_i_;
42 }
43
44 /**
45  Don't account for ledgerlines in the width.
46  */
47 Interval
48 Note_head::do_width () const
49 {
50   Molecule a =  lookup_l ()->notehead (balltype_i_, ""); // UGH
51   Interval i = a.dim_[X_AXIS];
52   return i;
53 }
54
55 Molecule*
56 Note_head::do_brew_molecule_p() const 
57 {
58   Molecule*out = 0;
59   Real inter_f = staff_line_leading_f ()/2;
60   int sz = lines_i ()-1;
61
62   int streepjes_i = abs (position_i_) < sz 
63     ? 0
64     : (abs(position_i_) - sz) /2;
65
66
67   String type; 
68   SCM style  =get_elt_property (style_scm_sym);
69   if (style != SCM_BOOL_F)
70     {
71       type = ly_scm2string (SCM_CDR(style));
72     }
73   
74   Molecule head (lookup_l()->notehead (balltype_i_, type));
75
76   
77   out = new Molecule (Molecule (head));
78
79   if (streepjes_i) 
80     {
81       Direction dir = sign (position_i_);
82       Interval hd = head.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->translate_axis (inter_f*position_i_, Y_AXIS);
101   return out;
102 }