2 constrained-breaking.hh -- declare a line breaker that
3 supports limits on the number of systems
5 source file of the GNU LilyPond music typesetter
7 (c) 2006--2009 Joe Neeman <joeneeman@gmail.com>
10 #ifndef CONSTRAINED_BREAKING_HH
11 #define CONSTRAINED_BREAKING_HH
13 #include "lily-guile.hh"
20 Interval extent_; /* Y-extent of the system */
22 Real padding_; /* compulsory space after this system (if we're not
26 Real space_; /* spring length */
29 SCM break_permission_;
38 /* The page-breaker deals with forbidden page breaks by "compressing"
39 two Line_detailses into one. The following fields are used by the
40 page-breaker to keep track of this. If the number of fields needed
41 by the page-breaker grows, it might be a good idea to create a separate
43 int compressed_lines_count_;
44 int compressed_nontitle_lines_count_;
55 break_permission_ = ly_symbol2scm ("allow");
56 page_permission_ = ly_symbol2scm ("allow");
57 turn_permission_ = ly_symbol2scm ("allow");
62 compressed_lines_count_ = 1;
63 compressed_nontitle_lines_count_ = 1;
66 Line_details (Prob *pb, Output_def *paper);
70 Helper to trace back an optimal path
72 struct Constrained_break_node
74 /* the number of bars in all the systems before this one
78 /* unlike the Gourlay breaker, this is the sum of all demerits up to,
79 * and including, this line */
81 struct Line_details details_;
83 Constrained_break_node ()
86 demerits_ = infinity_f;
91 printf ("prev break %d, demerits %f\n", prev_, demerits_);
96 A dynamic programming solution to breaking scores into lines
98 class Constrained_breaking
101 vector<Column_x_positions> solve (vsize start, vsize end, vsize sys_count);
102 vector<Column_x_positions> best_solution (vsize start, vsize end);
103 vector<Line_details> line_details (vsize start, vsize end, vsize sys_count);
105 Constrained_breaking (Paper_score *ps);
106 Constrained_breaking (Paper_score *ps, vector<vsize> const &start_col_posns);
108 int max_system_count (vsize start, vsize end);
109 int min_system_count (vsize start, vsize end);
112 Paper_score *pscore_;
113 vsize valid_systems_;
117 Real between_system_space_;
118 Real before_title_padding_;
119 Real between_system_padding_;
121 /* the (i,j)th entry is the configuration for breaking between
123 Matrix<Line_details> lines_;
125 /* the [i](j,k)th entry is the score for fitting the first k bars onto the
126 first j systems, starting at the i'th allowed starting column */
127 vector<Matrix<Constrained_break_node> > state_;
129 vector<vsize> start_; /* the columns at which we might be asked to start breaking */
130 vector<vsize> starting_breakpoints_; /* the corresponding index in breaks_ */
133 vector<vsize> breaks_;
136 void resize (vsize systems);
138 Column_x_positions space_line (vsize start_col, vsize end_col);
139 vsize prepare_solution (vsize start, vsize end, vsize sys_count);
141 Real combine_demerits (Real force, Real prev_force);
143 bool calc_subproblem (vsize start, vsize systems, vsize max_break_index);
144 void fill_line_details (Line_details *const, vsize, vsize);
146 #endif /* CONSTRAINED_BREAKING_HH */