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"
15 #include "paper-column.hh"
16 #include "paper-score.hh"
17 #include "paper-column.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 ()
28 protected_scms_ = scm_protect_object (gh_cons (SCM_BOOL_T, SCM_EOL));
31 Line_of_score * line_p = new Line_of_score;
32 typeset_unbroken_spanner (line_p);
37 Paper_score::Paper_score (Paper_score const &s)
43 Paper_score::~Paper_score ()
45 for (int i=span_p_arr_.size (); --i >=0 ; )
46 delete span_p_arr_[i];
47 for (int i=elem_p_arr_.size (); --i >=0 ; )
48 delete elem_p_arr_[i];
50 scm_unprotect_object (protected_scms_);
54 Paper_score::typeset_element (Score_element * elem_p)
56 elem_p_arr_.push (elem_p);
57 elem_p->pscore_l_ = this;
59 // take over protection.
60 assert (elem_p->self_scm_ != SCM_EOL);
61 SCM_CDR(protected_scms_) = gh_cons (elem_p->self_scm_,
62 SCM_CDR (protected_scms_));
63 scm_unprotect_object (elem_p->self_scm_);
65 SCM p = elem_p->remove_elt_property (break_helper_only_scm_sym);
67 break_helpers_arr_.push (elem_p);
72 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
74 span_p_arr_.push (span_p);
75 span_p->pscore_l_=this;
77 SCM p = span_p->remove_elt_property (break_helper_only_scm_sym);
79 break_helpers_arr_.push (span_p);
83 Paper_score::add_column (Paper_column *p)
85 p->set_rank (col_l_arr_.size ());
93 Paper_score::print () const
98 DEBUG_OUT << "Paper_score { ";
99 DEBUG_OUT << "\n elements: ";
100 for (int i=0; i < span_p_arr_.size (); i++)
101 span_p_arr_[i]->print ();
102 for (int i=0; i < elem_p_arr_.size (); i++)
103 elem_p_arr_[i]->print();
110 Paper_score::find_col_idx (Paper_column const *c) const
112 Paper_column const *what = c;
114 return col_l_arr_.find_i ((Paper_column*)what);
117 Array<Column_x_positions>
118 Paper_score::calc_breaking ()
120 Break_algorithm *algorithm_p=0;
121 Array<Column_x_positions> sol;
122 bool try_wrap = !paper_l_->get_var ("castingalgorithm");
126 algorithm_p = new Gourlay_breaking ;
127 algorithm_p->set_pscore (this);
128 sol = algorithm_p->solve ();
132 warning (_ ("Can't solve this casting problem exactly; reverting to Word_wrap"));
138 algorithm_p = new Word_wrap;
139 algorithm_p->set_pscore (this);
140 sol = algorithm_p->solve ();
149 Paper_score::process ()
151 Dictionary<int> type_stats;
152 type_stats["Item"] =0;
153 type_stats["Spanner"] =0;
154 type_stats["Total"]=0;
157 *mlog << _ ("Preprocessing elements...") << " " << flush;
158 line_l_->breakable_col_processing ();
159 line_l_->pre_processing ();
161 *mlog << '\n' << _ ("Calculating column positions...") << " " << flush;
162 line_l_->space_processing ();
164 Array<Column_x_positions> breaking = calc_breaking ();
167 Paper_stream* paper_stream_p = paper_l_->paper_stream_p ();
168 outputter_l_ = paper_l_->paper_outputter_p (paper_stream_p, header_l_, origin_str_);
170 Link_array<Line_of_score> lines;
171 for (int i=0; i < breaking.size (); i++)
173 Line_of_score *line_l = line_l_->set_breaking (breaking, i);
175 if (line_l != line_l_)
176 typeset_element (line_l);
179 if (experimental_features_global_b)
180 *mlog << _f ("%s elements", elem_p_arr_.size () + span_p_arr_.size ());
183 *mlog << _ ("Line ... ");
184 line_l_->break_processing ();
185 for (int i=0; i < lines.size (); i++)
187 *mlog << '[' << flush;
189 Line_of_score *line_l = lines[i];
191 line_l->post_processing ();
193 line_l->output_all (i + 1 == lines.size());
194 if (experimental_features_global_b)
195 *mlog << '(' << elem_p_arr_.size () + span_p_arr_.size () << ')';
197 *mlog << ']' << flush;
202 delete paper_stream_p;
209 if (experimental_features_global_b)
211 for (Dictionary_iter<int> i(type_stats); i.ok(); i++)
213 *mlog << i.key () << ": " << i.val () << " objects\n";
216 *mlog << '\n' << flush;
221 Paper_score::broken_col_range (Item const*l, Item const*r) const
223 Link_array<Item> ret;
229 ? find_col_idx (dynamic_cast<Paper_column*> ((Item*)l))+1
233 ? find_col_idx (dynamic_cast<Paper_column*>((Item*)r))
234 : col_l_arr_.size ();
238 Paper_column *c = col_l_arr_[start];
239 if (c->breakable_b () && !c->line_l_)