2 score-elem.cc -- implement Score_elem
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
10 #include "paper-def.hh"
12 #include "molecule.hh"
13 #include "score-elem.hh"
18 #include "scoreline.hh"
21 Score_elem::dependency(int i)const
23 return (Score_elem*) get_out_edge_arr()[i];
27 Score_elem::dependency_size() const
29 return get_out_edge_arr().size();
33 Score_elem::dependent(int i) const
35 return (Score_elem*) get_in_edge_arr()[i];
39 Score_elem::dependent_size() const
41 return get_in_edge_arr().size();
46 Score_elem::TeX_string() const
48 assert( status > POSTCALCED);
49 String s("\\placebox{%}{%}{%}");
51 a.push(print_dimen(offset_.y));
52 a.push(print_dimen(offset_.x));
53 a.push( output->TeX_string());
54 return substitute_args(s, a);
58 Score_elem::Score_elem(Score_elem const&s)
60 /* called from derived ctor, so most info points to the same deps
61 as (Directed_graph_node&)s. Nobody points to us, so don't copy
69 pscore_l_ = s.pscore_l_;
70 offset_ = Offset(0,0);
73 Score_elem::~Score_elem()
75 // some paranoia to prevent weird segv's
76 assert(status < DELETED);
80 assert(!group_element_i_ );
84 Score_elem::translate(Offset O)
90 Score_elem::do_width() const
95 Molecule*m = brew_molecule_p();
99 r = output->extent().x;
104 Score_elem::width() const
106 Interval r=do_width();
108 if (!r.empty_b()) // float exception on DEC Alpha
115 Score_elem::do_height() const
119 Molecule*m = brew_molecule_p();
123 r = output->extent().y;
128 Score_elem::height() const
130 Interval r=do_height();
140 Score_elem::print()const
143 mtor << name() << "{\n";
144 mtor << "deps: " << dependent_size() << "depts: \n" <<
145 dependency_size() << "\n";
156 Score_elem::Score_elem()
158 group_element_i_ = 0;
160 offset_ = Offset(0,0);
167 Score_elem::paper() const
170 return pscore_l_->paper_l_;
174 Score_elem::add_processing()
176 if (status >= VIRGIN)
183 Score_elem::pre_processing()
185 if (status >= PRECALCED )
188 assert(status != PRECALCING); // cyclic dependency
191 for (int i=0; i < dependency_size(); i++)
192 dependency(i)->pre_processing();
200 Score_elem::break_processing()
202 if (status >= BROKEN )
205 assert(status != BREAKING); // cyclic dependency
208 for (int i=0; i < dependency_size(); i++)
209 dependency(i)->break_processing();
212 do_break_processing();
217 Score_elem::do_break_processing()
219 handle_broken_dependencies();
224 Score_elem::post_processing()
226 if (status >= POSTCALCED)
228 assert(status != POSTCALCING);// cyclic dependency
232 for (int i=0; i < dependency_size(); i++)
233 dependency(i)->post_processing();
234 do_post_processing();
239 Score_elem::molecule_processing()
241 if (status >= OUTPUT)
243 status = OUTPUT; // do it only once.
245 for (int i=0; i < dependency_size(); i++)
246 dependency(i)->molecule_processing();
248 output= brew_molecule_p();
252 Score_elem::do_post_processing()
257 Score_elem::do_pre_processing()
262 Score_elem::do_add_processing()
268 Score_elem::do_substitute_dependency(Score_elem*,Score_elem*)
273 IMPLEMENT_STATIC_NAME(Score_elem);
276 Score_elem::brew_molecule_p()const
278 Atom a(paper()->lookup_l()->fill(Box(Interval(0,0), Interval(0,0))));
279 return new Molecule (a);
282 Score_elem::offset() const
288 Score_elem::line_l()const
293 /********************
298 Score_elem::remove_dependency(Score_elem*e)
301 do_substitute_dependency(e, 0);
305 Score_elem::add_dependency(Score_elem*e)
307 Directed_graph_node::add(e);
311 Score_elem::is_type_b(char const *s)
313 return s == static_name();
317 Score_elem::handle_broken_dependencies()
319 Line_of_score *line = line_l();
323 Link_array<Score_elem> remove_us_arr;
324 for (int i=0; i < dependency_size(); i++) {
325 Score_elem * elt = dependency(i);
326 if (elt->line_l() != line){
327 if (elt->spanner()) {
328 Spanner * sp = elt->spanner();
329 Spanner * broken = sp->find_broken_piece(line);
330 do_substitute_dependency(sp, broken);
331 add_dependency(broken);
332 remove_us_arr.push(sp);
334 remove_us_arr.push(elt);
339 remove_us_arr.default_sort();
340 remove_us_arr.uniq();
341 for (int i=0; i <remove_us_arr.size(); i++)
342 remove_dependency(remove_us_arr[i]);
350 Score_elem::unlink_all()
352 for (int i=0; i < dependency_size(); i++)
353 dependency(i)->unlink_all();
355 group_element_i_ = 0;
361 while ( dependency_size()) {
362 do_substitute_dependency(dependency(0),0);
363 remove_edge_out_idx(0);
365 while ( dependent_size() ) {
366 dependent(0)->remove_dependency(this);
373 Score_elem::OK()const
376 for (int i=0; i < dependency_size(); i++) {