]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head.cc
release: 1.3.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--1999 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 "lookup.hh"
14 #include "molecule.hh"
15 #include "musical-request.hh"
16 #include "stem.hh"
17
18 void
19 Note_head::flip_around_stem (Direction d)
20 {
21   translate_axis (do_width ().length () * d, X_AXIS);
22 }
23
24 Note_head::Note_head ()
25 {
26 }
27
28 void
29 Note_head::do_pre_processing ()
30 {
31   Rhythmic_head::do_pre_processing ();
32
33   // 8 ball looks the same as 4 ball:
34   String type; 
35   SCM style  = get_elt_property ("style");
36   if (style != SCM_UNDEFINED)
37     {
38       type = ly_scm2string (style);
39     }
40   
41   
42   if (balltype_i_ > 2 || type == "harmonic" || type == "cross")
43     balltype_i_ = 2;
44
45   if (dots_l_)                  // move into Rhythmic_head?
46     dots_l_->set_position(int (position_f ()));
47
48  
49 }
50
51
52
53 int
54 Note_head::compare (Note_head *const  &a, Note_head * const &b)
55 {
56   return sign(a->position_f () - b->position_f ());
57 }
58
59 /**
60  Don't account for ledgerlines in the width.
61  */
62 Interval
63 Note_head::do_width () const
64 {
65   return make_molecule ().dim_[X_AXIS];
66 }
67
68 Molecule
69 Note_head::make_molecule () const
70 {
71   String type; 
72   SCM style  = get_elt_property ("style");
73   if (style != SCM_UNDEFINED)
74     {
75       type = ly_scm2string (style);
76     }
77   
78   return lookup_l()->afm_find (String ("noteheads-")
79                                + to_str (balltype_i_) + type);
80 }
81
82 Molecule*
83 Note_head::do_brew_molecule_p() const 
84 {
85   Real inter_f = staff_line_leading_f ()/2;
86   int sz = lines_i ()-1;
87
88   int streepjes_i = abs (position_f ()) < sz 
89     ? 0
90     : (abs((int)position_f ()) - sz) /2;
91
92   Molecule*  out =  new Molecule (make_molecule ());
93
94   Box b = out->dim_;
95
96   if (streepjes_i) 
97     {
98       Direction dir = (Direction)sign (position_f ());
99       Interval hd = out->dim_[X_AXIS];
100       Real hw = hd.length ()/4;
101       
102       Molecule ledger
103         = lookup_l ()->ledger_line  (Interval (hd[LEFT] - hw,
104                                                hd[RIGHT] + hw));
105       
106       int parity =  abs(int (position_f ())) % 2;
107       
108       for (int i=0; i < streepjes_i; i++)
109         {
110           Molecule s (ledger);
111           s.translate_axis (-dir * inter_f * (i*2 + parity),
112                            Y_AXIS);
113           out->add_molecule (s);
114         }
115     }
116
117   out->dim_ = b;
118   return out;
119 }
120