2 separation-item.cc -- implement Separation_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "separation-item.hh"
11 #include "paper-column.hh"
13 #include "group-interface.hh"
14 #include "accidental-placement.hh"
17 Separation_item::add_item (Grob*s,Item* i)
20 Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"),i);
21 s->add_dependency (i);
25 Separation_item::add_conditional_item (Grob* me , Grob *e)
27 Pointer_group_interface::add_grob (me, ly_symbol2scm ("conditional-elements"), e);
31 Return the width of ME given that we are considering the object on
35 Separation_item::conditional_width (Grob * me, Grob * left)
37 Interval w = width (me);
39 Item *item = dynamic_cast<Item*> (me);
40 Paper_column * pc = item->get_column ();
43 for (SCM s = me->get_grob_property ("conditional-elements"); gh_pair_p (s); s = ly_cdr (s))
46 if (!unsmob_grob (elt))
49 Item *il = unsmob_item (elt);
50 if (pc != il->get_column ())
52 /* this shouldn't happen, but let's continue anyway. */
53 programming_error (_ ("Separation_item: I've been drinking too much"));
57 if (to_boolean (il->get_grob_property ("no-spacing-rods")))
62 if (Accidental_placement::has_interface (il))
64 w.unite (Accidental_placement::get_relevant_accidental_extent (il, pc, left));
68 SCM pad = me->get_grob_property ("padding");
70 if (gh_number_p (pad))
72 w[RIGHT] += gh_scm2double (pad)/2;
73 w[LEFT] -= gh_scm2double (pad)/2;
79 Separation_item::width (Grob *me)
81 SCM sw = me->get_grob_property ("X-extent");
82 if (ly_number_pair_p (sw))
84 return ly_scm2interval (sw);
87 Item *item = dynamic_cast<Item*> (me);
88 Paper_column * pc = item->get_column ();
91 for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s); s = ly_cdr (s))
94 if (!unsmob_grob (elt))
97 Item *il = unsmob_item (elt);
98 if (pc != il->get_column ())
100 /* this shouldn't happen, but let's continue anyway. */
101 programming_error (_ ("Separation_item: I've been drinking too much"));
102 continue; /*UGH UGH*/
105 if (to_boolean (il->get_grob_property ("no-spacing-rods")))
110 Interval iv (il->extent (pc, X_AXIS));
117 SCM pad = me->get_grob_property ("padding");
119 if (gh_number_p (pad))
121 w[RIGHT] += gh_scm2double (pad)/2;
122 w[LEFT] -= gh_scm2double (pad)/2;
126 me->set_grob_property ("X-extent", ly_interval2scm (w));
130 // add this->offset_ ? this-> relative_coordinate ()?
137 ADD_INTERFACE (Separation_item,"separation-item-interface",
138 "Item that computes widths to generate spacing rods.
140 Calc dimensions for the Separating_group_spanner; this has to be
141 an item to get dependencies correct. It can't be an grob_group
142 since these usually are in a different X_group
144 "X-extent conditional-elements elements");