]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-group-spanner.cc
* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[lilypond.git] / lily / separating-group-spanner.cc
1 /*   
2   separating-group-spanner.cc --  implement Separating_group_spanner
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "separating-group-spanner.hh"
11 #include "separation-item.hh"
12 #include "paper-column.hh"
13 #include "paper-def.hh"
14 #include "dimensions.hh"
15 #include "group-interface.hh"
16
17 void
18 Separating_group_spanner::find_rods (Item * r, SCM next, Real padding)
19 {
20
21   /*
22     This is an inner loop: look for the first normal (unbroken) Left
23     grob.  This looks like an inner loop (ie. quadratic total), but in
24     most cases, the interesting L will just be the first entry of
25     NEXT, making it linear in most of the cases.
26   */
27   if (Separation_item::width (r).is_empty ())
28     return; 
29
30
31   for (; ly_pair_p (next); next = ly_cdr (next))
32     {
33       Item *l = dynamic_cast<Item*> (unsmob_grob (ly_car ( next)));
34       Item *lb = l->find_prebroken_piece (RIGHT);
35
36       if (lb)
37         {
38           Interval li (Separation_item::width (lb));
39           Interval ri (Separation_item::conditional_width (r, lb));
40           if (!li.is_empty () && !ri.is_empty ())
41             {
42               Rod rod;
43
44               rod.item_l_drul_[LEFT] = lb;
45               rod.item_l_drul_[RIGHT] = r;
46
47               rod.distance_ = li[RIGHT] - ri[LEFT] + padding;
48               rod.add_to_cols ();
49             }
50         }
51
52       Interval li (Separation_item::width (l));
53       Interval ri (Separation_item::conditional_width (r, l));
54       if (!li.is_empty () && !ri.is_empty ())
55         {
56           Rod rod;
57
58           rod.item_l_drul_[LEFT] =l;
59           rod.item_l_drul_[RIGHT]=r;
60
61           rod.distance_ = li[RIGHT] - ri[LEFT] + padding;
62         
63           rod.add_to_cols ();
64           break;
65         }
66
67       /*
68         this grob doesn't cause a constraint. We look further until we
69         find one that does.
70       */
71
72     }
73 }
74
75 MAKE_SCHEME_CALLBACK (Separating_group_spanner,set_spacing_rods,1);
76 SCM
77 Separating_group_spanner::set_spacing_rods (SCM smob)
78 {
79   Grob*me = unsmob_grob (smob);
80
81   /*
82     Ugh: padding is added doubly, also for SeparationItem
83    */
84   Real padding = robust_scm2double (me->get_property ("padding"), 0.1);
85   
86   for (SCM s = me->get_property ("elements"); ly_pair_p (s) && ly_pair_p (ly_cdr (s)); s = ly_cdr (s))
87     {
88       /*
89         Order of elements is reversed!
90        */
91       SCM elt = ly_car (s);
92       Item *r = unsmob_item (elt);
93
94       if (!r)
95         continue;
96
97       Item *rb
98         = dynamic_cast<Item*> (r->find_prebroken_piece (LEFT));
99       
100       find_rods (r, ly_cdr (s), padding);
101       if (rb)
102         find_rods (rb, ly_cdr (s), padding);
103     }
104
105   return SCM_UNSPECIFIED ;
106 }
107
108 void
109 Separating_group_spanner::add_spacing_unit (Grob* me ,Item*i)
110 {
111   Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), i);
112   me->add_dependency (i);
113 }
114
115
116
117
118
119 ADD_INTERFACE (Separating_group_spanner,"separation-spanner-interface",
120                "A spanner that calculates spacing constraints (\"rods\") "
121                "using the @code{separation-item-interface} grobs in @code{elements}.",
122                "elements padding");