]> git.donarmstrong.com Git - lilypond.git/blob - lily/notehead.cc
release: 0.0.68pre
[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 IMPLEMENT_IS_TYPE_B1(Note_head,Item);
48
49 void
50 Note_head::do_print()const
51 {
52 #ifndef NPRINT
53     if (rest_b_)
54         mtor << "REST! ";
55     mtor << "balltype_i_ "<< balltype_i_ << ", position_i_ = "<< position_i_
56          << "dots_i_ " << dots_i_;
57 #endif
58 }
59
60
61 int
62 Note_head::compare(Note_head *const  &a, Note_head * const &b)
63 {
64     return a->position_i_ - b->position_i_;
65 }
66
67 Molecule*
68 Note_head::brew_molecule_p() const 
69 {
70     Molecule*out = 0;
71     Paper_def *p = paper();
72
73     Real dy = p->internote_f();
74     Symbol s;
75     if (!rest_b_)
76         s = p->lookup_l()->ball(balltype_i_);
77     else 
78         s = p->lookup_l()->rest(balltype_i_);
79     
80     out = new Molecule(Atom(s));
81     if (dots_i_) {
82         Symbol d = p->lookup_l()->dots(dots_i_);
83         Molecule dm;
84         dm.add(Atom(d));
85         if (!(position_i_ %2))
86             dm.translate_y(dy);
87         out->add_right(dm);
88     }
89     out->translate_x(x_dir_i_ * p->note_width());
90     bool streepjes = (position_i_<-1)||(position_i_ > staff_size_i_+1);
91     
92     if (rest_b_ && balltype_i_ > 2)
93         streepjes = false;
94     
95     if (streepjes) {
96         int dir = sign(position_i_);
97         int s =(position_i_<-1) ? -((-position_i_)/2): (position_i_-staff_size_i_)/2;
98         Symbol str = p->lookup_l()->streepjes(s);
99         Molecule sm;
100         sm.add(Atom(str));
101         if (position_i_ % 2)
102             sm.translate_y(-dy* dir);
103         out->add(sm);       
104     }
105     
106     out->translate_y(dy*position_i_);
107     return out;
108 }
109