2 break.cc -- implement Break_algorithm
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 #include "score-column.hh"
11 #include "paper-def.hh"
12 #include "line-spacer.hh"
14 #include "scoreline.hh"
17 #include "cpu-timer.hh"
20 Col_stats::str () const {
24 s += String (Real (cols_i_)/count_i_, _(", (with an average of %.1f columns)"));
30 Col_stats::add (Line_of_cols const& line)
33 cols_i_ += line.size ();
37 Col_stats::Col_stats ()
43 /* **************************************************************** */
46 Break_algorithm::all_cols () const
49 for (PCursor<Paper_column*> c (pscore_l_->col_p_list_.top ());
59 Break_algorithm::find_break_indices () const
61 Line_of_cols all (all_cols ());
64 for (int i=0; i < all.size (); i++)
65 if (all[i]->breakable_b_)
69 while (retval.size () >2)
75 /// return all breakable columns
77 Break_algorithm::find_breaks () const
79 Line_of_cols all (all_cols ());
82 for (int i=0; i < all.size (); i++)
83 if (all[i]->breakable_b_)
88 while (retval.size () >2)
99 Break_algorithm::generate_spacing_problem (Line_of_cols curline, Interval line) const
101 Line_spacer * sp= (*get_line_spacer) ();
103 sp->paper_l_ = pscore_l_->paper_l_;
104 sp->add_column (curline[0], true, line.min ());
105 for (int i=1; i< curline.size ()-1; i++)
106 sp->add_column (curline[i]);
108 if (line.length () > 0)
109 sp->add_column (curline.top (), true, line.max ());
111 sp->add_column (curline.top ());
117 Break_algorithm::Break_algorithm ()
125 Break_algorithm::set_pscore (Paper_score*s)
128 linelength = s->paper_l_->linewidth_f ();
133 Break_algorithm::feasible (Line_of_cols curline) const
138 for (int i=0; i < curline.size (); i++)
140 if (i && i < curline.size () -1
141 && ((Score_column*)curline[i])->forced_break_b ())
148 Break_algorithm::problem_OK () const
150 if (!pscore_l_->col_p_list_.size ())
151 error (_("Score does not have any columns"));
156 Break_algorithm::OK () const
159 iter_top (pscore_l_->col_p_list_,start);
160 PCursor<Paper_column *> end (pscore_l_->col_p_list_.bottom ());
162 assert (start->breakable_b_);
163 assert (end->breakable_b_);
167 Array<Col_hpositions>
168 Break_algorithm::solve () const
172 Array<Col_hpositions> h= do_solve ();
174 if (approx_stats_.count_i_)
175 *mlog << _ ("\nApproximated: ") << approx_stats_.str () << "\n";
176 if (exact_stats_.count_i_)
177 *mlog << _ ("Calculated exactly: ") << exact_stats_.str () << "\n";
178 *mlog << _ ("Time: ") << String (timer.read (), "%.2f") << _ (" seconds\n");
184 Break_algorithm::do_set_pscore ()