2 score-elem.cc -- implement Score_element
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "paper-score.hh"
13 #include "paper-def.hh"
15 #include "molecule.hh"
16 #include "score-element.hh"
19 #include "line-of-score.hh"
21 #include "paper-column.hh"
22 #include "molecule.hh"
24 #include "paper-outputter.hh"
25 #include "dimension-cache.hh"
29 Score_element::dim_cache_callback (Dimension_cache*c)
31 Score_element * e =dynamic_cast<Score_element*>( c->element_l());
32 if(e->dim_cache_[X_AXIS] == c)
33 return e->do_width ();
35 return e->do_height ();
38 Score_element::Score_element()
41 dim_cache_[X_AXIS]->set_callback (dim_cache_callback);
42 dim_cache_[Y_AXIS]->set_callback (dim_cache_callback);
48 element_property_alist_ = scm_protect_object (gh_cons (gh_cons (void_scm_sym, SCM_BOOL_T) , SCM_EOL));
51 Score_element::Score_element (Score_element const&s)
52 : Graphical_element (s)
55 original_l_ =(Score_element*) &s;
56 element_property_alist_ = scm_protect_object (scm_list_copy (s.element_property_alist_));
57 dependency_arr_ = s.dependency_arr_;
59 status_i_ = s.status_i_;
60 lookup_l_ = s.lookup_l_;
61 pscore_l_ = s.pscore_l_;
64 Score_element::~Score_element()
67 assert (status_i_ >=0);
72 Score_element::dependency (int i) const
74 return dependency_arr_ [i];
78 Score_element::dependency_size () const
80 return dependency_arr_.size ();
84 Score_element::get_elt_property (SCM sym) const
86 SCM s = scm_assq(sym, element_property_alist_);
88 // is this a good idea?
89 if (s == SCM_BOOL_F && pscore_l_ && pscore_l_->paper_l_)
90 s = pscore_l_->paper_l_->get_scm_var (sym);
96 Score_element::remove_elt_property (SCM key)
98 SCM s = get_elt_property (key);
99 SCM_CDR(element_property_alist_) = scm_assq_remove_x (SCM_CDR (element_property_alist_), key);
104 Score_element::set_elt_property (SCM s, SCM v)
106 SCM_CDR(element_property_alist_) =
107 scm_assoc_set_x (SCM_CDR (element_property_alist_), s, v);
111 Score_element::do_width() const
115 Molecule*m = output_p_ ? output_p_ : do_brew_molecule_p();
116 r = m->extent().x ();
125 Score_element::do_height() const
128 Molecule*m = output_p_ ? output_p_ : do_brew_molecule_p();
129 r = m->extent().y ();
137 Score_element::print() const
140 DEBUG_OUT << classname(this) << "{\n";
141 if (flower_dstream && !flower_dstream->silent_b ("Score_element"))
142 ly_display_scm (element_property_alist_);
143 DEBUG_OUT << "dependencies: " << dependency_size();
145 DEBUG_OUT << "Copy ";
146 Graphical_element::do_print ();
154 Score_element::paper_l () const
156 return pscore_l_->paper_l_;
160 Score_element::lookup_l () const
164 Score_element * urg = (Score_element*)this;
165 SCM sz = urg->remove_elt_property (fontsize_scm_sym);
166 int i = (sz != SCM_BOOL_F)
167 ? gh_scm2int (SCM_CDR (sz))
170 urg->lookup_l_ = (Lookup*)pscore_l_->paper_l_->lookup_l (i);
176 Score_element::add_processing()
178 assert (status_i_ >=0);
186 Score_element::calculate_dependencies (int final, int busy,
187 Score_element_method_pointer funcptr)
189 assert (status_i_ >=0);
191 if (status_i_ >= final)
194 assert (status_i_!= busy);
197 for (int i=0; i < dependency_arr_.size(); i++)
198 dependency_arr_[i]->calculate_dependencies (final, busy, funcptr);
200 Link_array<Score_element> extra (get_extra_dependencies());
201 for (int i=0; i < extra.size(); i++)
202 extra[i]->calculate_dependencies (final, busy, funcptr);
204 invalidate_cache (X_AXIS);
205 invalidate_cache (Y_AXIS);
211 Score_element::output_processing ()
213 if (get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
216 // we're being silly here.
220 output_p_ = do_brew_molecule_p ();
221 Offset o (relative_coordinate (0, X_AXIS), relative_coordinate (0, Y_AXIS));
223 pscore_l_->outputter_l_->output_molecule (output_p_,
234 Score_element::do_break_processing()
236 handle_broken_dependencies();
240 Score_element::do_post_processing()
245 Score_element::do_breakable_col_processing()
247 handle_prebroken_dependencies();
251 Score_element::do_pre_processing()
256 Score_element::do_space_processing ()
261 Score_element::do_add_processing()
266 Score_element::do_substitute_element_pointer (Score_element*,Score_element*)
272 Score_element::do_brew_molecule_p() const
274 Molecule a (lookup_l ()->fill (Box (Interval (0,0), Interval (0,0))));
275 return new Molecule (a);
280 Score_element::line_l() const
286 Score_element::add_dependency (Score_element*e)
290 dependency_arr_.push (e);
294 programming_error ("Null dependency added");
298 Score_element::substitute_dependency (Score_element* old, Score_element* new_l)
300 do_substitute_element_pointer (old,new_l);
301 old->do_substitute_element_pointer (this, 0);
305 Score_element::handle_broken_dependencies()
307 Line_of_score *line = line_l();
311 do_substitute_arrays ();
313 Link_array<Score_element> new_deps;
315 for (int i=0; i < dependency_size(); i++)
317 Score_element * elt = dependency (i);
318 if (elt->line_l() != line)
320 Score_element * broken = elt->find_broken_piece (line);
321 substitute_dependency (elt, broken);
327 dependency_arr_ = new_deps;
335 unlike with spanners, the number of items can increase
341 span: item1 item2 item3
343 How to let span (a derived class) know that this happened?
349 Score_element::handle_prebroken_dependencies()
351 /* dynamic_cast<Item*> (this) &&
352 if (!break_status_dir ())
355 Link_array<Score_element> old_arr, new_arr;
357 for (int i=0; i < dependency_size(); i++)
359 Score_element * elt = dependency (i);
360 Item *it_l = dynamic_cast <Item *> (elt);
361 if (it_l && it_l->broken_original_b ())
362 if (Item *me = dynamic_cast<Item*> (this) )
364 Score_element *new_l = it_l->find_broken_piece (me->break_status_dir ());
367 new_arr.push (new_l);
376 new_arr.push (it_l->find_broken_piece (d));
377 } while (flip(&d)!= LEFT);
381 for (int i=0; i < old_arr.size(); i++)
383 substitute_dependency (old_arr[i], new_arr[i]);
387 Score_element::handle_prebroken_dependents()
392 Score_element::handle_broken_dependents()
398 Link_array<Score_element>
399 Score_element::get_extra_dependencies() const
401 Link_array<Score_element> empty;
406 Score_element::linked_b() const
412 Score_element::do_print () const
417 Score_element::do_substitute_arrays ()
423 Score_element::find_broken_piece (Line_of_score*) const