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>
9 #include "super-elem.hh"
13 #include "paper-def.hh"
14 #include "scoreline.hh"
16 #include "tex-stream.hh"
19 #include "word-wrap.hh"
20 #include "gourlay-breaking.hh"
22 Paper_score::Paper_score ()
24 super_elem_l_ = new Super_elem;
25 typeset_element (super_elem_l_);
28 Paper_score::~Paper_score ()
30 super_elem_l_->unlink_all ();
31 for (PCursor<Score_elem*> i(elem_p_list_.top()); i.ok(); i++)
32 assert(!i->linked_b());
36 Paper_score::typeset_element (Score_elem * elem_p)
38 elem_p_list_.bottom ().add (elem_p);
39 elem_p->pscore_l_ = this;
41 elem_p->add_processing ();
45 Paper_score::typeset_broken_spanner (Spanner*span_p)
47 typeset_element (span_p);
52 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
54 span_p_list_.bottom ().add (span_p);
55 span_p->pscore_l_=this;
58 // do not init start/stop fields. These are for broken spans only.
59 span_p->add_processing ();
64 Paper_score::clean_cols ()
67 for (iter_top (col_p_list_,c); c.ok ();)
69 c->set_rank (rank_i++);
75 Paper_score::add_column (Paper_column *p)
77 col_p_list_.bottom ().add (p);
84 Paper_score::OK () const
87 for (PCursor<Score_elem*> i (elem_p_list_.top ()); i.ok (); i++)
93 Paper_score::print () const
98 DOUT << "Paper_score { ";
99 DOUT << "\n elements: ";
100 for (iter_top (elem_p_list_,cc); cc.ok (); cc++)
102 DOUT << "\n unbroken spanners: ";
103 for (iter (span_p_list_.top (), i); i.ok (); i++)
111 Paper_score::preprocess ()
113 super_elem_l_->breakable_col_processing ();
114 super_elem_l_->pre_processing ();
118 Paper_score::postprocess ()
120 super_elem_l_->post_processing ();
121 super_elem_l_->molecule_processing ();
124 PCursor<Paper_column *>
125 Paper_score::find_col (Paper_column const *c) const
127 Paper_column const *what = c;
129 return col_p_list_.find ((Paper_column*)what);
134 Paper_score::set_breaking (Array<Col_hpositions> const &breaking)
136 super_elem_l_->line_of_score_l_->set_breaking (breaking);
137 super_elem_l_->break_processing ();
140 for (iter (span_p_list_.top (),i); i.ok ();)
142 Spanner *span_p = i.remove_p ();
143 if (span_p->broken_b ())
149 typeset_broken_spanner (span_p);
152 for (iter (elem_p_list_.top (),i); i.ok () ;)
154 Item *i_l =i->item ();
155 if (i_l && !i_l->line_l ())
158 delete i.remove_p ();
166 Paper_score::calc_breaking ()
168 Break_algorithm *algorithm_p=0;
169 Array<Col_hpositions> sol;
170 bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
174 algorithm_p = new Gourlay_breaking ;
175 algorithm_p->set_pscore (this);
176 sol = algorithm_p->solve ();
180 warning ("Can not solve this casting problem exactly; revert to Word_wrap");
186 algorithm_p = new Word_wrap;
187 algorithm_p->set_pscore (this);
188 sol = algorithm_p->solve ();
195 Paper_score::process ()
199 *mlog << "Preprocessing elements... " <<flush;
201 *mlog << "\nCalculating column positions ... " <<flush;
203 *mlog << "\nPostprocessing elements..." << endl;
207 String outname = paper_l_->outfile_str_ ;
209 outname = default_out_str_+ ".tex";
211 *mlog << "TeX output to " << outname << " ...\n";
213 Tex_stream the_output (outname);
215 the_output << "% outputting Score, defined at: " << origin_str_ << "\n";
218 the_output << header_l_->TeX_string();
221 the_output << "\n "<< paper_l_->lookup_l ()->texsetting << "%(Tex id)\n";
222 the_output<< super_elem_l_->TeX_output_str ();
223 the_output << "\n\\EndLilyPondOutput";
226 /** Get all breakable columns between l and r, (not counting l and r). */
227 Link_array<Paper_column>
228 Paper_score::breakable_col_range (Paper_column*l,Paper_column*r) const
230 Link_array<Paper_column> ret;
232 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
233 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
236 ugh! windows-suck-suck-suck.
238 while (PCursor<Paper_column*>::compare (start,stop) < 0)
240 if (start->breakable_b_)
247 Link_array<Paper_column>
248 Paper_score::col_range (Paper_column*l, Paper_column*r) const
250 Link_array<Paper_column> ret;
252 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
253 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
257 ugh! windows-suck-suck-suck.
259 while (PCursor<Paper_column*>::compare (start,stop) < 0)
266 Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
268 Link_array<Item> ret;
269 Item const*l=l_item_l;
270 Item const*r=r_item_l;
272 while (! l->is_type_b(Paper_column::static_name ()))
273 l = l->axis_group_l_a_[X_AXIS]->item ();
275 while (! r->is_type_b(Paper_column::static_name ()))
276 r = r->axis_group_l_a_[X_AXIS]->item ();
278 PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
279 PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
282 ugh! windows-suck-suck-suck.
284 while (PCursor<Paper_column*>::compare (start,stop) < 0)
286 if (start->breakable_b_ && !start->line_l_)