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);
49 element_property_alist_ = scm_protect_object (gh_cons (gh_cons (void_scm_sym, SCM_BOOL_T) , SCM_EOL));
54 Score_element::Score_element (Score_element const&s)
55 : Graphical_element (s)
60 original_l_ =(Score_element*) &s;
61 element_property_alist_ = scm_protect_object (scm_list_copy (s.element_property_alist_));
62 dependency_arr_ = s.dependency_arr_;
64 status_i_ = s.status_i_;
65 lookup_l_ = s.lookup_l_;
66 pscore_l_ = s.pscore_l_;
71 Score_element::~Score_element()
74 assert (status_i_ >=0);
79 Score_element::dependency (int i) const
81 return dependency_arr_ [i];
85 Score_element::dependency_size () const
87 return dependency_arr_.size ();
91 Score_element::get_elt_property (SCM sym) const
93 SCM s = scm_assq(sym, element_property_alist_);
95 // is this a good idea?
96 if (s == SCM_BOOL_F && pscore_l_ && pscore_l_->paper_l_)
97 s = pscore_l_->paper_l_->get_scm_var (sym);
103 Score_element::remove_elt_property (SCM key)
105 SCM s = get_elt_property (key);
106 SCM_CDR(element_property_alist_) = scm_assq_remove_x (SCM_CDR (element_property_alist_), key);
111 Score_element::set_elt_property (SCM s, SCM v)
113 SCM_CDR(element_property_alist_) =
114 scm_assoc_set_x (SCM_CDR (element_property_alist_), s, v);
118 Score_element::do_width() const
122 Molecule*m = output_p_ ? output_p_ : do_brew_molecule_p();
123 r = m->extent().x ();
132 Score_element::do_height() const
135 Molecule*m = output_p_ ? output_p_ : do_brew_molecule_p();
136 r = m->extent().y ();
144 Score_element::print() const
147 DEBUG_OUT << classname(this) << "{\n";
148 if (flower_dstream && !flower_dstream->silent_b ("Score_element"))
149 ly_display_scm (element_property_alist_);
150 DEBUG_OUT << "dependencies: " << dependency_size();
152 DEBUG_OUT << "Copy ";
153 Graphical_element::do_print ();
161 Score_element::paper_l () const
163 return pscore_l_->paper_l_;
167 Score_element::lookup_l () const
171 Score_element * urg = (Score_element*)this;
172 SCM sz = urg->remove_elt_property (fontsize_scm_sym);
173 int i = (sz != SCM_BOOL_F)
174 ? gh_scm2int (SCM_CDR (sz))
177 urg->lookup_l_ = (Lookup*)pscore_l_->paper_l_->lookup_l (i);
183 Score_element::add_processing()
185 assert (status_i_ >=0);
193 Score_element::calculate_dependencies (int final, int busy,
194 Score_element_method_pointer funcptr)
196 assert (status_i_ >=0);
198 if (status_i_ >= final)
201 assert (status_i_!= busy);
204 for (int i=0; i < dependency_arr_.size(); i++)
205 dependency_arr_[i]->calculate_dependencies (final, busy, funcptr);
207 Link_array<Score_element> extra (get_extra_dependencies());
208 for (int i=0; i < extra.size(); i++)
209 extra[i]->calculate_dependencies (final, busy, funcptr);
211 invalidate_cache (X_AXIS);
212 invalidate_cache (Y_AXIS);
218 Score_element::output_processing ()
220 if (get_elt_property (transparent_scm_sym) != SCM_BOOL_F)
223 // we're being silly here.
227 output_p_ = do_brew_molecule_p ();
228 Offset o (relative_coordinate (0, X_AXIS), relative_coordinate (0, Y_AXIS));
230 pscore_l_->outputter_l_->output_molecule (output_p_,
244 Score_element::do_break_processing()
246 handle_broken_dependencies();
250 Score_element::do_post_processing()
255 Score_element::do_breakable_col_processing()
257 handle_prebroken_dependencies();
261 Score_element::do_pre_processing()
266 Score_element::do_space_processing ()
271 Score_element::do_add_processing()
276 Score_element::do_substitute_element_pointer (Score_element*,Score_element*)
282 Score_element::do_brew_molecule_p() const
284 Molecule a (lookup_l ()->fill (Box (Interval (0,0), Interval (0,0))));
285 return new Molecule (a);
290 Score_element::line_l() const
296 Score_element::add_dependency (Score_element*e)
300 dependency_arr_.push (e);
304 programming_error ("Null dependency added");
308 Score_element::substitute_dependency (Score_element* old, Score_element* new_l)
310 do_substitute_element_pointer (old,new_l);
311 old->do_substitute_element_pointer (this, 0);
315 Score_element::handle_broken_dependencies()
317 Line_of_score *line = line_l();
321 do_substitute_arrays ();
323 Link_array<Score_element> new_deps;
325 for (int i=0; i < dependency_size(); i++)
327 Score_element * elt = dependency (i);
328 if (elt->line_l() != line)
330 Score_element * broken = elt->find_broken_piece (line);
331 substitute_dependency (elt, broken);
337 dependency_arr_ = new_deps;
345 unlike with spanners, the number of items can increase
351 span: item1 item2 item3
353 How to let span (a derived class) know that this happened?
359 Score_element::handle_prebroken_dependencies()
361 /* dynamic_cast<Item*> (this) &&
362 if (!break_status_dir ())
365 Link_array<Score_element> old_arr, new_arr;
367 for (int i=0; i < dependency_size(); i++)
369 Score_element * elt = dependency (i);
370 Item *it_l = dynamic_cast <Item *> (elt);
371 if (it_l && it_l->broken_original_b ())
372 if (Item *me = dynamic_cast<Item*> (this) )
374 Score_element *new_l = it_l->find_broken_piece (me->break_status_dir ());
377 new_arr.push (new_l);
386 new_arr.push (it_l->find_broken_piece (d));
387 } while (flip(&d)!= LEFT);
391 for (int i=0; i < old_arr.size(); i++)
393 substitute_dependency (old_arr[i], new_arr[i]);
397 Score_element::handle_prebroken_dependents()
402 Score_element::handle_broken_dependents()
408 Link_array<Score_element>
409 Score_element::get_extra_dependencies() const
411 Link_array<Score_element> empty;
416 Score_element::linked_b() const
422 Score_element::do_print () const
427 Score_element::do_substitute_arrays ()
433 Score_element::find_broken_piece (Line_of_score*) const
439 Score_element::mark_smob (SCM ses)
441 void * mp = (void*) SCM_CDR(ses);
442 Score_element * s = (Score_element*) mp;
444 assert (s->self_scm_ == ses);
445 return s->element_property_alist_;
450 Score_element::print_smob (SCM s, SCM port, scm_print_state *)
452 Score_element *sc = (Score_element *) SCM_CDR (s);
454 scm_puts ("#<Score_element ", port);
455 scm_puts ((char *)sc->name (), port);
456 scm_puts (" >", port);
461 Score_element::do_smobify_self ()
463 scm_unprotect_object (element_property_alist_); // ugh
465 #include "ly-smobs.icc"
466 IMPLEMENT_SMOBS(Score_element);