2 p-score.cc -- implement Paper_score
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1999 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 Array<Column_x_positions>
126 Paper_score::calc_breaking ()
128 Break_algorithm *algorithm_p=0;
129 Array<Column_x_positions> sol;
130 bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
134 algorithm_p = new Gourlay_breaking ;
135 algorithm_p->set_pscore (this);
136 sol = algorithm_p->solve ();
140 warning (_ ("Can't solve this casting problem exactly; revert to Word_wrap"));
146 algorithm_p = new Word_wrap;
147 algorithm_p->set_pscore (this);
148 sol = algorithm_p->solve ();
157 Paper_score::process ()
161 *mlog << _ ("Preprocessing elements...") << " " << flush;
162 line_l_->breakable_col_processing ();
163 line_l_->pre_processing ();
165 *mlog << '\n' << _ ("Calculating column positions...") << " " << flush;
166 line_l_->space_processing ();
168 Array<Column_x_positions> breaking = calc_breaking ();
170 Paper_stream* paper_stream_p = paper_l_->paper_stream_p ();
171 outputter_l_ = paper_l_->paper_outputter_p (paper_stream_p, header_l_, origin_str_);
173 Link_array<Line_of_score> lines;
174 for (int i=0; i < breaking.size (); i++)
176 Line_of_score *line_l = line_l_->set_breaking (breaking, i);
178 if (line_l != line_l_)
179 typeset_broken_spanner (line_l);
183 *mlog << "\nLine ... ";
184 for (int i=0; i < lines.size (); i++)
186 *mlog << '[' << flush;
188 Line_of_score *line_l = lines[i];
189 line_l->break_processing ();
190 line_l->post_processing ();
192 line_l->output_all ();
193 *mlog << ']' << flush;
194 remove_line (line_l);
199 delete paper_stream_p;
202 *mlog << '\n' << flush;
206 Paper_score::remove_line (Line_of_score *l)
208 Link_array<Score_element> to_remove;
209 for (PCursor<Score_element*> i(elem_p_list_.top ()); i.ok (); )
211 if (i->line_l () == l)
212 to_remove.push (i.remove_p ());
217 for (PCursor<Spanner*> i (span_p_list_.top ()); i.ok (); )
219 Score_element *e = i.ptr ();
220 if (e->line_l () == l)
221 to_remove.push (i.remove_p ());
227 for (int i=0; i < to_remove.size (); i++)
229 to_remove[i]->unlink ();
230 assert (!to_remove[i]->linked_b ());
231 delete to_remove [i];
235 /** Get all breakable columns between l and r, (not counting l and r). */
236 Link_array<Paper_column>
237 Paper_score::breakable_col_range (Paper_column*l, Paper_column*r) const
239 Link_array<Paper_column> ret;
241 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
242 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
245 ugh! windows-suck-suck-suck.
247 while (PCursor<Paper_column*>::compare (start,stop) < 0)
249 if (start->breakable_b_)
258 Link_array<Paper_column>
259 Paper_score::col_range (Paper_column*l, Paper_column*r) const
261 Link_array<Paper_column> ret;
263 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
264 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
268 ugh! windows-suck-suck-suck.
270 while (PCursor<Paper_column*>::compare (start,stop) < 0)
277 Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
279 Link_array<Item> ret;
280 Item const*l=l_item_l;
281 Item const*r=r_item_l;
283 // huh? see Item::left_right_compare ()
285 while (! (dynamic_cast<Paper_column const *> (l)))
286 l = dynamic_cast<Item*> (l->axis_group_l_a_[X_AXIS]);
288 while (! (dynamic_cast<Paper_column const *> (r)))
289 r = dynamic_cast<Item*>(r->axis_group_l_a_[X_AXIS]);
294 PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
295 PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
298 ugh! windows-suck-suck-suck.
300 while (PCursor<Paper_column*>::compare (start,stop) < 0)
302 if (start->breakable_b_ && !start->line_l_)