2 p-score.cc -- implement Paper_score
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
10 #include "super-elem.hh"
14 #include "paper-def.hh"
15 #include "scoreline.hh"
17 #include "tex-stream.hh"
20 #include "word-wrap.hh"
21 #include "gourlay-breaking.hh"
22 #include "outputter.hh"
24 Paper_score::Paper_score ()
27 super_elem_l_ = new Super_elem;
28 typeset_element (super_elem_l_);
31 Paper_score::~Paper_score ()
33 super_elem_l_->unlink_all ();
34 for (PCursor<Score_elem*> i(elem_p_list_.top()); i.ok(); i++)
35 assert(!i->linked_b());
39 Paper_score::typeset_element (Score_elem * elem_p)
41 elem_p_list_.bottom ().add (elem_p);
42 elem_p->pscore_l_ = this;
44 elem_p->add_processing ();
48 Paper_score::typeset_broken_spanner (Spanner*span_p)
50 typeset_element (span_p);
55 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
57 span_p_list_.bottom ().add (span_p);
58 span_p->pscore_l_=this;
60 // do not init start/stop fields. These are for broken spans only.
61 span_p->add_processing ();
66 Paper_score::clean_cols ()
69 for (iter_top (col_p_list_,c); c.ok ();)
71 c->set_rank (rank_i++);
77 Paper_score::add_column (Paper_column *p)
79 col_p_list_.bottom ().add (p);
86 Paper_score::print () const
91 DOUT << "Paper_score { ";
92 DOUT << "\n elements: ";
93 for (iter_top (elem_p_list_,cc); cc.ok (); cc++)
95 DOUT << "\n unbroken spanners: ";
96 for (iter (span_p_list_.top (), i); i.ok (); i++)
103 PCursor<Paper_column *>
104 Paper_score::find_col (Paper_column const *c) const
106 Paper_column const *what = c;
108 return col_p_list_.find ((Paper_column*)what);
113 Paper_score::set_breaking (Array<Col_hpositions> const &breaking)
115 super_elem_l_->line_of_score_l_->set_breaking (breaking);
116 super_elem_l_->break_processing ();
119 for (iter (span_p_list_.top (),i); i.ok ();)
121 Spanner *span_p = i.remove_p ();
122 if (span_p->broken_b ())
128 typeset_broken_spanner (span_p);
131 for (iter (elem_p_list_.top (),i); i.ok () ;)
133 Item *i_l =i->item ();
134 if (i_l && !i_l->line_l ())
137 delete i.remove_p ();
145 Paper_score::calc_breaking ()
147 Break_algorithm *algorithm_p=0;
148 Array<Col_hpositions> sol;
149 bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
153 algorithm_p = new Gourlay_breaking ;
154 algorithm_p->set_pscore (this);
155 sol = algorithm_p->solve ();
159 warning (_("Can not solve this casting problem exactly; revert to Word_wrap"));
165 algorithm_p = new Word_wrap;
166 algorithm_p->set_pscore (this);
167 sol = algorithm_p->solve ();
174 Paper_score::process ()
178 *mlog << _("Preprocessing elements... ") <<flush;
179 super_elem_l_->breakable_col_processing ();
180 super_elem_l_->pre_processing ();
181 *mlog << _("\nCalculating column positions ... ") <<flush;
183 *mlog << _("\nPostprocessing elements...") << endl;
184 super_elem_l_->post_processing ();
190 Paper_score::tex_output ()
193 String outname = paper_l_->outfile_str_ ;
194 if (outname.empty_b ())
195 outname = default_out_str_+ ".tex";
197 *mlog << _("TeX output to ") << outname << " ...\n";
199 Tex_stream tex_out (outname);
200 Tex_outputter interfees (&tex_out);
202 outputter_l_ = &interfees;
204 tex_out << _("% outputting Score, defined at: ") << origin_str_ << "\n";
207 tex_out << header_l_->TeX_string();
209 tex_out << paper_l_->TeX_output_settings_str ();
212 if (experimental_features_global_b)
213 tex_out << "\\turnOnExperimentalFeatures%\n";
214 super_elem_l_->output_all ();
215 tex_out << "\n\\EndLilyPondOutput";
219 /** Get all breakable columns between l and r, (not counting l and r). */
220 Link_array<Paper_column>
221 Paper_score::breakable_col_range (Paper_column*l,Paper_column*r) const
223 Link_array<Paper_column> ret;
225 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
226 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
229 ugh! windows-suck-suck-suck.
231 while (PCursor<Paper_column*>::compare (start,stop) < 0)
233 if (start->breakable_b_)
240 Link_array<Paper_column>
241 Paper_score::col_range (Paper_column*l, Paper_column*r) const
243 Link_array<Paper_column> ret;
245 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
246 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
250 ugh! windows-suck-suck-suck.
252 while (PCursor<Paper_column*>::compare (start,stop) < 0)
259 Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
261 Link_array<Item> ret;
262 Item const*l=l_item_l;
263 Item const*r=r_item_l;
265 while (! l->is_type_b(Paper_column::static_name ()))
266 l = l->axis_group_l_a_[X_AXIS]->item ();
268 while (! r->is_type_b(Paper_column::static_name ()))
269 r = r->axis_group_l_a_[X_AXIS]->item ();
271 PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
272 PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
275 ugh! windows-suck-suck-suck.
277 while (PCursor<Paper_column*>::compare (start,stop) < 0)
279 if (start->breakable_b_ && !start->line_l_)