-/*
- 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_colunms (Grob*me,Link_array<Grob> *cols, Rational shortest)
-{
- Link_array<Grob> newcols;
- Real increment = gh_scm2double (me->get_grob_property ("spacing-increment"));
- for (int i=0; i < cols->size (); i++)
- {
- if (Item::breakable_b (cols->elem(i)) || Paper_column::musical_b (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_grob_property ("left-neighbors");
- lns = gh_pair_p (lns) ? gh_car (lns) : SCM_BOOL_F;
-
- SCM rns = c->get_grob_property ("right-neighbors");
- rns = gh_pair_p (rns) ? gh_car (rns) : SCM_BOOL_F;
-
- /*
- Either object can be non existent, if the score ends
- prematurely.
- */
- rns = gh_car (unsmob_grob (rns)->get_grob_property ("right-items"));
- c->set_grob_property ("between-cols", gh_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_grob_property ("spacing-wishes");
- gh_pair_p (s); s = gh_cdr (s))
- {
- Grob *sp = unsmob_grob (gh_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_f_ = 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)
-{
- for (int i=0; i < cols.size(); i++)
- {
- SCM right_neighbors = SCM_EOL;
- int min_rank = 100000; // inf.
-
-
- SCM wishes= cols[i]->get_grob_property ("spacing-wishes");
- for (SCM s =wishes; gh_pair_p (s); s = gh_cdr (s))
- {
- Item * wish = dynamic_cast<Item*> (unsmob_grob (gh_car (s)));
-
- Item * lc = wish->column_l ();
- Grob * right = Note_spacing::right_column (wish);
-
- if (!right)
- continue;
-
- Item * rc = dynamic_cast<Item*> (right);
-
- int right_rank = Paper_column::rank_i (rc);
- int left_rank = Paper_column::rank_i (lc);
-
- /*
- update the left column.
- */
- if (right_rank <= min_rank)
- {
- if (right_rank < min_rank)
- right_neighbors =SCM_EOL;
-
- min_rank = right_rank;
- right_neighbors = gh_cons (wish->self_scm (), right_neighbors);
- }
-
- /*
- update the right column of the wish.
- */
- int maxrank = 0;
- SCM left_neighs = rc->get_grob_property ("left-neighbors");
- if (gh_pair_p (left_neighs)
- && unsmob_grob (gh_car (left_neighs)))
- {
- Item * it = dynamic_cast<Item*> (unsmob_grob (gh_car (left_neighs)));
- maxrank = Paper_column::rank_i (it->column_l());
- }
-
- if (left_rank >= maxrank)
- {
- if (left_rank > maxrank)
- left_neighs = SCM_EOL;
-
- left_neighs = gh_cons (wish->self_scm (), left_neighs);
- rc->set_grob_property ("left-neighbors", right_neighbors);
- }
- }
-
- if (gh_pair_p (right_neighbors))
- {
- cols[i]->set_grob_property ("right-neighbors", right_neighbors);
- }
- }
-}
-
-/*
- Set neighboring columns that have no left/right-neighbor set
- yet. Only do breakable non-musical columns, and musical columns.
-*/
-void
-Spacing_spanner::set_implicit_neighbor_columns (Link_array<Grob> cols)
-{
- for (int i = 0; i < cols.size (); i++)
- {
- Item * it = dynamic_cast<Item*>(cols[i]);
- if (!Item::breakable_b (it) && !Paper_column::musical_b (it))
- continue;
-
- // it->breakable || it->musical
-
- /*
- sloppy with typnig left/right-neighbors should take list, but paper-column found instead.
- */
- SCM ln = cols[i] ->get_grob_property ("left-neighbors");
- if (!gh_pair_p (ln) && i )
- {
- cols[i]->set_grob_property ("left-neighbors", gh_cons (cols[i-1]->self_scm(), SCM_EOL));
- }
-
- SCM rn = cols[i] ->get_grob_property ("right-neighbors");
- if (!gh_pair_p (rn) && i < cols.size () - 1)
- {
- cols[i]->set_grob_property ("right-neighbors", gh_cons (cols[i + 1]->self_scm(), SCM_EOL));
- }
- }
-}
-
-
-MAKE_SCHEME_CALLBACK (Spacing_spanner, set_springs,1);