]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head.cc
release: 1.2.4
[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   // 8 ball looks the same as 4 ball:
33   if (balltype_i_ > 2)
34     balltype_i_ = 2;
35   if (dots_l_)                  // move into Rhythmic_head?
36     dots_l_->position_i_ = position_i ();
37 }
38
39
40
41 int
42 Note_head::compare (Note_head *const  &a, Note_head * const &b)
43 {
44   return a->position_i () - b->position_i ();
45 }
46
47 /**
48  Don't account for ledgerlines in the width.
49  */
50 Interval
51 Note_head::do_width () const
52 {
53   Molecule a =  lookup_l ()->notehead (balltype_i_, ""); // UGH
54   Interval i = a.dim_[X_AXIS];
55   return i;
56 }
57
58 Molecule*
59 Note_head::do_brew_molecule_p() const 
60 {
61   Real inter_f = staff_line_leading_f ()/2;
62   int sz = lines_i ()-1;
63
64   int streepjes_i = abs (position_i ()) < sz 
65     ? 0
66     : (abs(position_i ()) - sz) /2;
67
68
69   String type; 
70   SCM style  =get_elt_property (style_scm_sym);
71   if (style != SCM_BOOL_F)
72     {
73       type = ly_scm2string (SCM_CDR(style));
74     }
75   
76   Molecule*  out = new Molecule (lookup_l()->notehead (balltype_i_, type));
77
78   Box b = out->dim_;
79
80   if (streepjes_i) 
81     {
82       Direction dir = (Direction)sign (position_i ());
83       Interval hd = out->dim_[X_AXIS];
84       Real hw = hd.length ()/4;
85       
86       Molecule ledger
87         = lookup_l ()->ledger_line  (Interval (hd[LEFT] - hw,
88                                                hd[RIGHT] + hw));
89       
90       int parity =  abs(position_i ()) % 2;
91       
92       for (int i=0; i < streepjes_i; i++)
93         {
94           Molecule s (ledger);
95           s.translate_axis (-dir * inter_f * (i*2 + parity),
96                            Y_AXIS);
97           out->add_molecule (s);
98         }
99     }
100
101   out->dim_ = b;
102   return out;
103 }