lilypond-1.5.9
[lilypond.git] / lily / stem-beam-grav.cc
blob01564cd929c14c14b685e711cb6a5d8c3ee5ec6e
1 /*
2 stem-beam-reg.cc -- part of GNU LilyPond
4 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
5 */
7 #include "musical-request.hh"
8 #include "stem-beam-grav.hh"
9 #include "beam.hh"
10 #include "stem.hh"
11 #include "grouping.hh"
12 #include "text-spanner.hh"
13 #include "debug.hh"
14 #include "grouping.hh"
15 #include "note-head.hh"
16 #include "time-description.hh"
17 #include "duration-convert.hh"
19 Stem_beam_engraver::Stem_beam_engraver()
21 do_post_move_processing();
23 current_grouping = 0;
24 beam_p_ = 0;
25 default_dir_i_ =0;
26 start_req_l_ = 0;
29 bool
30 Stem_beam_engraver::do_try_request (Request*req_l)
33 Musical_req* mus_l = req_l->musical();
34 /* Debiele puntkomma's. Laat je er eentje per ongeluk achter een
35 if (..) staan, lijkt het net op een luis in gcc.
37 (ofwel Python rules)
39 if (!mus_l)
40 return false;
43 if ( mus_l->beam())
45 if (bool (beam_p_) == bool (mus_l->beam()->spantype == Span_req::START))
46 return false;
48 if (beam_req_l_ && beam_req_l_ ->equal_b (mus_l))
49 return false;
51 beam_req_l_ = mus_l->beam();
52 return true;
55 if ( mus_l->stem())
57 if (current_grouping && !current_grouping->child_fit_b (
58 get_staff_info().time_C_->whole_in_measure_))
59 return false;
61 if (stem_req_l_ && !stem_req_l_->equal_b (mus_l) )
62 return false;
64 stem_req_l_ = mus_l->stem();
65 return true;
67 return false;
70 void
71 Stem_beam_engraver::do_process_requests()
73 if (beam_req_l_)
75 if (beam_req_l_->spantype == Span_req::STOP)
77 end_beam_b_ = true;
78 start_req_l_ = 0;
80 else
82 beam_p_ = new Beam;
83 start_req_l_ = beam_req_l_;
84 beam_p_->left_col_l_ = get_staff_info().musical_pcol_l ();
85 current_grouping = new Rhythmic_grouping;
86 if (beam_req_l_->nplet)
88 Text_spanner* t = new Text_spanner();
89 Text_def *defp = new Text_def;
90 t->set_support (beam_p_);
91 defp->align_i_ = 0;
92 defp->text_str_ = beam_req_l_->nplet;
93 defp->style_str_="italic";
94 t->spec_p_ = defp;
95 announce_element (Score_elem_info (t,0));
96 typeset_element (t);
98 announce_element ( Score_elem_info (beam_p_, 0));
103 if (stem_req_l_)
105 stem_p_ = new Stem (8);
106 if (current_grouping)
107 current_grouping->add_child (
108 get_staff_info().time_C_->whole_in_measure_,
109 stem_req_l_->duration());
111 stem_p_->flag_i_ = Duration_convert::type2_i
112 (stem_req_l_->duration_.durlog_i_); // should change rep. of flags too.
114 if (beam_p_)
116 if (stem_req_l_->duration_.durlog_i_<= 2)
117 stem_req_l_->warning ("stem doesn't fit in Beam");
118 else
119 beam_p_->add (stem_p_);
120 stem_p_->print_flag_b_ = false;
122 else
124 stem_p_->print_flag_b_ = true;
127 announce_element (Score_elem_info (stem_p_, stem_req_l_));
131 void
132 Stem_beam_engraver::acknowledge_element (Score_elem_info info)
134 if (!stem_p_)
135 return;
137 if (info.elem_l_->name() == Note_head::static_name () &&
138 stem_req_l_->duration()
139 == info.req_l_->musical()->rhythmic ()->duration ())
141 Note_head * n_l= (Note_head*)info.elem_l_->item();
142 stem_p_->add (n_l);
145 void
146 Stem_beam_engraver::do_pre_move_processing()
148 if (stem_p_)
150 if (default_dir_i_)
151 stem_p_->dir_i_ = default_dir_i_;
153 typeset_element (stem_p_);
154 stem_p_ = 0;
156 if (beam_p_ && end_beam_b_)
158 Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
159 rg_C->extend (current_grouping->interval());
160 beam_p_->set_grouping (*rg_C, *current_grouping);
161 beam_p_->right_col_l_ = get_staff_info().musical_pcol_l ();
162 typeset_element (beam_p_);
163 delete current_grouping;
164 current_grouping = 0;
165 beam_p_ = 0;
167 end_beam_b_ = false;
169 void
170 Stem_beam_engraver::do_post_move_processing()
172 stem_p_ = 0;
173 beam_req_l_ = 0;
174 stem_req_l_ = 0;
175 end_beam_b_ = false;
178 Stem_beam_engraver::~Stem_beam_engraver()
180 if (beam_p_)
181 start_req_l_->warning ("unterminated beam");
184 void
185 Stem_beam_engraver::set_feature (Feature i)
187 if (i.type_ == "vdir")
188 default_dir_i_ = i.value_;
192 IMPLEMENT_IS_TYPE_B1(Stem_beam_engraver,Engraver);
193 ADD_THIS_ENGRAVER(Stem_beam_engraver);