lilypond-0.1.56
[lilypond.git] / lily / notehead.cc
blob97d69ec1ed5649be3608ec9b976671392f824778
1 /*
2 notehead.cc -- implement Note_head
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "misc.hh"
10 #include "dots.hh"
11 #include "note-head.hh"
12 #include "dimen.hh"
13 #include "debug.hh"
14 #include "paper-def.hh"
15 #include "lookup.hh"
16 #include "molecule.hh"
17 #include "musical-request.hh"
20 Note_head::Note_head ()
22 x_dir_ = CENTER;
23 staff_size_i_= 8; // UGH
24 position_i_ = 0;
25 extremal_i_ = 0;
28 void
29 Note_head::do_pre_processing ()
31 // 8 ball looks the same as 4 ball:
32 if (balltype_i_ > 2)
33 balltype_i_ = 2;
34 if (dots_l_) // move into Rhythmic_head?
35 dots_l_->position_i_ = position_i_;
38 IMPLEMENT_IS_TYPE_B1(Note_head,Rhythmic_head);
41 int
42 Note_head::compare (Note_head *const &a, Note_head * const &b)
44 return a->position_i_ - b->position_i_;
47 Interval
48 Note_head::do_width () const
50 Atom a = paper ()->lookup_l()->ball (balltype_i_);
51 Interval i = a.dim_[X_AXIS];
52 i+= x_dir_ * i.length ();
53 return i;
56 Molecule*
57 Note_head::brew_molecule_p() const
59 Molecule*out = 0;
60 Paper_def *p = paper();
61 Real inter_f = p->internote_f ();
63 // ugh
64 bool streepjes_b = (position_i_<-1) || (position_i_ > staff_size_i_+1);
66 Atom s = p->lookup_l()->ball (balltype_i_);
67 out = new Molecule (Atom (s));
68 out->translate (x_dir_ * s.dim_[X_AXIS].length (), X_AXIS);
70 if (streepjes_b)
72 int dir = sign (position_i_);
73 int s =(position_i_<-1)
74 ? -((-position_i_)/2)
75 : (position_i_-staff_size_i_)/2;
77 Atom str = p->lookup_l()->streepjes (balltype_i_, s);
78 Molecule sm;
79 sm.add (Atom (str));
80 if (position_i_ % 2)
81 sm.translate (-inter_f* dir, Y_AXIS);
82 out->add (sm);
85 out->translate (inter_f*position_i_, Y_AXIS);
86 return out;