]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head.cc
8806f5f7be55cb77a5a50ff91cdf625ba4d01cd5
[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--1998 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   staff_size_i_= 8;             // UGH
23   steps_i_ = 0;
24   position_i_ = 0;
25   extremal_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
39
40
41 int
42 Note_head::compare (Note_head *const  &a, Note_head * const &b)
43 {
44   return a->position_i_ - b->position_i_;
45 }
46
47 Interval
48 Note_head::do_width () const
49 {
50   Molecule a =  lookup_l ()->ball (balltype_i_);
51   Interval i = a.dim_[X_AXIS];
52   i+= x_dir_ * i.length ();
53   return i;
54 }
55
56 Molecule*
57 Note_head::do_brew_molecule_p() const 
58 {
59   Molecule*out = 0;
60   Paper_def *p = paper();
61   Real inter_f = p->internote_f ();
62
63   // ugh
64   int streepjes_i = abs (position_i_) < staff_size_i_/2 
65     ? 0
66     : (abs(position_i_) - staff_size_i_/2) /2;
67   
68   Molecule head; 
69
70   if (note_head_type_str_.length_i ()) {
71     if (note_head_type_str_ == "normal") // UGH
72       note_head_type_str_ = "";
73     head = lookup_l()->special_ball (balltype_i_, note_head_type_str_);
74     }
75   else
76     head = lookup_l()->ball (balltype_i_);
77   
78   out = new Molecule (Molecule (head));
79   out->translate_axis (x_dir_ * head.dim_[X_AXIS].length (), X_AXIS);
80
81
82
83   if (streepjes_i) 
84     {
85       Direction dir = sign (position_i_);
86       Interval hd = head.dim_[X_AXIS];
87       Real hw = hd.length ()/4;
88       
89       Molecule ledger
90         = lookup_l ()->ledger_line  (Interval (hd[LEFT] - hw,
91                                                hd[RIGHT] + hw));
92       
93       int parity =  abs(position_i_) % 2;
94       
95       for (int i=0; i < streepjes_i; i++)
96         {
97           Molecule s (ledger);
98           s.translate_axis (-dir * inter_f * (i*2 + parity),
99                            Y_AXIS);
100           out->add_molecule (s);
101         }
102     }
103   
104   out->translate_axis (inter_f*position_i_, Y_AXIS);
105   return out;
106 }