lilypond-1.3.65
[lilypond.git] / lily / score-grav.cc
blobbbcaec268544be65123d335d72aca32430972ef9
1 /*
2 score-grav.cc -- implement Score_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "super-elem.hh"
10 #include "scoreline.hh"
11 #include "debug.hh"
12 #include "item.hh"
13 #include "score-grav.hh"
14 #include "p-score.hh"
15 #include "musical-request.hh"
16 #include "score-column.hh"
17 #include "command-request.hh"
18 #include "paper-def.hh"
21 Score_engraver::Score_engraver()
23 break_penalty_i_ = 0;
24 scoreline_l_ =0;
25 command_column_l_ =0;
26 musical_column_l_ =0;
27 breaks_i_ =0;
28 pscore_p_ = 0;
31 void
32 Score_engraver::prepare (Moment w)
34 Global_translator::prepare (w);
35 set_columns (new Score_column (w), new Score_column (w));
37 break_penalty_i_ = 0;
38 post_move_processing();
41 void
42 Score_engraver::finish()
44 if ((breaks_i_%8))
45 *mlog << "[" << breaks_i_ << "]" << flush;
47 check_removal();
48 removal_processing();
51 void
52 Score_engraver::do_creation_processing()
54 scoreline_l_ = pscore_p_->super_elem_l_->line_of_score_l_;
55 scoreline_l_->set_bounds(LEFT,get_staff_info().command_pcol_l ());
56 command_column_l_->breakable_b_ = true;
57 Engraver_group_engraver::do_creation_processing();
60 void
61 Score_engraver::do_removal_processing()
63 Engraver_group_engraver::do_removal_processing();
64 scoreline_l_->set_bounds(RIGHT,get_staff_info().command_pcol_l ());
65 command_column_l_->breakable_b_ = true;
67 typeset_all ();
68 set_columns (0,0);
71 void
72 Score_engraver::process()
74 process_requests();
75 do_announces();
76 pre_move_processing();
77 check_removal();
80 void
81 Score_engraver::announce_element (Score_elem_info info)
83 announce_info_arr_.push (info);
84 info.origin_grav_l_arr_.push (this);
87 void
88 Score_engraver::do_announces()
90 /* All elements are propagated to the top upon announcement. If
91 something was created during one run of
92 Engraver_group_engraver::do_announces, then
93 announce_info_arr_.size() will be nonzero again
96 while (announce_info_arr_.size())
98 for (int i=0; i < announce_info_arr_.size(); i++)
100 TODO
102 More subtle spacing
104 if (announce_info_arr_[i].req_l_)
106 Musical_req *m = announce_info_arr_[i].req_l_->musical();
107 if (m && m->rhythmic())
109 musical_column_l_->add_duration (m->duration());
112 Engraver_group_engraver::do_announces();
117 void
118 Score_engraver::typeset_element (Score_elem *elem_p)
120 elem_p_arr_.push(elem_p);
123 void
124 Score_engraver::typeset_all()
126 for (int i =0; i < elem_p_arr_.size(); i++)
128 Score_elem * elem_p = elem_p_arr_[i];
129 if (elem_p->spanner())
131 Spanner *s = elem_p->spanner ();
132 pscore_p_->typeset_unbroken_spanner (s);
137 do something sensible if spanner not
138 spanned on 2 items.
140 Direction d = LEFT;
141 do {
142 if (!s->spanned_drul_[d])
144 s->set_bounds(d, command_column_l_);
145 ::warning ("Unbound spanner (type " + String (s->name ()) + ")");
147 } while (flip(&d) != LEFT);
149 else
151 Item *item_p = elem_p->item();
152 pscore_p_->typeset_element (item_p);
153 if (!item_p->axis_group_l_a_[X_AXIS]) {
154 if (item_p->breakable_b_)
155 command_column_l_->add_element(item_p);
156 else
157 musical_column_l_->add_element(item_p);
160 scoreline_l_->add (elem_p);
162 elem_p_arr_.clear();
165 void
166 Score_engraver::do_pre_move_processing()
168 if (break_penalty_i_ > Break_req::DISALLOW)
170 get_staff_info().command_pcol_l ()-> breakable_b_ = true;
171 breaks_i_ ++;
172 if (! (breaks_i_%8))
173 *mlog << "[" << breaks_i_ << "]" << flush;
175 // this generates all items.
176 Engraver_group_engraver::do_pre_move_processing();
178 typeset_all();
181 void
182 Score_engraver::set_columns (Score_column *new_command_l,
183 Score_column *new_musical_l)
185 if (command_column_l_ && command_column_l_->linked_b())
187 pscore_p_->add_column (command_column_l_);
188 scoreline_l_->add (command_column_l_);
190 else
192 delete command_column_l_ ;
193 command_column_l_ =0;
195 if (new_command_l)
197 command_column_l_ = new_command_l;
198 command_column_l_->musical_b_ = false;
200 if (musical_column_l_ && musical_column_l_->linked_b())
202 pscore_p_->add_column (musical_column_l_);
203 scoreline_l_->add (musical_column_l_);
205 else
207 delete musical_column_l_;
208 musical_column_l_ = 0;
211 if (new_musical_l)
213 musical_column_l_ = new_musical_l;
214 musical_column_l_->musical_b_ = true;
219 Staff_info
220 Score_engraver::get_staff_info() const
222 Staff_info inf = Engraver_group_engraver::get_staff_info();
224 inf.command_l_ = command_column_l_;
225 inf.musical_l_ = musical_column_l_;
227 return inf;
232 Music_output*
233 Score_engraver::get_output_p ()
235 Music_output * o = pscore_p_;
236 pscore_p_=0;
237 return o;
240 bool
241 Score_engraver::do_try_request (Request*r)
243 bool gotcha = Engraver_group_engraver::do_try_request (r);
245 if (gotcha || !r->command ())
246 return gotcha;
248 Command_req * c = r->command ();
249 if (c->linebreak ())
251 Break_req* b = (Break_req*)c->linebreak ();
252 if (b->penalty_i_ <= Break_req::DISALLOW)
253 break_penalty_i_ = b->penalty_i_;
254 else if (b->penalty_i_ >= Break_req::FORCE)
256 command_column_l_->break_penalty_i_ = b->penalty_i_;
257 gotcha = true;
260 return gotcha;
263 IMPLEMENT_IS_TYPE_B1(Score_engraver,Engraver_group_engraver);
264 ADD_THIS_TRANSLATOR(Score_engraver);
266 void
267 Score_engraver::do_add_processing ()
269 Translator_group::do_add_processing ();
270 assert (output_def_l_->is_type_b (Paper_def::static_name ()));
271 assert (!daddy_trans_l_);
272 pscore_p_ = new Paper_score;
273 pscore_p_->paper_l_ = (Paper_def*)output_def_l_;