2 p-score.cc -- implement Paper_score
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "paper-def.hh"
14 #include "line-of-score.hh"
21 #include "word-wrap.hh"
22 #include "gourlay-breaking.hh"
23 #include "paper-stream.hh"
24 #include "paper-outputter.hh"
25 #include "file-results.hh"
28 //#if 0 // has w32 advanced?
29 #if 1 // cygwin-b20: nope
30 // sucking Cygnus egcs - w32
35 Paper_score::Paper_score ()
38 Line_of_score * line_p = new Line_of_score;
39 typeset_unbroken_spanner (line_p);
44 Paper_score::~Paper_score ()
47 for (int i=0; i< line_l_arr_.size (); i++)
48 line_l_arr_[i]->unlink_all ();
50 for (PCursor<Score_element*> i(elem_p_list_.top()); i.ok(); i++)
55 assert (! i->linked_b ());
61 Paper_score::typeset_element (Score_element * elem_p)
63 elem_p_list_.bottom ().add (elem_p);
64 elem_p->pscore_l_ = this;
65 elem_p->add_processing ();
69 Paper_score::typeset_broken_spanner (Spanner*span_p)
71 typeset_element (span_p);
76 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
78 span_p_list_.bottom ().add (span_p);
79 span_p->pscore_l_=this;
81 // do not init start/stop fields. These are for broken spans only.
82 span_p->add_processing ();
87 Paper_score::clean_cols ()
90 for (iter_top (col_p_list_,c); c.ok ();)
92 c->set_rank (rank_i++);
98 Paper_score::add_column (Paper_column *p)
100 col_p_list_.bottom ().add (p);
107 Paper_score::print () const
112 DOUT << "Paper_score { ";
113 DOUT << "\n elements: ";
114 for (iter_top (elem_p_list_,cc); cc.ok (); cc++)
116 DOUT << "\n unbroken spanners: ";
117 for (iter (span_p_list_.top (), i); i.ok (); i++)
124 PCursor<Paper_column *>
125 Paper_score::find_col (Paper_column const *c) const
127 Paper_column const *what = c;
129 return col_p_list_.find ((Paper_column*)what);
135 Paper_score::set_breaking (Array<Column_x_positions> const &breaking)
137 for (iter (span_p_list_.top (),i); i.ok ();)
139 Spanner *span_p = i.remove_p ();
140 if (span_p->broken_b ()
141 || !((Score_element*)span_p)->line_l ())
148 typeset_broken_spanner (span_p);
151 for (iter (elem_p_list_.top (),i); i.ok () ;)
153 Item *i_l =dynamic_cast <Item *> (i);
154 if (i_l && !i_l->line_l ())
157 Score_element * item_p= i.remove_p ();
167 Array<Column_x_positions>
168 Paper_score::calc_breaking ()
170 Break_algorithm *algorithm_p=0;
171 Array<Column_x_positions> sol;
172 bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
176 algorithm_p = new Gourlay_breaking ;
177 algorithm_p->set_pscore (this);
178 sol = algorithm_p->solve ();
182 warning (_ ("Can't solve this casting problem exactly; revert to Word_wrap"));
188 algorithm_p = new Word_wrap;
189 algorithm_p->set_pscore (this);
190 sol = algorithm_p->solve ();
199 Paper_score::process ()
203 *mlog << _ ("Preprocessing elements...") << " " << flush;
204 line_l_->breakable_col_processing ();
205 line_l_->pre_processing ();
207 *mlog << '\n' << _ ("Calculating column positions...") << " " << flush;
208 line_l_->space_processing ();
210 Array<Column_x_positions> breaking = calc_breaking ();
212 Paper_stream* paper_stream_p = paper_l_->paper_stream_p ();
213 outputter_l_ = paper_l_->paper_outputter_p (paper_stream_p, header_l_, origin_str_);
215 Link_array<Line_of_score> lines;
216 for (int i=0; i < breaking.size (); i++)
218 Line_of_score *line_l = line_l_->set_breaking (breaking, i);
220 if (line_l != line_l_)
221 typeset_broken_spanner (line_l);
225 *mlog << "\nLine ... ";
226 for (int i=0; i < lines.size (); i++)
228 *mlog << '[' << flush;
230 Line_of_score *line_l = lines[i];
231 line_l->break_processing ();
232 line_l->post_processing ();
234 line_l->output_all ();
235 *mlog << ']' << flush;
236 remove_line (line_l);
241 delete paper_stream_p;
244 *mlog << '\n' << flush;
248 Paper_score::remove_line (Line_of_score *l)
250 Link_array<Score_element> to_remove;
251 for (PCursor<Score_element*> i(elem_p_list_.top ()); i.ok (); )
253 if (i->line_l () == l)
254 to_remove.push (i.remove_p ());
259 for (PCursor<Spanner*> i (span_p_list_.top ()); i.ok (); )
261 Score_element *e = i.ptr ();
262 if (e->line_l () == l)
263 to_remove.push (i.remove_p ());
269 for (int i=0; i < to_remove.size (); i++)
271 to_remove[i]->unlink ();
272 assert (!to_remove[i]->linked_b ());
273 delete to_remove [i];
277 /** Get all breakable columns between l and r, (not counting l and r). */
278 Link_array<Paper_column>
279 Paper_score::breakable_col_range (Paper_column*l, Paper_column*r) const
281 Link_array<Paper_column> ret;
283 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
284 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
287 ugh! windows-suck-suck-suck.
289 while (PCursor<Paper_column*>::compare (start,stop) < 0)
291 if (start->breakable_b_)
300 Link_array<Paper_column>
301 Paper_score::col_range (Paper_column*l, Paper_column*r) const
303 Link_array<Paper_column> ret;
305 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
306 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
310 ugh! windows-suck-suck-suck.
312 while (PCursor<Paper_column*>::compare (start,stop) < 0)
319 Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
321 Link_array<Item> ret;
322 Item const*l=l_item_l;
323 Item const*r=r_item_l;
325 // huh? see Item::left_right_compare ()
326 while (! (dynamic_cast<Paper_column const *> (l)))
327 l = dynamic_cast<Item*> (l->axis_group_l_a_[X_AXIS]);
329 while (! (dynamic_cast<Paper_column const *> (r)))
330 r = dynamic_cast<Item*>(r->axis_group_l_a_[X_AXIS]);
332 PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
333 PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
336 ugh! windows-suck-suck-suck.
338 while (PCursor<Paper_column*>::compare (start,stop) < 0)
340 if (start->breakable_b_ && !start->line_l_)