]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/slur-configuration.cc
* lily/include/group-interface.hh (extract_grob_array): rename
[lilypond.git] / lily / slur-configuration.cc
index a8d52ca0b72331ace3aa4da264e334bc4986a562..ec1bb088408c5f384e293a296579e0e4e840cde7 100644 (file)
@@ -1,12 +1,14 @@
 /* 
-  slur-configuration.cc --  implement Slur_configuration
+  slur-configuration.cc -- implement Slur_configuration
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
   
 */
 
+#include "slur-configuration.hh"
+
 #include <math.h>
 
 #include "stem.hh"
@@ -16,7 +18,6 @@
 #include "group-interface.hh"
 #include "slur.hh"
 #include "slur-scoring.hh"
-#include "slur-configuration.hh"
 #include "spanner.hh"
 #include "staff-symbol-referencer.hh"
 #include "libc-extension.hh"
@@ -25,7 +26,7 @@ Bezier
 avoid_staff_line (Slur_score_state const &state, 
                  Bezier bez)
 {
-  Offset horiz (1,0);
+  Offset horiz (1, 0);
   Array<Real> ts = bez.solve_derivative (horiz);
 
   /* TODO: handle case of broken slur.  */
@@ -94,11 +95,9 @@ fit_factor (Offset dz_unit, Offset dz_perp,
   return fit_factor;
 }
        
-
-Bezier
-get_bezier (Slur_score_state const &state,
-           Drul_array<Offset> attachments,
-           Real r_0, Real h_inf)
+void
+Slur_configuration::generate_curve (Slur_score_state const &state,
+                                   Real r_0, Real h_inf )
 {
   Link_array<Grob> encompasses = state.columns_;
 
@@ -116,7 +115,7 @@ get_bezier (Slur_score_state const &state,
     }
 
   Link_array<Grob> extra_encompasses
-    = Pointer_group_interface__extract_grobs (state.slur_, (Grob *)0, "encompass-objects");
+    = extract_grob_array (state.slur_, ly_symbol2scm ("encompass-objects"));
   for (int i = 0;  i < extra_encompasses.size (); i++)
     if (Slur::has_interface (extra_encompasses[i]))
       {
@@ -131,7 +130,7 @@ get_bezier (Slur_score_state const &state,
        avoid.push (z);
       }
 
-  Offset dz = attachments[RIGHT]- attachments[LEFT];;
+  Offset dz = attachment_[RIGHT]- attachment_[LEFT];;
   Offset dz_unit = dz;
   dz_unit *= 1 / dz.length ();
   Offset dz_perp = dz_unit * Offset (0, 1);
@@ -179,44 +178,36 @@ get_bezier (Slur_score_state const &state,
   Real x2 = (excentricity - indent);
   
   Bezier curve;
-  curve.control_[0] = attachments[LEFT];
-  curve.control_[1] = attachments[LEFT] + dz_perp * height * state.dir_
+  curve.control_[0] = attachment_[LEFT];
+  curve.control_[1] = attachment_[LEFT] + dz_perp * height * state.dir_
     + dz_unit * x1;
-  curve.control_[2] = attachments[RIGHT] + dz_perp * height * state.dir_
+  curve.control_[2] = attachment_[RIGHT] + dz_perp * height * state.dir_
     + dz_unit * x2;
-  curve.control_[3] = attachments[RIGHT];
+  curve.control_[3] = attachment_[RIGHT];
 
   Real ff = fit_factor (dz_unit, dz_perp, curve, state.dir_, avoid);
   
   height = height >? ((height * ff) <? max_h);
 
-  curve.control_[0] = attachments[LEFT];
-  curve.control_[1] = attachments[LEFT] + dz_perp * height * state.dir_
+  curve.control_[0] = attachment_[LEFT];
+  curve.control_[1] = attachment_[LEFT] + dz_perp * height * state.dir_
     + dz_unit * x1;
-  curve.control_[2] = attachments[RIGHT] + dz_perp * height * state.dir_
+  curve.control_[2] = attachment_[RIGHT] + dz_perp * height * state.dir_
     + dz_unit * x2;
-  curve.control_[3] = attachments[RIGHT];
+  curve.control_[3] = attachment_[RIGHT];
 
-  return curve;
+  curve_ = avoid_staff_line (state, curve);
+  height_ = height;
 }
 
 Slur_configuration::Slur_configuration()
 {
   score_ = 0.0;
+  index_ = -1; 
 };
 
-void
-Slur_configuration::generate_curve (Slur_score_state const &state,
-                                   Real r_0, Real h_inf )
-{
-  Bezier bez = get_bezier (state,
-                          attachment_, r_0, h_inf);
 
-  bez = avoid_staff_line (state, bez);
-  attachment_[LEFT] = bez.control_[0];
-  attachment_[RIGHT] = bez.control_[3];
-  curve_ = bez;
-}
+
 
 void
 Slur_configuration::score_encompass (Slur_score_state const &state)
@@ -229,23 +220,14 @@ Slur_configuration::score_encompass (Slur_score_state const &state)
     attachment points.
   */
   Array<Real> convex_head_distances;
-  Array<Real> edge_distances;
   for (int j = 0; j < state.encompass_infos_.size (); j++)
     {
       Real x = state.encompass_infos_[j].x_;
 
-      bool l_edge = j==0;
-      bool r_edge = j==state.encompass_infos_.size ()-1;
+      bool l_edge = j == 0;
+      bool r_edge = j == state.encompass_infos_.size ()-1;
       bool edge =  l_edge || r_edge;
 
-
-      if (edge)
-       {
-         edge_distances.push (fabs (attachment_[l_edge ? LEFT : RIGHT][Y_AXIS]
-                                    - state.encompass_infos_[j].get_point (state.dir_)));
-       }
-       
-       
       if (! (x < attachment_[RIGHT][X_AXIS]
             && x > attachment_[LEFT][X_AXIS]))
        continue;
@@ -292,7 +274,7 @@ Slur_configuration::score_encompass (Slur_score_state const &state)
 
       if (state.dir_ * (y - state.encompass_infos_[j].stem_) < 0)
        {
-         Real stem_dem =state.parameters_.stem_encompass_penalty_ ;
+         Real stem_dem = state.parameters_.stem_encompass_penalty_ ;
          if ((l_edge && state.dir_ == UP)
              || (r_edge && state.dir_ == DOWN))
            stem_dem /= 5;
@@ -330,16 +312,12 @@ Slur_configuration::score_encompass (Slur_score_state const &state)
        For slurs over 3 or 4 heads, the average distance is not a
        good normalizer.
       */
-      int n =  convex_head_distances.size ();
-      if (convex_head_distances.size () <= 2)
+      Real n =  convex_head_distances.size ();
+      if (n <= 2)
        {
-         //          Real min_edge_dist = 1e6;
-         for (int j = 0; j < edge_distances.size (); j++)
-           {
-             avg_distance += edge_distances[j];
-             n++;
-           }
-
+         Real fact = 1.0;
+         avg_distance += height_ * fact;
+         n += fact;
        }
 
       /*
@@ -349,11 +327,14 @@ Slur_configuration::score_encompass (Slur_score_state const &state)
       avg_distance /= n;
       variance_penalty = state.parameters_.head_slur_distance_max_ratio_;
       if (min_dist > 0.0)
-       variance_penalty = ((avg_distance / (min_dist  +state.parameters_.free_head_distance_)) - 1.0)
+       variance_penalty =
+         (avg_distance / (min_dist + state.parameters_.absolute_closeness_measure_ ) - 1.0)
          <? variance_penalty;
 
+      variance_penalty = variance_penalty >? 0.0;
       variance_penalty *= state.parameters_.head_slur_distance_factor_;
     }
+
 #if DEBUG_SLUR_SCORING
   score_card_ += to_string ("C%.2f", demerit);
   score_card_ += to_string ("D%.2f", variance_penalty);