]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/span-bar.cc
release: 1.3.10
[lilypond.git] / lily / span-bar.cc
index a371dc019d312527a0ccf65250ea5acfeedeeb57..2f43cd985f8b5b60aa14006ac9a8ffd866da2663 100644 (file)
@@ -3,60 +3,71 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
-
-#include "dimen.hh"
+#include "dimension-cache.hh"
 #include "span-bar.hh"
 #include "lookup.hh"
-#include "atom.hh"
+#include "dimensions.hh"
 #include "paper-def.hh"
 #include "molecule.hh"
-#include "vertical-align-elem.hh"
+#include "align-element.hh"
+#include "warn.hh"
+#include "group-interface.hh"
+
 
 void
-Span_bar::add (Bar*b)
+Span_bar::add_bar (Score_element*b)
 {
-  spanning_l_arr_.push (b);
+  Group_interface gi (this);
+  gi.add_element (b);
+
   add_dependency (b);
 }
 
 
-
-void
-Span_bar::do_substitute_dependency (Score_elem*o, Score_elem*n)
+Interval
+Span_bar::width_callback (Dimension_cache const * c)
 {
-  spanning_l_arr_.unordered_substitute (o, n);
+  Span_bar*  s= dynamic_cast<Span_bar*> (c->element_l ());  
+  Molecule m = s->lookup_l ()->bar (s->type_str_, 40 PT, s->paper_l ());
+  
+  return m.extent (X_AXIS);
 }
 
-
 void
-Span_bar::set (Vertical_align_element *a)
+Span_bar::do_pre_processing ()
 {
-  add_dependency (a);
-}
+  Bar::do_pre_processing ();
   
+  evaluate_empty ();
+  
+  //  set_empty (false, Y_AXIS); // a hack to make mark scripts work.
+}
 
-Interval
-Span_bar::do_width() const
+void
+Span_bar::do_post_processing ()
 {
-  return paper()->lookup_l ()->bar (type_str_, 40 PT).dim_.x (); // ugh
+  Bar::do_post_processing ();
+  Interval i(get_spanned_interval ());
+
+  translate_axis (i.center (), Y_AXIS);
 }
 
 void
-Span_bar::do_pre_processing()
-{
-  Bar::do_pre_processing ();
-  
-  if (spanning_l_arr_.size() < 1) 
+Span_bar::evaluate_empty ()
+{ 
+  if (!gh_pair_p (get_elt_property ("elements"))) 
     {
-      transparent_b_ = true;
-      set_empty (true);   
+      set_elt_property ("transparent", SCM_BOOL_T);
+      set_empty (X_AXIS);
+      set_empty (Y_AXIS);   
     }
   if (type_str_.empty_b ()) 
     {
-      transparent_b_=true;
-      set_empty (true);
+      set_elt_property ("transparent", SCM_BOOL_T);
+      set_empty (X_AXIS);
+      set_empty (Y_AXIS);   
     }
   else if (type_str_ == "|:") 
     {
@@ -66,40 +77,67 @@ Span_bar::do_pre_processing()
     {
       type_str_ = "|.";
     }
+  else if (type_str_ == ":|:")
+    {
+      type_str_ = ".|.";
+    }
 }
 
-Atom
-Span_bar::get_bar_sym (Real dy) const
+Interval
+Span_bar::get_spanned_interval () const
 {
-  return paper()->lookup_l ()->bar (type_str_, dy);
+  Interval y_int;
+
+  for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
+    {
+      Score_element *bar = unsmob_element ( gh_car (s));
+
+      if (!bar)
+       continue;
+      
+      Score_element*common = common_refpoint (bar, Y_AXIS);
+
+      Interval iv (bar->extent(Y_AXIS));
+      if (!iv.empty_b ())
+       {
+         Real y = bar->relative_coordinate (common, Y_AXIS)  
+           - relative_coordinate (common, Y_AXIS);
+
+         y_int.unite (y + iv);
+       }
+    }
+  return y_int;
 }
 
+Interval
+Span_bar::height_callback (Dimension_cache const *c) 
+{
+  Span_bar * s= dynamic_cast<Span_bar*> (c->element_l ()); 
+  return s->get_spanned_interval ();
+}
 
 Molecule*
-Span_bar::brew_molecule_p() const
+Span_bar::do_brew_molecule_p () const
 {
-  Interval y_int;
-  for (int i=0; i < spanning_l_arr_.size(); i++) 
+  Interval iv (get_spanned_interval ());
+  Molecule*output = new Molecule;
+  if (!iv.empty_b())
     {
-      Axis_group_element *common = 
-       common_group (spanning_l_arr_[i], Y_AXIS);
-       
-      Real y = spanning_l_arr_[i]->relative_coordinate (common, Y_AXIS)  
-       -relative_coordinate (common,Y_AXIS);
-
-      y_int.unite (y + spanning_l_arr_[i]->height());
+      output->add_molecule (lookup_l ()->bar (type_str_, iv.length (), paper_l ()));
+    }
+  else
+    {
+      programming_error("Huh? My children deflated (FIXME)");
     }
-
-  Atom s = get_bar_sym (y_int.length());
-  Molecule*output = new Molecule (Atom (s));
-  output->translate_axis (y_int.center(), Y_AXIS);
   return output;
 }
 
 
-IMPLEMENT_IS_TYPE_B1(Span_bar,Bar);
 
-Span_bar::Span_bar()
+Span_bar::Span_bar ()
 {
   type_str_ = "";
+  dim_cache_[X_AXIS]->set_callback (width_callback);
+  dim_cache_[Y_AXIS]->set_callback (height_callback);  
 }
+