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
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 outname = paper_l_->outfile_str_ ;
203 if (outname.empty_b ())
205 outname = default_outname_base_global;
206 int def = paper_l_->get_next_default_count ();
209 outname += "-" + String(def);
213 *mlog << _("TeX output to ") << outname << " ...\n";
215 Tex_stream tex_out (outname);
216 Tex_outputter interfees (&tex_out);
218 outputter_l_ = &interfees;
220 tex_out << _("% outputting Score, defined at: ") << origin_str_ << "\n";
223 tex_out << header_l_->TeX_string();
225 tex_out << paper_l_->TeX_output_settings_str ();
228 if (experimental_features_global_b)
229 tex_out << "\\turnOnExperimentalFeatures%\n";
230 tex_out << "\\turnOnPostScript%\n";
231 super_elem_l_->output_all ();
232 tex_out << "\n\\EndLilyPondOutput";
236 /** Get all breakable columns between l and r, (not counting l and r). */
237 Link_array<Paper_column>
238 Paper_score::breakable_col_range (Paper_column*l,Paper_column*r) const
240 Link_array<Paper_column> ret;
242 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
243 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
246 ugh! windows-suck-suck-suck.
248 while (PCursor<Paper_column*>::compare (start,stop) < 0)
250 if (start->breakable_b_)
257 Link_array<Paper_column>
258 Paper_score::col_range (Paper_column*l, Paper_column*r) const
260 Link_array<Paper_column> ret;
262 PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
263 PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
267 ugh! windows-suck-suck-suck.
269 while (PCursor<Paper_column*>::compare (start,stop) < 0)
276 Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
278 Link_array<Item> ret;
279 Item const*l=l_item_l;
280 Item const*r=r_item_l;
282 while (! l->is_type_b(Paper_column::static_name ()))
283 l = l->axis_group_l_a_[X_AXIS]->item ();
285 while (! r->is_type_b(Paper_column::static_name ()))
286 r = r->axis_group_l_a_[X_AXIS]->item ();
288 PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
289 PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
292 ugh! windows-suck-suck-suck.
294 while (PCursor<Paper_column*>::compare (start,stop) < 0)
296 if (start->breakable_b_ && !start->line_l_)