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"
27 Score_element::dim_cache_callback (Dimension_cache*c)
29 Score_element * e =dynamic_cast<Score_element*>( c->element_l());
30 if(e->dim_cache_[X_AXIS] == c)
31 return e->do_width ();
33 return e->do_height ();
36 Score_element::Score_element()
39 dim_cache_[X_AXIS]->set_callback (dim_cache_callback);
40 dim_cache_[Y_AXIS]->set_callback (dim_cache_callback);
46 element_property_alist_ = scm_protect_object (gh_cons (gh_cons (void_scm_sym, SCM_BOOL_T) , SCM_EOL));
49 Score_element::Score_element (Score_element const&s)
50 : Graphical_element (s)
53 original_l_ =(Score_element*) &s;
54 element_property_alist_ = scm_protect_object (scm_list_copy (s.element_property_alist_));
55 dependency_arr_ = s.dependency_arr_;
57 status_i_ = s.status_i_;
58 lookup_l_ = s.lookup_l_;
59 pscore_l_ = s.pscore_l_;
62 Score_element::~Score_element()
65 assert (status_i_ >=0);
70 Score_element::dependency (int i) const
72 return dependency_arr_ [i];
76 Score_element::dependency_size () const
78 return dependency_arr_.size ();
82 Score_element::get_elt_property (SCM sym) const
84 SCM s = scm_assq(sym, element_property_alist_);
86 // is this a good idea?
87 if (s == SCM_BOOL_F && pscore_l_ && pscore_l_->paper_l_)
88 s = pscore_l_->paper_l_->get_scm_var (sym);
94 Score_element::remove_elt_property (SCM key)
96 SCM s = get_elt_property (key);
97 SCM_CDR(element_property_alist_) = scm_assq_remove_x (SCM_CDR (element_property_alist_), key);
102 Score_element::set_elt_property (SCM s, SCM v)
104 SCM_CDR(element_property_alist_) =
105 scm_assoc_set_x (SCM_CDR (element_property_alist_), s, v);
109 Score_element::do_width() const
113 Molecule*m = output_p_ ? output_p_ : do_brew_molecule_p();
114 r = m->extent().x ();
123 Score_element::do_height() const
126 Molecule*m = output_p_ ? output_p_ : do_brew_molecule_p();
127 r = m->extent().y ();
135 Score_element::print() const
138 DOUT << classname(this) << "{\n";
139 if (check_debug && !monitor->silent_b ("Score_element"))
140 ly_display_scm (element_property_alist_);
141 DOUT << "dependencies: " << dependency_size();
144 Graphical_element::do_print ();
152 Score_element::paper_l () const
154 return pscore_l_->paper_l_;
158 Score_element::lookup_l () const
162 Score_element * me = (Score_element*)this;
163 SCM sz = me->remove_elt_property (fontsize_scm_sym);
164 int i = (sz != SCM_BOOL_F)
165 ? gh_scm2int (SCM_CDR (sz))
168 me->lookup_l_ = pscore_l_->paper_l_->lookup_l (i);
174 Score_element::add_processing()
176 assert (status_i_ >=0);
184 Score_element::calculate_dependencies (int final, int busy,
185 Score_element_method_pointer funcptr)
187 assert (status_i_ >=0);
189 if (status_i_ >= final)
192 assert (status_i_!= busy);
195 for (int i=0; i < dependency_arr_.size(); i++)
196 dependency_arr_[i]->calculate_dependencies (final, busy, funcptr);
198 Link_array<Score_element> extra (get_extra_dependencies());
199 for (int i=0; i < extra.size(); i++)
200 extra[i]->calculate_dependencies (final, busy, funcptr);
202 invalidate_cache (X_AXIS);
203 invalidate_cache (Y_AXIS);
209 Score_element::output_processing ()
211 if (get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
214 // we're being silly here.
218 output_p_ = do_brew_molecule_p ();
219 Offset o (absolute_coordinate (X_AXIS), absolute_coordinate (Y_AXIS));
221 pscore_l_->outputter_l_->output_molecule (output_p_,
232 Score_element::do_break_processing()
234 handle_broken_dependencies();
238 Score_element::do_post_processing()
243 Score_element::do_breakable_col_processing()
245 handle_prebroken_dependencies();
249 Score_element::do_pre_processing()
254 Score_element::do_space_processing ()
259 Score_element::do_add_processing()
264 Score_element::do_substitute_element_pointer (Score_element*,Score_element*)
270 Score_element::do_brew_molecule_p() const
272 Molecule a (lookup_l ()->fill (Box (Interval (0,0), Interval (0,0))));
273 return new Molecule (a);
278 Score_element::line_l() const
290 Score_element::remove_dependency (Score_element*e)
293 while ((i = dependency_arr_.find_i (e)) >=0 )
294 dependency_arr_.unordered_del (i);
296 substitute_dependency (e, 0);
300 Score_element::add_dependency (Score_element*e)
304 dependency_arr_.push (e);
308 programming_error ("Null dependency added");
312 Score_element::substitute_dependency (Score_element* old, Score_element* new_l)
314 do_substitute_element_pointer (old,new_l);
315 old->do_substitute_element_pointer (this, 0);
319 Score_element::handle_broken_dependencies()
321 Line_of_score *line = line_l();
325 Link_array<Score_element> remove_us_arr;
326 for (int i=0; i < dependency_size(); i++)
328 Score_element * elt = dependency (i);
329 if (elt->line_l() != line)
331 if (Spanner *sp = dynamic_cast<Spanner *> (elt))
333 Spanner * broken = sp->find_broken_piece (line);
334 substitute_dependency (sp, broken);
337 add_dependency (broken);
339 else if (Item *original = dynamic_cast <Item *> (elt))
341 Item * my_item = original->find_prebroken_piece (line);
343 substitute_dependency (elt, my_item);
345 add_dependency (my_item);
347 remove_us_arr.push (elt);
351 remove_us_arr.default_sort();
352 remove_us_arr.uniq();
353 for (int i=0; i <remove_us_arr.size(); i++)
354 remove_dependency (remove_us_arr[i]);
360 unlike with spanners, the number of items can increase
366 span: item1 item2 item3
368 How to let span (a derived class) know that this happened?
371 Score_element::handle_prebroken_dependencies()
373 /* dynamic_cast<Item*> (this) &&
374 if (!break_status_dir ())
377 Link_array<Score_element> old_arr, new_arr;
379 for (int i=0; i < dependency_size(); i++)
381 Score_element * elt = dependency (i);
382 Item *it_l = dynamic_cast <Item *> (elt);
383 if (it_l && it_l->broken_original_b ())
384 if (Item *me = dynamic_cast<Item*> (this) )
386 Score_element *new_l = it_l->find_prebroken_piece (me->break_status_dir ());
389 new_arr.push (new_l);
398 new_arr.push (it_l->find_prebroken_piece (d));
399 } while (flip(&d)!= LEFT);
403 for (int i=0; i < old_arr.size(); i++)
405 substitute_dependency (old_arr[i], new_arr[i]);
409 Score_element::handle_prebroken_dependents()
414 Score_element::handle_broken_dependents()
420 Link_array<Score_element>
421 Score_element::get_extra_dependencies() const
423 Link_array<Score_element> empty;
428 Score_element::linked_b() const
434 Score_element::do_print () const