source file of the GNU LilyPond music typesetter
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
#include "script-column.hh"
-#include "debug.hh"
-#include "script.hh"
-#include "note-head.hh"
-#include "stem.hh"
-
-IMPLEMENT_STATIC_NAME(Script_column);
+#include "side-position-interface.hh"
+#include "warn.hh"
+#include "group-interface.hh"
void
-Script_column::add(Script*s_l)
+Script_column::add_staff_sided (Grob *me, Item *i)
{
- script_l_arr_.push(s_l);
- add_element(s_l);
-}
+ SCM p = i->get_property ("script-priority");
+ if (!scm_is_number (p))
+ return;
+ Pointer_group_interface::add_grob (me, ly_symbol2scm ("scripts"), i);
-void
-Script_column::do_print()const
-{
- mtor << "scripts: " << script_l_arr_.size() << '\n';
+ me->add_dependency (i);
}
+LY_DEFINE (ly_grob_script_priority_less, "ly:grob-script-priority-less",
+ 2, 0, 0, (SCM a, SCM b),
+ "Compare two grobs by script priority. For internal use.")
+{
+ Grob *i1 = unsmob_grob (a);
+ Grob *i2 = unsmob_grob (b);
-void
-Script_column::do_pre_processing()
+ SCM p1 = i1->get_property ("script-priority");
+ SCM p2 = i2->get_property ("script-priority");
+
+ return scm_to_int (p1) < scm_to_int (p2) ? SCM_BOOL_T : SCM_BOOL_F;
+}
+
+MAKE_SCHEME_CALLBACK (Script_column, before_line_breaking, 1);
+SCM
+Script_column::before_line_breaking (SCM smob)
{
- if (!script_l_arr_.size())
- return;
- /* up+outside, up+inside, down+outside, down+inside */
- Array<Script*> placed_l_arr_a[4];
- for (int i=0; i < script_l_arr_.size(); i++) {
- Script*s_l = script_l_arr_[i];
- int j = (s_l->dir_i_ >0) ? 0 : 2;
- if (!s_l->inside_staff_b_)
- j ++;
-
- placed_l_arr_a[j].push(s_l);
- }
-
- for (int j =0; j <4; j++) {
- placed_l_arr_a[j].sort( Script::compare);
- }
+ Grob *me = unsmob_grob (smob);
+ Drul_array<SCM> scripts (SCM_EOL, SCM_EOL);
+ Link_array<Grob> staff_sided;
+ for (SCM s = me->get_property ("scripts"); scm_is_pair (s); s = scm_cdr (s))
+ {
+ Grob *sc = unsmob_grob (scm_car (s));
- for (int j =0; j < 4; j++) {
- if (placed_l_arr_a[j].size())
- for (int i=0; i < support_l_arr_.size(); i++)
- placed_l_arr_a[j][0]->add_support( support_l_arr_[i]);
- }
- Item * support_l=0;
- int j = 0;
- for (; j < 2; j++ ) {
- for (int i=1; i < placed_l_arr_a[j].size(); i++) {
- if (support_l)
- placed_l_arr_a[j][i]->add_support(support_l);
- support_l = placed_l_arr_a[j][i];
- }
+ /*
+ Don't want to consider scripts horizontally next to notes.
+ */
+ if (!sc->has_offset_callback (Side_position_interface::aligned_side_proc,
+ X_AXIS))
+ staff_sided.push (sc);
}
- support_l = 0;
- for (; j < 4; j++ ) {
- for (int i=1; i < placed_l_arr_a[j].size(); i++) {
- if (support_l)
- placed_l_arr_a[j][i]->add_support(support_l);
- support_l = placed_l_arr_a[j][i];
+
+ for (int i = 0; i < staff_sided.size (); i++)
+ {
+ Grob *g = staff_sided[i];
+ Direction d = Side_position_interface::get_direction (g);
+ if (!d)
+ {
+ programming_error ("no direction for script");
+ d = DOWN;
+ g->set_property ("direction", scm_int2num (d));
}
+
+ scripts[d] = scm_cons (g->self_scm (), scripts[d]);
}
-}
+ Direction d = DOWN;
+ do
+ {
+ SCM ss = scm_reverse_x (scripts[d], SCM_EOL);
+ ss = scm_stable_sort_x (ss, ly_grob_script_priority_less_proc);
-void
-Script_column::add_support(Item*i_l)
-{
- support_l_arr_.push(i_l);
- add_element(i_l);
-}
+ Grob *last = 0;
+ for (SCM s = ss; scm_is_pair (s); s = scm_cdr (s))
+ {
+ Grob *g = unsmob_grob (scm_car (s));
+ if (last)
+ Side_position_interface::add_support (g, last);
-void
-Script_column::do_substitute_dependency(Score_elem*o,Score_elem*n)
-{
- Element_group::do_substitute_dependency(o,n);
- if (o->item()) {
- script_l_arr_.substitute((Script*)o->item(),(Script*) (n?n->item():0));
- support_l_arr_.substitute(o->item(), (n?n->item():0));
+ last = g;
+ }
}
+ while (flip (&d) != DOWN);
+
+ return SCM_UNSPECIFIED;
}
+
+ADD_INTERFACE (Script_column, "script-column-interface",
+ "An interface that sorts scripts "
+ "according to their @code{script-priority}",
+ "");