]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head.cc
release: 1.1.6
[lilypond.git] / lily / note-head.cc
1 /*
2   notehead.cc -- implement Note_head
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "misc.hh"
10 #include "dots.hh"
11 #include "note-head.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 Note_head::Note_head ()
20 {
21   x_dir_ = CENTER;
22   staff_size_i_= 8;             // UGH
23   position_i_ = 0;
24   extremal_i_ = 0;
25 }
26
27 void
28 Note_head::do_pre_processing ()
29 {
30   // 8 ball looks the same as 4 ball:
31   if (balltype_i_ > 2)
32     balltype_i_ = 2;
33   if (dots_l_)                  // move into Rhythmic_head?
34     dots_l_->position_i_ = position_i_;
35 }
36
37
38
39
40 int
41 Note_head::compare (Note_head *const  &a, Note_head * const &b)
42 {
43   return a->position_i_ - b->position_i_;
44 }
45
46 Interval
47 Note_head::do_width () const
48 {
49   Atom a =  lookup_l ()->ball (balltype_i_);
50   Interval i = a.dim_[X_AXIS];
51   i+= x_dir_ * i.length ();
52   return i;
53 }
54
55 Molecule*
56 Note_head::brew_molecule_p() const 
57 {
58   Molecule*out = 0;
59   Paper_def *p = paper();
60   Real inter_f = p->internote_f ();
61
62   // ugh
63   int streepjes_i = abs (position_i_) < staff_size_i_/2 
64     ? 0
65     : (abs(position_i_) - staff_size_i_/2) /2;
66   
67   Atom  s = lookup_l()->ball (balltype_i_);
68   out = new Molecule (Atom (s));
69   out->translate_axis (x_dir_ * s.dim_[X_AXIS].length (), X_AXIS);
70
71   if (streepjes_i) 
72     {
73       int dir = sign (position_i_);
74       Atom streepje = lookup_l ()->streepje (balltype_i_);
75       
76       int parity =  (position_i_ % 2) ? 1 : 0;
77         
78       
79       for (int i=0; i < streepjes_i; i++)
80         {
81           Atom s = streepje;
82           s.translate_axis (-dir * inter_f * (i*2 + parity),
83                            Y_AXIS);
84           out->add_atom (s);
85         }
86     }
87   
88   out->translate_axis (inter_f*position_i_, Y_AXIS);
89   return out;
90 }