2 spacing-interface.cc -- functionality that is shared between Note_spacing
5 source file of the GNU LilyPond music typesetter
7 (c) 2007 Joe Neeman <joeneeman@gmail.com>
10 #include "spacing-interface.hh"
13 #include "grob-array.hh"
15 #include "note-column.hh"
16 #include "pointer-group-interface.hh"
17 #include "paper-column.hh"
18 #include "separation-item.hh"
21 /* return the minimum distance between the left-items and the right-items of
22 this spacing object */
24 Spacing_interface::minimum_distance (Grob *me)
26 Drul_array<Skyline> skylines = Drul_array<Skyline> (Skyline (RIGHT), Skyline (LEFT));
27 Drul_array<vector<Grob*> > items (ly_scm2link_array (me->get_object ("left-items")),
28 ly_scm2link_array (me->get_object ("right-items")));
33 for (vsize i = 0; i < items[d].size (); i++)
34 if (Separation_item::has_interface (items[d][i]))
36 SCM sky_scm = items[d][i]->get_property ("horizontal-skylines");
37 Skyline_pair *sky = Skyline_pair::unsmob (sky_scm);
38 skylines[d].merge ((*sky)[-d]);
40 if (d == RIGHT && items[LEFT].size ())
41 skylines[d].merge (Separation_item::conditional_skyline (items[d][i], items[LEFT][0]));
44 while (flip (&d) != LEFT);
46 return skylines[LEFT].distance (skylines[RIGHT]);
50 Compute the column of the right-items. This is a big function,
51 since RIGHT-ITEMS may span more columns (eg. if a clef is inserted,
52 this will add a new column to RIGHT-ITEMS. Here we look at the
53 columns, and return the left-most. If there are multiple columns, we
57 Spacing_interface::right_column (Grob *me)
62 Grob_array *a = unsmob_grob_array (me->get_object ("right-items"));
64 int min_rank = INT_MAX;
66 for (vsize i = 0; a && i < a->size (); i++)
68 Item *ri = a->item (i);
69 Item *col = ri->get_column ();
71 int rank = Paper_column::get_rank (col);
85 vector<Grob*> &right = a->array_reference ();
86 for (vsize i = right.size (); i--;)
88 if (dynamic_cast<Item *> (right[i])->get_column () != mincol)
89 right.erase (right.begin () + i);
97 Spacing_interface::left_column (Grob *me)
102 return dynamic_cast<Item *> (me)->get_column ();
106 get_note_columns (vector<Grob*> const &elts)
110 for (vsize i = 0; i < elts.size (); i++)
111 if (Note_column::has_interface (elts[i]))
112 ret.push_back (dynamic_cast<Item*> (elts[i]));
118 Spacing_interface::right_note_columns (Grob *me)
120 extract_grob_set (me, "right-items", elts);
121 return get_note_columns (elts);
125 Spacing_interface::left_note_columns (Grob *me)
127 extract_grob_set (me, "left-items", elts);
128 return get_note_columns (elts);
131 ADD_INTERFACE (Spacing_interface,
132 "This object calculates the desired and minimum distances between two columns.",