2 separation-item.cc -- implement Separation_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "separation-item.hh"
12 #include "paper-column.hh"
14 #include "pointer-group-interface.hh"
15 #include "accidental-placement.hh"
18 Separation_item::add_item (Grob *s, Item *i)
21 Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"), i);
25 Separation_item::add_conditional_item (Grob *me, Grob *e)
27 Pointer_group_interface::add_grob (me, ly_symbol2scm ("conditional-elements"), e);
31 Separation_item::set_skyline_distance (Drul_array<Item *> items,
34 Drul_array<Skyline_pair*> lines (Skyline_pair::unsmob (items[LEFT]->get_property ("skylines")),
35 Skyline_pair::unsmob (items[RIGHT]->get_property ("skylines")));
36 Skyline right = conditional_skyline (items[RIGHT], items[LEFT]);
37 right.merge ((*lines[RIGHT])[LEFT]);
39 Real dist = padding + (*lines[LEFT])[RIGHT].distance (right);
44 rod.item_drul_ = items;
52 Separation_item::set_distance (Drul_array<Item *> items,
55 set_skyline_distance (items, padding);
60 Return the width of ME given that we are considering the object on
64 Separation_item::conditional_skyline (Grob *me, Grob *left)
66 vector<Box> bs = boxes (me, left);
67 return Skyline (bs, 0.1, Y_AXIS, LEFT);
71 MAKE_SCHEME_CALLBACK(Separation_item,calc_skylines,1);
73 Separation_item::calc_skylines (SCM smob)
75 Item *me = unsmob_item (smob);
76 vector<Box> bs = boxes (me, 0);
77 /* todo: the horizon_padding is somewhat arbitrary */
78 return Skyline_pair (bs, 0.1, Y_AXIS).smobbed_copy ();
81 /* if left is non-NULL, get the boxes corresponding to the
82 conditional-elements (conditioned on the grob LEFT). This
83 sounds more general than it is: conditional-elements are
84 always accidentals attached to a tied note.
87 Separation_item::boxes (Grob *me, Grob *left)
89 Item *item = dynamic_cast<Item *> (me);
91 int very_large = INT_MAX;
92 Paper_column *pc = item->get_column ();
94 extract_grob_set (me, left ? "conditional-elements" : "elements", read_only_elts);
98 elts = Accidental_placement::get_break_reminder_accidentals (read_only_elts, left);
100 elts = read_only_elts;
102 Grob *ycommon = common_refpoint_of_array (elts, me, Y_AXIS);
104 for (vsize i = 0; i < elts.size (); i++)
106 Item *il = dynamic_cast<Item *> (elts[i]);
107 if (pc != il->get_column ())
112 Interval y (il->pure_height (ycommon, 0, very_large));
113 Interval x (il->extent (pc, X_AXIS));
115 Interval extra = robust_scm2interval (elts[i]->get_property ("extra-spacing-width"),
117 x[LEFT] += extra[LEFT];
118 x[RIGHT] += extra[RIGHT];
119 if (to_boolean (elts[i]->get_property ("infinite-spacing-height")))
120 y = Interval (-infinity_f, infinity_f);
122 out.push_back (Box (x, y));
129 Separation_item::width (Grob *me)
131 SCM sw = me->get_property ("X-extent");
132 return ly_scm2interval (sw);
136 Separation_item::relative_width (Grob *me, Grob *common)
138 Interval iv = width (me);
140 return dynamic_cast<Item *> (me)->get_column ()->relative_coordinate (common, X_AXIS) + iv;
144 Try to find the break-aligned symbol in SEPARATION_ITEM that is
145 sticking out at direction D. The x size is put in LAST_EXT
148 Separation_item::extremal_break_aligned_grob (Grob *me,
152 Grob *col = dynamic_cast<Item *> (me)->get_column ();
153 last_ext->set_empty ();
156 extract_grob_set (me, "elements", elts);
157 for (vsize i = elts.size (); i--;)
159 Grob *break_item = elts[i];
160 if (!scm_is_symbol (break_item->get_property ("break-align-symbol")))
163 if (!scm_is_pair (break_item->get_property ("space-alist")))
166 Interval ext = break_item->extent (col, X_AXIS);
172 || (last_grob && d * (ext[d]- (*last_ext)[d]) > 0))
175 last_grob = break_item;
182 ADD_INTERFACE (Separation_item,
183 "Item that computes widths to generate spacing rods. "
184 "This is done in concert with @ref{separating-group-spanner-interface}.",
187 "conditional-elements "