]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-column.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[lilypond.git] / lily / script-column.cc
1 /*   
2   script-column.cc --  implement Script_column
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9 #include "script-column.hh"
10 #include "side-position-interface.hh"
11 #include "warn.hh"
12 #include "group-interface.hh"
13
14 void
15 Script_column::add_staff_sided (Grob *me, Item *i)
16 {
17   SCM p = i->get_grob_property ("script-priority");
18   if (!gh_number_p (p))
19     return;
20
21   Pointer_group_interface::add_grob (me, ly_symbol2scm ("scripts"),i);
22   
23   me->add_dependency (i);
24 }
25
26 LY_DEFINE(grob_script_priority_less,
27           "ly-grob-script-priority-less", 2, 0, 0, 
28           (SCM a, SCM b),
29           "Compare two grobs by script priority. For internal use.")
30 {
31   Grob * i1 = unsmob_grob (a);
32   Grob* i2 = unsmob_grob (b);
33
34   SCM p1 = i1->get_grob_property ("script-priority");
35   SCM p2 = i2->get_grob_property ("script-priority");
36
37   return gh_scm2int (p1) < gh_scm2int (p2) ? SCM_BOOL_T : SCM_BOOL_F;
38 }
39
40
41
42 MAKE_SCHEME_CALLBACK (Script_column,before_line_breaking,1);
43 SCM
44 Script_column::before_line_breaking (SCM smob)
45 {
46   Grob* me = unsmob_grob (smob);
47   Drul_array<SCM> scripts (SCM_EOL, SCM_EOL);
48   Link_array<Grob> staff_sided 
49     = Pointer_group_interface__extract_grobs (me, (Grob*)0, "scripts");
50                                      
51   for (int i=0; i < staff_sided.size (); i++)
52     {
53       Grob* g = staff_sided[i];
54       Direction d = Side_position_interface::get_direction (g);
55       if (!d)
56         {
57           programming_error ( "No direction for script?");
58           d = DOWN;
59           g->set_grob_property ("direction", gh_int2scm (d));
60         }
61       
62       scripts[d] = scm_cons (g->self_scm(), scripts[d]);
63     }
64
65   Direction d = DOWN;
66   do {
67     SCM ss = scm_reverse_x (scripts[d], SCM_EOL);
68     
69     ss = scm_stable_sort_x (ss,  grob_script_priority_less_proc);
70
71     Grob * last = 0;
72     for (SCM s = ss; gh_pair_p (s); s = gh_cdr (s))
73       {
74         Grob* g = unsmob_grob (gh_car (s));
75         if (last)
76           Side_position_interface::add_support (g,last);
77
78         last = g;
79       }
80     
81   } while (flip (&d) != DOWN);
82
83   return SCM_UNSPECIFIED;
84 }
85
86
87 ADD_INTERFACE (Script_column,"script-column-interface",
88   "An interface that sorts scripts according to their @code{script-priority}",
89   "");
90
91