-/*
- separating-group-spanner.cc -- implement Separating_group_spanner
-
+/*
+ separating-group-spanner.cc -- implement Separating_group_spanner
+
source file of the GNU LilyPond music typesetter
-
- (c) 1998--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-
- */
+
+ (c) 1998--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
+*/
#include "separating-group-spanner.hh"
+
#include "separation-item.hh"
#include "paper-column.hh"
-#include "paper-def.hh"
+#include "output-def.hh"
#include "dimensions.hh"
-#include "group-interface.hh"
+#include "pointer-group-interface.hh"
void
-Separating_group_spanner::find_rods (Item * r, SCM next)
+Separating_group_spanner::find_rods (Item *r,
+ vector<Grob*> const &separators,
+ vsize idx,
+ Real padding)
{
- Interval ri (Separation_item::my_width (r));
- if (ri.empty_b ())
- return;
/*
- This is an inner loop, however, in most cases, the interesting L
- will just be the first entry of NEXT, making it linear in most of
- the cases. */
- for(; gh_pair_p (next); next = gh_cdr (next))
+ This is an inner loop: look for the first normal (unbroken) Left
+ grob. This looks like an inner loop (ie. quadratic total), but in
+ most cases, the interesting L will just be the first entry of
+ NEXT, making it linear in most of the cases.
+ */
+ for (; idx != VPOS; idx--)
{
- Item *l = dynamic_cast<Item*> (unsmob_grob (gh_car( next)));
+ Item *l = dynamic_cast<Item *> (separators[idx]);
Item *lb = l->find_prebroken_piece (RIGHT);
if (lb)
{
- Interval li (Separation_item::my_width (lb));
-
- if (!li.empty_b ())
- {
- Rod rod;
-
- rod.item_l_drul_[LEFT] = lb;
- rod.item_l_drul_[RIGHT] = r;
-
- rod.distance_f_ = li[RIGHT] - ri[LEFT];
-
- rod.columnize ();
- rod.add_to_cols ();
- }
+ Separation_item::set_distance (Drul_array<Item*> (lb, r), padding);
}
- Interval li (Separation_item::my_width (l));
- if (!li.empty_b ())
- {
- Rod rod;
-
- rod.item_l_drul_[LEFT] =l;
- rod.item_l_drul_[RIGHT]=r;
-
- rod.distance_f_ = li[RIGHT] - ri[LEFT];
-
- rod.columnize ();
- rod.add_to_cols ();
+ if (Separation_item::set_distance (Drul_array<Item *> (l, r), padding))
+ break;
- break;
- }
- else
- /*
- this grob doesn't cause a constraint. We look further until we
- find one that does. */
- ;
+ /*
+ this grob doesn't cause a constraint. We look further until we
+ find one that does.
+ */
}
}
-MAKE_SCHEME_CALLBACK (Separating_group_spanner,set_spacing_rods,1);
+MAKE_SCHEME_CALLBACK (Separating_group_spanner, set_spacing_rods, 1);
SCM
Separating_group_spanner::set_spacing_rods (SCM smob)
{
- Grob*me = unsmob_grob (smob);
-
- for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s) && gh_pair_p (gh_cdr (s)); s = gh_cdr (s))
- {
- /*
- Order of elements is reversed!
- */
- SCM elt = gh_car (s);
- Item *r = dynamic_cast<Item*> (unsmob_grob (elt));
+ Grob *me = unsmob_grob (smob);
+
+ /*
+ Ugh: padding is added doubly, also for SeparationItem
+ */
+ Real padding = robust_scm2double (me->get_property ("padding"), 0.1);
+ extract_grob_set (me, "elements", elts);
+ for (vsize i = elts.size (); i-- > 1;)
+ {
+ Item *r = dynamic_cast<Item *> (elts[i]);
if (!r)
continue;
+ if (Separation_item::width (r).is_empty ())
+ continue;
+
Item *rb
- = dynamic_cast<Item*> (r->find_prebroken_piece (LEFT));
-
- find_rods (r, gh_cdr (s));
- if (rb)
- find_rods (rb, gh_cdr (s));
- }
+ = dynamic_cast<Item *> (r->find_prebroken_piece (LEFT));
- find_musical_sequences (me);
-#if 0
- /*
- TODO; restore this.
- */
- /*
- We've done our job, so we get lost.
- */
- for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
- {
- Item * it =dynamic_cast<Item*> (unsmob_grob (gh_car (s)));
- if (it && it->broken_b ())
- {
- it->find_prebroken_piece (LEFT) ->suicide ();
- it->find_prebroken_piece (RIGHT)->suicide ();
- }
- it->suicide ();
+ find_rods (r, elts, i - 1, padding);
+ if (rb)
+ find_rods (rb, elts, i - 1, padding);
}
- me->suicide ();
-#endif
- return SCM_UNSPECIFIED ;
-}
-void
-Separating_group_spanner::add_spacing_unit (Grob* me ,Item*i)
-{
- Pointer_group_interface::add_element (me, "elements",i);
- me->add_dependency (i);
+ return SCM_UNSPECIFIED;
}
-
void
-Separating_group_spanner::find_musical_sequences (Grob *me)
+Separating_group_spanner::add_spacing_unit (Grob *me, Item *i)
{
- Item *last = 0;
- Item *llast = 0;
- for (SCM s = me->get_grob_property ("elements");
- gh_pair_p (s); s = gh_cdr (s))
- {
- Item *it = dynamic_cast<Item*> (unsmob_grob (gh_car (s)));
- if (last)
- {
- Item *lcol = last->column_l ();
- Item *col = it->column_l ();
-
- int lrank = Paper_column::rank_i (lcol);
- int rank = Paper_column ::rank_i (col);
-
- bool mus = Paper_column::musical_b (col);
- bool lmus = Paper_column::musical_b (lcol);
-
- if ((lrank - rank == 2) && lmus && mus)
- {
- SCM seq = col->get_grob_property ("spacing-sequence");
- col->set_grob_property ("spacing-sequence",
- gh_cons (gh_cons (it->self_scm (), last->self_scm ()), seq));
- }
-
- if (llast && !Paper_column::breakable_b (last))
- {
- Item *llcol = llast->column_l ();
- int llrank = Paper_column::rank_i (llcol);
- bool llmus= Paper_column::musical_b (llcol);
- if (llrank - lrank == 1
- && lrank - rank == 1
- && llmus && !lmus && mus)
- {
- SCM seq = col->get_grob_property ("spacing-sequence");
- col->set_grob_property ("spacing-sequence",
- gh_cons (gh_cons (it->self_scm (), last->self_scm ()), seq));
- }
- else if (!lmus)
- {
- SCM between = lcol->get_grob_property ("between-cols");
-
- if (!gh_pair_p (between))
- {
- between = gh_cons (it->self_scm (), llast->self_scm ());
- lcol ->set_grob_property ("between-cols", between);
- }
-
- Item * left
- = dynamic_cast<Item*> (unsmob_grob (gh_car (between)));
- if(Paper_column::rank_i (left->column_l ()) < rank)
- gh_set_car_x (between, col->self_scm());
-
- Item * right
- = dynamic_cast<Item*> (unsmob_grob (gh_cdr (between)));
- if (Paper_column::rank_i (right->column_l ()) > llrank )
- gh_set_cdr_x (between, llcol->self_scm ());
- }
- }
- }
-
- llast = last;
- last = it;
- }
-}
-
-#if 0
-void
-Separating_group_spanner::set_loose_rods ()
-{
- // loose columns should also generate minimum distances.
- // TODO
+ Pointer_group_interface::add_unordered_grob (me, ly_symbol2scm ("elements"), i);
}
-#endif
+ADD_INTERFACE (Separating_group_spanner,
+ "A spanner that calculates spacing constraints (\"rods\") "
+ "using the @code{separation-item-interface} grobs in @code{elements}.",
-void
-Separating_group_spanner::set_interface (Grob*)
-{
-}
-
-bool
-Separating_group_spanner::has_interface (Grob*)
-{//todo
- assert (false);
-}
+ /* properties */
+ "elements "
+ "padding ");