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_;
49 if (breakstat == -1) {
51 }else if (breakstat == 1) {
60 Paper_score::typeset_broken_spanner (Spanner*span_p)
62 span_p->left_col_l_->starters.bottom().add (span_p);
63 assert (span_p->left_col_l_->line_l_ == span_p->right_col_l_->line_l_);
65 typeset_element (span_p);
70 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
72 span_p_list_.bottom().add (span_p);
73 span_p->pscore_l_=this;
75 if (span_p->left_col_l_)
76 span_p->left_col_l_->used_b_ = true;
77 if ( span_p->right_col_l_)
78 span_p->right_col_l_->used_b_ = true;
80 // do not init start/stop fields. These are for broken spans only.
81 span_p->add_processing();
86 Paper_score::clean_cols()
89 for (iter_top (col_p_list_,c); c.ok();)
93 c->set_rank (rank_i++);
99 Paper_score::add (PCol *p)
102 if (p->breakable_b()){
103 p->prebreak_p_->pscore_l_ = this;
104 p->postbreak_p_->pscore_l_ = this;
106 col_p_list_.bottom().add (p);
110 Paper_score::output (Tex_stream &ts)
112 ts << "\n "<< paper_l_->lookup_l()->texsetting << "%(Tex id)\n";
113 ts<< super_elem_l_->TeX_string();
114 ts << "\n\\EndLilyPondOutput";
119 Paper_score::OK()const
122 for (iter_top (col_p_list_,cc); cc.ok(); cc++)
124 for (PCursor<Score_elem*> i (elem_p_list_.top()); i.ok (); i++)
130 Paper_score::print() const
135 DOUT << "Paper_score { ";
137 DOUT << "\n elements: ";
138 for (iter_top (elem_p_list_,cc); cc.ok(); cc++)
140 DOUT << "\n unbroken spanners: ";
141 for (iter (span_p_list_.top(), i); i.ok (); i++)
143 DOUT << "\ncolumns: ";
144 for (iter_top (col_p_list_,cc); cc.ok(); cc++)
152 Paper_score::preprocess()
154 super_elem_l_->breakable_col_processing();
155 super_elem_l_->pre_processing();
159 Paper_score::postprocess()
161 super_elem_l_->post_processing();
162 super_elem_l_->molecule_processing();
166 Paper_score::find_col (PCol const *c)const
168 PCol const *what = c;
170 what = what->daddy_l_;
172 return col_p_list_.find ((PCol*)what);
177 Paper_score::set_breaking (Array<Col_hpositions> const &breaking)
179 super_elem_l_->line_of_score_l_->set_breaking (breaking);
180 super_elem_l_->break_processing();
183 for (iter (span_p_list_.top(),i); i.ok ();) {
184 Spanner *span_p = i.remove_p();
185 if (span_p->broken_b()) {
189 typeset_broken_spanner (span_p);
192 for (iter (elem_p_list_.top(),i); i.ok () ;) {
193 Item *i_l =i->item();
194 if ( i_l && !i_l->pcol_l_->line_l_) {
201 for (iter_top (col_p_list_, i); i.ok(); i++)
202 i->clean_breakable_items();
206 Paper_score::calc_breaking()
208 Break_algorithm *algorithm_p;
209 Array<Col_hpositions> sol;
210 bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
213 algorithm_p = new Gourlay_breaking ;
214 algorithm_p->set_pscore (this);
215 sol = algorithm_p->solve();
218 warning ("Can not solve this casting problem exactly; revert to Word_wrap");
223 algorithm_p = new Word_wrap;
224 algorithm_p->set_pscore (this);
225 sol = algorithm_p->solve();
232 Paper_score::process()
236 *mlog << "Preprocessing elements... " <<flush;
238 *mlog << "\nCalculating column positions ... " <<flush;
240 *mlog << "\nPostprocessing elements..." << endl;
244 for (PCursor<Score_elem*> i (elem_p_list_.top()); i.ok (); i++)
245 assert (i->status() >= 9);
249 /** Get all breakable columns between l and r, (not counting l and r). */
251 Paper_score::breakable_col_range (PCol*l,PCol*r)const
253 Link_array<PCol> ret;
255 PCursor<PCol*> start (l ? find_col (l)+1 : col_p_list_.top());
256 PCursor<PCol*> stop (r ? find_col (r) : col_p_list_.bottom());
259 ugh! windows-suck-suck-suck.
261 while ( PCursor<PCol*>::compare (start,stop) < 0) {
262 if (start->breakable_b())
270 Paper_score::col_range (PCol*l,PCol*r)const
272 Link_array<PCol> ret;
274 PCursor<PCol*> start (l ? find_col (l)+1 : col_p_list_.top());
275 PCursor<PCol*> stop (r ? find_col (r) : col_p_list_.bottom());
279 ugh! windows-suck-suck-suck.
281 while ( PCursor<PCol*>::compare (start,stop) < 0)
288 Paper_score::broken_col_range (PCol*l,PCol*r)const
290 Link_array<PCol> ret;
292 PCursor<PCol*> start (l ? find_col (l)+1 : col_p_list_.top());
293 PCursor<PCol*> stop (r ? find_col (r) : col_p_list_.bottom());
296 ugh! windows-suck-suck-suck.
298 while ( PCursor<PCol*>::compare (start,stop) < 0) {
299 if (start->breakable_b() && !start->line_l_)