]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam-quanting.cc
* The grand 2005-2006 replace.
[lilypond.git] / lily / beam-quanting.cc
index 689cf7c2ec3d6a81c9f578643e3d7676ca27acc7..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"
@@ -23,11 +23,9 @@ Real
 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;
 }
 
@@ -35,7 +33,7 @@ void
 Beam_quant_parameters::fill (Grob *him)
 {
   SCM details = him->get_property ("details");
-  
+
   INTER_QUANT_PENALTY = get_detail (details, ly_symbol2scm ("inter-quant-penalty"), 1000.0);
   SECONDARY_BEAM_DEMERIT = get_detail (details, ly_symbol2scm ("secondary-beam-demerit"), 10.0);
   STEM_LENGTH_DEMERIT_FACTOR = get_detail (details, ly_symbol2scm ("stem-length-demerit-factor"), 5);
@@ -95,19 +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
@@ -195,7 +191,7 @@ Beam::quanting (SCM smob)
   bool is_knee = dirs_found[LEFT] && dirs_found[RIGHT];
 
   int region_size = (int) parameters.REGION_SIZE;
-  
+
   /*
     Knees are harder, lets try some more possibilities for knees.
   */
@@ -279,10 +275,10 @@ Beam::quanting (SCM smob)
       }
 
   int best_idx = best_quant_score_idx (qscores);
-  
+
 #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);
@@ -303,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);
 
@@ -324,7 +324,7 @@ Beam::quanting (SCM smob)
     }
 #endif
 
-  return SCM_UNSPECIFIED;
+  return ly_interval2scm (final_positions);
 }
 
 Real
@@ -336,8 +336,7 @@ Beam::score_stem_lengths (Link_array<Grob> const &stems,
                          bool knee,
                          Real yl, Real yr,
 
-                         Beam_quant_parameters const*parameters
-                         )
+                         Beam_quant_parameters const *parameters)
 {
   Real limit_penalty = parameters->STEM_LENGTH_LIMIT_PENALTY;
   Drul_array<Real> score (0, 0);
@@ -358,7 +357,7 @@ Beam::score_stem_lengths (Link_array<Grob> const &stems,
       Stem_info info = stem_infos[i];
       Direction d = info.dir_;
 
-      score[d] += limit_penalty * max (0.0,  (d * (info.shortest_y_ - current_y)));
+      score[d] += limit_penalty * max (0.0, (d * (info.shortest_y_ - current_y)));
 
       Real ideal_diff = d * (current_y - info.ideal_y_);
       Real ideal_score = shrink_extra_weight (ideal_diff, 1.5);
@@ -376,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];
 }
@@ -389,8 +387,8 @@ Beam::score_slopes_dy (Real yl, Real yr,
                       Real dy_mus, Real dy_damp,
                       Real dx,
                       bool xstaff,
-                      
-                      Beam_quant_parameters const*parameters)
+
+                      Beam_quant_parameters const *parameters)
 {
   Real dy = yr - yl;
   Real dem = 0.0;
@@ -404,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;
 
@@ -442,8 +439,8 @@ Beam::score_forbidden_quants (Real yl, Real yr,
                              Real thickness, Real beam_translation,
                              Drul_array<int> beam_counts,
                              Direction ldir, Direction rdir,
-                             
-                             Beam_quant_parameters const*parameters)
+
+                             Beam_quant_parameters const *parameters)
 {
   Real dy = yr - yl;
   Drul_array<Real> y (yl, yr);