]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head.cc
4ddaac08487a9e3cb95d3b741c2bf651c2a1f342
[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 #include "staff-symbol-referencer.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   // 8 ball looks the same as 4 ball:
42   String type; 
43   SCM style  = get_elt_property ("style");
44   if (style != SCM_UNDEFINED)
45     {
46       type = ly_scm2string (style);
47     }
48   
49   
50   if (balltype_i () > 2 || type == "harmonic" || type == "cross")
51     set_elt_property ("duration-log", gh_int2scm (2));
52
53   if (Dots *d = dots_l ())
54     { // move into Rhythmic_head?
55
56       Staff_symbol_referencer_interface si (d);
57       Staff_symbol_referencer_interface me (this);      
58       
59       si.set_position(int (me.position_f ()));
60     }
61 }
62
63 int
64 Note_head::compare (Note_head *const  &a, Note_head * const &b)
65 {
66   Staff_symbol_referencer_interface s1(a);
67   Staff_symbol_referencer_interface s2(b);      
68
69   return sign(s1.position_f () - s2.position_f ());
70 }
71
72 Molecule
73 Note_head::make_molecule () const
74 {
75   String type; 
76   SCM style  = get_elt_property ("style");
77   if (style != SCM_UNDEFINED)
78     {
79       type = ly_scm2string (style);
80     }
81   
82   return lookup_l()->afm_find (String ("noteheads-")
83                                + to_str (balltype_i ()) + type);
84 }
85
86 Molecule*
87 Note_head::do_brew_molecule_p() const 
88 {
89   Staff_symbol_referencer_interface si (this);
90   
91   Real inter_f = si.staff_line_leading_f ()/2;
92   int sz = si.lines_i ()-1;
93   Real p = si.position_f ();
94   int streepjes_i = abs (p) < sz 
95     ? 0
96     : (abs((int)p) - sz) /2;
97
98   Molecule*  out =  new Molecule (make_molecule ());
99
100   Box b = out->dim_;
101
102   if (streepjes_i) 
103     {
104       Direction dir = (Direction)sign (p);
105       Interval hd = out->dim_[X_AXIS];
106       Real hw = hd.length ()/4;
107       
108       Molecule ledger
109         = lookup_l ()->ledger_line  (Interval (hd[LEFT] - hw,
110                                                hd[RIGHT] + hw));
111       
112       int parity =  abs(int (p)) % 2;
113       
114       for (int i=0; i < streepjes_i; i++)
115         {
116           Molecule s (ledger);
117           s.translate_axis (-dir * inter_f * (i*2 + parity),
118                            Y_AXIS);
119           out->add_molecule (s);
120         }
121     }
122
123   out->dim_ = b;
124   return out;
125 }
126