This contains a bug-fix, an optimisation (been doing some profiling :)) and a
new feature (adding page-turn-penalties). The bug-fix and the feature won't
affect 2.8 because 2.7 doesn't use the full capabilities of the
constrained-breaker, but I think the bug fix at least should go in.
Index: lily/constrained-breaking.cc
===================================================================
RCS file: /sources/lilypond/lilypond/lily/constrained-breaking.cc,v
retrieving revision 1.3
diff -u -r1.3 constrained-breaking.cc
--- lily/constrained-breaking.cc 23 Feb 2006 10:52:07 -0000 1.3
+++ lily/constrained-breaking.cc 7 Mar 2006 21:54:08 -0000
@@ -82,8 +82,8 @@
if (0 == sys && j > 0)
break; /* the first line cannot have its first break after the beginning */
- Column_x_positions const &cur = cols_[(j + start_col)*cols_rank_ + brk];
- Column_x_positions prev;
+ Column_x_positions const *cur = &cols_[(j + start_col)*cols_rank_ + brk];
+ Column_x_positions const *prev = NULL;
Real prev_dem = 0;
if (sys > 0)
@@ -97,7 +97,7 @@
Real dem;
Real force;
Real pen;
- combine_demerits(prev, cur, &force, &pen, &dem);
+ combine_demerits (prev, cur, &force, &pen, &dem);
dem += prev_dem;
if (isinf (dem))
continue;
@@ -229,7 +229,7 @@
for (vsize cur_sys = sys; cur_sys != VPOS; cur_sys--)
{
assert (brk != VPOS);
- ret.push_back( st[cur_sys*rank + brk].line_config_ );
+ ret.push_back( *st[cur_sys*rank + brk].line_config_ );
brk = st[cur_sys*rank + brk].prev_;
}
reverse (ret);
@@ -284,7 +284,7 @@
}
Real
-Constrained_breaking::get_page_penalty (vsize start, vsize end, vsize sys_count, vsize sys_num)
+Constrained_breaking::get_page_penalty (vsize start, vsize end, vsize sys_count, vsize sys_num, bool turn)
{
vsize rank;
vsize brk;
@@ -296,16 +296,21 @@
if (brk == VPOS) /* we didn't satisfy constraints */
return 0;
- vector<Grob*> &cols = state_[start][sys*rank + brk].line_config_.cols_;
+ vector<Grob*> const &cols = state_[start][sys*rank + brk].line_config_->cols_;
if (cols.empty ())
return 0;
- Grob *pc = cols.back ();
+ Grob const *pc = cols.back ();
if (pc->original ())
{
SCM pen = pc->get_property ("page-penalty");
- if (scm_is_number (pen) && fabs (scm_to_double (pen)) < 10000)
- return scm_to_double (pen);
+ SCM turn_pen = pc->get_property ("page-turn-penalty");
+ Real ret = 0;
+ if (!turn && scm_is_number (pen) && fabs (scm_to_double (pen)) < 10000)
+ ret = scm_to_double (pen);
+ if (turn && scm_is_number (turn_pen) && fabs (scm_to_double (turn_pen)) < 10000)
+ ret = scm_to_double (turn_pen);
+ return ret;
}
return 0;
}
@@ -331,13 +336,13 @@
return sys_count + 1;
}
/* no possible breaks satisfy constraints */
- return 0;
+ return 1;
}
int
Constrained_breaking::get_max_systems (vsize start, vsize end)
{
- vsize brk = (end >= start_.size ()) ? breaks_.size () - 1 : start_[end];
+ vsize brk = (end >= start_.size ()) ? breaks_.size () - 1 : starting_breakpoints_[end];
return brk - starting_breakpoints_[start];
}
@@ -369,20 +374,22 @@
}
void
-Constrained_breaking::combine_demerits (Column_x_positions const &prev,
- Column_x_positions const &col,
+Constrained_breaking::combine_demerits (Column_x_positions const *prev,
+ Column_x_positions const *col,
Real *force,
Real *penalty,
Real *demerits) const
{
+ Real prev_f = prev ? prev->force_ : 0;
+
*penalty = 0;
- if (col.cols_.empty () || !col.satisfies_constraints_)
+ if (col->cols_.empty () || !col->satisfies_constraints_)
*force = infinity_f;
else
{
- *force = col.force_;
+ *force = col->force_;
- Grob *pc = col.cols_.back ();
+ Grob *pc = col->cols_.back ();
if (pc->original ())
{
SCM pen = pc->get_property ("penalty");
@@ -391,6 +398,6 @@
}
}
- *demerits = (*force) * (*force) + abs (prev.force_ - *force) + *penalty;
+ *demerits = (*force) * (*force) + abs (prev_f - *force) + *penalty;
}
Index: lily/include/constrained-breaking.hh
===================================================================
RCS file: /sources/lilypond/lilypond/lily/include/constrained-breaking.hh,v
retrieving revision 1.3
diff -u -r1.3 constrained-breaking.hh
--- lily/include/constrained-breaking.hh 23 Feb 2006 10:52:07 -0000 1.3
+++ lily/include/constrained-breaking.hh 7 Mar 2006 21:54:08 -0000
@@ -26,7 +26,7 @@
Real demerits_;
Real force_;
Real penalty_;
- Column_x_positions line_config_;
+ Column_x_positions const *line_config_;
Constrained_break_node ()
{
@@ -34,7 +34,7 @@
demerits_ = infinity_f;
force_ = infinity_f;
penalty_ = 0;
- line_config_.satisfies_constraints_ = false;
+ line_config_ = 0;
}
void print () const
@@ -62,7 +62,7 @@
int get_min_systems (vsize start, vsize end);
/* get the page penalty of system number sys with the given breaking */
- Real get_page_penalty (vsize start, vsize end, vsize sys_count, vsize sys);
+ Real get_page_penalty (vsize start, vsize end, vsize sys_count, vsize sys, bool turn);
void resize (vsize systems);
@@ -88,7 +88,7 @@
Column_x_positions space_line (vsize start_col, vsize end_col);
void prepare_solution (vsize start, vsize end, vsize sys_count, vsize *rank, vsize *brk);
- void combine_demerits (Column_x_positions const &, Column_x_positions const &,
+ void combine_demerits (Column_x_positions const *, Column_x_positions const *,
Real *force, Real *pen, Real *dem) const;
bool calc_subproblem(vsize start, vsize systems, vsize max_break_index);
Index: ChangeLog
===================================================================
RCS file: /sources/lilypond/lilypond/ChangeLog,v
retrieving revision 1.4730
diff -u -r1.4730 ChangeLog
--- ChangeLog 7 Mar 2006 18:14:22 -0000 1.4730
+++ ChangeLog 7 Mar 2006 21:54:16 -0000
@@ -1,3 +1,10 @@
+2006-03-08 Joe Neeman <[EMAIL PROTECTED]>
+ * lily/constrained-breaking.cc (get_max_systems): used to return a
+ much too big value
+ (combine_demerits): use pointers to reduce copying data
+ (calc_subproblem): idem
+ (get_page_penalty): add page turn penalties
+
2006-03-07 Han-Wen Nienhuys <[EMAIL PROTECTED]>
* lily/slur.cc (outside_slur_callback): only calculate offsets if
_______________________________________________
lilypond-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-devel