]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-grav.cc
release: 0.1.47
[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 #include "abbrev.hh"
16
17 Stem_engraver::Stem_engraver()
18 {
19   abbrev_req_l_ = 0;
20   stem_p_ = 0;
21   abbrev_p_ = 0;
22   default_abbrev_i_ = 16;
23   dir_ = CENTER;
24 }
25
26 void
27 Stem_engraver::do_creation_processing ()
28 {
29   Scalar prop = get_property ("abbrev");
30   if (prop.isnum_b ()) 
31     {
32       default_abbrev_i_  = prop;
33     }
34 }
35
36 void
37 Stem_engraver::acknowledge_element(Score_elem_info i)
38 {
39   if (i.elem_l_->is_type_b (Rhythmic_head::static_name()))
40     {
41       Rhythmic_head *h  = (Rhythmic_head*) i.elem_l_->item();
42       if (!stem_p_) 
43         {
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;
48
49           
50           if (abbrev_req_l_)
51             {
52               int t = abbrev_req_l_->type_i_;
53               if (!t)
54                 t = default_abbrev_i_;
55               else
56                 default_abbrev_i_ = t;
57
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);
61             }
62           announce_element (Score_elem_info (stem_p_, r));
63         }
64       stem_p_->add (h);
65     }
66 }
67
68 void
69 Stem_engraver::do_pre_move_processing()
70 {
71   if (abbrev_p_)
72     {
73       abbrev_p_->set_stem (stem_p_);
74       typeset_element (abbrev_p_);
75       abbrev_p_ = 0;
76     }
77   if (stem_p_)
78     {
79       Scalar prop = get_property ("ydirection");
80       dir_ = prop.isnum_b () ? int(prop) : CENTER;
81       if (dir_)
82         stem_p_->dir_ = dir_;
83
84       typeset_element(stem_p_);
85       stem_p_ = 0;
86     }
87   abbrev_req_l_ = 0;
88 }
89
90 bool
91 Stem_engraver::do_try_request (Request* r)
92 {
93   Musical_req* mus_l = r->musical ();
94   if (!mus_l)
95     return false;
96   
97   Abbreviation_req* a = mus_l->abbrev ();
98   if (!a)
99     return false;
100
101   abbrev_req_l_ = a;
102
103   return true;
104 }
105
106 IMPLEMENT_IS_TYPE_B1(Stem_engraver, Engraver);
107 ADD_THIS_TRANSLATOR(Stem_engraver);