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