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