2 p-score.cc -- implement Paper_score
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "paper-def.hh"
14 #include "line-of-score.hh"
19 #include "word-wrap.hh"
20 #include "gourlay-breaking.hh"
21 #include "paper-stream.hh"
22 #include "paper-outputter.hh"
23 #include "file-results.hh"
26 Paper_score::Paper_score ()
30 Line_of_score * line_p = new Line_of_score;
31 typeset_unbroken_spanner (line_p);
36 Paper_score::Paper_score (Paper_score const &s)
42 Paper_score::~Paper_score ()
44 for (int i=0; i < span_p_arr_.size (); i++)
45 delete span_p_arr_[i];
46 for (int i=0; i < elem_p_arr_.size (); i++)
47 delete elem_p_arr_[i];
51 Paper_score::typeset_element (Score_element * elem_p)
53 elem_p_arr_.push (elem_p);
54 elem_p->pscore_l_ = this;
55 elem_p->add_processing ();
57 SCM p = elem_p->remove_elt_property (break_helper_only_scm_sym);
59 break_helpers_arr_.push (elem_p);
64 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
66 span_p_arr_.push (span_p);
67 span_p->pscore_l_=this;
68 span_p->add_processing ();
70 SCM p = span_p->remove_elt_property (break_helper_only_scm_sym);
72 break_helpers_arr_.push (span_p);
76 Paper_score::add_column (Paper_column *p)
78 p->set_rank (col_l_arr_.size ());
86 Paper_score::print () const
91 DOUT << "Paper_score { ";
92 DOUT << "\n elements: ";
93 for (int i=0; i < span_p_arr_.size (); i++)
94 span_p_arr_[i]->print ();
95 for (int i=0; i < elem_p_arr_.size (); i++)
96 elem_p_arr_[i]->print();
103 Paper_score::find_col_idx (Paper_column const *c) const
105 Paper_column const *what = c;
107 return col_l_arr_.find_i ((Paper_column*)what);
110 Array<Column_x_positions>
111 Paper_score::calc_breaking ()
113 Break_algorithm *algorithm_p=0;
114 Array<Column_x_positions> sol;
115 bool try_wrap = !paper_l_->get_var ("castingalgorithm");
119 algorithm_p = new Gourlay_breaking ;
120 algorithm_p->set_pscore (this);
121 sol = algorithm_p->solve ();
125 warning (_ ("Can't solve this casting problem exactly; revert to Word_wrap"));
131 algorithm_p = new Word_wrap;
132 algorithm_p->set_pscore (this);
133 sol = algorithm_p->solve ();
142 not clean. Should update elem_p_arr_ and span_p_arr_. That would
143 also repair the stats.
145 This may be done efficiently by first sorting the arrays. */
147 delete_array_contents (Link_array<Score_element> &to_remove, Dictionary<int> &type_stats)
149 for (int i=0; i < to_remove.size (); i++)
151 Score_element * e = to_remove[i];
152 String nm = e->name();
153 if (type_stats.elem_b (nm))
158 if (dynamic_cast<Item*> (e))
159 type_stats["Item"] ++;
160 else if (dynamic_cast<Spanner*>(e))
161 type_stats["Spanner"] ++;
162 type_stats["Total"] ++;
166 to_remove.tighten_maxsize ();
170 Paper_score::schedule_for_delete (Score_element*e)
172 to_delete_arr_.push (e);
176 Paper_score::process ()
178 Dictionary<int> type_stats;
179 type_stats["Item"] =0;
180 type_stats["Spanner"] =0;
181 type_stats["Total"]=0;
184 *mlog << _ ("Preprocessing elements...") << " " << flush;
185 line_l_->breakable_col_processing ();
186 line_l_->pre_processing ();
188 *mlog << '\n' << _ ("Calculating column positions...") << " " << flush;
189 line_l_->space_processing ();
191 Array<Column_x_positions> breaking = calc_breaking ();
194 delete_array_contents (break_helpers_arr_, type_stats);
196 Paper_stream* paper_stream_p = paper_l_->paper_stream_p ();
197 outputter_l_ = paper_l_->paper_outputter_p (paper_stream_p, header_l_, origin_str_);
199 Link_array<Line_of_score> lines;
200 for (int i=0; i < breaking.size (); i++)
202 Line_of_score *line_l = line_l_->set_breaking (breaking, i);
204 if (line_l != line_l_)
205 typeset_element (line_l);
208 if (experimental_features_global_b)
209 *mlog << elem_p_arr_.size () + span_p_arr_.size () << " elements. ";
211 *mlog << "\nLine ... ";
212 for (int i=0; i < lines.size (); i++)
214 *mlog << '[' << flush;
216 Line_of_score *line_l = lines[i];
217 line_l->break_processing ();
218 line_l->post_processing ();
220 line_l->output_all ();
222 if (experimental_features_global_b)
223 *mlog << '(' << elem_p_arr_.size () + span_p_arr_.size () << ')';
225 *mlog << ']' << flush;
227 delete_array_contents (to_delete_arr_, type_stats);
232 delete paper_stream_p;
239 if (experimental_features_global_b)
241 for (Dictionary_iter<int> i(type_stats); i.ok(); i++)
243 *mlog << i.key () << ": " << i.val () << " objects\n";
246 *mlog << '\n' << flush;
251 Paper_score::broken_col_range (Item const*l, Item const*r) const
253 Link_array<Item> ret;
259 ? find_col_idx (dynamic_cast<Paper_column*> ((Item*)l))+1
263 ? find_col_idx (dynamic_cast<Paper_column*>((Item*)r))
264 : col_l_arr_.size ();
268 Paper_column *c = col_l_arr_[start];
269 if (c->breakable_b () && !c->line_l_)