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>
10 #include "super-element.hh"
14 #include "paper-def.hh"
15 #include "line-of-score.hh"
20 #include "tex-stream.hh"
23 #include "word-wrap.hh"
24 #include "gourlay-breaking.hh"
25 #include "tex-outputter.hh"
26 #include "file-results.hh"
29 // sucking Cygnus egcs - w32
33 Paper_score::Paper_score ()
36 super_elem_l_ = new Super_elem;
37 typeset_element (super_elem_l_);
40 Paper_score::~Paper_score ()
42 super_elem_l_->unlink_all ();
43 for (PCursor<Score_element*> i(elem_p_list_.top()); i.ok(); i++)
44 assert(!i->linked_b());
48 Paper_score::typeset_element (Score_element * elem_p)
50 elem_p_list_.bottom ().add (elem_p);
51 elem_p->pscore_l_ = this;
53 elem_p->add_processing ();
57 Paper_score::typeset_broken_spanner (Spanner*span_p)
59 typeset_element (span_p);
64 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
66 span_p_list_.bottom ().add (span_p);
67 span_p->pscore_l_=this;
69 // do not init start/stop fields. These are for broken spans only.
70 span_p->add_processing ();
75 Paper_score::clean_cols ()
78 for (iter_top (col_p_list_,c); c.ok ();)
80 c->set_rank (rank_i++);
86 Paper_score::add_column (Paper_column *p)
88 col_p_list_.bottom ().add (p);
95 Paper_score::print () const
100 DOUT << "Paper_score { ";
101 DOUT << "\n elements: ";
102 for (iter_top (elem_p_list_,cc); cc.ok (); cc++)
104 DOUT << "\n unbroken spanners: ";
105 for (iter (span_p_list_.top (), i); i.ok (); i++)
112 PCursor<Paper_column *>
113 Paper_score::find_col (Paper_column const *c) const
115 Paper_column const *what = c;
117 return col_p_list_.find ((Paper_column*)what);
122 Paper_score::set_breaking (Array<Column_x_positions> const &breaking)
124 super_elem_l_->line_of_score_l_->set_breaking (breaking);
125 super_elem_l_->break_processing ();
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 =i->access_Item ();
144 if (i_l && !i_l->line_l ())
147 Score_element * item_p= i.remove_p ();
156 Paper_score::calc_breaking ()
158 Break_algorithm *algorithm_p=0;
159 Array<Column_x_positions> sol;
160 bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
164 algorithm_p = new Gourlay_breaking ;
165 algorithm_p->set_pscore (this);
166 sol = algorithm_p->solve ();
170 warning (_ ("Can't solve this casting problem exactly; revert to Word_wrap"));
176 algorithm_p = new Word_wrap;
177 algorithm_p->set_pscore (this);
178 sol = algorithm_p->solve ();
185 Paper_score::process ()
189 *mlog << _ ("Preprocessing elements...") << " " << flush;
190 super_elem_l_->breakable_col_processing ();
191 super_elem_l_->pre_processing ();
193 *mlog << '\n' << _ ("Calculating column positions...") << " " << flush;
194 super_elem_l_->space_processing ();
197 *mlog << _ ("Postprocessing elements...") << " " << endl;
198 super_elem_l_->post_processing ();
204 Paper_score::tex_output ()
207 String base_outname = paper_l_->outfile_str_ ;
208 if (base_outname.empty_b ())
210 base_outname = default_outname_base_global;
211 int def = paper_l_->get_next_default_count ();
214 base_outname += "-" + to_str (def);
218 String outname = base_outname;
221 target_str_global_array.push (outname);
223 *mlog << _f ("TeX output to %s...",
224 outname == "-" ? String ("<stdout>") : outname ) << endl;
226 Tex_stream tex_out (outname);
227 Tex_outputter interfees (&tex_out);
229 outputter_l_ = &interfees;
233 tex_out << header_global_p->TeX_string ();
237 tex_out << _ ("% outputting Score, defined at: ") << origin_str_ << '\n';
241 tex_out << header_l_->TeX_string();
243 tex_out << paper_l_->TeX_output_settings_str ();
246 if (experimental_features_global_b)
247 tex_out << "\\turnOnExperimentalFeatures%\n";
249 tex_out << "\\turnOnPostScript%\n";
250 super_elem_l_->output_all ();
251 tex_out << "\n\\EndLilyPondOutput";
255 /** Get all breakable columns between l and r, (not counting l and r). */
256 Link_array<Paper_column>
257 Paper_score::breakable_col_range (Paper_column*l, Paper_column*r) const
259 Link_array<Paper_column> ret;
261 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
262 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
265 ugh! windows-suck-suck-suck.
267 while (PCursor<Paper_column*>::compare (start,stop) < 0)
269 if (start->breakable_b_)
278 Link_array<Paper_column>
279 Paper_score::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 ());
288 ugh! windows-suck-suck-suck.
290 while (PCursor<Paper_column*>::compare (start,stop) < 0)
297 Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
299 Link_array<Item> ret;
300 Item const*l=l_item_l;
301 Item const*r=r_item_l;
303 while (! l->is_type_b(Paper_column::static_name ()))
304 l = l->axis_group_l_a_[X_AXIS]->access_Score_element ()->access_Item ();
306 while (! r->is_type_b(Paper_column::static_name ()))
307 r = r->axis_group_l_a_[X_AXIS]->access_Score_element ()->access_Item ();
309 PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
310 PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
313 ugh! windows-suck-suck-suck.
315 while (PCursor<Paper_column*>::compare (start,stop) < 0)
317 if (start->breakable_b_ && !start->line_l_)