]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-group-spanner.cc
db22eaa86e7873cae746c8cb0370f903e2842ca8
[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--2002 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)
19 {
20   Interval ri (Separation_item::my_width (r));
21   if (ri.empty_b ())
22     return;
23
24   /*
25     This is an inner loop, however, in most cases, the interesting L
26     will just be the first entry of NEXT, making it linear in most of
27     the cases.  */
28   for(; gh_pair_p (next); next = ly_cdr (next))
29     {
30       Item *l = dynamic_cast<Item*> (unsmob_grob (ly_car( next)));
31       Item *lb = l->find_prebroken_piece (RIGHT);
32
33       if (lb)
34         {
35           Interval li (Separation_item::my_width (lb));
36
37           if (!li.empty_b ())
38             {
39               Rod rod;
40
41               rod.item_l_drul_[LEFT] = lb;
42               rod.item_l_drul_[RIGHT] = r;
43
44               rod.distance_f_ = li[RIGHT] - ri[LEFT];
45         
46               rod.columnize ();
47               rod.add_to_cols ();
48             }
49         }
50
51       Interval li (Separation_item::my_width (l));
52       if (!li.empty_b ())
53         {
54           Rod rod;
55
56           rod.item_l_drul_[LEFT] =l;
57           rod.item_l_drul_[RIGHT]=r;
58
59           rod.distance_f_ = li[RIGHT] - ri[LEFT];
60         
61           rod.columnize ();
62           rod.add_to_cols ();
63
64           break;
65         }
66       else
67         /*
68           this grob doesn't cause a constraint. We look further until we
69           find one that does.  */
70         ;
71     }
72 }
73
74 MAKE_SCHEME_CALLBACK (Separating_group_spanner,set_spacing_rods_and_seqs,1);
75 SCM
76 Separating_group_spanner::set_spacing_rods_and_seqs (SCM smob)
77 {
78   set_spacing_rods (smob);
79
80   return SCM_UNSPECIFIED;
81 }
82
83 MAKE_SCHEME_CALLBACK (Separating_group_spanner,set_spacing_rods,1);
84 SCM
85 Separating_group_spanner::set_spacing_rods (SCM smob)
86 {
87   Grob*me = unsmob_grob (smob);
88   
89   for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s) && gh_pair_p (ly_cdr (s)); s = ly_cdr (s))
90     {
91       /*
92         Order of elements is reversed!
93        */
94       SCM elt = ly_car (s);
95       Item *r = unsmob_item (elt);
96
97       if (!r)
98         continue;
99
100       Item *rb
101         = dynamic_cast<Item*> (r->find_prebroken_piece (LEFT));
102       
103       find_rods (r, ly_cdr (s));
104       if (rb)
105         find_rods (rb, ly_cdr (s));
106     }
107
108   return SCM_UNSPECIFIED ;
109 }
110
111 void
112 Separating_group_spanner::add_spacing_unit (Grob* me ,Item*i)
113 {
114   Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), i);
115   me->add_dependency (i);
116 }
117
118
119
120
121
122 ADD_INTERFACE (Separating_group_spanner,"separation-spanner-interface",
123   "Spanner that containing @code{separation-item-interface} grobs to calculate rods",
124   "");