]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam-quanting.cc
* The grand 2005-2006 replace.
[lilypond.git] / lily / beam-quanting.cc
index b72da881f69d408b391709a7ab29aa597223a4c0..90ace1f4012a5dbd2dc2ea71943c21dce1127b2d 100644 (file)
@@ -3,14 +3,14 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
   Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "beam.hh"
 
 #include <algorithm>
-#include <math.h>
+using namespace std;
 
 #include "warn.hh"
 #include "staff-symbol-referencer.hh"
@@ -25,9 +25,7 @@ get_detail (SCM alist, SCM sym, Real def)
   SCM entry = scm_assq (sym, alist);
 
   if (scm_is_pair (entry))
-    {
-      return robust_scm2double (scm_cdr (entry), def);
-    }
+    return robust_scm2double (scm_cdr (entry), def);
   return def;
 }
 
@@ -95,18 +93,17 @@ best_quant_score_idx (Array<Quant_score> const &qscores)
   return best_idx;
 }
 
-MAKE_SCHEME_CALLBACK (Beam, quanting, 1);
+MAKE_SCHEME_CALLBACK (Beam, quanting, 2);
 SCM
-Beam::quanting (SCM smob)
+Beam::quanting (SCM smob, SCM posns)
 {
   Grob *me = unsmob_grob (smob);
 
   Beam_quant_parameters parameters;
   parameters.fill (me);
 
-  SCM s = me->get_property ("positions");
-  Real yl = scm_to_double (scm_car (s));
-  Real yr = scm_to_double (scm_cdr (s));
+  Real yl = scm_to_double (scm_car (posns));
+  Real yr = scm_to_double (scm_cdr (posns));
 
   /*
     Calculations are relative to a unit-scaled staff, i.e. the quants are
@@ -281,7 +278,7 @@ Beam::quanting (SCM smob)
 
 #if DEBUG_QUANTING
   SCM inspect_quants = me->get_property ("inspect-quants");
-  if (to_boolean (me->get_layout ()->lookup_variable (ly_symbol2scm ("debug-beam-quanting")))
+  if (to_boolean (me->layout ()->lookup_variable (ly_symbol2scm ("debug-beam-quanting")))
       && scm_is_pair (inspect_quants))
     {
       Drul_array<Real> ins = ly_scm2interval (inspect_quants);
@@ -302,18 +299,22 @@ Beam::quanting (SCM smob)
        programming_error ("can't find quant");
     }
 #endif
+
+  Interval final_positions;
   if (best_idx < 0)
     {
       warning (_ ("no feasible beam position"));
-      me->set_property ("positions", ly_interval2scm (Interval (0, 0)));
+      final_positions = Interval (0, 0);
     }
   else
-    me->set_property ("positions",
-                     ly_interval2scm (Drul_array<Real> (qscores[best_idx].yl,
-                                                        qscores[best_idx].yr)));
+    {
+      final_positions = Drul_array<Real> (qscores[best_idx].yl,
+                                         qscores[best_idx].yr);
+    }
+  
 #if DEBUG_QUANTING
   if (best_idx >= 0
-      && to_boolean (me->get_layout ()->lookup_variable (ly_symbol2scm ("debug-beam-quanting"))))
+      && to_boolean (me->layout ()->lookup_variable (ly_symbol2scm ("debug-beam-quanting"))))
     {
       qscores[best_idx].score_card_ += to_string ("i%d", best_idx);
 
@@ -323,7 +324,7 @@ Beam::quanting (SCM smob)
     }
 #endif
 
-  return SCM_UNSPECIFIED;
+  return ly_interval2scm (final_positions);
 }
 
 Real
@@ -374,10 +375,9 @@ Beam::score_stem_lengths (Link_array<Grob> const &stems,
 
   Direction d = DOWN;
   do
-    {
-      score[d] /= max (count[d], 1);
-    }
-  while (flip (&d) != DOWN);
+    score[d] /= max (count[d], 1);
+  while (flip (&d) != DOWN)
+    ;
 
   return score[LEFT] + score[RIGHT];
 }
@@ -402,11 +402,10 @@ Beam::score_slopes_dy (Real yl, Real yr,
   */
   if (fabs (dy / dx) > parameters->ROUND_TO_ZERO_SLOPE
       && sign (dy_damp) != sign (dy))
-    {
-      dem += parameters->DAMPING_DIRECTION_PENALTY;
-    }
+    dem += parameters->DAMPING_DIRECTION_PENALTY;
 
-  dem += parameters->MUSICAL_DIRECTION_FACTOR *max (0.0, (fabs (dy) - fabs (dy_mus)));
+  dem += parameters->MUSICAL_DIRECTION_FACTOR
+    * max (0.0, (fabs (dy) - fabs (dy_mus)));
 
   Real slope_penalty = parameters->IDEAL_SLOPE_FACTOR;