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 (Paper_def*p)
25 super_elem_l_ = new Super_elem;
26 typeset_element (super_elem_l_);
29 Paper_score::~Paper_score()
31 super_elem_l_->unlink_all();
35 Paper_score::typeset_element (Score_elem * elem_p)
37 elem_p_list_.bottom().add (elem_p);
38 elem_p->pscore_l_ = this;
40 elem_p->add_processing();
44 Paper_score::typeset_item (Item *i, PCol *c)
47 int breakstat = i->break_status_i_;
52 }else if (breakstat == 1)
62 Paper_score::typeset_broken_spanner (Spanner*span_p)
64 span_p->left_col_l_->starters.bottom().add (span_p);
65 assert (span_p->left_col_l_->line_l_ == span_p->right_col_l_->line_l_);
67 typeset_element (span_p);
72 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
74 span_p_list_.bottom().add (span_p);
75 span_p->pscore_l_=this;
77 if (span_p->left_col_l_)
78 span_p->left_col_l_->used_b_ = true;
79 if ( span_p->right_col_l_)
80 span_p->right_col_l_->used_b_ = true;
82 // do not init start/stop fields. These are for broken spans only.
83 span_p->add_processing();
88 Paper_score::clean_cols()
91 for (iter_top (col_p_list_,c); c.ok();)
98 c->set_rank (rank_i++);
104 Paper_score::add (PCol *p)
107 if (p->breakable_b())
109 p->prebreak_p_->pscore_l_ = this;
110 p->postbreak_p_->pscore_l_ = this;
112 col_p_list_.bottom().add (p);
116 Paper_score::output (Tex_stream &ts)
118 ts << "\n "<< paper_l_->lookup_l()->texsetting << "%(Tex id)\n";
119 ts<< super_elem_l_->TeX_string();
120 ts << "\n\\EndLilyPondOutput";
125 Paper_score::OK()const
128 for (iter_top (col_p_list_,cc); cc.ok(); cc++)
130 for (PCursor<Score_elem*> i (elem_p_list_.top()); i.ok (); i++)
136 Paper_score::print() const
141 DOUT << "Paper_score { ";
143 DOUT << "\n elements: ";
144 for (iter_top (elem_p_list_,cc); cc.ok(); cc++)
146 DOUT << "\n unbroken spanners: ";
147 for (iter (span_p_list_.top(), i); i.ok (); i++)
149 DOUT << "\ncolumns: ";
150 for (iter_top (col_p_list_,cc); cc.ok(); cc++)
158 Paper_score::preprocess()
160 super_elem_l_->breakable_col_processing();
161 super_elem_l_->pre_processing();
165 Paper_score::postprocess()
167 super_elem_l_->post_processing();
168 super_elem_l_->molecule_processing();
172 Paper_score::find_col (PCol const *c)const
174 PCol const *what = c;
176 what = what->daddy_l_;
178 return col_p_list_.find ((PCol*)what);
183 Paper_score::set_breaking (Array<Col_hpositions> const &breaking)
185 super_elem_l_->line_of_score_l_->set_breaking (breaking);
186 super_elem_l_->break_processing();
189 for (iter (span_p_list_.top(),i); i.ok ();)
191 Spanner *span_p = i.remove_p();
192 if (span_p->broken_b())
198 typeset_broken_spanner (span_p);
201 for (iter (elem_p_list_.top(),i); i.ok () ;)
203 Item *i_l =i->item();
204 if ( i_l && !i_l->pcol_l_->line_l_)
213 for (iter_top (col_p_list_, i); i.ok(); i++)
214 i->clean_breakable_items();
218 Paper_score::calc_breaking()
220 Break_algorithm *algorithm_p;
221 Array<Col_hpositions> sol;
222 bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
226 algorithm_p = new Gourlay_breaking ;
227 algorithm_p->set_pscore (this);
228 sol = algorithm_p->solve();
232 warning ("Can not solve this casting problem exactly; revert to Word_wrap");
238 algorithm_p = new Word_wrap;
239 algorithm_p->set_pscore (this);
240 sol = algorithm_p->solve();
247 Paper_score::process()
251 *mlog << "Preprocessing elements... " <<flush;
253 *mlog << "\nCalculating column positions ... " <<flush;
255 *mlog << "\nPostprocessing elements..." << endl;
259 for (PCursor<Score_elem*> i (elem_p_list_.top()); i.ok (); i++)
260 assert (i->status() >= 9);
264 /** Get all breakable columns between l and r, (not counting l and r). */
266 Paper_score::breakable_col_range (PCol*l,PCol*r)const
268 Link_array<PCol> ret;
270 PCursor<PCol*> start (l ? find_col (l)+1 : col_p_list_.top());
271 PCursor<PCol*> stop (r ? find_col (r) : col_p_list_.bottom());
274 ugh! windows-suck-suck-suck.
276 while ( PCursor<PCol*>::compare (start,stop) < 0)
278 if (start->breakable_b())
286 Paper_score::col_range (PCol*l,PCol*r)const
288 Link_array<PCol> ret;
290 PCursor<PCol*> start (l ? find_col (l)+1 : col_p_list_.top());
291 PCursor<PCol*> stop (r ? find_col (r) : col_p_list_.bottom());
295 ugh! windows-suck-suck-suck.
297 while ( PCursor<PCol*>::compare (start,stop) < 0)
304 Paper_score::broken_col_range (PCol*l,PCol*r)const
306 Link_array<PCol> ret;
308 PCursor<PCol*> start (l ? find_col (l)+1 : col_p_list_.top());
309 PCursor<PCol*> stop (r ? find_col (r) : col_p_list_.bottom());
312 ugh! windows-suck-suck-suck.
314 while ( PCursor<PCol*>::compare (start,stop) < 0)
316 if (start->breakable_b() && !start->line_l_)