2 break.cc -- implement Break_algorithm
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
9 #include "score-column.hh"
11 #include "paper-def.hh"
12 #include "spring-spacer.hh"
14 #include "scoreline.hh"
17 #include "cpu-timer.hh"
18 #include "command-request.hh"
21 Col_stats::str () const
26 s += String (Real (cols_i_)/count_i_, _(", (with an average of %.1f columns)"));
32 Col_stats::add (Line_of_cols const& line)
35 cols_i_ += line.size ();
39 Col_stats::Col_stats ()
45 /* **************************************************************** */
48 Break_algorithm::all_cols () const
51 for (PCursor<Paper_column*> c (pscore_l_->col_p_list_.top ());
61 Break_algorithm::find_break_indices () const
63 Line_of_cols all (all_cols ());
66 for (int i=0; i < all.size (); i++)
67 if (all[i]->breakable_b_)
71 while (retval.size () >2)
77 /// return all breakable columns
79 Break_algorithm::find_breaks () const
81 Line_of_cols all (all_cols ());
84 for (int i=0; i < all.size (); i++)
85 if (all[i]->breakable_b_)
90 while (retval.size () >2)
101 Break_algorithm::generate_spacing_problem (Line_of_cols curline, Interval line) const
103 Spring_spacer * sp= (Spring_spacer*) (*get_line_spacer) (); // ugh
105 sp->paper_l_ = pscore_l_->paper_l_;
106 sp->add_column (curline[0], true, line.min ());
107 for (int i=1; i< curline.size ()-1; i++)
108 sp->add_column (curline[i]);
110 if (line.length () > 0)
112 sp->add_column (curline.top (), true, line[RIGHT]);
113 sp->energy_normalisation_f_ = sqr (line.length ());
116 sp->add_column (curline.top ());
122 Break_algorithm::Break_algorithm ()
130 Break_algorithm::set_pscore (Paper_score*s)
133 linelength = s->paper_l_->linewidth_f ();
138 Break_algorithm::feasible (Line_of_cols curline) const
143 for (int i=0; i < curline.size (); i++)
145 if (i && i < curline.size () -1
146 && (((Score_column*)curline[i])->break_penalty_i () >= Break_req::FORCE))
153 Break_algorithm::problem_OK () const
155 if (!pscore_l_->col_p_list_.size ())
156 error (_("Score does not have any columns"));
161 Break_algorithm::OK () const
164 iter_top (pscore_l_->col_p_list_,start);
165 PCursor<Paper_column *> end (pscore_l_->col_p_list_.bottom ());
167 assert (start->breakable_b_);
168 assert (end->breakable_b_);
172 Array<Col_hpositions>
173 Break_algorithm::solve () const
177 Array<Col_hpositions> h= do_solve ();
179 if (approx_stats_.count_i_)
180 *mlog << _ ("\n(Approximated: ") << approx_stats_.str () << ")\n";
181 if (exact_stats_.count_i_)
182 *mlog << _ ("(Calculated exactly: ") << exact_stats_.str () << ")\n";
183 *mlog << _ ("Time: ") << String (timer.read (), "%.2f") << _ (" seconds\n");
189 Break_algorithm::do_set_pscore ()