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"
20 #include "tex-stream.hh"
23 #include "word-wrap.hh"
24 #include "gourlay-breaking.hh"
25 #include "outputter.hh"
27 // sucking Cygnus egcs - w32
29 #include "pcursor.tcc"
31 Paper_score::Paper_score ()
34 super_elem_l_ = new Super_elem;
35 typeset_element (super_elem_l_);
38 Paper_score::~Paper_score ()
40 super_elem_l_->unlink_all ();
41 for (PCursor<Score_elem*> i(elem_p_list_.top()); i.ok(); i++)
42 assert(!i->linked_b());
46 Paper_score::typeset_element (Score_elem * elem_p)
48 elem_p_list_.bottom ().add (elem_p);
49 elem_p->pscore_l_ = this;
51 elem_p->add_processing ();
55 Paper_score::typeset_broken_spanner (Spanner*span_p)
57 typeset_element (span_p);
62 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
64 span_p_list_.bottom ().add (span_p);
65 span_p->pscore_l_=this;
67 // do not init start/stop fields. These are for broken spans only.
68 span_p->add_processing ();
73 Paper_score::clean_cols ()
76 for (iter_top (col_p_list_,c); c.ok ();)
78 c->set_rank (rank_i++);
84 Paper_score::add_column (Paper_column *p)
86 col_p_list_.bottom ().add (p);
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++)
110 PCursor<Paper_column *>
111 Paper_score::find_col (Paper_column const *c) const
113 Paper_column const *what = c;
115 return col_p_list_.find ((Paper_column*)what);
120 Paper_score::set_breaking (Array<Col_hpositions> const &breaking)
122 super_elem_l_->line_of_score_l_->set_breaking (breaking);
123 super_elem_l_->break_processing ();
126 for (iter (span_p_list_.top (),i); i.ok ();)
128 Spanner *span_p = i.remove_p ();
129 if (span_p->broken_b ())
135 typeset_broken_spanner (span_p);
138 for (iter (elem_p_list_.top (),i); i.ok () ;)
140 Item *i_l =i->item ();
141 if (i_l && !i_l->line_l ())
144 delete i.remove_p ();
152 Paper_score::calc_breaking ()
154 Break_algorithm *algorithm_p=0;
155 Array<Col_hpositions> sol;
156 bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
160 algorithm_p = new Gourlay_breaking ;
161 algorithm_p->set_pscore (this);
162 sol = algorithm_p->solve ();
166 warning (_("Can not solve this casting problem exactly; revert to Word_wrap"));
172 algorithm_p = new Word_wrap;
173 algorithm_p->set_pscore (this);
174 sol = algorithm_p->solve ();
181 Paper_score::process ()
185 *mlog << _("Preprocessing elements... ") <<flush;
186 super_elem_l_->breakable_col_processing ();
187 super_elem_l_->pre_processing ();
188 *mlog << _("\nCalculating column positions ... ") <<flush;
190 *mlog << _("\nPostprocessing elements...") << endl;
191 super_elem_l_->post_processing ();
197 Paper_score::tex_output ()
200 String outname = paper_l_->outfile_str_ ;
201 if (outname.empty_b ())
203 outname = default_outname_base_global;
204 int def = paper_l_->get_next_default_count ();
207 outname += "-" + String(def);
211 *mlog << _("TeX output to ") << outname << " ...\n";
213 Tex_stream tex_out (outname);
214 Tex_outputter interfees (&tex_out);
216 outputter_l_ = &interfees;
218 tex_out << _("% outputting Score, defined at: ") << origin_str_ << "\n";
221 tex_out << header_l_->TeX_string();
223 tex_out << paper_l_->TeX_output_settings_str ();
226 if (experimental_features_global_b)
227 tex_out << "\\turnOnExperimentalFeatures%\n";
228 if (postscript_global_b)
229 tex_out << "\\turnOnPostScript%\n";
230 super_elem_l_->output_all ();
231 tex_out << "\n\\EndLilyPondOutput";
235 /** Get all breakable columns between l and r, (not counting l and r). */
236 Link_array<Paper_column>
237 Paper_score::breakable_col_range (Paper_column*l,Paper_column*r) const
239 Link_array<Paper_column> ret;
241 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
242 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
245 ugh! windows-suck-suck-suck.
247 while (PCursor<Paper_column*>::compare (start,stop) < 0)
249 if (start->breakable_b_)
256 Link_array<Paper_column>
257 Paper_score::col_range (Paper_column*l, Paper_column*r) const
259 Link_array<Paper_column> ret;
261 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
262 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
266 ugh! windows-suck-suck-suck.
268 while (PCursor<Paper_column*>::compare (start,stop) < 0)
275 Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
277 Link_array<Item> ret;
278 Item const*l=l_item_l;
279 Item const*r=r_item_l;
281 while (! l->is_type_b(Paper_column::static_name ()))
282 l = l->axis_group_l_a_[X_AXIS]->item ();
284 while (! r->is_type_b(Paper_column::static_name ()))
285 r = r->axis_group_l_a_[X_AXIS]->item ();
287 PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
288 PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
291 ugh! windows-suck-suck-suck.
293 while (PCursor<Paper_column*>::compare (start,stop) < 0)
295 if (start->breakable_b_ && !start->line_l_)