]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head.cc
9b53dc498ea13d68b30e0752affdff1b0eeedc55
[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 "paper-def.hh"
14 #include "lookup.hh"
15 #include "molecule.hh"
16 #include "musical-request.hh"
17
18
19 Note_head::Note_head ()
20 {
21   x_dir_ = CENTER;
22   position_i_ = 0;
23   extremal_i_ = 0;
24 }
25
26 void
27 Note_head::do_pre_processing ()
28 {
29   // 8 ball looks the same as 4 ball:
30   if (balltype_i_ > 2)
31     balltype_i_ = 2;
32   if (dots_l_)                  // move into Rhythmic_head?
33     dots_l_->position_i_ = position_i_;
34 }
35
36 int
37 Note_head::compare (Note_head *const  &a, Note_head * const &b)
38 {
39   return a->position_i_ - b->position_i_;
40 }
41
42 Interval
43 Note_head::do_width () const
44 {
45   Molecule a =  lookup_l ()->ball (balltype_i_);
46   Interval i = a.dim_[X_AXIS];
47   i+= x_dir_ * i.length ();
48   return i;
49 }
50
51 Molecule*
52 Note_head::do_brew_molecule_p() const 
53 {
54   Molecule*out = 0;
55   Paper_def *p = paper_l ();
56   Real inter_f = staff_line_leading_f ()/2;
57   int sz = lines_i ()-1;
58   // ugh
59   int streepjes_i = abs (position_i_) < sz 
60     ? 0
61     : (abs(position_i_) - sz) /2;
62   
63   Molecule head; 
64
65   if (note_head_type_str_.length_i ()) {
66     if (note_head_type_str_ == "normal") // UGH
67       note_head_type_str_ = "";
68     head = lookup_l()->special_ball (balltype_i_, note_head_type_str_);
69     }
70   else
71     head = lookup_l()->ball (balltype_i_);
72   
73   out = new Molecule (Molecule (head));
74   out->translate_axis (x_dir_ * head.dim_[X_AXIS].length (), X_AXIS);
75
76
77
78   if (streepjes_i) 
79     {
80       Direction dir = sign (position_i_);
81       Interval hd = head.dim_[X_AXIS];
82       Real hw = hd.length ()/4;
83       
84       Molecule ledger
85         = lookup_l ()->ledger_line  (Interval (hd[LEFT] - hw,
86                                                hd[RIGHT] + hw));
87       
88       int parity =  abs(position_i_) % 2;
89       
90       for (int i=0; i < streepjes_i; i++)
91         {
92           Molecule s (ledger);
93           s.translate_axis (-dir * inter_f * (i*2 + parity),
94                            Y_AXIS);
95           out->add_molecule (s);
96         }
97     }
98   
99   out->translate_axis (inter_f*position_i_, Y_AXIS);
100   return out;
101 }