]> git.donarmstrong.com Git - lilypond.git/blob - lily/notehead.cc
release: 0.0.67
[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
20 Note_head::Note_head(int ss)
21 {
22     x_dir_i_ = 0;
23     staff_size_i_=ss;
24     position_i_ = 0;
25     balltype_i_ = 0;
26     dots_i_ = 0;
27     extremal_i_ = 0;
28     rest_b_ = false;
29 }
30
31 void
32 Note_head::do_pre_processing()
33 {
34    // 8 ball looks the same as 4 ball:
35     if (balltype_i_ > 4 && !rest_b_)
36         balltype_i_ = 4;
37 }
38
39 void
40 Note_head::set_rhythmic(Rhythmic_req*r_req_l)
41 {
42     balltype_i_ = r_req_l->duration_.type_i_;
43     dots_i_ = r_req_l->duration_.dots_i_;
44 }
45     
46 IMPLEMENT_STATIC_NAME(Note_head);
47
48 void
49 Note_head::do_print()const
50 {
51 #ifndef NPRINT
52     if (rest_b_)
53         mtor << "REST! ";
54     mtor << "balltype_i_ "<< balltype_i_ << ", position_i_ = "<< position_i_
55          << "dots_i_ " << dots_i_;
56 #endif
57 }
58
59
60 int
61 Note_head::compare(Note_head *const  &a, Note_head * const &b)
62 {
63     return a->position_i_ - b->position_i_;
64 }
65
66 Molecule*
67 Note_head::brew_molecule_p() const 
68 {
69     Molecule*out = 0;
70     Paper_def *p = paper();
71
72     Real dy = p->internote_f();
73     Symbol s;
74     if (!rest_b_)
75         s = p->lookup_l()->ball(balltype_i_);
76     else 
77         s = p->lookup_l()->rest(balltype_i_);
78     
79     out = new Molecule(Atom(s));
80     if (dots_i_) {
81         Symbol d = p->lookup_l()->dots(dots_i_);
82         Molecule dm;
83         dm.add(Atom(d));
84         if (!(position_i_ %2))
85             dm.translate(Offset(0,dy));
86         out->add_right(dm);
87     }
88     out->translate(Offset(x_dir_i_ * p->note_width(),0));
89     bool streepjes = (position_i_<-1)||(position_i_ > staff_size_i_+1);
90     
91     if (rest_b_ && balltype_i_ > 2)
92         streepjes = false;
93     
94     if (streepjes) {
95         int dir = sign(position_i_);
96         int s =(position_i_<-1) ? -((-position_i_)/2): (position_i_-staff_size_i_)/2;
97         Symbol str = p->lookup_l()->streepjes(s);
98         Molecule sm;
99         sm.add(Atom(str));
100         if (position_i_ % 2)
101             sm.translate(Offset(0,-dy* dir));
102         out->add(sm);       
103     }
104     
105     out->translate(Offset(0,dy*position_i_));
106     return out;
107 }
108