2 p-score.cc -- implement Paper_score
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1998 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"
26 #include "file-results.hh"
27 // sucking Cygnus egcs - w32
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 ();
189 *mlog << _("\nCalculating column positions ... ") <<flush;
190 super_elem_l_->space_processing ();
192 *mlog << _("\nPostprocessing elements...") << endl;
193 super_elem_l_->post_processing ();
199 Paper_score::tex_output ()
202 String base_outname = paper_l_->outfile_str_ ;
203 if (base_outname.empty_b ())
205 base_outname = default_outname_base_global;
206 int def = paper_l_->get_next_default_count ();
209 base_outname += "-" + String(def);
213 String outname = base_outname + ".tex";
214 target_str_global_array.push (outname);
217 *mlog << _("TeX output to ") << outname << " ...\n";
219 Tex_stream tex_out (outname);
220 Tex_outputter interfees (&tex_out);
222 outputter_l_ = &interfees;
224 tex_out << _("% outputting Score, defined at: ") << origin_str_ << "\n";
227 tex_out << header_l_->TeX_string();
229 tex_out << paper_l_->TeX_output_settings_str ();
232 if (experimental_features_global_b)
233 tex_out << "\\turnOnExperimentalFeatures%\n";
234 tex_out << "\\turnOnPostScript%\n";
235 super_elem_l_->output_all ();
236 tex_out << "\n\\EndLilyPondOutput";
240 /** Get all breakable columns between l and r, (not counting l and r). */
241 Link_array<Paper_column>
242 Paper_score::breakable_col_range (Paper_column*l,Paper_column*r) const
244 Link_array<Paper_column> ret;
246 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
247 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
250 ugh! windows-suck-suck-suck.
252 while (PCursor<Paper_column*>::compare (start,stop) < 0)
254 if (start->breakable_b_)
261 Link_array<Paper_column>
262 Paper_score::col_range (Paper_column*l, Paper_column*r) const
264 Link_array<Paper_column> ret;
266 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
267 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
271 ugh! windows-suck-suck-suck.
273 while (PCursor<Paper_column*>::compare (start,stop) < 0)
280 Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
282 Link_array<Item> ret;
283 Item const*l=l_item_l;
284 Item const*r=r_item_l;
286 while (! l->is_type_b(Paper_column::static_name ()))
287 l = l->axis_group_l_a_[X_AXIS]->item ();
289 while (! r->is_type_b(Paper_column::static_name ()))
290 r = r->axis_group_l_a_[X_AXIS]->item ();
292 PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
293 PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
296 ugh! windows-suck-suck-suck.
298 while (PCursor<Paper_column*>::compare (start,stop) < 0)
300 if (start->breakable_b_ && !start->line_l_)