lilypond-1.3.12
[lilypond.git] / lily / g-script-column.cc
blobd16a9cb7959833d3b34a66e474933bea12657916
1 /*
2 g-script-column.cc -- implement G_script_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include "g-script-column.hh"
10 #include "g-staff-side.hh"
12 static G_staff_side_item *
13 get_g_staff_side (Item *i)
15 Graphical_element *e1 = i->dim_cache_[Y_AXIS]->parent_l_->element_l ();
17 return dynamic_cast<G_staff_side_item*>(e1);
20 void
21 G_script_column::add_staff_sided (Item *i)
23 SCM p = get_g_staff_side (i)->get_elt_property (script_priority_scm_sym);
24 if (p == SCM_BOOL_F)
25 return;
27 staff_sided_item_l_arr_.push (i);
28 add_dependency (i);
31 static int
32 staff_side_compare (Item * const &i1,
33 Item * const &i2)
35 Score_element *e1 = get_g_staff_side (i1);
36 Score_element *e2 = get_g_staff_side (i2);
38 SCM p1 = e1->get_elt_property (script_priority_scm_sym);
39 SCM p2 = e2->get_elt_property (script_priority_scm_sym);
41 return gh_scm2int (SCM_CDR(p1)) - gh_scm2int (SCM_CDR(p2));
44 void
45 G_script_column::do_pre_processing ()
47 Drul_array<Link_array<Item> > arrs;
49 for (int i=0; i < staff_sided_item_l_arr_.size (); i++)
51 G_staff_side_item * ip = get_g_staff_side (staff_sided_item_l_arr_[i]);
52 arrs[ip->dir_].push (staff_sided_item_l_arr_[i]);
55 Direction d = DOWN;
56 do {
57 Link_array<Item> &arr(arrs[d]);
59 arr.sort (staff_side_compare);
61 Item * last = 0;
62 for (int i=0; i < arr.size (); i++)
64 G_staff_side_item * gs = get_g_staff_side (arr[i]);
65 if (last)
67 gs->add_support (last);
68 gs->add_support (get_g_staff_side (last));
71 gs->remove_elt_property (script_priority_scm_sym);
72 last = arr[i];
75 } while (flip (&d) != DOWN);