]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/beam.cc (calc_least_squares_dy): use property callback.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 26 Oct 2005 10:14:41 +0000 (10:14 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 26 Oct 2005 10:14:41 +0000 (10:14 +0000)
* lily/beam-concave.cc (calc_concaveness): use property callback.

ChangeLog
lily/beam-concave.cc
lily/beam.cc
lily/include/beam.hh
scm/define-grobs.scm

index 8bf927ddc55db8055385c0ed1a6405ec56376c18..6ed69971e3c2778a8e200528c5757c8bd95662b4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2005-10-26  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * lily/beam.cc (calc_least_squares_dy): use property callback.
+
+       * lily/beam-concave.cc (calc_concaveness): use property callback.
+
        * ly/paper-defaults.ly: move fixed dimensions from paper.scm 
 
 2005-10-25  Jan Nieuwenhuizen  <janneke@gnu.org>
index f8b31f460a6d1f926daa6d68513820a0c362efa7..7c38e96aa1b58bfd34acd13c783bcfecf043a2c9 100644 (file)
@@ -57,7 +57,7 @@ is_concave_single_notes (Array<int> const &positions, Direction beam_dir)
 }
 
 Real
-calc_concaveness (Array<int> const &positions, Direction beam_dir)
+calc_positions_concaveness (Array<int> const &positions, Direction beam_dir)
 {
   Real dy = positions.top () - positions[0];
   Real slope = dy / Real (positions.size () - 1);
@@ -80,9 +80,10 @@ calc_concaveness (Array<int> const &positions, Direction beam_dir)
   return concaveness;
 }
 
-MAKE_SCHEME_CALLBACK (Beam, check_concave, 1);
+
+MAKE_SCHEME_CALLBACK (Beam, calc_concaveness, 1);
 SCM
-Beam::check_concave (SCM smob)
+Beam::calc_concaveness (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
 
@@ -90,7 +91,7 @@ Beam::check_concave (SCM smob)
     = extract_grob_array (me, "stems");
 
   if (is_knee (me))
-    return SCM_UNSPECIFIED;
+    return scm_from_double (0.0);
 
   Direction beam_dir = CENTER;
   for (int i = stems.size (); i--;)
@@ -125,8 +126,12 @@ Beam::check_concave (SCM smob)
       far_positions.push ((int) rint (posns[-beam_dir]));
     }
 
+  Real concaveness = 0.0;
+
   if (is_concave_single_notes (far_positions, beam_dir))
     {
+      (void) me->get_property ("least-squares-dy"); // ugh. dependency handling.
+
       Drul_array<Real> pos = ly_scm2interval (me->get_property ("positions"));
       Real r = linear_combination (pos, 0.0);
 
@@ -136,11 +141,9 @@ Beam::check_concave (SCM smob)
     }
   else
     {
-      Real concaveness = (calc_concaveness (far_positions, beam_dir)
-                         + calc_concaveness (close_positions, beam_dir)) / 2;
-
-      me->set_property ("concaveness", scm_from_double (concaveness));
+      concaveness = (calc_positions_concaveness (far_positions, beam_dir)
+                    + calc_positions_concaveness (close_positions, beam_dir)) / 2;
     }
 
-  return SCM_UNSPECIFIED;
+  return scm_from_double (concaveness);
 }
index 32d6a08be556e1a0e7064073cd97119aa5d7f599..acc48074923ed94de0fa3b559d2cef6d0545347b 100644 (file)
@@ -769,11 +769,11 @@ set_minimum_dy (Grob *me, Real *dy)
 }
 
 /*
-  Compute  a first approximation to the beam slope.
+  Compute a first approximation to the beam slope.
 */
-MAKE_SCHEME_CALLBACK (Beam, least_squares, 1);
+MAKE_SCHEME_CALLBACK (Beam, calc_least_squares_dy, 1);
 SCM
-Beam::least_squares (SCM smob)
+Beam::calc_least_squares_dy (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
 
@@ -783,7 +783,7 @@ Beam::least_squares (SCM smob)
   if (count < 1)
     {
       me->set_property ("positions", ly_interval2scm (pos));
-      return SCM_UNSPECIFIED;
+      return scm_from_double (0.0);
     }
 
   Array<Real> x_posns;
@@ -814,7 +814,7 @@ Beam::least_squares (SCM smob)
   Real y = 0;
   Real slope = 0;
   Real dy = 0;
-
+  Real ldy = 0.0;
   if (!ideal.delta ())
     {
       Interval chord (Stem::chord_start_y (first_visible_stem (me)),
@@ -842,8 +842,7 @@ Beam::least_squares (SCM smob)
        slope esp. of the first part of a broken beam should predict
        where the second part goes.
       */
-      me->set_property ("least-squares-dy",
-                       scm_from_double (pos[RIGHT] - pos[LEFT]));
+      ldy = pos[RIGHT] - pos[LEFT];
     }
   else
     {
@@ -864,7 +863,8 @@ Beam::least_squares (SCM smob)
       dy = slope * dx;
 
       set_minimum_dy (me, &dy);
-      me->set_property ("least-squares-dy", scm_from_double (dy));
+
+      ldy = dy;
       pos = Interval (y, (y + dy));
     }
 
@@ -875,7 +875,7 @@ Beam::least_squares (SCM smob)
 
   me->set_property ("positions", ly_interval2scm (pos));
 
-  return SCM_UNSPECIFIED;
+  return scm_from_double (ldy);
 }
 
 /*
@@ -991,11 +991,16 @@ Beam::slope_damping (SCM smob)
   if (visible_stem_count (me) <= 1)
     return SCM_UNSPECIFIED;
 
+  /* trigger callback. */
+  (void) me->get_property ("least-squares-dy");
+  
   SCM s = me->get_property ("damping");
   Real damping = scm_to_double (s);
 
   if (damping)
     {
+      Real concaveness = robust_scm2double (me->get_property ("concaveness"), 0.0);
+
       Drul_array<Real> pos = ly_scm2interval (me->get_property ("positions"));
       scale_drul (&pos, Staff_symbol_referencer::staff_space (me));
 
@@ -1011,8 +1016,6 @@ Beam::slope_damping (SCM smob)
 
       Real slope = dy && dx ? dy / dx : 0;
 
-      Real concaveness = robust_scm2double (me->get_property ("concaveness"), 0.0);
-
       slope = 0.6 * tanh (slope) / (damping + concaveness);
 
       Real damped_dy = slope * dx;
index 1fdf5732af9decd1d34c2efed8c2da3fba6f7a8b..d688cacd369512b98496ba2ced4a1bfb00c62586 100644 (file)
@@ -59,10 +59,10 @@ public:
   DECLARE_SCHEME_CALLBACK (print, (SCM));
   DECLARE_SCHEME_CALLBACK (calc_direction, (SCM));
   DECLARE_SCHEME_CALLBACK (calc_positions, (SCM));
+  DECLARE_SCHEME_CALLBACK (calc_least_squares_dy, (SCM));
+  DECLARE_SCHEME_CALLBACK (calc_concaveness, (SCM));
 
   /* position callbacks */
-  DECLARE_SCHEME_CALLBACK (least_squares, (SCM));
-  DECLARE_SCHEME_CALLBACK (check_concave, (SCM));
   DECLARE_SCHEME_CALLBACK (slope_damping, (SCM));
   DECLARE_SCHEME_CALLBACK (shift_region_to_valid, (SCM));
   DECLARE_SCHEME_CALLBACK (quanting, (SCM));
index 9284ff078a2e6a25595ee53d51e95c2a8d2e42b8..189d9bdf9c2b038bbf4ee78c3f67d39ace68b795 100644 (file)
        ;; todo: clean this up a bit: the list is getting
        ;; rather long.
        (gap . 0.8)
-       (position-callbacks . (,Beam::least_squares
-                              ,Beam::check_concave
-                              ,Beam::slope_damping
+       
+       (position-callbacks . (,Beam::slope_damping
                               ,Beam::shift_region_to_valid
                               ,Beam::quanting))
-
+       (least-squares-dy . ,Beam::calc_least_squares_dy)
+       (concaveness . ,Beam::calc_concaveness)
        (positions . ,Beam::calc_positions)
        (direction . ,Beam::calc_direction)
        (stencil . ,Beam::print)