]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam-quanting.cc
* buildscripts/mf-to-table.py (base): break table every three
[lilypond.git] / lily / beam-quanting.cc
index e20393afd54d3ad475a2b96293299169dc6dcf9a..4d95ed4e655ebb80e912b1bc73823cc1cbe94ba5 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   Jan Nieuwenhuizen <janneke@gnu.org>
   
 */
@@ -172,7 +172,10 @@ Beam::quanting (SCM smob)
    */
   if (knee_b)
     region_size += 2;
-  
+
+  /*
+    Asymetry ? should run to <= region_size ?
+   */
   for (int i = -region_size ; i < region_size; i++)
     for (int j = 0; j < num_quants; j++)
       {
@@ -218,7 +221,7 @@ Beam::quanting (SCM smob)
                                     beam_count, ldir, rdir); 
       }
 
-  ; /* silly gdb thinks best_idx is inside for loop. */
+  //  ; /* silly gdb thinks best_idx is inside for loop. */
   for (int i = qscores.size (); i--;)
     if (qscores[i].demerits < reasonable_score)
       {
@@ -230,7 +233,7 @@ Beam::quanting (SCM smob)
                                 qscores[i].yl, qscores[i].yr);
       }
 
-  ; /* silly gdb thinks best_idx is inside for loop. */
+  //  ; /* silly gdb thinks best_idx is inside for loop. */
   int best_idx = best_quant_score_idx (qscores);
   me->set_grob_property ("positions",
                         gh_cons (gh_double2scm (qscores[best_idx].yl),
@@ -249,15 +252,15 @@ Beam::quanting (SCM smob)
 }
 
 Real
-Beam::score_stem_lengths (Link_array<Grob>stems,
-                         Array<Stem_info> stem_infos,
-                         Array<Real> base_stem_ys,
-                         Array<Real> stem_xs,
+Beam::score_stem_lengths (Link_array<Grob> const &stems,
+                         Array<Stem_info> const &stem_infos,
+                         Array<Real> const &base_stem_ys,
+                         Array<Real> const &stem_xs,
                          Real xl, Real xr, 
                          bool knee, 
                          Real yl, Real yr)
 {
-  Real limit_pen = STEM_LENGTH_LIMIT_PENALTY;
+  Real limit_penalty = STEM_LENGTH_LIMIT_PENALTY;
   Drul_array<Real> score (0, 0);
   Drul_array<int> count (0, 0);
   
@@ -271,16 +274,16 @@ Beam::score_stem_lengths (Link_array<Grob>stems,
       Real dx = xr-xl;
       Real beam_y = yr *(x - xl)/dx + yl * ( xr - x)/dx;
       Real current_y = beam_y + base_stem_ys[i];
-      Real length_pen = STEM_LENGTH_LIMIT_PENALTY;
+      Real length_pen = STEM_LENGTH_DEMERIT_FACTOR;
       
       Stem_info info = stem_infos[i];
       Direction d = info.dir_;
 
-      score[d] += limit_pen * (0 >? (d * (info.shortest_y_ - current_y)));
+      score[d] += limit_penalty * (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);
-
+      
       /* We introduce a power, to make the scoring strictly
          convex. Otherwise a symmetric knee beam (up/down/up/down)
          does not have an optimum in the middle. */
@@ -291,11 +294,14 @@ Beam::score_stem_lengths (Link_array<Grob>stems,
 
       count[d] ++;
     }
-  
-  if(count[LEFT])
-    score[LEFT] /= count[LEFT];
-  if(count[RIGHT])
-    score[RIGHT] /= count[RIGHT];
+
+  Direction d = DOWN;
+  do
+    { 
+      if(count[d])
+       score[d] /= count[d];
+    }
+  while (flip (&d) != DOWN);
 
   return score[LEFT]+score[RIGHT];
 }
@@ -337,7 +343,7 @@ my_modf (Real x)
 
 Real
 Beam::score_forbidden_quants (Real yl, Real yr,
-                             Real rad,
+                             Real radius,
                              Real slt,
                              Real thickness, Real beam_translation,
                              int beam_count,
@@ -346,25 +352,26 @@ Beam::score_forbidden_quants (Real yl, Real yr,
   Real dy = yr - yl;
 
   Real dem = 0.0;
-  if (fabs (yl) < rad && fabs ( my_modf (yl) - 0.5) < 1e-3)
-    dem += INTER_QUANT_PENALTY;
-  if (fabs (yr) < rad && fabs ( my_modf (yr) - 0.5) < 1e-3)
-    dem += INTER_QUANT_PENALTY;
+  for (int i = 0; i < 2; i++)
+    {
+      Real y = i? yl : yr;
+      if (fabs (y) <= (radius + 0.5) && fabs ( my_modf (y) - 0.5) < 1e-3)
+       dem += INTER_QUANT_PENALTY;
+    }
 
   // todo: use beam_count of outer stems.
   if (beam_count >= 2)
     {
-     
       Real straddle = 0.0;
       Real sit = (thickness - slt) / 2;
       Real inter = 0.5;
       Real hang = 1.0 - (thickness - slt) / 2;
       
 
-      if (fabs (yl - ldir * beam_translation) < rad
+      if (fabs (yl - ldir * beam_translation) < radius
          && fabs (my_modf (yl) - inter) < 1e-3)
        dem += SECONDARY_BEAM_DEMERIT;
-      if (fabs (yr - rdir * beam_translation) < rad
+      if (fabs (yr - rdir * beam_translation) < radius
          && fabs (my_modf (yr) - inter) < 1e-3)
        dem += SECONDARY_BEAM_DEMERIT;
 
@@ -373,15 +380,15 @@ Beam::score_forbidden_quants (Real yl, Real yr,
       /*
        Can't we simply compute the distance between the nearest
        staffline and the secondary beam? That would get rid of the
-       silly case analysis here (which is probably not when we have
-       different beam-thicknesses.)
+       silly case analysis here (which is probably not valid when we
+       have different beam-thicknesses.)
 
        --hwn
        */
 
 
       // hmm, without Interval/Drul_array, you get ~ 4x same code...
-      if (fabs (yl - ldir * beam_translation) < rad + inter)
+      if (fabs (yl - ldir * beam_translation) < radius + inter)
        {
          if (ldir == UP && dy <= eps
              && fabs (my_modf (yl) - sit) < eps)
@@ -392,7 +399,7 @@ Beam::score_forbidden_quants (Real yl, Real yr,
            dem += SECONDARY_BEAM_DEMERIT;
        }
 
-      if (fabs (yr - rdir * beam_translation) < rad + inter)
+      if (fabs (yr - rdir * beam_translation) < radius + inter)
        {
          if (rdir == UP && dy >= eps
              && fabs (my_modf (yr) - sit) < eps)
@@ -405,7 +412,7 @@ Beam::score_forbidden_quants (Real yl, Real yr,
       
       if (beam_count >= 3)
        {
-         if (fabs (yl - 2 * ldir * beam_translation) < rad + inter)
+         if (fabs (yl - 2 * ldir * beam_translation) < radius + inter)
            {
              if (ldir == UP && dy <= eps
                  && fabs (my_modf (yl) - straddle) < eps)
@@ -414,9 +421,9 @@ Beam::score_forbidden_quants (Real yl, Real yr,
              if (ldir == DOWN && dy >= eps
                  && fabs (my_modf (yl) - straddle) < eps)
                dem += SECONDARY_BEAM_DEMERIT;
-       }
+           }
          
-         if (fabs (yr - 2 * rdir * beam_translation) < rad + inter)
+         if (fabs (yr - 2 * rdir * beam_translation) < radius + inter)
            {
              if (rdir == UP && dy >= eps
                  && fabs (my_modf (yr) - straddle) < eps)