]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
release: 1.3.36
[lilypond.git] / lily / beam.cc
index 1daf73682b395abf745300f592038973e4ba448c..d641c8912c3443a4f2dd14d9af479c004459b7a8 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
     Jan Nieuwenhuizen <janneke@gnu.org>
 
 */
@@ -14,6 +14,8 @@
     * move paper vars to scm
 
 */
+
+
 #include <math.h>              // tanh.
 
 #include "directional-element-interface.hh"
@@ -22,7 +24,7 @@
 #include "beam.hh"
 #include "misc.hh"
 #include "debug.hh"
-#include "leastsquares.hh"
+#include "least-squares.hh"
 #include "stem.hh"
 #include "paper-def.hh"
 #include "lookup.hh"
@@ -48,10 +50,10 @@ Beam::add_stem (Stem*s)
   assert (!s->beam_l ());
   s->set_elt_property ("beam", self_scm_);
 
-  if (!spanned_drul_[LEFT])
-    set_bounds (LEFT,s);
+  if (!get_bound (LEFT))
+    set_bound (LEFT,s);
   else
-    set_bounds (RIGHT,s);
+    set_bound (RIGHT,s);
 }
 
 int
@@ -77,13 +79,13 @@ Beam::get_multiplicity () const
    their beam, during 'final-pre-processing'.]
  */
 void
-Beam::do_pre_processing ()
+Beam::before_line_breaking ()
 {
   // Why?
   if (visible_stem_count () < 2)
     {
       warning (_ ("beam has less than two stems"));
-      set_elt_property ("transparent", SCM_BOOL_T);
+      //      set_elt_property ("transparent", SCM_BOOL_T);
     }
 
   if (!directional_element (this).get ())
@@ -91,7 +93,6 @@ Beam::do_pre_processing ()
 
   auto_knees ();
   set_stem_directions ();
-
   set_stem_shorten (); 
 }
 
@@ -262,39 +263,44 @@ Beam::set_stem_shorten ()
   Adjust stem lengths to reach beam.
  */
 void
-Beam::do_post_processing ()
+Beam::after_line_breaking ()
 {
   /* first, calculate y, dy */
   Real y, dy;
   calc_position_and_height (&y, &dy);
-  if (suspect_slope_b (y, dy))
-    dy = 0;
+  if (visible_stem_count ())
+    {
+      if (suspect_slope_b (y, dy))
+       dy = 0;
 
-  Real damped_dy = calc_slope_damping_f (dy);
-  Real quantised_dy = quantise_dy_f (damped_dy);
+      Real damped_dy = calc_slope_damping_f (dy);
+      Real quantised_dy = quantise_dy_f (damped_dy);
 
-  y += (dy - quantised_dy) / 2;
-  dy = quantised_dy;
-  
+      y += (dy - quantised_dy) / 2;
+      dy = quantised_dy;
+    }
   /*
     until here, we used only stem_info, which acts as if dir=up
    */
   y *= directional_element (this).get ();
   dy *= directional_element (this).get ();
 
-  /* set or read dy as necessary */
-  SCM s = get_elt_property ("height");
+  Staff_symbol_referencer_interface st (this);
+  Real half_space = st.staff_space () / 2;
+
+  /* check for user-override of dy */
+  SCM s = remove_elt_property ("height-hs");
   if (gh_number_p (s))
-    dy = gh_scm2double (s);
-  else
-    set_elt_property ("height", gh_double2scm (dy));
+    {
+      dy = gh_scm2double (s) * half_space;
+    }
+  set_elt_property ("height", gh_double2scm (dy));
 
-  /* set or read y as necessary */
-  s = get_elt_property ("y-position");
+  /* check for user-override of y */
+  s = remove_elt_property ("y-position-hs");
   if (gh_number_p (s))
     {
-      y = gh_scm2double (s);
-      set_stem_length (y, dy);
+      y = gh_scm2double (s) * half_space;
     }
   else
     { 
@@ -305,8 +311,6 @@ Beam::do_post_processing ()
       set_stem_length (y, dy);
       y_shift = check_stem_length_f (y, dy);
 
-      Staff_symbol_referencer_interface st (this);
-      Real half_space = st.staff_space () / 2;
       if (y_shift > half_space / 4)
        {
          y += y_shift;
@@ -319,11 +323,12 @@ Beam::do_post_processing ()
          if (abs (y_shift) > half_space / 2)
            quant_dir = sign (y_shift) * directional_element (this).get ();
          y = quantise_y_f (y, dy, quant_dir);
-         set_stem_length (y, dy);
        }
-
-      set_elt_property ("y-position", gh_double2scm (y));
     }
+  // UGH. Y is not in staff position unit?
+  // Ik dacht datwe daar juist van weg wilden?
+  set_stem_length (y, dy);
+  set_elt_property ("y-position", gh_double2scm (y)); 
 }
 
 /*
@@ -344,18 +349,18 @@ Beam::calc_position_and_height (Real* y, Real* dy) const
       return;
     }
 
-  Least_squares ls;
+  Array<Offset> ideals;
   Real x0 = first_visible_stem ()->hpos_f ();
   for (int i=0; i < stem_count (); i++)
     {
       Stem* s = stem (i);
       if (s->invisible_b ())
         continue;
-      ls.input.push (Offset (s->hpos_f () - x0, 
-        s->calc_stem_info ().idealy_f_));
+      ideals.push (Offset (s->hpos_f () - x0, 
+                          s->calc_stem_info ().idealy_f_));
     }
   Real dydx;
-  ls.minimise (dydx, *y); // duh, takes references
+  minimise_least_squares (&dydx, y, ideals); // duh, takes references
 
   Real dx = last_visible_stem ()->hpos_f () - x0;
   *dy = dydx * dx;
@@ -364,6 +369,7 @@ Beam::calc_position_and_height (Real* y, Real* dy) const
 bool
 Beam::suspect_slope_b (Real y, Real dy) const
 {
+  /* first, calculate y, dy */
   /*
     steep slope running against lengthened stem is suspect
   */
@@ -593,12 +599,14 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
 
 
   Real interbeam_f = paper_l ()->interbeam_f (multiplicity);
-  Real thick = gh_scm2double (get_elt_property ("beam-thickness"));;
+  Real thick = gh_scm2double (get_elt_property ("beam-thickness"));
 
   Real bdy = interbeam_f;
   Real stemdx = staffline_f;
 
-  Real dx = last_visible_stem ()->hpos_f () - first_visible_stem ()->hpos_f ();
+  Real dx = visible_stem_count () ?
+    last_visible_stem ()->hpos_f () - first_visible_stem ()->hpos_f ()
+    : 0.0;
   Real dy = get_real ("height");
   Real dydx = dy && dx ? dy/dx : 0;
 
@@ -700,15 +708,25 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
 }
 
 
-Molecule*
-Beam::do_brew_molecule_p () const
+Molecule 
+Beam::do_brew_molecule () const
 {
-  Molecule *mol_p = new Molecule;
+  Molecule mol;
   if (!stem_count ())
-    return mol_p;
+    return mol;
+  Real x0,dx;
+  if (visible_stem_count ())
+    {
+      x0 = first_visible_stem ()->hpos_f ();
+      dx = last_visible_stem ()->hpos_f () - x0;
+    }
+  else
+    {
+      x0 = stem (0)->hpos_f ();
+      dx = stem_top ()->hpos_f () - x0;
+    }
+  
   
-  Real x0 = first_visible_stem ()->hpos_f ();
-  Real dx = last_visible_stem ()->hpos_f () - x0;
   Real dy = get_real ("height");
   Real dydx = dy && dx ? dy/dx : 0;
   Real y = get_real ("y-position");
@@ -721,12 +739,12 @@ Beam::do_brew_molecule_p () const
       Molecule sb = stem_beams (i, next, prev);
       Real x = i->hpos_f ()-x0;
       sb.translate (Offset (x, x * dydx + y));
-      mol_p->add_molecule (sb);
+      mol.add_molecule (sb);
     }
-  mol_p->translate_axis (x0 
-    - spanned_drul_[LEFT]->relative_coordinate (0, X_AXIS), X_AXIS);
+  mol.translate_axis (x0 
+    - get_bound (LEFT)->relative_coordinate (0, X_AXIS), X_AXIS);
 
-  return mol_p;
+  return mol;
 }
 
 int
@@ -798,9 +816,6 @@ Beam::first_visible_stem () const
       if (!s->invisible_b ())
         return s;
     }
-
-  assert (0);
-
   return 0;
 }
 
@@ -813,8 +828,5 @@ Beam::last_visible_stem () const
       if (!s->invisible_b ())
         return s;
     }
-
-  assert (0);
-  // sigh
   return 0;
 }