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"
11 #include "axis-group-interface.hh"
15 #include "paper-column.hh"
17 #include "pointer-group-interface.hh"
18 #include "accidental-placement.hh"
21 Separation_item::add_item (Grob *s, Item *i)
24 Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"), i);
28 Separation_item::add_conditional_item (Grob *me, Grob *e)
30 Pointer_group_interface::add_grob (me, ly_symbol2scm ("conditional-elements"), e);
34 Separation_item::set_distance (Item *l, Item *r, Real padding)
36 Drul_array<Skyline_pair*> lines (Skyline_pair::unsmob (l->get_property ("horizontal-skylines")),
37 Skyline_pair::unsmob (r->get_property ("horizontal-skylines")));
38 Skyline right = conditional_skyline (r, l);
39 right.merge ((*lines[RIGHT])[LEFT]);
41 Real dist = padding + (*lines[LEFT])[RIGHT].distance (right);
46 rod.item_drul_ = Drul_array<Item*> (l, r);
52 return max (dist, 0.0);
56 Separation_item::is_empty (Grob *me)
58 Skyline_pair *sky = Skyline_pair::unsmob (me->get_property ("horizontal-skylines"));
59 return (!sky || sky->is_empty ());
63 Return the width of ME given that we are considering the object on
67 Separation_item::conditional_skyline (Grob *me, Grob *left)
69 vector<Box> bs = boxes (me, left);
70 return Skyline (bs, 0.1, Y_AXIS, LEFT);
74 MAKE_SCHEME_CALLBACK (Separation_item, calc_skylines,1);
76 Separation_item::calc_skylines (SCM smob)
78 Item *me = unsmob_item (smob);
79 vector<Box> bs = boxes (me, 0);
80 /* todo: the horizon_padding is somewhat arbitrary */
81 return Skyline_pair (bs, 0.1, Y_AXIS).smobbed_copy ();
84 /* if left is non-NULL, get the boxes corresponding to the
85 conditional-elements (conditioned on the grob LEFT). This
86 sounds more general than it is: conditional-elements are
87 always accidentals attached to a tied note.
90 Separation_item::boxes (Grob *me, Grob *left)
92 Item *item = dynamic_cast<Item *> (me);
94 int very_large = INT_MAX;
95 Paper_column *pc = item->get_column ();
97 extract_grob_set (me, left ? "conditional-elements" : "elements", read_only_elts);
101 elts = Accidental_placement::get_relevant_accidentals (read_only_elts, left);
103 elts = read_only_elts;
105 Grob *ycommon = common_refpoint_of_array (elts, me, Y_AXIS);
107 for (vsize i = 0; i < elts.size (); i++)
109 Item *il = dynamic_cast<Item *> (elts[i]);
110 if (pc != il->get_column ())
112 if (Axis_group_interface::has_interface (il))
115 Interval y (il->pure_height (ycommon, 0, very_large));
116 Interval x (il->extent (pc, X_AXIS));
118 Interval extra = robust_scm2interval (elts[i]->get_property ("extra-spacing-width"),
119 Interval (-0.1, 0.1));
120 x[LEFT] += extra[LEFT];
121 x[RIGHT] += extra[RIGHT];
122 if (to_boolean (elts[i]->get_property ("infinite-spacing-height")))
123 y = Interval (-infinity_f, infinity_f);
125 if (!x.is_empty () && !y.is_empty ())
126 out.push_back (Box (x, y));
132 extern bool debug_skylines;
133 MAKE_SCHEME_CALLBACK (Separation_item, print, 1)
135 Separation_item::print (SCM smob)
140 Grob *me = unsmob_grob (smob);
142 if (Skyline_pair *s = Skyline_pair::unsmob (me->get_property ("horizontal-skylines")))
144 ret.add_stencil (Lookup::points_to_line_stencil (0.1, (*s)[LEFT].to_points (Y_AXIS)).in_color (255, 255, 0));
145 ret.add_stencil (Lookup::points_to_line_stencil (0.1, (*s)[RIGHT].to_points (Y_AXIS)).in_color (0, 255, 255));
147 return ret.smobbed_copy ();
150 ADD_INTERFACE (Separation_item,
151 "Item that computes widths to generate spacing rods. "
155 "conditional-elements "
158 "horizontal-skylines "