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 "ps-stream.hh"
25 #include "tex-stream.hh"
26 #include "paper-outputter.hh"
27 #include "ps-outputter.hh"
28 #include "tex-outputter.hh"
29 #include "file-results.hh"
32 // sucking Cygnus egcs - w32
36 Paper_score::Paper_score ()
39 Line_of_score * line_p = new Line_of_score;
40 typeset_unbroken_spanner (line_p);
45 Paper_score::~Paper_score ()
48 for (int i=0; i< line_l_arr_.size (); i++)
49 line_l_arr_[i]->unlink_all ();
51 for (PCursor<Score_element*> i(elem_p_list_.top()); i.ok(); i++)
56 assert (! i->linked_b ());
62 Paper_score::base_output_str () const
65 String str = paper_l_->get_default_output ();
69 str = default_outname_base_global;
70 int def = paper_l_->get_next_default_count ();
72 str += "-" + to_str (def);
78 Paper_score::typeset_element (Score_element * elem_p)
80 elem_p_list_.bottom ().add (elem_p);
81 elem_p->pscore_l_ = this;
82 elem_p->add_processing ();
86 Paper_score::typeset_broken_spanner (Spanner*span_p)
88 typeset_element (span_p);
93 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
95 span_p_list_.bottom ().add (span_p);
96 span_p->pscore_l_=this;
98 // do not init start/stop fields. These are for broken spans only.
99 span_p->add_processing ();
104 Paper_score::clean_cols ()
107 for (iter_top (col_p_list_,c); c.ok ();)
109 c->set_rank (rank_i++);
115 Paper_score::add_column (Paper_column *p)
117 col_p_list_.bottom ().add (p);
124 Paper_score::print () const
129 DOUT << "Paper_score { ";
130 DOUT << "\n elements: ";
131 for (iter_top (elem_p_list_,cc); cc.ok (); cc++)
133 DOUT << "\n unbroken spanners: ";
134 for (iter (span_p_list_.top (), i); i.ok (); i++)
141 PCursor<Paper_column *>
142 Paper_score::find_col (Paper_column const *c) const
144 Paper_column const *what = c;
146 return col_p_list_.find ((Paper_column*)what);
152 Paper_score::set_breaking (Array<Column_x_positions> const &breaking)
154 for (iter (span_p_list_.top (),i); i.ok ();)
156 Spanner *span_p = i.remove_p ();
157 if (span_p->broken_b ()
158 || !((Score_element*)span_p)->line_l ())
165 typeset_broken_spanner (span_p);
168 for (iter (elem_p_list_.top (),i); i.ok () ;)
170 Item *i_l =i->access_Item ();
171 if (i_l && !i_l->line_l ())
174 Score_element * item_p= i.remove_p ();
184 Array<Column_x_positions>
185 Paper_score::calc_breaking ()
187 Break_algorithm *algorithm_p=0;
188 Array<Column_x_positions> sol;
189 bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
193 algorithm_p = new Gourlay_breaking ;
194 algorithm_p->set_pscore (this);
195 sol = algorithm_p->solve ();
199 warning (_ ("Can't solve this casting problem exactly; revert to Word_wrap"));
205 algorithm_p = new Word_wrap;
206 algorithm_p->set_pscore (this);
207 sol = algorithm_p->solve ();
214 Paper_score::process ()
218 *mlog << _ ("Preprocessing elements...") << " " << flush;
219 line_l_->breakable_col_processing ();
220 line_l_->pre_processing ();
222 *mlog << '\n' << _ ("Calculating column positions...") << " " << flush;
223 line_l_->space_processing ();
225 Array<Column_x_positions> breaking = calc_breaking ();
227 Paper_stream* pstream_p = paper_stream_p ();
228 outputter_l_ = paper_outputter_p (pstream_p);
230 Link_array<Line_of_score> lines;
231 for (int i=0; i < breaking.size (); i++)
233 Line_of_score *line_l = line_l_->set_breaking (breaking, i);
235 if (line_l != line_l_)
236 typeset_broken_spanner (line_l);
240 *mlog << "\nLine ... ";
241 for (int i=0; i < lines.size (); i++)
243 *mlog << '[' << flush;
245 Line_of_score *line_l = lines[i];
246 line_l->break_processing ();
247 line_l->post_processing ();
249 line_l->output_all ();
250 *mlog << ']' << flush;
251 remove_line (line_l);
262 Paper_score::remove_line (Line_of_score *l)
264 Link_array<Score_element> to_remove;
265 for (PCursor<Score_element*> i(elem_p_list_.top ()); i.ok (); )
267 if (i->line_l () == l)
268 to_remove.push (i.remove_p ());
273 for (PCursor<Spanner*> i (span_p_list_.top ()); i.ok (); )
275 Score_element *e = i.ptr ();
276 if (e->line_l () == l)
277 to_remove.push (i.remove_p ());
283 for (int i=0; i < to_remove.size (); i++)
285 to_remove[i]->unlink ();
286 assert (!to_remove[i]->linked_b ());
287 delete to_remove [i];
291 /** Get all breakable columns between l and r, (not counting l and r). */
292 Link_array<Paper_column>
293 Paper_score::breakable_col_range (Paper_column*l, Paper_column*r) const
295 Link_array<Paper_column> ret;
297 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
298 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
301 ugh! windows-suck-suck-suck.
303 while (PCursor<Paper_column*>::compare (start,stop) < 0)
305 if (start->breakable_b_)
314 Link_array<Paper_column>
315 Paper_score::col_range (Paper_column*l, Paper_column*r) const
317 Link_array<Paper_column> ret;
319 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
320 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
324 ugh! windows-suck-suck-suck.
326 while (PCursor<Paper_column*>::compare (start,stop) < 0)
333 Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
335 Link_array<Item> ret;
336 Item const*l=l_item_l;
337 Item const*r=r_item_l;
339 while (! l->is_type_b(Paper_column::static_name ()))
340 l = l->axis_group_l_a_[X_AXIS]->access_Score_element ()->access_Item ();
342 while (! r->is_type_b(Paper_column::static_name ()))
343 r = r->axis_group_l_a_[X_AXIS]->access_Score_element ()->access_Item ();
345 PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
346 PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
349 ugh! windows-suck-suck-suck.
351 while (PCursor<Paper_column*>::compare (start,stop) < 0)
353 if (start->breakable_b_ && !start->line_l_)