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 "paper-column.hh"
17 #include "separation-item.hh"
20 /* return the minimum distance between the left-items and the right-items of
21 this spacing object */
23 Spacing_interface::minimum_distance (Grob *me)
25 Drul_array<Skyline> skylines = Drul_array<Skyline> (Skyline (RIGHT), Skyline (LEFT));
26 Drul_array<vector<Grob*> > items (ly_scm2link_array (me->get_object ("left-items")),
27 ly_scm2link_array (me->get_object ("right-items")));
32 for (vsize i = 0; i < items[d].size (); i++)
33 if (Separation_item::has_interface (items[d][i]))
35 SCM sky_scm = items[d][i]->get_property ("horizontal-skylines");
36 Skyline_pair *sky = Skyline_pair::unsmob (sky_scm);
37 skylines[d].merge ((*sky)[-d]);
39 if (d == RIGHT && items[LEFT].size ())
40 skylines[d].merge (Separation_item::conditional_skyline (items[d][i], items[LEFT][0]));
43 while (flip (&d) != LEFT);
45 return skylines[LEFT].distance (skylines[RIGHT]);
49 Compute the column of the right-items. This is a big function,
50 since RIGHT-ITEMS may span more columns (eg. if a clef is inserted,
51 this will add a new column to RIGHT-ITEMS. Here we look at the
52 columns, and return the left-most. If there are multiple columns, we
56 Spacing_interface::right_column (Grob *me)
61 Grob_array *a = unsmob_grob_array (me->get_object ("right-items"));
63 int min_rank = INT_MAX;
65 for (vsize i = 0; a && i < a->size (); i++)
67 Item *ri = a->item (i);
68 Item *col = ri->get_column ();
70 int rank = Paper_column::get_rank (col);
84 vector<Grob*> &right = a->array_reference ();
85 for (vsize i = right.size (); i--;)
87 if (dynamic_cast<Item *> (right[i])->get_column () != mincol)
88 right.erase (right.begin () + i);
96 Spacing_interface::left_column (Grob *me)
101 return dynamic_cast<Item *> (me)->get_column ();
105 Spacing_interface::note_columns (Grob *me)
107 Drul_array<Item*> ret (0, 0);
108 Drul_array<vector<Grob*> > items (ly_scm2link_array (me->get_object ("left-items")),
109 ly_scm2link_array (me->get_object ("right-items")));
114 for (vsize i = 0; i < items[d].size (); i++)
115 if (Note_column::has_interface (items[d][i]))
116 ret[d] = dynamic_cast<Item*> (items[d][i]);
118 while (flip (&d) != LEFT);
123 ADD_INTERFACE (Spacing_interface,
124 "This object calculates the desired and minimum distances between two columns.",