-
-/*
- TODO: this file/class is too complex. Should figure out how to chop
- this up even more.
-
- */
-
-class Spacing_spanner
-{
-public:
- static void standard_breakable_column_spacing (Grob * me, Item*l, Item*r,
- Real * fixed, Real * space, Moment);
-
-
- static Real default_bar_spacing (Grob*,Grob*,Grob*,Moment);
- static Real note_spacing (Grob*,Grob*,Grob*,Moment, bool*);
- static Real get_duration_space (Grob*,Moment dur, Rational shortest, bool*);
- static Rational find_shortest (Grob *, Link_array<Grob> const &);
- static void breakable_column_spacing (Grob*, Item* l, Item *r, Moment);
- static void find_loose_columns () {}
- static void prune_loose_columns (Grob*,Link_array<Grob> *cols, Rational);
- static void find_loose_columns (Link_array<Grob> cols);
- static void set_explicit_neighbor_columns (Link_array<Grob> cols);
- static void set_implicit_neighbor_columns (Link_array<Grob> cols);
- static void do_measure (Rational, Grob*me,Link_array<Grob> *cols);
- static void musical_column_spacing (Grob*,Item*,Item*, Real, Rational);
- DECLARE_SCHEME_CALLBACK (set_springs, (SCM ));
- static bool has_interface (Grob*);
-};
-
-/*
- Return whether COL is fixed to its neighbors by some kind of spacing
- constraint.
-
-
- If in doubt, then we're not loose; the spacing engine should space
- for it, risking suboptimal spacing.
-
- (Otherwise, we might risk core dumps, and other weird stuff.)
-
-*/
-static bool
-loose_column (Grob *l, Grob *c, Grob *r)
-{
- SCM rns = c->get_property ("right-neighbors");
- SCM lns = c->get_property ("left-neighbors");
-
- /*
- If this column doesn't have a proper neighbor, we should really
- make it loose, but spacing it correctly is more than we can
- currently can handle.
-
- (this happens in the following situation:
-
- |
- | clef G
- *
-
- | | ||
- | | ||
- O O ||
-
-
- the column containing the clef is really loose, and should be
- attached right to the first column, but that is a lot of work for
- such a borderline case.)
-
- */
- if (!scm_is_pair (lns) || !scm_is_pair (rns))
- return false;
-
- Item * l_neighbor = dynamic_cast<Item*> (unsmob_grob (ly_car (lns)));
- Item * r_neighbor = dynamic_cast<Item*> (unsmob_grob (ly_car (rns)));
-
- if (!l_neighbor || !r_neighbor)
- return false;
-
- l_neighbor = l_neighbor->get_column ();
- r_neighbor = dynamic_cast<Item*> (Note_spacing::right_column (r_neighbor));
-
- if (l == l_neighbor && r == r_neighbor)
- return false;
-
- if (!l_neighbor || !r_neighbor)
- return false;
-
-
-
- /*
- Only declare loose if the bounds make a little sense. This means
- some cases (two isolated, consecutive clef changes) won't be
- nicely folded, but hey, then don't do that.
- */
- if (! ((Paper_column::is_musical (l_neighbor) || Item::is_breakable (l_neighbor))
- && (Paper_column::is_musical (r_neighbor) || Item::is_breakable (r_neighbor))) )
- {
- return false;
- }
-
-
- /*
- A rather hairy check, but we really only want to move around clefs. (anything else?)
-
- in any case, we don't want to move bar lines.
- */
- for (SCM e = c->get_property ("elements"); scm_is_pair (e); e = ly_cdr (e))
- {
- Grob * g = unsmob_grob (ly_car (e));
- if (g && Break_align_interface::has_interface (g))
- {
- for (SCM s = g->get_property ("elements"); scm_is_pair (s);
- s = ly_cdr (s))
- {
- Grob *h = unsmob_grob (ly_car (s));
-
- /*
- ugh. -- fix staff-bar name?
- */
- if (h && h->get_property ("break-align-symbol") == ly_symbol2scm ("staff-bar"))
- return false;
- }
- }
- }
-
- return true;
-}
-
-/*
- Remove columns that are not tightly fitting from COLS. In the
- removed columns, set 'between-cols to the columns where it is in
- between.
-*/
-void
-Spacing_spanner::prune_loose_columns (Grob*me,Link_array<Grob> *cols, Rational shortest)
-{
- Link_array<Grob> newcols;
- Real increment = robust_scm2double (me->get_property ("spacing-increment"), 1.2);
- for (int i=0; i < cols->size (); i++)
- {
- if (Item::is_breakable (cols->elem (i)) || Paper_column::is_musical (cols->elem (i)))
- {
- newcols.push (cols->elem (i));
- continue;
- }
-
- Grob *c = cols->elem (i);
- if (loose_column (cols->elem (i-1), c, cols->elem (i+1)))
- {
- SCM lns = c->get_property ("left-neighbors");
- lns = scm_is_pair (lns) ? ly_car (lns) : SCM_BOOL_F;
-
- SCM rns = c->get_property ("right-neighbors");
- rns = scm_is_pair (rns) ? ly_car (rns) : SCM_BOOL_F;
-
- /*
- Either object can be non existent, if the score ends
- prematurely.
- */
- rns = ly_car (unsmob_grob (rns)->get_property ("right-items"));
- c->set_property ("between-cols", scm_cons (lns,
- rns));
-
- /*
- Set distance constraints for loose columns
- */
- Drul_array<Grob*> next_door;
- next_door[LEFT] =cols->elem (i - 1);
- next_door[RIGHT] =cols->elem (i + 1);
- Direction d = LEFT;
- Drul_array<Real> dists (0,0);
-
- do
- {
- dists[d] = 0.0;
- Item *lc = dynamic_cast<Item*> ((d == LEFT) ? next_door[LEFT] : c);
- Item *rc = dynamic_cast<Item*> (d == LEFT ? c : next_door[RIGHT]);
-
- for (SCM s = lc->get_property ("spacing-wishes");
- scm_is_pair (s); s = ly_cdr (s))
- {
- Grob *sp = unsmob_grob (ly_car (s));
- if (Note_spacing::left_column (sp) != lc
- || Note_spacing::right_column (sp) != rc)
- continue;
-
- Real space, fixed;
- fixed = 0.0;
- bool dummy;
-
- if (d == LEFT)
- {
- /*
- The note spacing should be taken from the musical
- columns.
-
- */
- Real base = note_spacing (me, lc, rc, shortest, &dummy);
- Note_spacing::get_spacing (sp, rc, base, increment, &space, &fixed);
-
- space -= increment;
-
- dists[d] = dists[d] >? space;
- }
- else
- {
- Real space, fixed_space;
- Staff_spacing::get_spacing_params (sp,
- &space, &fixed_space);
-
- dists[d] = dists[d] >? fixed_space;
- }
-
- }
- }
- while (flip (&d) != LEFT);
-
- Rod r;
- r.distance_ = dists[LEFT] + dists[RIGHT];
- r.item_l_drul_[LEFT] = dynamic_cast<Item*> (cols->elem (i-1));
- r.item_l_drul_[RIGHT] = dynamic_cast<Item*> (cols->elem (i+1));
-
- r.add_to_cols ();
- }
- else
- {
- newcols.push (c);
- }
- }
-
- *cols = newcols;
-}
-
-/*
- Set neighboring columns determined by the spacing-wishes grob property.
-*/
-void
-Spacing_spanner::set_explicit_neighbor_columns (Link_array<Grob> cols)