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);
39 skylines[d].merge ((*sky)[-d]);
41 programming_error ("separation item has no skyline");
43 if (d == RIGHT && items[LEFT].size ())
44 skylines[d].merge (Separation_item::conditional_skyline (items[d][i], items[LEFT][0]));
47 while (flip (&d) != LEFT);
49 return skylines[LEFT].distance (skylines[RIGHT]);
53 Compute the column of the right-items. This is a big function,
54 since RIGHT-ITEMS may span more columns (eg. if a clef is inserted,
55 this will add a new column to RIGHT-ITEMS. Here we look at the
56 columns, and return the left-most. If there are multiple columns, we
60 Spacing_interface::right_column (Grob *me)
65 Grob_array *a = unsmob_grob_array (me->get_object ("right-items"));
67 int min_rank = INT_MAX;
69 for (vsize i = 0; a && i < a->size (); i++)
71 Item *ri = a->item (i);
72 Item *col = ri->get_column ();
74 int rank = Paper_column::get_rank (col);
88 vector<Grob*> &right = a->array_reference ();
89 for (vsize i = right.size (); i--;)
91 if (dynamic_cast<Item *> (right[i])->get_column () != mincol)
92 right.erase (right.begin () + i);
100 Spacing_interface::left_column (Grob *me)
105 return dynamic_cast<Item *> (me)->get_column ();
109 get_note_columns (vector<Grob*> const &elts)
113 for (vsize i = 0; i < elts.size (); i++)
114 if (Note_column::has_interface (elts[i]))
115 ret.push_back (dynamic_cast<Item*> (elts[i]));
121 Spacing_interface::right_note_columns (Grob *me)
123 extract_grob_set (me, "right-items", elts);
124 return get_note_columns (elts);
128 Spacing_interface::left_note_columns (Grob *me)
130 extract_grob_set (me, "left-items", elts);
131 return get_note_columns (elts);
134 ADD_INTERFACE (Spacing_interface,
135 "This object calculates the desired and minimum distances between two columns.",