]> git.donarmstrong.com Git - lilypond.git/blob - lily/notehead.cc
release: 0.0.56
[lilypond.git] / lily / notehead.cc
1 #include "misc.hh"
2 #include "notehead.hh"
3 #include "dimen.hh" 
4 #include "debug.hh"
5 #include "paper-def.hh"
6 #include "lookup.hh"
7 #include "molecule.hh"
8 #include "musical-request.hh"
9
10
11
12 Notehead::Notehead(int ss)
13 {
14     x_dir_i_ = 0;
15     staff_size_i_=ss;
16     position_i_ = 0;
17     balltype_i_ = 0;
18     dots_i_ = 0;
19     extremal_i_ = 0;
20     rest_b_ = false;
21 }
22
23 void
24 Notehead::set_rhythmic(Rhythmic_req*r_req_l)
25 {
26     balltype_i_ = r_req_l->duration_.type_i_;
27     dots_i_ = r_req_l->duration_.dots_i_;
28 }
29     
30 IMPLEMENT_STATIC_NAME(Notehead);
31
32 void
33 Notehead::do_print()const
34 {
35 #ifndef NPRINT
36     if (rest_b_)
37         mtor << "REST! ";
38     mtor << "balltype_i_ "<< balltype_i_ << ", position_i_ = "<< position_i_
39          << "dots_i_ " << dots_i_;
40 #endif
41 }
42
43
44 int
45 Notehead::compare(Notehead *const  &a, Notehead * const &b)
46 {
47     return a->position_i_ - b->position_i_;
48 }
49
50 Molecule*
51 Notehead::brew_molecule_p() const 
52 {
53     Molecule*out = 0;
54     Paper_def *p = paper();
55
56     Real dy = p->internote();
57     Symbol s;
58     if (!rest_b_)
59         s = p->lookup_l()->ball(balltype_i_);
60     else 
61         s = p->lookup_l()->rest(balltype_i_);
62     
63     out = new Molecule(Atom(s));
64     if (dots_i_) {
65         Symbol d = p->lookup_l()->dots(dots_i_);
66         Molecule dm;
67         dm.add(Atom(d));
68         if (!(position_i_ %2))
69             dm.translate(Offset(0,dy));
70         out->add_right(dm);
71     }
72     out->translate(Offset(x_dir_i_ * p->note_width(),0));
73     bool streepjes = (position_i_<-1)||(position_i_ > staff_size_i_+1);
74     
75     if (rest_b_ && balltype_i_ > 2)
76         streepjes = false;
77     
78     if (streepjes) {
79         int dir = sign(position_i_);
80         int s =(position_i_<-1) ? -((-position_i_)/2): (position_i_-staff_size_i_)/2;
81         Symbol str = p->lookup_l()->streepjes(s);
82         Molecule sm;
83         sm.add(Atom(str));
84         if (position_i_ % 2)
85             sm.translate(Offset(0,-dy* dir));
86         out->add(sm);       
87     }
88     
89     out->translate(Offset(0,dy*position_i_));
90     return out;
91 }
92