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 1 // has w32 advanced?
31 // sucking Cygnus egcs - w32
37 Paper_score::Paper_score ()
40 Line_of_score * line_p = new Line_of_score;
41 typeset_unbroken_spanner (line_p);
46 Paper_score::~Paper_score ()
51 Paper_score::typeset_element (Score_element * elem_p)
53 elem_p_list_.bottom ().add (elem_p);
54 elem_p->pscore_l_ = this;
55 elem_p->add_processing ();
59 Paper_score::typeset_broken_spanner (Spanner*span_p)
61 typeset_element (span_p);
66 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
68 span_p_list_.bottom ().add (span_p);
69 span_p->pscore_l_=this;
71 // do not init start/stop fields. These are for broken spans only.
72 span_p->add_processing ();
77 Paper_score::clean_cols ()
80 for (iter_top (col_p_list_,c); c.ok ();)
82 c->set_rank (rank_i++);
88 Paper_score::add_column (Paper_column *p)
90 col_p_list_.bottom ().add (p);
97 Paper_score::print () const
102 DOUT << "Paper_score { ";
103 DOUT << "\n elements: ";
104 for (iter_top (elem_p_list_,cc); cc.ok (); cc++)
106 DOUT << "\n unbroken spanners: ";
107 for (iter (span_p_list_.top (), i); i.ok (); i++)
114 PCursor<Paper_column *>
115 Paper_score::find_col (Paper_column const *c) const
117 Paper_column const *what = c;
119 return col_p_list_.find ((Paper_column*)what);
125 Paper_score::set_breaking (Array<Column_x_positions> const &breaking)
127 for (iter (span_p_list_.top (),i); i.ok ();)
129 Spanner *span_p = i.remove_p ();
130 if (span_p->broken_b ()
131 || !((Score_element*)span_p)->line_l ())
138 typeset_broken_spanner (span_p);
141 for (iter (elem_p_list_.top (),i); i.ok () ;)
143 Item *i_l =dynamic_cast <Item *> (i);
144 if (i_l && !i_l->line_l ())
147 Score_element * item_p= i.remove_p ();
157 Array<Column_x_positions>
158 Paper_score::calc_breaking ()
160 Break_algorithm *algorithm_p=0;
161 Array<Column_x_positions> sol;
162 bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
166 algorithm_p = new Gourlay_breaking ;
167 algorithm_p->set_pscore (this);
168 sol = algorithm_p->solve ();
172 warning (_ ("Can't solve this casting problem exactly; revert to Word_wrap"));
178 algorithm_p = new Word_wrap;
179 algorithm_p->set_pscore (this);
180 sol = algorithm_p->solve ();
189 Paper_score::process ()
193 *mlog << _ ("Preprocessing elements...") << " " << flush;
194 line_l_->breakable_col_processing ();
195 line_l_->pre_processing ();
197 *mlog << '\n' << _ ("Calculating column positions...") << " " << flush;
198 line_l_->space_processing ();
200 Array<Column_x_positions> breaking = calc_breaking ();
202 Paper_stream* paper_stream_p = paper_l_->paper_stream_p ();
203 outputter_l_ = paper_l_->paper_outputter_p (paper_stream_p, header_l_, origin_str_);
205 Link_array<Line_of_score> lines;
206 for (int i=0; i < breaking.size (); i++)
208 Line_of_score *line_l = line_l_->set_breaking (breaking, i);
210 if (line_l != line_l_)
211 typeset_broken_spanner (line_l);
215 *mlog << "\nLine ... ";
216 for (int i=0; i < lines.size (); i++)
218 *mlog << '[' << flush;
220 Line_of_score *line_l = lines[i];
221 line_l->break_processing ();
222 line_l->post_processing ();
224 line_l->output_all ();
225 *mlog << ']' << flush;
226 remove_line (line_l);
231 delete paper_stream_p;
234 *mlog << '\n' << flush;
238 Paper_score::remove_line (Line_of_score *l)
240 Link_array<Score_element> to_remove;
241 for (PCursor<Score_element*> i(elem_p_list_.top ()); i.ok (); )
243 if (i->line_l () == l)
244 to_remove.push (i.remove_p ());
249 for (PCursor<Spanner*> i (span_p_list_.top ()); i.ok (); )
251 Score_element *e = i.ptr ();
252 if (e->line_l () == l)
253 to_remove.push (i.remove_p ());
259 for (int i=0; i < to_remove.size (); i++)
261 to_remove[i]->unlink ();
262 assert (!to_remove[i]->linked_b ());
263 delete to_remove [i];
267 /** Get all breakable columns between l and r, (not counting l and r). */
268 Link_array<Paper_column>
269 Paper_score::breakable_col_range (Paper_column*l, Paper_column*r) const
271 Link_array<Paper_column> ret;
273 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
274 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
277 ugh! windows-suck-suck-suck.
279 while (PCursor<Paper_column*>::compare (start,stop) < 0)
281 if (start->breakable_b_)
290 Link_array<Paper_column>
291 Paper_score::col_range (Paper_column*l, Paper_column*r) const
293 Link_array<Paper_column> ret;
295 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
296 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
300 ugh! windows-suck-suck-suck.
302 while (PCursor<Paper_column*>::compare (start,stop) < 0)
309 Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
311 Link_array<Item> ret;
312 Item const*l=l_item_l;
313 Item const*r=r_item_l;
315 // huh? see Item::left_right_compare ()
317 while (! (dynamic_cast<Paper_column const *> (l)))
318 l = dynamic_cast<Item*> (l->axis_group_l_a_[X_AXIS]);
320 while (! (dynamic_cast<Paper_column const *> (r)))
321 r = dynamic_cast<Item*>(r->axis_group_l_a_[X_AXIS]);
326 PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
327 PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
330 ugh! windows-suck-suck-suck.
332 while (PCursor<Paper_column*>::compare (start,stop) < 0)
334 if (start->breakable_b_ && !start->line_l_)