lilypond-1.5.9
[lilypond.git] / lily / separating-group-spanner.cc
blob9a1c85d51b07622c68c0ac75dc02d127809282dd
1 /*
2 separating-group-spanner.cc -- implement Separating_group_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
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"
17 void
18 Separating_group_spanner::find_rods (Item * r, SCM next)
20 Interval ri (Separation_item::my_width (r));
21 if (ri.empty_b ())
22 return;
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 = gh_cdr (next))
30 Item *l = dynamic_cast<Item*> (unsmob_grob (gh_car( next)));
31 Item *lb = l->find_prebroken_piece (RIGHT);
33 if (lb)
35 Interval li (Separation_item::my_width (lb));
37 if (!li.empty_b ())
39 Rod rod;
41 rod.item_l_drul_[LEFT] = lb;
42 rod.item_l_drul_[RIGHT] = r;
44 rod.distance_f_ = li[RIGHT] - ri[LEFT];
46 rod.columnize ();
47 rod.add_to_cols ();
51 Interval li (Separation_item::my_width (l));
52 if (!li.empty_b ())
54 Rod rod;
56 rod.item_l_drul_[LEFT] =l;
57 rod.item_l_drul_[RIGHT]=r;
59 rod.distance_f_ = li[RIGHT] - ri[LEFT];
61 rod.columnize ();
62 rod.add_to_cols ();
64 break;
66 else
68 this grob doesn't cause a constraint. We look further until we
69 find one that does. */
74 MAKE_SCHEME_CALLBACK (Separating_group_spanner,set_spacing_rods,1);
75 SCM
76 Separating_group_spanner::set_spacing_rods (SCM smob)
78 Grob*me = unsmob_grob (smob);
80 for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s) && gh_pair_p (gh_cdr (s)); s = gh_cdr (s))
83 Order of elements is reversed!
85 SCM elt = gh_car (s);
86 Item *r = dynamic_cast<Item*> (unsmob_grob (elt));
88 if (!r)
89 continue;
91 Item *rb
92 = dynamic_cast<Item*> (r->find_prebroken_piece (LEFT));
94 find_rods (r, gh_cdr (s));
95 if (rb)
96 find_rods (rb, gh_cdr (s));
99 find_musical_sequences (me);
100 #if 0
102 TODO; restore this.
105 We've done our job, so we get lost.
107 for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
109 Item * it =dynamic_cast<Item*> (unsmob_grob (gh_car (s)));
110 if (it && it->broken_b ())
112 it->find_prebroken_piece (LEFT) ->suicide ();
113 it->find_prebroken_piece (RIGHT)->suicide ();
115 it->suicide ();
117 me->suicide ();
118 #endif
119 return SCM_UNSPECIFIED ;
122 void
123 Separating_group_spanner::add_spacing_unit (Grob* me ,Item*i)
125 Pointer_group_interface::add_element (me, "elements",i);
126 me->add_dependency (i);
130 void
131 Separating_group_spanner::find_musical_sequences (Grob *me)
133 Item *last = 0;
134 Item *llast = 0;
135 for (SCM s = me->get_grob_property ("elements");
136 gh_pair_p (s); s = gh_cdr (s))
138 Item *it = dynamic_cast<Item*> (unsmob_grob (gh_car (s)));
139 if (last)
141 Item *lcol = last->column_l ();
142 Item *col = it->column_l ();
144 int lrank = Paper_column::rank_i (lcol);
145 int rank = Paper_column ::rank_i (col);
147 bool mus = Paper_column::musical_b (col);
148 bool lmus = Paper_column::musical_b (lcol);
150 if ((lrank - rank == 2) && lmus && mus)
152 SCM seq = col->get_grob_property ("spacing-sequence");
153 col->set_grob_property ("spacing-sequence",
154 gh_cons (gh_cons (it->self_scm (), last->self_scm ()), seq));
157 if (llast && !Paper_column::breakable_b (last))
159 Item *llcol = llast->column_l ();
160 int llrank = Paper_column::rank_i (llcol);
161 bool llmus= Paper_column::musical_b (llcol);
162 if (llrank - lrank == 1
163 && lrank - rank == 1
164 && llmus && !lmus && mus)
166 SCM seq = col->get_grob_property ("spacing-sequence");
167 col->set_grob_property ("spacing-sequence",
168 gh_cons (gh_cons (it->self_scm (), last->self_scm ()), seq));
170 else if (!lmus)
172 SCM between = lcol->get_grob_property ("between-cols");
174 if (!gh_pair_p (between))
176 between = gh_cons (it->self_scm (), llast->self_scm ());
177 lcol ->set_grob_property ("between-cols", between);
180 Item * left
181 = dynamic_cast<Item*> (unsmob_grob (gh_car (between)));
182 if(Paper_column::rank_i (left->column_l ()) < rank)
183 gh_set_car_x (between, col->self_scm());
185 Item * right
186 = dynamic_cast<Item*> (unsmob_grob (gh_cdr (between)));
187 if (Paper_column::rank_i (right->column_l ()) > llrank )
188 gh_set_cdr_x (between, llcol->self_scm ());
193 llast = last;
194 last = it;
198 #if 0
199 void
200 Separating_group_spanner::set_loose_rods ()
202 // loose columns should also generate minimum distances.
203 // TODO
205 #endif
208 void
209 Separating_group_spanner::set_interface (Grob*)
213 bool
214 Separating_group_spanner::has_interface (Grob*)
215 {//todo
216 assert (false);