]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/slur-scoring.cc
* The grand 2005-2006 replace.
[lilypond.git] / lily / slur-scoring.cc
index bcb65320ed5d6029e400321a0cb0d34d750f220c..57fa3c6183e4a938c83921cc5b3c3ec9050abbf5 100644 (file)
@@ -3,12 +3,10 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1996--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
   Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
-#include <cmath>
-using namespace std;
 
 #include "slur-scoring.hh"
 #include "libc-extension.hh"
@@ -79,7 +77,7 @@ get_detail (SCM alist, SCM sym)
 void
 Slur_score_parameters::fill (Grob *me)
 {
-  SCM details = me->get_property ("slur-details");
+  SCM details = me->get_property ("details");
 
   region_size_
     = (int) get_detail (details, ly_symbol2scm ("region-size"));
@@ -105,8 +103,8 @@ Slur_score_parameters::fill (Grob *me)
     = get_detail (details, ly_symbol2scm ("free-head-distance"));
   absolute_closeness_measure_
     = get_detail (details, ly_symbol2scm ("absolute-closeness-measure"));
-  extra_object_collision_
-    = get_detail (details, ly_symbol2scm ("extra-object-collision"));
+  extra_object_collision_penalty_
+    = get_detail (details, ly_symbol2scm ("extra-object-collision-penalty"));
   accidental_collision_
     = get_detail (details, ly_symbol2scm ("accidental-collision"));
   extra_encompass_free_distance_
@@ -127,7 +125,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;
@@ -136,7 +134,7 @@ 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]));
       int common_j = common_k + hdir;
@@ -163,7 +161,7 @@ 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;
@@ -238,38 +236,41 @@ Slur_score_state::get_bound_info () const
        {
          extremes[d].note_column_ = extremes[d].bound_;
          extremes[d].stem_ = Note_column::get_stem (extremes[d].note_column_);
-         extremes[d].stem_dir_ = get_grob_direction (extremes[d].stem_);
-
-         for (int a = X_AXIS; a < NO_AXES; a++)
+         if (extremes[d].stem_)
            {
-             Axis ax = Axis (a);
-             Interval s = extremes[d].stem_->extent (common_[ax], ax);
-             if (s.is_empty ())
+             extremes[d].stem_dir_ = get_grob_direction (extremes[d].stem_);
+
+             for (int a = X_AXIS; a < NO_AXES; a++)
                {
-                 /*
-                   do not issue warning. This happens for rests and
-                   whole notes.
-                 */
-                 s = Interval (0, 0)
-                   + extremes[d].stem_->relative_coordinate (common_[ax], ax);
+                 Axis ax = Axis (a);
+                 Interval s = extremes[d].stem_->extent (common_[ax], ax);
+                 if (s.is_empty ())
+                   {
+                     /*
+                       do not issue warning. This happens for rests and
+                       whole notes.
+                     */
+                     s = Interval (0, 0)
+                       + extremes[d].stem_->relative_coordinate (common_[ax], ax);
+                   }
+                 extremes[d].stem_extent_[ax] = s;
                }
-             extremes[d].stem_extent_[ax] = s;
-           }
 
-         extremes[d].slur_head_
-           = Stem::extremal_heads (extremes[d].stem_)[dir];
-         if (!extremes[d].slur_head_
-             && Note_column::has_rests (extremes[d].bound_))
-           extremes[d].slur_head_ = Note_column::get_rest (extremes[d].bound_);
+             extremes[d].slur_head_
+               = Stem::extremal_heads (extremes[d].stem_)[dir];
+             if (!extremes[d].slur_head_
+                 && Note_column::has_rests (extremes[d].bound_))
+               extremes[d].slur_head_ = Note_column::get_rest (extremes[d].bound_);
+             extremes[d].staff_ = Staff_symbol_referencer
+               ::get_staff_symbol (extremes[d].stem_);
+             extremes[d].staff_space_ = Staff_symbol_referencer
+               ::staff_space (extremes[d].stem_);
+           }
 
          if (extremes[d].slur_head_)
-           extremes[d].slur_head_extent_
+           extremes[d].slur_head_x_extent_
              = extremes[d].slur_head_->extent (common_[X_AXIS], X_AXIS);
 
-         extremes[d].staff_ = Staff_symbol_referencer
-           ::get_staff_symbol (extremes[d].stem_);
-         extremes[d].staff_space_ = Staff_symbol_referencer
-           ::staff_space (extremes[d].stem_);
        }
     }
   while (flip (&d) != LEFT);
@@ -291,7 +292,7 @@ Slur_score_state::fill (Grob *me)
     }
 
   staff_space_ = Staff_symbol_referencer::staff_space (me);
-  Real lt = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
+  Real lt = me->layout ()->get_dimension (ly_symbol2scm ("linethickness"));
   thickness_ = robust_scm2double (me->get_property ("thickness"), 1.0) * lt;
 
   dir_ = get_grob_direction (me);
@@ -345,7 +346,8 @@ Slur_score_state::fill (Grob *me)
   Direction d = LEFT;
   do
     {
-      if (!is_broken_)
+      if (!is_broken_
+         && extremes_[d].slur_head_)
        musical_dy_ += d
          * extremes_[d].slur_head_->relative_coordinate (common_[Y_AXIS], Y_AXIS);
     }
@@ -361,14 +363,18 @@ Slur_score_state::fill (Grob *me)
     musical_dy_ = 0.0;
 }
 
-void
-set_slur_control_points (Grob *me)
+
+MAKE_SCHEME_CALLBACK(Slur, calc_control_points, 1)
+SCM
+Slur::calc_control_points (SCM smob)
 {
+  Spanner *me = unsmob_spanner (smob);
+
   Slur_score_state state;
   state.fill (me);
 
   if (!state.valid_)
-    return;
+    return SCM_EOL;
 
   state.generate_curves ();
 
@@ -388,7 +394,8 @@ set_slur_control_points (Grob *me)
                  me->relative_coordinate (state.common_[Y_AXIS], Y_AXIS));
       controls = scm_cons (ly_offset2scm (o), controls);
     }
-  me->set_property ("control-points", controls);
+
+  return controls;
 }
 
 Bezier
@@ -399,7 +406,7 @@ Slur_score_state::get_best_curve ()
 
 #if DEBUG_SLUR_SCORING
   SCM inspect_quants = slur_->get_property ("inspect-quants");
-  if (to_boolean (slur_->get_layout ()
+  if (to_boolean (slur_->layout ()
                  ->lookup_variable (ly_symbol2scm ("debug-slur-scoring")))
       && scm_is_pair (inspect_quants))
     {
@@ -595,6 +602,9 @@ Real
 Slur_score_state::move_away_from_staffline (Real y,
                                            Grob *on_staff) const
 {
+  if (!on_staff)
+    return y;
+  
   Grob *staff_symbol = Staff_symbol_referencer::get_staff_symbol (on_staff);
   if (!staff_symbol)
     return y;
@@ -632,19 +642,30 @@ Slur_score_state::generate_avoid_offsets () const
 
   extract_grob_set (slur_, "encompass-objects", extra_encompasses);
   for (int i = 0; i < extra_encompasses.size (); i++)
-    if (Slur::has_interface (extra_encompasses[i]))
-      {
-       Grob *small_slur = extra_encompasses[i];
-       Bezier b = Slur::get_curve (small_slur);
+    {
+      if (Slur::has_interface (extra_encompasses[i]))
+       {
+         Grob *small_slur = extra_encompasses[i];
+         Bezier b = Slur::get_curve (small_slur);
 
-       Offset z = b.curve_point (0.5);
-       z += Offset (small_slur->relative_coordinate (common_[X_AXIS], X_AXIS),
-                    small_slur->relative_coordinate (common_[Y_AXIS], Y_AXIS));
+         Offset z = b.curve_point (0.5);
+         z += Offset (small_slur->relative_coordinate (common_[X_AXIS], X_AXIS),
+                      small_slur->relative_coordinate (common_[Y_AXIS], Y_AXIS));
 
-       z[Y_AXIS] += dir_ * parameters_.free_slur_distance_;
-       avoid.push (z);
-      }
+         z[Y_AXIS] += dir_ * parameters_.free_slur_distance_;
+         avoid.push (z);
+       }
+      else if (extra_encompasses[i]->get_property ("avoid-slur") == ly_symbol2scm ("inside"))
+       {
+         Grob *g = extra_encompasses [i];
+         Interval xe = g->extent (common_[X_AXIS], X_AXIS);
+         Interval ye = g->extent (common_[Y_AXIS], Y_AXIS);
 
+         if (!xe.is_empty ()
+             && !ye.is_empty ())
+           avoid.push (Offset (xe.center(), ye[dir_]));
+       }
+    }  
   return avoid;
 }
 
@@ -708,9 +729,10 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
            {
              do
                {
-                 if (extremes_[d].slur_head_)
+                 if (extremes_[d].slur_head_
+                     && !extremes_[d].slur_head_x_extent_.is_empty ())
                    {
-                     os[d][X_AXIS] = extremes_[d].slur_head_extent_.center ();
+                     os[d][X_AXIS] = extremes_[d].slur_head_x_extent_.center ();
                      attach_to_stem[d] = false;
                    }
                }
@@ -728,7 +750,7 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
 
                     TODO: parameter */
                  os[d][X_AXIS]
-                   -= dir_ * extremes_[d].slur_head_extent_.length ()
+                   -= dir_ * extremes_[d].slur_head_x_extent_.length ()
                    * sin (dz.arg ()) / 3;
                }
            }
@@ -788,7 +810,7 @@ Slur_score_state::get_extra_encompass_infos () const
                                         k - 1.0,
                                         xext,
                                         yext,
-                                        parameters_.extra_object_collision_);
+                                        parameters_.extra_object_collision_penalty_);
              collision_infos.push (info);
            }
        }
@@ -799,7 +821,7 @@ Slur_score_state::get_extra_encompass_infos () const
          Interval ye = g->extent (common_[Y_AXIS], Y_AXIS);
 
          Real xp = 0.0;
-         Real penalty = parameters_.extra_object_collision_;
+         Real penalty = parameters_.extra_object_collision_penalty_;
          if (Accidental_interface::has_interface (g))
            {
              penalty = parameters_.accidental_collision_;
@@ -843,4 +865,21 @@ Slur_score_state::get_extra_encompass_infos () const
 
   return collision_infos;
 }
+Extra_collision_info::Extra_collision_info (Grob *g, Real idx, Interval x, Interval y, Real p)
+{
+  idx_ = idx;
+  extents_[X_AXIS] = x;
+  extents_[Y_AXIS] = y;
+  penalty_ = p;
+  grob_ = g;
+  type_ = g->get_property ("avoid-slur");
+}
 
+Extra_collision_info::Extra_collision_info ()
+{
+  idx_ = 0.0;
+  penalty_ = 0.;
+  grob_ = 0;
+  type_ = SCM_EOL; 
+}