lilypond-1.4.4
[lilypond.git] / lily / stem-grav.cc
blob01ba63ead423bc4075d70d5d5270b5a97bd4c5da
1 /*
2 stem-grav.cc -- implement Stem_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "stem-grav.hh"
10 #include "note-head.hh"
11 #include "stem.hh"
12 #include "musical-request.hh"
13 #include "duration-convert.hh"
14 #include "misc.hh"
15 #include "abbrev.hh"
17 Stem_engraver::Stem_engraver()
19 abbrev_req_l_ = 0;
20 stem_p_ = 0;
21 abbrev_p_ = 0;
22 default_abbrev_i_ = 16;
23 dir_ = CENTER;
26 void
27 Stem_engraver::do_creation_processing ()
29 Scalar prop = get_property ("abbrev");
30 if (prop.isnum_b ())
32 default_abbrev_i_ = prop;
36 void
37 Stem_engraver::acknowledge_element(Score_elem_info i)
39 if (i.elem_l_->is_type_b (Rhythmic_head::static_name()))
41 Rhythmic_head *h = (Rhythmic_head*) i.elem_l_->item();
42 if (!stem_p_)
44 Rhythmic_req * r = i.req_l_->musical()->rhythmic();
45 stem_p_ = new Stem;
46 int durlog_i = r->duration_.durlog_i_;
47 stem_p_->flag_i_ = durlog_i;
50 if (abbrev_req_l_)
52 int t = abbrev_req_l_->type_i_;
53 if (!t)
54 t = default_abbrev_i_;
55 else
56 default_abbrev_i_ = t;
58 abbrev_p_ = new Abbreviation;
59 announce_element (Score_elem_info (abbrev_p_, abbrev_req_l_));
60 abbrev_p_->abbrev_flags_i_ =intlog2 (t) - (durlog_i>? 2);
62 announce_element (Score_elem_info (stem_p_, r));
64 stem_p_->add (h);
68 void
69 Stem_engraver::do_pre_move_processing()
71 if (abbrev_p_)
73 abbrev_p_->set_stem (stem_p_);
74 typeset_element (abbrev_p_);
75 abbrev_p_ = 0;
77 if (stem_p_)
79 Scalar prop = get_property ("ydirection");
80 dir_ = prop.isnum_b () ? (Direction)int(prop) : CENTER;
81 if (dir_)
83 stem_p_->dir_ = dir_;
84 stem_p_->dir_forced_b_ = true;
87 typeset_element(stem_p_);
88 stem_p_ = 0;
90 abbrev_req_l_ = 0;
93 bool
94 Stem_engraver::do_try_request (Request* r)
96 Musical_req* mus_l = r->musical ();
97 if (!mus_l)
98 return false;
100 Abbreviation_req* a = mus_l->abbrev ();
101 if (!a)
102 return false;
104 abbrev_req_l_ = a;
106 return true;
109 IMPLEMENT_IS_TYPE_B1(Stem_engraver, Engraver);
110 ADD_THIS_TRANSLATOR(Stem_engraver);