2 script-column.cc -- implement Script_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "script-column.hh"
11 #include "side-position-interface.hh"
13 #include "group-interface.hh"
16 Script_column::add_staff_sided (Grob *me, Item *i)
18 SCM p = i->get_property ("script-priority");
19 if (!scm_is_number (p))
22 Pointer_group_interface::add_grob (me, ly_symbol2scm ("scripts"), i);
24 me->add_dependency (i);
27 LY_DEFINE (ly_grob_script_priority_less, "ly:grob-script-priority-less",
28 2, 0, 0, (SCM a, SCM b),
29 "Compare two grobs by script priority. For internal use.")
31 Grob *i1 = unsmob_grob (a);
32 Grob *i2 = unsmob_grob (b);
34 SCM p1 = i1->get_property ("script-priority");
35 SCM p2 = i2->get_property ("script-priority");
37 return scm_to_int (p1) < scm_to_int (p2) ? SCM_BOOL_T : SCM_BOOL_F;
40 MAKE_SCHEME_CALLBACK (Script_column, before_line_breaking, 1);
42 Script_column::before_line_breaking (SCM smob)
44 Grob *me = unsmob_grob (smob);
45 Drul_array<SCM> scripts (SCM_EOL, SCM_EOL);
46 Link_array<Grob> staff_sided;
48 for (SCM s = me->get_property ("scripts"); scm_is_pair (s); s = scm_cdr (s))
50 Grob *sc = unsmob_grob (scm_car (s));
53 Don't want to consider scripts horizontally next to notes.
55 if (!sc->has_offset_callback (Side_position_interface::aligned_side_proc,
57 staff_sided.push (sc);
60 for (int i = 0; i < staff_sided.size (); i++)
62 Grob *g = staff_sided[i];
63 Direction d = Side_position_interface::get_direction (g);
66 programming_error ("No direction for script?");
68 g->set_property ("direction", scm_int2num (d));
71 scripts[d] = scm_cons (g->self_scm (), scripts[d]);
77 SCM ss = scm_reverse_x (scripts[d], SCM_EOL);
78 ss = scm_stable_sort_x (ss, ly_grob_script_priority_less_proc);
81 for (SCM s = ss; scm_is_pair (s); s = scm_cdr (s))
83 Grob *g = unsmob_grob (scm_car (s));
85 Side_position_interface::add_support (g, last);
91 while (flip (&d) != DOWN);
93 return SCM_UNSPECIFIED;
96 ADD_INTERFACE (Script_column, "script-column-interface",
97 "An interface that sorts scripts "
98 "according to their @code{script-priority}",