]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-grav.cc
release: 0.1.13
[lilypond.git] / lily / stem-grav.cc
1 /*
2   stem-grav.cc -- implement Stem_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
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
16 Stem_engraver::Stem_engraver()
17 {
18   abbrev_req_l_ = 0;
19   stem_p_ = 0;
20   dir_ = CENTER;
21 }
22
23 void
24 Stem_engraver::acknowledge_element(Score_elem_info i)
25 {
26   if (i.elem_l_->is_type_b (Note_head::static_name()))
27     {
28       Note_head *h  = (Note_head*) i.elem_l_->item();
29       if (!stem_p_) 
30         {
31           Rhythmic_req * r = i.req_l_->musical()->rhythmic();
32           stem_p_ = new Stem;
33           int durlog_i = r->duration_.durlog_i_;
34           stem_p_->flag_i_ = Duration_convert::type2_i(durlog_i);
35           if (abbrev_req_l_)
36             stem_p_->abbrev_flag_i_ = intlog2 (abbrev_req_l_->type_i_) 
37               - (durlog_i>? 2);
38           announce_element (Score_elem_info (stem_p_, r));
39         }
40       stem_p_->add (h);
41     }
42 }
43
44 void
45 Stem_engraver::do_pre_move_processing()
46 {
47   if (stem_p_)
48     {
49       dir_ = (Direction) int(get_property ("ydirection"));
50       if (dir_)
51         stem_p_->dir_ = dir_;
52
53       typeset_element(stem_p_);
54       stem_p_ = 0;
55     }
56   abbrev_req_l_ = 0;
57 }
58
59 bool
60 Stem_engraver::do_try_request (Request* r)
61 {
62   Musical_req* mus_l = r->musical ();
63   if (!mus_l)
64     return false;
65   
66   Abbreviation_req* a = mus_l->abbrev ();
67   if (!a)
68     return false;
69
70   abbrev_req_l_ = a;
71
72   return true;
73 }
74
75 IMPLEMENT_IS_TYPE_B1(Stem_engraver, Engraver);
76 ADD_THIS_TRANSLATOR(Stem_engraver);