X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fseparating-group-spanner.cc;h=fb8cce00226d91ec9171f54cca78be2e907cb2da;hb=a491ce3b527c6baa8a261147d8684ca82c61e903;hp=6b5c2302a82d96992e443e587bb8022ab18e2345;hpb=0af2486a28f1c60b9de929a9101964d880927e54;p=lilypond.git diff --git a/lily/separating-group-spanner.cc b/lily/separating-group-spanner.cc index 6b5c2302a8..fb8cce0022 100644 --- a/lily/separating-group-spanner.cc +++ b/lily/separating-group-spanner.cc @@ -1,113 +1,94 @@ -/* - 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--2000 Han-Wen Nienhuys - - */ + + (c) 1998--2006 Han-Wen Nienhuys +*/ #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" -static Rod -make_rod (Item *l, Item *r) +void +Separating_group_spanner::find_rods (Item *r, + vector const &separators, + vsize idx, + Real padding) { - Rod rod; - Interval li (Separation_item::my_width (l)); - Interval ri (Separation_item::my_width (r)); + /* + 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 (separators[idx]); + Item *lb = l->find_prebroken_piece (RIGHT); - rod.item_l_drul_[LEFT] =l; - rod.item_l_drul_[RIGHT]=r; + if (lb) + { + Separation_item::set_distance (Drul_array (lb, r), padding); + } - if (li.empty_b () || ri.empty_b ()) - rod.distance_f_ = 0; - else - rod.distance_f_ = li[RIGHT] - ri[LEFT]; + if (Separation_item::set_distance (Drul_array (l, r), padding)) + break; - rod.columnize (); - return rod; + /* + this grob doesn't cause a constraint. We look further until we + find one that does. + */ + } } - -Array -Separating_group_spanner::get_rods () const +MAKE_SCHEME_CALLBACK (Separating_group_spanner, set_spacing_rods, 1); +SCM +Separating_group_spanner::set_spacing_rods (SCM smob) { - Array a; - - for (SCM s = get_elt_property ("elements"); gh_pair_p (s) && gh_pair_p (gh_cdr (s)); s = gh_cdr (s)) - { - /* - Order of elements is reversed! - */ - SCM elt = gh_cadr (s); - SCM next_elt = gh_car (s); + Grob *me = unsmob_grob (smob); + + /* + Ugh: padding is added doubly, also for SeparationItem + */ + Real padding = robust_scm2double (me->get_property ("padding"), 0.1); - Item *l = dynamic_cast (unsmob_element (elt)); - Item *r = dynamic_cast (unsmob_element ( next_elt)); + extract_grob_set (me, "elements", elts); + for (vsize i = elts.size (); i-- > 1;) + { + Item *r = dynamic_cast (elts[i]); + if (!r) + continue; - if (!r || !l) + if (Separation_item::width (r).is_empty ()) continue; - - Item *lb - = dynamic_cast(l->find_prebroken_piece (RIGHT)); Item *rb - = dynamic_cast(r->find_prebroken_piece (LEFT)); - - a.push (make_rod(l, r)); - if (lb) - { - Rod rod(make_rod (lb, r)); - a.push (rod); - } - + = dynamic_cast (r->find_prebroken_piece (LEFT)); + + find_rods (r, elts, i - 1, padding); if (rb) - { - a.push (make_rod (l, rb)); - } - - if (lb && rb) - { - Rod rod(make_rod (lb, rb)); - a.push (rod); - } + find_rods (rb, elts, i - 1, padding); } - /* - We've done our job, so we get lost. - */ - for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s)) - { - Item * it =dynamic_cast(unsmob_element (gh_car (s))); - if (it && it->broken_b ()) - { - it->find_prebroken_piece (LEFT) ->suicide (); - it->find_prebroken_piece (RIGHT)->suicide (); - } - it->suicide (); - } - - ((Separating_group_spanner *)this)->suicide (); - - return a; + return SCM_UNSPECIFIED; } void -Separating_group_spanner::add_spacing_unit (Score_element* me ,Item*i) +Separating_group_spanner::add_spacing_unit (Grob *me, Item *i) { - Pointer_group_interface (me, "elements").add_element (i); - me->add_dependency (i); + Pointer_group_interface::add_unordered_grob (me, ly_symbol2scm ("elements"), i); } +ADD_INTERFACE (Separating_group_spanner, + "A spanner that calculates spacing constraints (\"rods\") " + "using the @code{separation-item-interface} grobs in @code{elements}.", -Separating_group_spanner::Separating_group_spanner (SCM s) - : Spanner (s) -{ - set_elt_property ("elements", SCM_EOL); -} + /* properties */ + "elements " + "padding ");