lilypond-1.3.7
[lilypond.git] / lily / script-column.cc
blob6fabed4d90bc0eeaec360e1a95975a17722deb96
1 /*
2 g-script-column.cc -- implement Script_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include "script-column.hh"
10 #include "staff-side.hh"
11 #include "dimension-cache.hh"
13 static Staff_side_item *
14 get_Staff_side (Item *i)
16 Graphical_element *e1 = i->parent_l(Y_AXIS);
18 return dynamic_cast<Staff_side_item*>(e1);
21 void
22 Script_column::add_staff_sided (Item *i)
24 SCM p = get_Staff_side (i)->get_elt_property ("script-priority");
25 if (p == SCM_UNDEFINED)
26 return;
28 staff_sided_item_l_arr_.push (i);
29 add_dependency (i);
32 static int
33 staff_side_compare (Item * const &i1,
34 Item * const &i2)
36 Score_element *e1 = get_Staff_side (i1);
37 Score_element *e2 = get_Staff_side (i2);
39 SCM p1 = e1->get_elt_property ("script-priority");
40 SCM p2 = e2->get_elt_property ("script-priority");
42 return gh_scm2int (p1) - gh_scm2int (p2);
45 void
46 Script_column::do_pre_processing ()
48 Drul_array<Link_array<Item> > arrs;
50 for (int i=0; i < staff_sided_item_l_arr_.size (); i++)
52 Staff_side_item * ip = get_Staff_side (staff_sided_item_l_arr_[i]);
53 arrs[ip->get_direction ()].push (staff_sided_item_l_arr_[i]);
56 Direction d = DOWN;
57 do {
58 Link_array<Item> &arr(arrs[d]);
60 arr.sort (staff_side_compare);
62 Item * last = 0;
63 for (int i=0; i < arr.size (); i++)
65 Staff_side_item * gs = get_Staff_side (arr[i]);
66 if (last)
68 gs->add_support (last);
69 gs->add_support (get_Staff_side (last));
72 gs->remove_elt_property ("script-priority");
73 last = arr[i];
76 } while (flip (&d) != DOWN);