]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-grav.cc
08f07ff59f4e39ab184269dfad1b1e6112b43b2a
[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       if (dir_)
50         stem_p_->dir_ = dir_;
51
52       typeset_element(stem_p_);
53       stem_p_ = 0;
54     }
55   abbrev_req_l_ = 0;
56 }
57
58 bool
59 Stem_engraver::do_try_request (Request* r)
60 {
61   Musical_req* mus_l = r->musical ();
62   if (!mus_l)
63     return false;
64   
65   Abbreviation_req* a = mus_l->abbrev ();
66   if (!a)
67     return false;
68
69   abbrev_req_l_ = a;
70
71   return true;
72 }
73
74 void
75 Stem_engraver::set_feature (Feature i)
76 {
77   if (i.type_ == "vdir")        
78     dir_ = (Direction) int(i.value_);
79 }
80
81 IMPLEMENT_IS_TYPE_B1(Stem_engraver, Engraver);
82 ADD_THIS_ENGRAVER(Stem_engraver);