2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2010 Joe Neeman <joeneeman@gmail.com>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef CONSTRAINED_BREAKING_HH
21 #define CONSTRAINED_BREAKING_HH
23 #include "lily-guile.hh"
28 * Begin/rest-of-line hack. This geometrical shape is a crude approximation
29 * of Skyline, but it is better than a rectangle.
39 Line_shape (Interval begin, Interval rest);
40 Line_shape piggyback (Line_shape mount, Real padding) const;
47 Interval refpoint_extent_; /* The refpoints of the first and last
48 spaceable staff in this line. min-distance
49 should be measured from the bottom
50 refpoint_extent of one line to the
51 top refpoint_extent of the next. */
52 Real tallness_; /* Y-extent, adjusted according to begin/rest-of-line*/
54 Real padding_; /* compulsory space after this system (if we're not
58 Real title_min_distance_;
60 Real space_; /* spring length */
63 SCM break_permission_;
72 /* The page-breaker deals with forbidden page breaks by "compressing"
73 two Line_detailses into one. The following fields are used by the
74 page-breaker to keep track of this. If the number of fields needed
75 by the page-breaker grows, it might be a good idea to create a separate
77 int compressed_lines_count_;
78 int compressed_nontitle_lines_count_;
79 bool last_markup_line_;
80 bool first_markup_line_;
91 title_min_distance_ = 0;
94 tight_spacing_ = false;
95 break_permission_ = ly_symbol2scm ("allow");
96 page_permission_ = ly_symbol2scm ("allow");
97 turn_permission_ = ly_symbol2scm ("allow");
102 compressed_lines_count_ = 1;
103 compressed_nontitle_lines_count_ = 1;
104 last_markup_line_ = false;
105 first_markup_line_ = false;
109 Line_details (Prob *pb, Output_def *paper);
110 Real full_height () const;
111 Real tallness () const;
115 Helper to trace back an optimal path
117 struct Constrained_break_node
119 /* the number of bars in all the systems before this one
123 /* unlike the Gourlay breaker, this is the sum of all demerits up to,
124 * and including, this line */
126 struct Line_details details_;
128 Constrained_break_node ()
131 demerits_ = infinity_f;
136 printf ("prev break %d, demerits %f\n", prev_, demerits_);
141 A dynamic programming solution to breaking scores into lines
143 class Constrained_breaking
146 vector<Column_x_positions> solve (vsize start, vsize end, vsize sys_count);
147 vector<Column_x_positions> best_solution (vsize start, vsize end);
148 vector<Line_details> line_details (vsize start, vsize end, vsize sys_count);
150 Constrained_breaking (Paper_score *ps);
151 Constrained_breaking (Paper_score *ps, vector<vsize> const &start_col_posns);
153 int max_system_count (vsize start, vsize end);
154 int min_system_count (vsize start, vsize end);
157 Paper_score *pscore_;
158 vsize valid_systems_;
163 Real system_system_min_distance_;
164 Real system_system_padding_;
165 Real system_system_space_;
166 Real score_system_min_distance_;
167 Real score_system_padding_;
168 Real score_markup_min_distance_;
169 Real score_markup_padding_;
171 /* the (i,j)th entry is the configuration for breaking between
173 Matrix<Line_details> lines_;
175 /* the [i](j,k)th entry is the score for fitting the first k bars onto the
176 first j systems, starting at the i'th allowed starting column */
177 vector<Matrix<Constrained_break_node> > state_;
179 vector<vsize> start_; /* the columns at which we might be asked to start breaking */
180 vector<vsize> starting_breakpoints_; /* the corresponding index in breaks_ */
183 vector<vsize> breaks_;
186 void resize (vsize systems);
188 Column_x_positions space_line (vsize start_col, vsize end_col);
189 vsize prepare_solution (vsize start, vsize end, vsize sys_count);
191 Real combine_demerits (Real force, Real prev_force);
193 bool calc_subproblem (vsize start, vsize systems, vsize max_break_index);
194 void fill_line_details (Line_details *const, vsize, vsize);
196 #endif /* CONSTRAINED_BREAKING_HH */