2 break.cc -- implement Break_algorithm
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "score-column.hh"
11 #include "paper-def.hh"
12 #include "spring-spacer.hh"
14 #include "line-of-score.hh"
17 #include "cpu-timer.hh"
18 #include "command-request.hh"
21 Col_stats::str () const
26 else if (count_i_ == 1)
27 s = _f ("1 line (of %.0f columns)", (Real)cols_i_/count_i_);
29 s = _f ("%d lines (with an average of %.1f columns)",
30 count_i_, (Real)cols_i_/count_i_);
35 Col_stats::add (Line_of_cols const& line)
38 cols_i_ += line.size ();
42 Col_stats::Col_stats ()
48 /* **************************************************************** */
51 Break_algorithm::all_cols () const
54 for (PCursor<Paper_column*> c (pscore_l_->col_p_list_.top ());
64 Break_algorithm::find_break_indices () const
66 Line_of_cols all (all_cols ());
69 for (int i=0; i < all.size (); i++)
70 if (all[i]->breakable_b_)
74 while (retval.size () >2)
80 /// return all breakable columns
82 Break_algorithm::find_breaks () const
84 Line_of_cols all (all_cols ());
87 for (int i=0; i < all.size (); i++)
88 if (all[i]->breakable_b_)
93 while (retval.size () >2)
104 Break_algorithm::generate_spacing_problem (Line_of_cols curline, Interval line) const
106 Spring_spacer * sp= (Spring_spacer*) (*get_line_spacer) (); // ugh
108 sp->paper_l_ = pscore_l_->paper_l_;
109 sp->add_column (curline[0], true, line[LEFT]);
110 for (int i=1; i< curline.size ()-1; i++)
111 sp->add_column (curline[i]);
113 if (line.length () > 0)
115 sp->add_column (curline.top (), true, line[RIGHT]);
116 sp->energy_normalisation_f_ = sqr (line.length ());
119 sp->add_column (curline.top ());
125 Break_algorithm::Break_algorithm ()
133 Break_algorithm::set_pscore (Paper_score*s)
136 linelength = s->paper_l_->linewidth_f ();
141 Break_algorithm::feasible (Line_of_cols curline) const
146 for (int i=0; i < curline.size (); i++)
148 if (i && i < curline.size () -1
149 && (((Score_column*)curline[i])->break_penalty_i () >= Break_req::FORCE))
156 Break_algorithm::problem_OK () const
158 if (!pscore_l_->col_p_list_.size ())
159 error (_("score does not have any columns"));
164 Break_algorithm::OK () const
167 iter_top (pscore_l_->col_p_list_,start);
168 PCursor<Paper_column *> end (pscore_l_->col_p_list_.bottom ());
170 assert (start->breakable_b_);
171 assert (end->breakable_b_);
175 Array<Column_x_positions>
176 Break_algorithm::solve () const
180 Array<Column_x_positions> h= do_solve ();
182 if (approx_stats_.count_i_)
183 *mlog << '\n' << _f ("approximated: %s", approx_stats_.str ()) << endl;
184 if (exact_stats_.count_i_)
185 *mlog << _f ("calculated exactly: %s", exact_stats_.str ()) << endl;
186 *mlog << _f ("time: %.2f seconds", timer.read ()) << endl;
192 Break_algorithm::do_set_pscore ()