]> git.donarmstrong.com Git - lilypond.git/blob - lily/notehead.cc
release: 0.1.8
[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_ > 4 && !rest_b_)
49         balltype_i_ = 4;
50         
51     if (rest_b_) { 
52         if (balltype_i_ == 1)
53             position_i_ += 6;
54         else if (balltype_i_ == 2)
55             position_i_ += 4;
56     }
57 }
58
59 void
60 Note_head::set_rhythmic (Rhythmic_req*r_req_l)
61 {
62     balltype_i_ = r_req_l->duration_.type_i_;
63     dots_i_ = r_req_l->duration_.dots_i_;
64 }
65     
66
67 IMPLEMENT_IS_TYPE_B1(Note_head,Item);
68
69 void
70 Note_head::do_print()const
71 {
72 #ifndef NPRINT
73     if (rest_b_)
74         DOUT << "REST! ";
75     DOUT << "balltype_i_ "<< balltype_i_ << ", position_i_ = "<< position_i_
76          << "dots_i_ " << dots_i_;
77 #endif
78 }
79
80
81 int
82 Note_head::compare (Note_head *const  &a, Note_head * const &b)
83 {
84     return a->position_i_ - b->position_i_;
85 }
86
87 void
88 Note_head::set_dots()
89 {
90     if (!(position_i_ %2) && rest_b_ && balltype_i_ == 1)
91         dot_delta_y_i_ = -1;
92     else if (!(position_i_ %2))
93         dot_delta_y_i_ = 1;
94 }
95
96 /*
97   Ugh, hairy.
98  */
99 Molecule*
100 Note_head::brew_molecule_p() const 
101 {
102     ((Note_head*)this)->set_dots(); // UGH GUH
103     Molecule*out = 0;
104     Paper_def *p = paper();
105     Real inter_f = p->internote_f();
106     Symbol s;
107
108     // ugh
109     bool streepjes_b = (position_i_<-1) || (position_i_ > staff_size_i_+1);
110     
111     if (!rest_b_)
112         s = p->lookup_l()->ball (balltype_i_);
113     else {
114         s = p->lookup_l()->rest (balltype_i_, streepjes_b);
115     }
116     out = new Molecule (Atom (s));
117     out->translate (x_dir_i_ * s.dim.x().length () , X_AXIS);
118     if (dots_i_) {
119         Symbol d = p->lookup_l()->dots (dots_i_);
120         Molecule dm;
121         dm.add (Atom (d));
122         dm.translate (inter_f * dot_delta_y_i_ , Y_AXIS);
123         out->add_right (dm);
124     }
125
126     
127     if (rest_b_) {
128         streepjes_b = false;
129     }
130     
131     if (streepjes_b) {
132         int dir = sign (position_i_);
133         int s =(position_i_<-1) ? -((-position_i_)/2): (position_i_-staff_size_i_)/2;
134         
135         Symbol str = p->lookup_l()->streepjes (s);
136         Molecule sm;
137         sm.add (Atom (str));
138         if (position_i_ % 2)
139             sm.translate (-inter_f* dir, Y_AXIS);
140         out->add (sm);      
141     }
142     
143     out->translate (inter_f*position_i_, Y_AXIS);
144     return out;
145 }
146