]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/slur-scoring.cc
* input/regression/font-name.ly: show Pango fonts for
[lilypond.git] / lily / slur-scoring.cc
index 1e4279baf85077dfe0a425b939b4c829a9a7cdae..400e08a9a82726370043aa34deb074f2c4fb8c3b 100644 (file)
@@ -3,24 +3,22 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1996--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include <math.h>
 
+#include "slur-scoring.hh"
 #include "libc-extension.hh"
 #include "slur-configuration.hh"
-#include "slur-scoring.hh"
 #include "beam.hh"
 #include "directional-element-interface.hh"
 #include "group-interface.hh"
-#include "lily-guile.hh"
 #include "slur.hh"
 #include "note-column.hh"
 #include "output-def.hh"
 #include "pitch.hh"
-#include "bezier.hh"
 #include "spanner.hh"
 #include "staff-symbol-referencer.hh"
 #include "staff-symbol.hh"
   - calculate encompass scoring directly after determining slur shape.
 
   - optimize.
-
 */
 struct Slur_score_state;
 
-Slur_score_state::Slur_score_state()
+Slur_score_state::Slur_score_state ()
 {
   musical_dy_ = 0.0;
   valid_ = false;
@@ -63,18 +60,13 @@ Slur_score_state::Slur_score_state()
   slur_ = 0;
   common_[X_AXIS] = 0;
   common_[Y_AXIS] = 0;
-  scores_ = 0;
 }
 
 Slur_score_state::~Slur_score_state ()
 {
-  delete scores_;
+  junk_pointers (configurations_);
 }
 
-
-
-
-
 Real
 get_detail (SCM alist, SCM sym)
 {
@@ -86,46 +78,47 @@ get_detail (SCM alist, SCM sym)
 }
 
 void
-init_score_param (Grob *me,
-                  Slur_score_parameters *score_param)
+Slur_score_parameters::fill (Grob *me)
 {
   SCM details = me->get_property ("slur-details");
 
-  score_param->region_size_
+  region_size_
     = (int) get_detail (details, ly_symbol2scm ("region-size"));
-  score_param->head_encompass_penalty_
+  head_encompass_penalty_
     = get_detail (details, ly_symbol2scm ("head-encompass-penalty"));
-  score_param->stem_encompass_penalty_
+  stem_encompass_penalty_
     = get_detail (details, ly_symbol2scm ("stem-encompass-penalty"));
-  score_param->closeness_factor_
+  closeness_factor_
     = get_detail (details, ly_symbol2scm ("closeness-factor"));
-  score_param->edge_attraction_factor_
+  edge_attraction_factor_
     = get_detail (details, ly_symbol2scm ("edge-attraction-factor"));
-  score_param->same_slope_penalty_
+  same_slope_penalty_
     = get_detail (details, ly_symbol2scm ("same-slope-penalty"));
-  score_param->steeper_slope_factor_
+  steeper_slope_factor_
     = get_detail (details, ly_symbol2scm ("steeper-slope-factor"));
-  score_param->non_horizontal_penalty_
+  non_horizontal_penalty_
     = get_detail (details, ly_symbol2scm ("non-horizontal-penalty"));
-  score_param->max_slope_
+  max_slope_
     = get_detail (details, ly_symbol2scm ("max-slope"));
-  score_param->max_slope_factor_
+  max_slope_factor_
     = get_detail (details, ly_symbol2scm ("max-slope-factor"));
-  score_param->free_head_distance_
+  free_head_distance_
     = get_detail (details, ly_symbol2scm ("free-head-distance"));
-  score_param->extra_object_collision_
+  absolute_closeness_measure_
+    = get_detail (details, ly_symbol2scm ("absolute-closeness-measure"));
+  extra_object_collision_
     = get_detail (details, ly_symbol2scm ("extra-object-collision"));
-  score_param->accidental_collision_
+  accidental_collision_
     = get_detail (details, ly_symbol2scm ("accidental-collision"));
-  score_param->extra_encompass_free_distance_
+  extra_encompass_free_distance_
     = get_detail (details, ly_symbol2scm ("extra-encompass-free-distance"));
-  score_param->head_slur_distance_factor_
+  head_slur_distance_factor_
     = get_detail (details, ly_symbol2scm ("head-slur-distance-factor"));
-  score_param->head_slur_distance_max_ratio_
+  head_slur_distance_max_ratio_
     = get_detail (details, ly_symbol2scm ("head-slur-distance-max-ratio"));
-  score_param->free_slur_distance_
+  free_slur_distance_
     = get_detail (details, ly_symbol2scm ("free-slur-distance"));
-  score_param->edge_slope_exponent_
+  edge_slope_exponent_
     = get_detail (details, ly_symbol2scm ("edge-slope-exponent"));
 }
 
@@ -135,7 +128,7 @@ broken_trend_y (Slur_score_state const &state, Direction hdir)
   /* A broken slur should maintain the same vertical trend
      the unbroken slur would have had.  */
   Real by = 0.0;
-  if (Spanner *mother = dynamic_cast<Spanner*> (state.slur_->original_))
+  if (Spanner *mother = dynamic_cast<Spanner *> (state.slur_->original_))
     {
       int k = broken_spanner_index (state.slur_);
       int j = k + hdir;
@@ -144,35 +137,34 @@ broken_trend_y (Slur_score_state const &state, Direction hdir)
 
       Grob *neighbor = mother->broken_intos_[j];
       Spanner *common_mother
-       = dynamic_cast<Spanner*> (state.common_[Y_AXIS]->original_);
+       = dynamic_cast<Spanner *> (state.common_[Y_AXIS]->original_);
       int common_k
-       = broken_spanner_index (dynamic_cast<Spanner*> (state.common_[Y_AXIS]));
+       = broken_spanner_index (dynamic_cast<Spanner *> (state.common_[Y_AXIS]));
       int common_j = common_k + hdir;
 
       if (common_j < 0 || common_j >= common_mother->broken_intos_.size ())
        return by;
 
       Grob *common_next_system = common_mother->broken_intos_[common_j];
-      
-      SCM last_point =  scm_car (scm_last_pair (neighbor->get_property ("control-points")));
-      
+
+      SCM last_point = scm_car (scm_last_pair (neighbor->get_property ("control-points")));
+
       return scm_to_double (scm_cdr (last_point))
        + neighbor->relative_coordinate (common_next_system, Y_AXIS);
     }
   return by;
 }
 
-
 /*
   copy slur dir forwards across line break.
 */
 void
-Slur_score_state::set_next_direction () 
+Slur_score_state::set_next_direction ()
 {
   if (extremes_[RIGHT].note_column_)
     return;
-  
-  if (Spanner *mother = dynamic_cast<Spanner*> (slur_->original_))
+
+  if (Spanner *mother = dynamic_cast<Spanner *> (slur_->original_))
     {
       int k = broken_spanner_index (slur_);
       int j = k + 1;
@@ -192,7 +184,7 @@ Slur_score_state::get_encompass_info (Grob *col) const
 
   if (!stem)
     {
-      programming_error ("No stem for note column?");
+      programming_error ("no stem for note column");
       ei.x_ = col->relative_coordinate (common_[X_AXIS], X_AXIS);
       ei.head_ = ei.stem_ = col->extent (common_[Y_AXIS],
                                         Y_AXIS)[dir_];
@@ -232,9 +224,6 @@ Slur_score_state::get_encompass_info (Grob *col) const
   return ei;
 }
 
-
-
-
 Drul_array<Bound_info>
 Slur_score_state::get_bound_info () const
 {
@@ -274,32 +263,33 @@ Slur_score_state::get_bound_info () const
        }
     }
   while (flip (&d) != LEFT);
+
   return extremes;
 }
 
 void
 Slur_score_state::fill (Grob *me)
 {
-  slur_ = dynamic_cast<Spanner*> (me);
-  columns_ 
-    = Pointer_group_interface__extract_grobs (me, (Grob *) 0, "note-columns");
-  
+  slur_ = dynamic_cast<Spanner *> (me);
+  columns_
+    = extract_grob_array (me, ly_symbol2scm ("note-columns"));
+
   if (columns_.is_empty ())
     {
       me->suicide ();
-      return ;
+      return;
     }
 
   staff_space_ = Staff_symbol_referencer::staff_space (me);
-  Real lt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness"));
-  thickness_ = robust_scm2double (me->get_property ("thickness"), 1.0) *  lt;
-  
+  Real lt = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
+  thickness_ = robust_scm2double (me->get_property ("thickness"), 1.0) * lt;
+
   dir_ = get_grob_direction (me);
-  init_score_param (me, &parameters_);
-  
+  parameters_.fill (me);
+
   SCM eltlist = me->get_property ("note-columns");
   SCM extra_list = me->get_property ("encompass-objects");
-  Spanner *sp = dynamic_cast<Spanner*> (me);
+  Spanner *sp = dynamic_cast<Spanner *> (me);
 
   for (int i = X_AXIS; i < NO_AXES; i++)
     {
@@ -308,30 +298,38 @@ Slur_score_state::fill (Grob *me)
       common_[a] = common_refpoint_of_list (extra_list, common_[a], a);
 
       Direction d = LEFT;
-      do {
-       common_[a] = common_[a]->common_refpoint (sp->get_bound (d), a);
-      }
+      do
+       {
+         /*
+           If bound is not in note-columns, we don't want to know about
+           its Y-position
+         */
+         if (a != Y_AXIS)
+           common_[a] = common_[a]->common_refpoint (sp->get_bound (d), a);
+       }
       while (flip (&d) != LEFT);
     }
 
   extremes_ = get_bound_info ();
   is_broken_ = (!extremes_[LEFT].note_column_
-                     || !extremes_[RIGHT].note_column_); 
+               || !extremes_[RIGHT].note_column_);
+
+  has_same_beam_
+    = (extremes_[LEFT].stem_ && extremes_[RIGHT].stem_
+       && Stem::get_beam (extremes_[LEFT].stem_) == Stem::get_beam (extremes_[RIGHT].stem_));
 
-  
   base_attachments_ = get_base_attachments ();
 
   Drul_array<Real> end_ys
     = get_y_attachment_range ();
 
-  scores_ = enumerate_attachments ( end_ys);
+  configurations_ = enumerate_attachments (end_ys);
   for (int i = 0; i < columns_.size (); i++)
-    encompass_infos_.push (get_encompass_info ( columns_[i]));
+    encompass_infos_.push (get_encompass_info (columns_[i]));
 
   extra_encompass_infos_ = get_extra_encompass_infos ();
   valid_ = true;
 
-
   musical_dy_ = 0.0;
   Direction d = LEFT;
   do
@@ -341,16 +339,11 @@ Slur_score_state::fill (Grob *me)
          * extremes_[d].slur_head_->relative_coordinate (common_[Y_AXIS], Y_AXIS);
     }
   while (flip (&d) != LEFT);
-  
+
   edge_has_beams_
     = (extremes_[LEFT].stem_ && Stem::get_beam (extremes_[LEFT].stem_))
     || (extremes_[RIGHT].stem_ && Stem::get_beam (extremes_[RIGHT].stem_));
 
-  has_same_beam_ =
-    (extremes_[LEFT].stem_ && extremes_[RIGHT].stem_
-     && Stem::get_beam (extremes_[LEFT].stem_) == Stem::get_beam (extremes_[RIGHT].stem_));
-
-  
   set_next_direction ();
 
   if (is_broken_)
@@ -365,77 +358,96 @@ set_slur_control_points (Grob *me)
 
   if (!state.valid_)
     return;
-  
+
   state.generate_curves ();
-  Bezier best (state.get_best_curve());
 
+  SCM end_ys = me->get_property ("positions");
+  Bezier best;
+
+  if (is_number_pair (end_ys))
+    {
+      best = state.configurations_[state.get_closest_index (end_ys)]->curve_;
+    }
+  else
+    {
+      best = state.get_best_curve ();
+    }
 
   SCM controls = SCM_EOL;
   for (int i = 4; i--;)
     {
       Offset o = best.control_[i]
        - Offset (me->relative_coordinate (state.common_[X_AXIS], X_AXIS),
-                 me->relative_coordinate (state.common_[Y_AXIS], Y_AXIS));
+                 me->relative_coordinate (state.common_[Y_AXIS], Y_AXIS));
       controls = scm_cons (ly_offset2scm (o), controls);
     }
   me->set_property ("control-points", controls);
 }
 
-
 Bezier
 Slur_score_state::get_best_curve ()
 {
-  for (int i = 0; i < scores_->size (); i++)
+  for (int i = 0; i < configurations_.size (); i++)
     {
-      scores_->elem (i).score (*this);
+      configurations_[i]->score (*this);
     }
-  
+
   Real opt = 1e6;
   int opt_idx = -1;
-  for (int i = 0; i < scores_->size (); i++)
+  for (int i = 0; i < configurations_.size (); i++)
     {
-      if ((*scores_)[i].score_ < opt)
+      if (configurations_[i]->score_ < opt)
        {
-         opt = (*scores_)[i].score_;
+         opt = configurations_[i]->score_;
          opt_idx = i;
        }
     }
 
 #if DEBUG_SLUR_SCORING
   SCM inspect_quants = slur_->get_property ("inspect-quants");
-  if (to_boolean (slur_->get_paper ()
+  if (to_boolean (slur_->get_layout ()
                  ->lookup_variable (ly_symbol2scm ("debug-slur-scoring")))
       && scm_is_pair (inspect_quants))
-    {
-      Drul_array<Real> ins = ly_scm2interval (inspect_quants);
-      Real mindist = 1e6;
-      for (int i = 0; i < scores_->size (); i ++)
-       {
-         Real d =fabs ((*scores_)[i].attachment_[LEFT][Y_AXIS] - ins[LEFT])
-           + fabs ((*scores_)[i].attachment_[RIGHT][Y_AXIS] - ins[RIGHT]);
-         if (d < mindist)
-           {
-             opt_idx = i;
-             mindist= d;
-           }
-       }
-      if (mindist > 1e5)
-       programming_error ("Could not find quant.");
-    }
-  (*scores_)[opt_idx].score_card_ += to_string ("i%d", opt_idx);
+    opt_idx = get_closest_index (inspect_quants);
+
+  configurations_[opt_idx]->score_card_ += to_string ("=%.2f", opt);
+  configurations_[opt_idx]->score_card_ += to_string ("i%d", opt_idx);
 
   // debug quanting
   slur_->set_property ("quant-score",
-                   scm_makfrom0str ((*scores_)[opt_idx].score_card_.to_str0 ()));
+                      scm_makfrom0str (configurations_[opt_idx]->score_card_.to_str0 ()));
+
 #endif
 
-  return scores_->elem (opt_idx).curve_;
+  return configurations_[opt_idx]->curve_;
+}
+
+int
+Slur_score_state::get_closest_index (SCM inspect_quants) const
+{
+  Drul_array<Real> ins = ly_scm2interval (inspect_quants);
+
+  int opt_idx = -1;
+  Real mindist = 1e6;
+  for (int i = 0; i < configurations_.size (); i++)
+    {
+      Real d = fabs (configurations_[i]->attachment_[LEFT][Y_AXIS] - ins[LEFT])
+       + fabs (configurations_[i]->attachment_[RIGHT][Y_AXIS] - ins[RIGHT]);
+      if (d < mindist)
+       {
+         opt_idx = i;
+         mindist = d;
+       }
+    }
+  if (mindist > 1e5)
+    programming_error ("can't not find quant");
+  return opt_idx;
 }
 
 /*
   TODO: should analyse encompasses to determine sensible region, and
   should limit slopes available.
- */
+*/
 
 Drul_array<Real>
 Slur_score_state::get_y_attachment_range () const
@@ -447,9 +459,9 @@ Slur_score_state::get_y_attachment_range () const
       if (extremes_[d].note_column_)
        {
          end_ys[d] = dir_
-           * ((dir_ * (base_attachments_[d][Y_AXIS] +  parameters_.region_size_* dir_))
+           * ((dir_ * (base_attachments_[d][Y_AXIS] + parameters_.region_size_ * dir_))
               >? (dir_ * (dir_ + extremes_[d].note_column_->extent (common_[Y_AXIS],
-                                                                Y_AXIS)[dir_]))
+                                                                    Y_AXIS)[dir_]))
               >? (dir_ * base_attachments_[-d][Y_AXIS]));
        }
       else
@@ -461,21 +473,21 @@ Slur_score_state::get_y_attachment_range () const
 }
 
 bool
-spanner_less (Spanner *s1, Spanners2)
+spanner_less (Spanner *s1, Spanner *s2)
 {
   Slice b1, b2;
-  Direction d  = LEFT;
+  Direction d = LEFT;
   do
     {
       b1[d] = s1->get_bound (d)->get_column ()->rank_;
       b2[d] = s2->get_bound (d)->get_column ()->rank_;
-    } while (flip (&d) != LEFT);
+    }
+  while (flip (&d) != LEFT);
 
   return b2[LEFT] <= b1[LEFT] && b2[RIGHT] >= b1[RIGHT]
     && (b2[LEFT] != b1[LEFT] || b2[RIGHT] != b1[RIGHT]);
 }
 
-
 Drul_array<Offset>
 Slur_score_state::get_base_attachments () const
 {
@@ -490,11 +502,12 @@ Slur_score_state::get_base_attachments () const
       Real y = 0.0;
       if (extremes_[d].note_column_)
        {
-        
+
          /*
            fixme: X coord should also be set in this case.
-          */
+         */
          if (stem
+             && !Stem::is_invisible (stem)
              && extremes_[d].stem_dir_ == dir_
              && Stem::get_beaming (stem, -d)
              && (!spanner_less (slur_, Stem::get_beam (stem))
@@ -504,28 +517,17 @@ Slur_score_state::get_base_attachments () const
            y = head->extent (common_[Y_AXIS], Y_AXIS)[dir_];
          y += dir_ * 0.5 * staff_space_;
 
-         Real pos
-           = (y - extremes_[d].staff_->relative_coordinate (common_[Y_AXIS],
-                                                           Y_AXIS))
-           * 2.0 / staff_space_;
-
-         /* start off staffline. */
-         if (fabs (pos - my_round (pos)) < 0.2
-             && Staff_symbol_referencer::on_staffline (head, (int) rint (pos))
-             && Staff_symbol_referencer::line_count (head) - 1 >= rint (pos)
-             )
-           // TODO: calc from slur thick & line thick, parameter.      
-           y += 1.5 * staff_space_ * dir_ / 10;
-
-         Grob * fh = Note_column::first_head (extremes_[d].note_column_);
-         x =
-        (fh ? fh->extent (common_[X_AXIS], X_AXIS)
-            : extremes_[d].bound_->extent (common_[X_AXIS], X_AXIS))
+         y = move_away_from_staffline (y, head);
+
+         Grob *fh = Note_column::first_head (extremes_[d].note_column_);
+         x
+           = (fh ? fh->extent (common_[X_AXIS], X_AXIS)
+              : extremes_[d].bound_->extent (common_[X_AXIS], X_AXIS))
            .linear_combination (CENTER);
        }
       base_attachment[d] = Offset (x, y);
-
-    } while (flip (&d) != LEFT);
+    }
+  while (flip (&d) != LEFT);
 
   do
     {
@@ -540,43 +542,79 @@ Slur_score_state::get_base_attachments () const
            {
              x = slur_->get_broken_left_end_align ();
            }
-         Grob * col = (d == LEFT) ? columns_[0] : columns_.top();
-             
+         Grob *col = (d == LEFT) ? columns_[0] : columns_.top ();
+
          if (extremes_[-d].bound_ != col)
            {
              y = robust_relative_extent (col, common_[Y_AXIS], Y_AXIS)[dir_];
-             if (get_grob_direction (col) == dir_)
-               y -= dir_ ;
+             y += dir_ * 0.5 * staff_space_;
+
+             if (get_grob_direction (col) == dir_
+                 && Note_column::get_stem (col)
+                 && !Stem::is_invisible (Note_column::get_stem (col)))
+               y -= dir_ * 1.5 * staff_space_;
            }
          else
            y = base_attachment[-d][Y_AXIS];
 
-         base_attachment[d] = Offset (x, y);  
+         y = move_away_from_staffline (y, col);
+
+         base_attachment[d] = Offset (x, y);
        }
     }
   while (flip (&d) != LEFT);
 
+
+  do
+    {
+      for (int a = X_AXIS; a < NO_AXES; a++)
+       {
+         Real &b = base_attachment[d][Axis (a)];
+
+         if (isinf (b) || isnan (b))
+           {
+             programming_error ("slur attachment is inf/nan");
+             b = 0.0;
+           }
+           
+       }
+    }
+  while (flip (&d) != LEFT);
+  
+  
   return base_attachment;
 }
 
+Real
+Slur_score_state::move_away_from_staffline (Real y,
+                                           Grob *on_staff) const
+{
+  Real pos
+    = (y - Staff_symbol_referencer::get_staff_symbol (on_staff)->relative_coordinate (common_[Y_AXIS],
+                                                                                     Y_AXIS))
+    * 2.0 / staff_space_;
+
+  if (fabs (pos - my_round (pos)) < 0.2
+      && Staff_symbol_referencer::on_staffline (on_staff, (int) rint (pos))
+      && Staff_symbol_referencer::line_count (on_staff) - 1 >= rint (pos))
+    y += 1.5 * staff_space_ * dir_ / 10;
+
+  return y;
+}
+
 void
 Slur_score_state::generate_curves () const
 {
   Real r_0 = robust_scm2double (slur_->get_property ("ratio"), 0.33);
-  Real h_inf = staff_space_ *scm_to_double (slur_->get_property ("height-limit"));
-  for (int i = 0; i < scores_->size (); i++)
-    scores_->elem(i).generate_curve (*this, r_0, h_inf);
+  Real h_inf = staff_space_ * scm_to_double (slur_->get_property ("height-limit"));
+  for (int i = 0; i < configurations_.size (); i++)
+    configurations_[i]->generate_curve (*this, r_0, h_inf);
 }
 
-
-
-
-Array<Slur_configuration> *
+Link_array<Slur_configuration>
 Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
 {
-  /*ugh.   */
-  Array<Slur_configuration> scores;
-
+  Link_array<Slur_configuration> scores;
 
   Drul_array<Offset> os;
   os[LEFT] = base_attachments_[LEFT];
@@ -600,28 +638,25 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
                {
                  Interval stem_y = extremes_[d].stem_extent_[Y_AXIS];
                  stem_y.widen (0.25 * staff_space_);
-                 if (dir_ == -d
-                     && stem_y.contains (os[d][Y_AXIS]))
+                 if (stem_y.contains (os[d][Y_AXIS]))
                    {
-                     os[d][X_AXIS] =  extremes_[d].slur_head_extent_[-d]
+                     os[d][X_AXIS] = extremes_[d].stem_extent_[X_AXIS][-d]
                        - d * 0.3;
                      attach_to_stem[d] = true;
                    }
-                 else if (dir_ *extremes_[d].stem_extent_[Y_AXIS][dir_]
-                            < dir_ * os[d][Y_AXIS]
-                          && !extremes_[d].stem_extent_[X_AXIS].is_empty ()
-                          )
-               
+                 else if (dir_ * extremes_[d].stem_extent_[Y_AXIS][dir_]
+                          < dir_ * os[d][Y_AXIS]
+                          && !extremes_[d].stem_extent_[X_AXIS].is_empty ())
+
                    os[d][X_AXIS] = extremes_[d].stem_extent_[X_AXIS].center ();
                }
            }
          while (flip (&d) != LEFT);
 
-         Offset dz;    
+         Offset dz;
          dz = os[RIGHT] - os[LEFT];
          if (dz[X_AXIS] < minimum_length
-             || fabs (dz[Y_AXIS] / dz[X_AXIS]) > parameters_.max_slope_
-             )
+             || fabs (dz[Y_AXIS] / dz[X_AXIS]) > parameters_.max_slope_)
            {
              do
                {
@@ -642,7 +677,7 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
                {
                  /* Horizontally move tilted slurs a little.  Move
                     more for bigger tilts.
-               
+
                     TODO: parameter */
                  os[d][X_AXIS]
                    -= dir_ * extremes_[d].slur_head_extent_.length ()
@@ -650,10 +685,12 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
                }
            }
          while (flip (&d) != LEFT);
-       
+
          s.attachment_ = os;
-         scores.push (s);
-       
+         s.index_ = scores.size ();
+
+         scores.push (new Slur_configuration (s));
+
          os[RIGHT][Y_AXIS] += dir_ * staff_space_ / 2;
        }
 
@@ -661,22 +698,20 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
     }
 
   assert (scores.size () > 0);
-  return new Array<Slur_configuration> (scores);
+  return scores;
 }
 
-
 Array<Extra_collision_info>
-Slur_score_state::get_extra_encompass_infos ( ) const
+Slur_score_state::get_extra_encompass_infos () const
 {
   Link_array<Grob> encompasses
-    = Pointer_group_interface__extract_grobs (slur_, (Grob *)0,
-                                             "encompass-objects");
+    = extract_grob_array (slur_, ly_symbol2scm ("encompass-objects"));
   Array<Extra_collision_info> collision_infos;
-  for (int i = encompasses.size (); i--; )
+  for (int i = encompasses.size (); i--;)
     {
       if (Slur::has_interface (encompasses[i]))
        {
-         Spanner * small_slur = dynamic_cast<Spanner*> (encompasses[i]);
+         Spanner *small_slur = dynamic_cast<Spanner *> (encompasses[i]);
          Bezier b = Slur::get_curve (small_slur);
 
          Offset relative (small_slur->relative_coordinate (common_[X_AXIS], X_AXIS),
@@ -684,7 +719,7 @@ Slur_score_state::get_extra_encompass_infos ( ) const
 
          for (int k = 0; k < 3; k++)
            {
-             Direction hdir =  Direction (k /2 - 1);
+             Direction hdir = Direction (k / 2 - 1);
 
              /*
                Only take bound into account if small slur starts
@@ -692,9 +727,8 @@ Slur_score_state::get_extra_encompass_infos ( ) const
              */
              if (hdir && small_slur->get_bound (hdir) != slur_->get_bound (hdir))
                continue;
-       
 
-             Offset z = b.curve_point ( k / 2.0);
+             Offset z = b.curve_point (k / 2.0);
              z += relative;
 
              Interval yext;
@@ -702,7 +736,7 @@ Slur_score_state::get_extra_encompass_infos ( ) const
              yext[dir_] = z[Y_AXIS] + dir_ * thickness_ * 1.0;
 
              Interval xext (-1, 1);
-             xext = xext * (thickness_*2) + z[X_AXIS];
+             xext = xext * (thickness_ * 2) + z[X_AXIS];
              Extra_collision_info info (small_slur,
                                         k - 1.0,
                                         xext,
@@ -729,7 +763,7 @@ Slur_score_state::get_extra_encompass_infos ( ) const
                  SCM cstyle = g->get_property ("cautionary-style");
                  parens = ly_c_equal_p (cstyle, ly_symbol2scm ("parentheses"));
                }
-       
+
              SCM accs = g->get_property ("accidentals");
              SCM scm_style = g->get_property ("style");
              if (!scm_is_symbol (scm_style)
@@ -742,10 +776,10 @@ Slur_score_state::get_extra_encompass_infos ( ) const
                    case FLAT:
                    case DOUBLE_FLAT:
                      xp = LEFT;
-                     break ;
+                     break;
                    case SHARP:
                      xp = 0.5 * dir_;
-                     break ;
+                     break;
                    case NATURAL:
                      xp = -dir_;
                      break;
@@ -755,7 +789,7 @@ Slur_score_state::get_extra_encompass_infos ( ) const
 
          ye.widen (thickness_ * 0.5);
          xe.widen (thickness_ * 1.0);
-         Extra_collision_info info (g, xp, xe, ye,  penalty);
+         Extra_collision_info info (g, xp, xe, ye, penalty);
          collision_infos.push (info);
        }
     }