2 score-elem.cc -- implement Score_elem
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
8 #include "outputter.hh"
10 #include "paper-def.hh"
12 #include "molecule.hh"
13 #include "score-elem.hh"
18 #include "scoreline.hh"
21 #include "molecule.hh"
23 Score_elem::Score_elem()
25 transparent_b_
= false;
30 Score_elem::Score_elem (Score_elem
const&s
)
31 : Directed_graph_node (s
), Graphical_element (s
)
33 /* called from derived ctor, so most info points to the same deps
34 as (Directed_graph_node&)s. Nobody points to us, so don't copy
38 transparent_b_
= s
.transparent_b_
;
39 status_i_
= s
.status_i_
;
40 pscore_l_
= s
.pscore_l_
;
43 Score_elem::~Score_elem()
45 assert (status_i_
>=0);
50 Score_elem::dependency (int i
) const
52 return (Score_elem
*) get_out_edge_arr ()[i
];
56 Score_elem::dependency_size () const
58 return get_out_edge_arr ().size ();
62 Score_elem::dependent (int i
) const
64 return (Score_elem
*) get_in_edge_arr()[i
];
68 Score_elem::dependent_size() const
70 return get_in_edge_arr().size ();
76 Score_elem::do_width() const
80 Molecule
*m
= brew_molecule_p();
88 Score_elem::do_height() const
91 Molecule
*m
= brew_molecule_p();
102 Score_elem::print() const
105 DOUT
<< name() << "{\n";
106 DOUT
<< "dets: " << dependent_size() << "dependencies: " <<
109 Graphical_element::print ();
118 Score_elem::paper() const
121 return pscore_l_
->paper_l_
;
126 Score_elem::add_processing()
136 Score_elem::calcalute_dependencies (int final
, int busy
,
137 Score_elem_method_pointer funcptr
)
139 if (status_i_
>= final
)
142 assert (status_i_
!= busy
);
145 for (int i
=0; i
< dependency_size(); i
++)
146 dependency (i
)->calcalute_dependencies (final
, busy
, funcptr
);
148 Link_array
<Score_elem
> extra (get_extra_dependencies());
149 for (int i
=0; i
< extra
.size(); i
++)
150 extra
[i
]->calcalute_dependencies (final
, busy
, funcptr
);
152 invalidate_cache (X_AXIS
);
153 invalidate_cache (Y_AXIS
);
159 Score_elem::do_brew_molecule ()
163 Molecule
*output
= brew_molecule_p ();
164 pscore_l_
->outputter_l_
->output_molecule (output
, absolute_offset ());
174 Score_elem::do_break_processing()
176 handle_broken_dependencies();
180 Score_elem::do_post_processing()
185 Score_elem::do_breakable_col_processing()
187 handle_prebroken_dependencies();
191 Score_elem::do_pre_processing()
196 Score_elem::do_space_processing ()
201 Score_elem::do_add_processing()
206 Score_elem::do_substitute_dependency (Score_elem
*,Score_elem
*)
210 Score_elem::do_substitute_dependent (Score_elem
*,Score_elem
*)
215 Score_elem::do_unlink()
220 Score_elem::do_junk_links()
224 IMPLEMENT_IS_TYPE_B1(Score_elem
, Graphical_element
);
227 Score_elem::brew_molecule_p() const
229 Atom
a (paper()->lookup_l ()->fill (Box (Interval (0,0), Interval (0,0))));
230 return new Molecule (a
);
235 Score_elem::line_l() const
247 Score_elem::remove_dependency (Score_elem
*e
)
250 substitute_dependency (e
, 0);
254 Score_elem::add_dependency (Score_elem
*e
)
256 Directed_graph_node::add (e
);
259 Score_elem::substitute_dependency (Score_elem
* old
, Score_elem
* new_l
)
261 do_substitute_dependency (old
,new_l
);
262 old
->do_substitute_dependent (this, 0);
266 Score_elem::handle_broken_dependencies()
268 Line_of_score
*line
= line_l();
272 Link_array
<Score_elem
> remove_us_arr
;
273 for (int i
=0; i
< dependency_size(); i
++)
275 Score_elem
* elt
= dependency (i
);
276 if (elt
->line_l() != line
)
280 Spanner
* sp
= elt
->spanner();
281 Spanner
* broken
= sp
->find_broken_piece (line
);
282 substitute_dependency (sp
, broken
);
284 add_dependency (broken
);
286 else if (elt
->item())
288 Item
* my_item
= elt
->item()->find_prebroken_piece (line
);
290 substitute_dependency (elt
, my_item
);
292 add_dependency (my_item
);
294 remove_us_arr
.push (elt
);
298 remove_us_arr
.default_sort();
299 remove_us_arr
.uniq();
300 for (int i
=0; i
<remove_us_arr
.size(); i
++)
301 remove_dependency (remove_us_arr
[i
]);
307 unlike with spanners, the number of items can increase
313 span: item1 item2 item3
315 How to let span (a derived class) know that this happened?
318 Score_elem::handle_prebroken_dependencies()
320 Link_array
<Score_elem
> old_arr
, new_arr
;
322 for (int i
=0; i
< dependency_size(); i
++)
324 Score_elem
* elt
= dependency (i
);
325 Item
*it_l
= elt
->item();
326 if (it_l
&& it_l
->breakable_b_
)
329 Score_elem
*new_l
= it_l
->find_prebroken_piece (item()->break_status_i_
);
332 new_arr
.push (new_l
);
338 new_arr
.push (it_l
->broken_to_drul_
[LEFT
]);
341 new_arr
.push (it_l
->broken_to_drul_
[RIGHT
]);
345 for (int i
=0; i
< old_arr
.size(); i
++)
347 substitute_dependency (old_arr
[i
], new_arr
[i
]);
352 Score_elem::junk_links ()
354 Directed_graph_node::junk_links();
355 Graphical_element::junk_links ();
363 while (dependency_size())
365 do_substitute_dependency (dependency (0),0);
366 remove_edge_out_idx (0);
368 while (dependent_size())
370 dependent (0)->remove_dependency (this);
372 for (int j
=0; j
< 2; j
++)
373 if (axis_group_l_a_
[j
])
374 axis_group_l_a_
[j
]->remove_element (this);
378 Link_array
<Score_elem
>
379 Score_elem::get_extra_dependencies() const
381 Link_array
<Score_elem
> empty
;
386 Score_elem::linked_b() const
388 return get_extra_dependencies().size() ||