]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-grav.cc
4cef2a9594ad8ec1003324a7401ca2e4e1e2cc9a
[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   default_abbrev_i_ = 16;
21   dir_ = CENTER;
22 }
23
24 void
25 Stem_engraver::do_creation_processing ()
26 {
27   Scalar prop = get_property ("abbrev");
28   if (prop.isnum_b ()) 
29     {
30       default_abbrev_i_  = prop;
31     }
32 }
33
34 void
35 Stem_engraver::acknowledge_element(Score_elem_info i)
36 {
37   if (i.elem_l_->is_type_b (Rhythmic_head::static_name()))
38     {
39       Rhythmic_head *h  = (Rhythmic_head*) i.elem_l_->item();
40       if (!stem_p_) 
41         {
42           Rhythmic_req * r = i.req_l_->musical()->rhythmic();
43           stem_p_ = new Stem;
44           int durlog_i = r->duration_.durlog_i_;
45           stem_p_->flag_i_ = durlog_i;
46
47           
48           if (abbrev_req_l_)
49             {
50               int t = abbrev_req_l_->type_i_;
51               if (!t)
52                 t = default_abbrev_i_;
53               else
54                 default_abbrev_i_ = t;
55               stem_p_->abbrev_flag_i_ =intlog2 (t) - (durlog_i>? 2);
56             }
57           announce_element (Score_elem_info (stem_p_, r));
58         }
59       stem_p_->add (h);
60     }
61 }
62
63 void
64 Stem_engraver::do_pre_move_processing()
65 {
66   if (stem_p_)
67     {
68       Scalar prop = get_property ("ydirection");
69       dir_ = prop.isnum_b () ? int(prop) : CENTER;
70       if (dir_)
71         stem_p_->dir_ = dir_;
72
73       typeset_element(stem_p_);
74       stem_p_ = 0;
75     }
76   abbrev_req_l_ = 0;
77 }
78
79 bool
80 Stem_engraver::do_try_request (Request* r)
81 {
82   Musical_req* mus_l = r->musical ();
83   if (!mus_l)
84     return false;
85   
86   Abbreviation_req* a = mus_l->abbrev ();
87   if (!a)
88     return false;
89
90   abbrev_req_l_ = a;
91
92   return true;
93 }
94
95 IMPLEMENT_IS_TYPE_B1(Stem_engraver, Engraver);
96 ADD_THIS_TRANSLATOR(Stem_engraver);