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