]> git.donarmstrong.com Git - lilypond.git/blob - lily/notehead.cc
6871240ff97166c38112074f1dab9763dd664cde
[lilypond.git] / lily / notehead.cc
1 /*
2   notehead.cc -- implement Note_head
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "misc.hh"
10 #include "note-head.hh"
11 #include "dimen.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   TODO
20   
21   Separate notehead into 
22
23
24    Rhythmic_head
25      Note_head
26      Rest
27
28    and Stem takes Rhythmic_heads 
29  */
30
31
32 Note_head::Note_head (int ss)
33 {
34   x_dir_i_ = 0;
35   staff_size_i_=ss;
36   position_i_ = 0;
37   balltype_i_ = 0;
38   dots_i_ = 0;
39   dot_delta_y_i_ = 0;
40   extremal_i_ = 0;
41   rest_b_ = false;
42 }
43
44 void
45 Note_head::do_pre_processing()
46 {
47   // 8 ball looks the same as 4 ball:
48   if (balltype_i_ > 2 && !rest_b_)
49         balltype_i_ = 2;
50         
51   if (rest_b_) 
52     {
53         if (balltype_i_ == 0)
54             position_i_ += 6;
55         else if (balltype_i_ == 0)
56             position_i_ += 4;
57     }
58 }
59
60 void
61 Note_head::set_rhythmic (Rhythmic_req*r_req_l)
62 {
63   balltype_i_ = r_req_l->duration_.durlog_i_;
64   dots_i_ = r_req_l->duration_.dots_i_;
65 }
66   
67
68 IMPLEMENT_IS_TYPE_B1(Note_head,Item);
69
70 void
71 Note_head::do_print()const
72 {
73 #ifndef NPRINT
74   if (rest_b_)
75         DOUT << "REST! ";
76   DOUT << "balltype_i_ "<< balltype_i_ << ", position_i_ = "<< position_i_
77          << "dots_i_ " << dots_i_;
78 #endif
79 }
80
81
82 int
83 Note_head::compare (Note_head *const  &a, Note_head * const &b)
84 {
85   return a->position_i_ - b->position_i_;
86 }
87
88 void
89 Note_head::set_dots()
90 {
91   if (!(position_i_ %2) && rest_b_ && balltype_i_ == 0)
92         dot_delta_y_i_ = -1;
93   else if (!(position_i_ %2))
94         dot_delta_y_i_ = 1;
95 }
96
97 /*
98   Ugh, hairy.
99  */
100 Molecule*
101 Note_head::brew_molecule_p() const 
102 {
103   ((Note_head*)this)->set_dots(); // UGH GUH
104   Molecule*out = 0;
105   Paper_def *p = paper();
106   Real inter_f = p->internote_f();
107   Symbol s;
108
109   // ugh
110   bool streepjes_b = (position_i_<-1) || (position_i_ > staff_size_i_+1);
111   
112   if (!rest_b_)
113         s = p->lookup_l()->ball (balltype_i_);
114   else 
115     {
116         s = p->lookup_l()->rest (balltype_i_, streepjes_b);
117     }
118   out = new Molecule (Atom (s));
119   out->translate (x_dir_i_ * s.dim.x().length () , X_AXIS);
120   if (dots_i_) 
121     {
122         Symbol d = p->lookup_l()->dots (dots_i_);
123         Molecule dm;
124         dm.add (Atom (d));
125         dm.translate (inter_f * dot_delta_y_i_ , Y_AXIS);
126         out->add_right (dm);
127     }
128
129   
130   if (rest_b_) 
131     {
132         streepjes_b = false;
133     }
134   
135   if (streepjes_b) 
136     {
137         int dir = sign (position_i_);
138         int s =(position_i_<-1) ? -((-position_i_)/2): (position_i_-staff_size_i_)/2;
139         
140         Symbol str = p->lookup_l()->streepjes (s);
141         Molecule sm;
142         sm.add (Atom (str));
143         if (position_i_ % 2)
144             sm.translate (-inter_f* dir, Y_AXIS);
145         out->add (sm);      
146     }
147   
148   out->translate (inter_f*position_i_, Y_AXIS);
149   return out;
150 }
151