]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-engraver.cc
patch::: 1.1.19.jcn5: isb
[lilypond.git] / lily / stem-engraver.cc
1 /*
2   stem-grav.cc -- implement Stem_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "stem-engraver.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 #include "staff-info.hh"
17
18 Stem_engraver::Stem_engraver()
19 {
20   abbrev_req_l_ = 0;
21   stem_p_ = 0;
22   abbrev_p_ = 0;
23   default_abbrev_i_ = 16;
24 }
25
26 void
27 Stem_engraver::do_creation_processing ()
28 {
29   Scalar prop = get_property ("abbrev", 0);
30   if (prop.isnum_b ()) 
31     {
32       default_abbrev_i_  = prop;
33     }
34 }
35
36 void
37 Stem_engraver::acknowledge_element(Score_element_info i)
38 {
39   if (dynamic_cast<Rhythmic_head *> (i.elem_l_))
40     {
41       Rhythmic_head *h  = dynamic_cast<Rhythmic_head *> (i.elem_l_);
42       if (!stem_p_) 
43         {
44           Rhythmic_req * r = dynamic_cast <Rhythmic_req *> (i.req_l_);
45           stem_p_ = new Stem;
46           int durlog_i = r->duration_.durlog_i_;
47           stem_p_->flag_i_ = durlog_i;
48
49           stem_p_->staff_sym_l_ = get_staff_info ().staff_sym_l_;
50           
51           if (abbrev_req_l_)
52             {
53               /*
54                 suggests typing of:
55                    c8:16 c: c: c:
56                 hmm, which isn't so bad?
57               */
58               int t = abbrev_req_l_->type_i_;
59               if (!t)
60                 t = default_abbrev_i_;
61               else
62                 default_abbrev_i_ = t;
63
64               if (t)
65                 {
66                   abbrev_p_ = new Abbreviation;
67                   announce_element (Score_element_info (abbrev_p_, abbrev_req_l_));
68                   abbrev_p_->abbrev_flags_i_ =intlog2 (t) - (durlog_i>? 2);
69                 }
70             }
71
72           // must give the request, to preserve the rhythmic info.
73           announce_element (Score_element_info (stem_p_, r));
74         }
75       stem_p_->add_head (h);
76     }
77 }
78
79 void
80 Stem_engraver::do_pre_move_processing()
81 {
82   if (abbrev_p_)
83     {
84       abbrev_p_->set_stem (stem_p_);
85       typeset_element (abbrev_p_);
86       abbrev_p_ = 0;
87     }
88
89   if (stem_p_)
90     {
91       Scalar prop = get_property ("ydirection", 0);
92       Direction dir = prop.isnum_b () ? (Direction)int(prop) : CENTER;
93       if (dir)
94         {
95           stem_p_->dir_ = dir;
96           stem_p_->dir_forced_b_ = true;
97         }
98
99       Translator const *which;
100       prop = get_property ("stemLeftBeamCount", &which);
101       if (prop.isnum_b ())
102         {
103           stem_p_->beams_i_drul_[LEFT] = prop;
104           ((Translator*)which)->set_property ("stemLeftBeamCount", "");
105         }
106       prop = get_property ("stemRightBeamCount", &which);
107       if (prop.isnum_b ())
108         {
109           stem_p_->beams_i_drul_[RIGHT] = prop;
110           ((Translator*)which)->set_property ("stemRightBeamCount", "");
111         }
112
113
114       typeset_element(stem_p_);
115       stem_p_ = 0;
116     }
117   abbrev_req_l_ = 0;
118 }
119
120 bool
121 Stem_engraver::do_try_music (Music* r)
122 {
123   if (Abbreviation_req* a = dynamic_cast <Abbreviation_req *> (r))
124     {
125       abbrev_req_l_ = a;
126       return true;
127     }
128   return false;
129 }
130
131
132 ADD_THIS_TRANSLATOR(Stem_engraver);