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