static Moment when_mom (Grob *);
static bool is_used (Grob *);
static bool is_breakable (Grob *);
+ static Real minimum_distance (Grob *l, Grob *r);
};
#endif // PAPER_COLUMN_HH
#include "rational.hh"
#include "std-vector.hh"
#include "grob-interface.hh"
+#include "spring.hh"
class Spacing_spanner
{
public:
static vector<Grob*> get_columns (Grob *me);
static Real note_spacing (Grob *, Grob *, Grob *, Spacing_options const *);
- static void standard_breakable_column_spacing (Grob *me, Item *l, Item *r,
- Real *fixed, Real *space,
- Spacing_options const *);
+ static Spring standard_breakable_column_spacing (Grob *me, Item *l, Item *r, Spacing_options const *);
DECLARE_SCHEME_CALLBACK (set_springs, (SCM));
DECLARE_SCHEME_CALLBACK (calc_common_shortest_duration, (SCM));
void set_min_distance (Real);
void set_inverse_stretch_strength (Real);
void set_inverse_compress_strength (Real);
+ void set_default_strength ();
void operator*= (Real);
Grob *other_;
#include "system.hh"
#include "spring.hh"
#include "lookup.hh"
+#include "separation-item.hh"
#include "string-convert.hh"
Grob *
return scm_is_symbol (me->get_property ("line-break-permission"));
}
+Real
+Paper_column::minimum_distance (Grob *left, Grob *right)
+{
+ Drul_array<Grob*> cols (left, right);
+ Drul_array<Skyline> skys = Drul_array<Skyline> (Skyline (RIGHT), Skyline (LEFT));
+
+ Direction d = LEFT;
+ do
+ {
+ extract_grob_set (cols[d], "elements", elts);
+
+ for (vsize i = 0; i < elts.size (); i++)
+ if (Separation_item::has_interface (elts[i]))
+ {
+ Skyline_pair *sp = Skyline_pair::unsmob (elts[i]->get_property ("horizontal-skylines"));
+ if (sp)
+ skys[d].merge ((*sp)[-d]);
+ }
+ }
+ while (flip (&d) != LEFT);
+
+ return min (0.0, skys[LEFT].distance (skys[RIGHT]));
+}
+
/*
Print a vertical line and the rank number, to aid debugging.
*/
#include "warn.hh"
#include "pointer-group-interface.hh"
#include "system.hh"
+#include "spacing-interface.hh"
+#include "spring.hh"
/*
LilyPond spaces by taking a simple-minded spacing algorithm, and
The one-size-fits all spacing. It doesn't take into account
different spacing wishes from one to the next column.
*/
-void
-Spacing_spanner::standard_breakable_column_spacing (Grob *me, Item *l, Item *r,
- Real *fixed, Real *space,
- Spacing_options const *options)
+Spring
+Spacing_spanner::standard_breakable_column_spacing (Grob *me, Item *l, Item *r, Spacing_options const *options)
{
- *fixed = 0.0;
- Direction d = LEFT;
- Drul_array<Item *> cols (l, r);
-
- do
- {
- /*
- TODO: this is fishy, the extent gets distorted due to wide
- \marks, so better not do this.
- */
- if (!Paper_column::is_musical (cols[d]))
- {
- /*
- Tied accidentals over barlines cause problems, so lets see
- what happens if we do this for non musical columns only.
- */
- Interval lext = cols[d]->extent (cols [d], X_AXIS);
- if (!lext.is_empty ())
- *fixed += -d * lext[-d];
- }
- }
- while (flip (&d) != LEFT);
+ Real min_dist = Paper_column::minimum_distance (l, r);
+ Real ideal;
if (Paper_column::is_breakable (l) && Paper_column::is_breakable (r))
{
Real incr = robust_scm2double (me->get_property ("spacing-increment"), 1);
- *space = *fixed + incr * double (mlen.main_part_ / options->global_shortest_) * 0.8;
+ ideal = min_dist + incr * double (mlen.main_part_ / options->global_shortest_) * 0.8;
}
else
{
In this case, Staff_spacing should handle the job,
using dt when it is 0 is silly.
*/
- *space = *fixed + 0.5;
+ ideal = min_dist + 0.5;
}
else
- *space = *fixed + options->get_duration_space (dt.main_part_);
+ ideal = min_dist + options->get_duration_space (dt.main_part_);
}
+ return Spring (ideal, min_dist);
}
Moment *
the broken piece.
FIXME: this only works for the left column. There is only one spacing
- grob for the original and non-original right column and we have no way
+ grob for both the original and non-original right columns and we have no way
to tell which one we need */
Grob *orig = me->original () ? me->original () : me;
&options);
else
{
- Real fixed, space;
-
- Spacing_spanner::standard_breakable_column_spacing (spacing,
- loose_col, next_col,
- &fixed, &space,
- &options);
-
- base_note_space = space;
+ Spring spring = Spacing_spanner::standard_breakable_column_spacing (spacing,
+ loose_col, next_col,
+ &options);
+
+ base_note_space = spring.distance ();
}
base_note_space = max (base_note_space,
Spacing_spanner::breakable_column_spacing (Grob *me, Item *l, Item *r,
Spacing_options const *options)
{
- Real compound_fixed = 0.0;
- Real compound_space = 0.0;
- Real max_fixed = 0.0;
- Real max_space = 0.0;
-
- int wish_count = 0;
+ vector<Spring> springs;
+ Spring spring;
Moment dt = Paper_column::when_mom (r) - Paper_column::when_mom (l);
*/
assert (spacing_grob->get_column () == l);
- Spring sp = Staff_spacing::get_spacing (spacing_grob);
- Real space = sp.distance ();
- Real fixed = sp.min_distance ();
-
- if (Paper_column::when_mom (r).grace_part_)
- {
- /*
- Correct for grace notes.
-
- Ugh. The 0.8 is arbitrary.
- */
- space *= 0.8;
- }
-
- max_space = max (max_space, space);
- max_fixed = max (max_fixed, fixed);
-
- compound_space += space;
- compound_fixed += fixed;
- wish_count++;
+ springs.push_back (Staff_spacing::get_spacing (spacing_grob));
}
}
- if (compound_space <= 0.0 || !wish_count)
- {
- standard_breakable_column_spacing (me, l, r, &compound_fixed, &compound_space,
- options);
- wish_count = 1;
- }
+ if (springs.empty ())
+ spring = standard_breakable_column_spacing (me, l, r, options);
else
+ spring = merge_springs (springs);
+
+ if (Paper_column::when_mom (r).grace_part_)
{
- if (to_boolean (me->get_property ("average-spacing-wishes")))
- {
- compound_space /= wish_count;
- compound_fixed /= wish_count;
- }
- else
- {
- compound_fixed = max_fixed;
- compound_space = max_space;
- }
-
+ /*
+ Correct for grace notes.
+
+ Ugh. The 0.8 is arbitrary.
+ */
+ spring *= 0.8;
}
if (Paper_column::is_musical (r)
&& l->break_status_dir () == CENTER
&& fills_measure (me, l, r))
{
- compound_space += 1.0;
+ spring.set_distance (spring.distance () + 1.0);
+ spring.set_default_strength ();
}
if (options->stretch_uniformly_ && l->break_status_dir () != RIGHT)
- compound_fixed = 0.0;
-
- assert (!isinf (compound_space));
- compound_space = max (compound_space, compound_fixed);
-
- Real inverse_strength = (compound_space - compound_fixed);
- Real distance = compound_space;
+ {
+ spring.set_min_distance (0.0);
+ spring.set_default_strength ();
+ }
- Spaceable_grob::add_spring (l, r, distance, inverse_strength);
+ Spaceable_grob::add_spring (l, r, spring);
}
ADD_INTERFACE (Spacing_spanner,