2 spanner.cc -- implement Spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "dimension-cache.hh"
11 #include "paper-column.hh"
12 #include "paper-score.hh"
13 #include "molecule.hh"
14 #include "paper-outputter.hh"
15 #include "score-column.hh"
16 #include "line-of-score.hh"
19 Spanner::do_print() const
22 DOUT << "Between " << classname (spanned_drul_[LEFT])
23 << " and " << classname (spanned_drul_[RIGHT]) << '\n';
26 DOUT << "Broken in " << to_str (broken_into_l_arr_.size ()) << " pieces";
31 Spanner::break_into_pieces ()
36 Item * left = spanned_drul_[LEFT];
37 Item * right = spanned_drul_[RIGHT];
41 warning (_ ("left spanpoint is right spanpoint\n"));
45 Link_array<Item> break_points = pscore_l_->broken_col_range (left,right);
47 break_points.insert (left,0);
48 break_points.push (right);
50 for (int i=1; i < break_points.size(); i++)
52 Breaking_information info;
53 info.bounds_[LEFT] = break_points[i-1];
54 info.bounds_[RIGHT] = break_points[i];
58 Item *&pc_l = info.bounds_[d] ;
60 pc_l = pc_l->find_prebroken_piece(- d);
64 info.line_l_ = pc_l-> line_l ();
66 assert( info.line_l_ = pc_l->line_l ());
69 while ((flip(&d))!= LEFT);
71 Spanner *span_p = dynamic_cast<Spanner*>(clone ());
72 span_p->set_bounds(LEFT,info.bounds_[LEFT]);
73 span_p->set_bounds(RIGHT,info.bounds_[RIGHT]);
74 pscore_l_->typeset_element (span_p);
76 info.broken_spanner_l_ = span_p;
77 span_p->handle_broken_dependencies();
79 broken_into_l_arr_.push (span_p);
84 Spanner::set_my_columns()
86 Direction i = (Direction)1;
89 if (!spanned_drul_[i]->line_l())
90 set_bounds(i,spanned_drul_[i]->find_prebroken_piece((Direction)-i));
92 while (flip(&i) != 1);
96 Spanner::set_bounds(Direction d, Item*i)
106 set_parent ( i, X_AXIS);
109 if (spanned_drul_[Direction(-d)] == spanned_drul_[d]
111 warning (_f ("Spanner `%s\' with equal left and right spanpoints", classname (this)));
115 Spanner::do_break_processing()
118 break_into_pieces ();
120 handle_broken_dependencies();
125 spanned_drul_[LEFT]=0;
126 spanned_drul_[RIGHT]=0;
129 Spanner::Spanner (Spanner const &s)
132 spanned_drul_[LEFT] = spanned_drul_[RIGHT] =0;
137 Spanner::do_width() const
139 Real l = spanned_drul_[LEFT]->relative_coordinate (0, X_AXIS);
140 Real r = spanned_drul_[RIGHT]->relative_coordinate (0, X_AXIS);
143 warning ("Spanner with negative length");
145 return Interval (0, r-l);
149 Spanner::line_l() const
151 if (!spanned_drul_[LEFT] || !spanned_drul_[RIGHT])
153 if (spanned_drul_[LEFT]->line_l() != spanned_drul_[RIGHT]->line_l())
155 return spanned_drul_[LEFT]->line_l();
160 Spanner::find_broken_piece (Line_of_score*l) const
162 for (int i=0; i < broken_into_l_arr_.size (); i++)
164 if (broken_into_l_arr_[i]->line_l () == l)
165 return broken_into_l_arr_[i];
172 Spanner::broken_b() const
174 return broken_into_l_arr_.size();
178 Spanner::get_rods () const
185 Spanner::get_springs () const
192 Spanner::do_space_processing ()
194 Array<Rod> rs (get_rods ());
195 for (int i=0; i < rs.size (); i++)
197 rs[i].add_to_cols ();
200 Array<Spring> ss (get_springs ());
201 for (int i=0; i < ss.size (); i++)
203 ss[i].add_to_cols ();
211 Spanner::handle_broken_dependents ()
213 Spanner *unbrok = dynamic_cast<Spanner*> (original_l_);
214 if (!unbrok || parent_l(Y_AXIS))
217 Spanner *refpoint = dynamic_cast<Spanner*> (unbrok->parent_l (Y_AXIS));
221 Spanner * broken_refpoint = refpoint->find_broken_piece (line_l ());
223 set_parent ( broken_refpoint,Y_AXIS);
225 programming_error ("Spanner y -refpoint lost.");
229 // If this is a broken spanner, return the amount the left end is to
230 // be shifted horizontally so that the spanner starts after the
231 // initial clef and key on the staves. This is necessary for ties,
232 // slurs, crescendo and decrescendo signs, for example.
234 Spanner::get_broken_left_end_align () const
238 Score_column *sc = dynamic_cast<Score_column*> (spanned_drul_[LEFT]->column_l());
240 // Relevant only if left span point is first column in line
241 if(sc != NULL && sc->line_l ()->cols_.find_i (sc) == 0)
243 // We could possibly return the right edge of the whole Score_column here,
244 // but we do a full search for the Break_align_item.
245 for(i = 0; i < sc->elem_l_arr_.size (); i++)
247 if(0 == strcmp (classname (sc->elem_l_arr_[i]), "Break_align_item"))
249 return sc->elem_l_arr_[i]->extent (X_AXIS) [RIGHT];