]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/slur.cc
release: 1.3.17
[lilypond.git] / lily / slur.cc
index 827e9a022214dca804688bd7b53ace3b334dbe1f..e5be36ae521a5f999ef4c310ec781320e26a1fdf 100644 (file)
@@ -3,46 +3,46 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996,  1997--1999, 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1996,  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
     Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 /*
   [TODO]
-    * URG: share code with tie
-    * begin and end should be treated as a Script.
-    * damping
-    * slur from notehead to stemend: c''()b''
+    * begin and end should be treated as a/acknowledge Scripts.
+    * broken slur should have uniform trend
  */
 
+#include "directional-element-interface.hh"
+#include "group-interface.hh"
 #include "slur.hh"
-#include "scalar.hh"
 #include "lookup.hh"
 #include "paper-def.hh"
 #include "note-column.hh"
 #include "stem.hh"
-#include "p-col.hh"
+#include "paper-column.hh"
 #include "molecule.hh"
 #include "debug.hh"
 #include "box.hh"
 #include "bezier.hh"
-#include "encompass-info.hh"
 #include "main.hh"
-
+#include "cross-staff.hh"
+#include "group-interface.hh"
 
 Slur::Slur ()
 {
+  set_elt_property ("note-columns", SCM_EOL);
 }
 
 void
 Slur::add_column (Note_column*n)
 {
-  if (!n->head_l_arr_.size ())
-    warning (_ ("Putting slur over rest. Ignoring"));
+  if (!gh_pair_p (n->get_elt_property ("note-heads")))
+    warning (_ ("Putting slur over rest.  Ignoring."));
   else
     {
-      encompass_arr_.push (n);
-      //  n->stem_l_->slur_l_ = this;
+      Group_interface gi (this, "note-columns");
+      gi.add_element (n);
       add_dependency (n);
     }
 }
@@ -50,10 +50,13 @@ Slur::add_column (Note_column*n)
 Direction
 Slur::get_default_dir () const
 {
+  Link_array<Note_column> encompass_arr =
+    Group_interface__extract_elements (this, (Note_column*)0, "note-columns");
+  
   Direction d = DOWN;
-  for (int i=0; i < encompass_arr_.size (); i ++) 
+  for (int i=0; i < encompass_arr.size (); i ++) 
     {
-      if (encompass_arr_[i]->dir () < 0) 
+      if (encompass_arr[i]->dir () < 0) 
        {
          d = UP;
          break;
@@ -65,9 +68,11 @@ Slur::get_default_dir () const
 void
 Slur::do_add_processing ()
 {
-  set_bounds (LEFT, encompass_arr_[0]);    
-  if (encompass_arr_.size () > 1)
-    set_bounds (RIGHT, encompass_arr_.top ());
+  Link_array<Note_column> encompass_arr =
+    Group_interface__extract_elements (this, (Note_column*)0, "note-columns");
+  set_bounds (LEFT, encompass_arr[0]);    
+  if (encompass_arr.size () > 1)
+    set_bounds (RIGHT, encompass_arr.top ());
 }
 
 void
@@ -76,293 +81,432 @@ Slur::do_pre_processing ()
   // don't set directions
 }
 
-void
-Slur::do_substitute_element_pointer (Score_element*o, Score_element*n)
+
+Offset
+Slur::encompass_offset (Note_column const* col) const
 {
-  int i;
-  while ((i = encompass_arr_.find_i (dynamic_cast<Note_column *> (o))) >=0) 
+  Offset o;
+  Stem* stem_l = col->stem_l ();
+  Direction dir = directional_element (this).get ();
+  
+  if (!stem_l)
     {
-      if (n)
-       encompass_arr_[i] = dynamic_cast<Note_column *> (n);
-      else
-       encompass_arr_.del (i);
+      warning (_ ("Slur over rest?"));
+      o[X_AXIS] = col->hpos_f ();
+      o[Y_AXIS] = col->extent (Y_AXIS)[dir];
+      return o;  
     }
-}
+  Direction stem_dir = directional_element (stem_l).get ();
+  o[X_AXIS] = stem_l->hpos_f ();
 
-static int 
-Note_column_compare (Note_column *const&n1 , Note_column* const&n2)
-{
-  return Item::left_right_compare (n1, n2);
-}
+  /*
+    Simply set x to middle of notehead
+   */
 
-bool
-Slur::broken_edge_b ( Direction dir) const
-{
-  return extrema ()[dir] != spanned_drul_[dir];
-}
+  o[X_AXIS] -= 0.5 * stem_dir * col->extent (X_AXIS).length ();
 
-bool
-Slur::normal_edge_b ( Direction dir) const
-{
-  Note_column *n = extrema ()[dir];
-  return !broken_edge_b ( dir)
-    && n->stem_l_
-    && n->stem_l_->get_elt_property (transparent_scm_sym) == SCM_BOOL_F
-    && n->head_l_arr_.size ();
-}
+  if ((stem_dir == dir)
+      && !stem_l->extent (Y_AXIS).empty_b ())
+    {
+      o[Y_AXIS] = stem_l->extent (Y_AXIS)[dir];
+    }
+  else
+    {
+      o[Y_AXIS] = col->extent (Y_AXIS)[dir];
+    }
 
-Drul_array<Note_column*>
-Slur::extrema ()const
-{
-  Drul_array<Note_column*> extrema;
-  extrema[LEFT] = encompass_arr_[0];
-  extrema[RIGHT] = encompass_arr_.top ();
-  return extrema;
+  /*
+   leave a gap: slur mustn't touch head/stem
+   */
+  o[Y_AXIS] += dir * paper_l ()->get_var ("slur_y_free");
+  o[Y_AXIS] -= calc_interstaff_dist (stem_l, this);
+  return o;
 }
 
 /*
-  TODO.
+  ARGRARGRARGRARGAR!
 
-  Unhair this.
+  Fixme
  */
 void
 Slur::do_post_processing ()
 {
-  encompass_arr_.sort (Note_column_compare);
-  if (!dir_)
-    dir_ = get_default_dir ();
+  Link_array<Note_column> encompass_arr =
+    Group_interface__extract_elements (this, (Note_column*)0, "note-columns");
+
+  if (!encompass_arr.size ())
+    {
+      set_elt_property ("transparent", SCM_BOOL_T);
+      set_empty (X_AXIS);
+      set_empty (Y_AXIS);
+      return;
+    }
 
-  Real interline_f = paper_l ()->get_realvar (interline_scm_sym);
-  Real internote_f = interline_f / 2;
-  // URG
-  Real notewidth_f = paper_l ()->note_width () * 0.8;
+  if (!directional_element (this).get ())
+    directional_element (this).set (get_default_dir ());
 
   /* 
-   [OSU]: slur and tie placement
+   Slur and tie placement [OSU]
 
-   slurs:
-   * x = center of head (upside-down: inner raakpunt stem) - d * gap
+   Slurs:
+   * x = centre of head - d * x_gap_f
 
-   * y = length < 5ss : horizontal raakpunt + d * 0.25 ss
+   TODO:
+   * y = length < 5ss : horizontal tangent + d * 0.25 ss
      y = length >= 5ss : y next interline - d * 0.25 ss
-     --> height <= 5 length ?? we use <= 3 length, now...
    */
-  
-  Real gap_f = paper_l ()->get_var ("slur_x_gap");
 
+  Real staff_space = paper_l ()->get_var ("interline");
+  Real half_staff_space = staff_space / 2;
+
+  Real x_gap_f = paper_l ()->get_var ("slur_x_gap");
+  Real y_gap_f = paper_l ()->get_var ("slur_y_gap");
 
-  Direction d=LEFT;
+  Drul_array<Note_column*> note_column_drul;
+  note_column_drul[LEFT] = encompass_arr[0];
+  note_column_drul[RIGHT] = encompass_arr.top ();
+
+  bool fix_broken_b = false;
+
+  Direction my_dir = directional_element (this).get ();
+  
+  Direction d = LEFT;
   do 
     {
-      if (broken_edge_b (d))
+      dx_f_drul_[d] = 0;
+      dy_f_drul_[d] = 0;
+      
+      if ((note_column_drul[d] == spanned_drul_[d])
+         && note_column_drul[d]->first_head ()
+         && (note_column_drul[d]->stem_l ()))
        {
-         // ugh -- check if needed
-         dx_f_drul_[d] = -d 
-           *(spanned_drul_[d]->extent (X_AXIS).length () - 0.5 * notewidth_f);
-
-         // prebreak
-         if (d == RIGHT)
+         Stem* stem_l = note_column_drul[d]->stem_l ();
+         /*
+           side directly attached to note head;
+           no beam getting in the way
+         */
+         if ((stem_l->extent (Y_AXIS).empty_b ()
+              || !((stem_l->get_direction () == my_dir) && (my_dir != d)))
+             && !((my_dir == stem_l->get_direction ())
+                  && stem_l->beam_l () && (stem_l->beam_count (-d) >= 1)))
            {
-             dx_f_drul_[LEFT] = spanned_drul_[LEFT]->extent (X_AXIS).length ();
-             
-             // urg -- check if needed
-             if (encompass_arr_.size () > 1)
-               dx_f_drul_[RIGHT] += notewidth_f;
+             dx_f_drul_[d] = spanned_drul_[d]->extent (X_AXIS).length () / 2;
+             dx_f_drul_[d] -= d * x_gap_f;
+
+             if (stem_l->get_direction () != my_dir)
+               {
+                 dy_f_drul_[d] = note_column_drul[d]->extent (Y_AXIS)[my_dir];
+               }
+             else
+               {
+                 dy_f_drul_[d] = stem_l->chord_start_f ()
+                   + my_dir * half_staff_space;
+               }
+             dy_f_drul_[d] += my_dir * y_gap_f;
            }
-       }
-      /*
-        normal slur
-       */
-      else if (normal_edge_b (d))
-        {
-         Real notewidth_f = extrema ()[d]->extent (X_AXIS).length ();
-         dy_f_drul_[d] = (int)rint (extrema ()[d]->stem_l_-> extent (Y_AXIS)[dir_]);
-         dx_f_drul_[d] += 0.5 * notewidth_f - d * gap_f;
-         if (dir_ == extrema ()[d]->stem_l_->dir_)
+         /*
+           side attached to (visible) stem
+         */
+         else
            {
-             if (dir_ == d)
-               dx_f_drul_[d] += 0.5 * dir_ * notewidth_f;
+             dx_f_drul_[d] = stem_l->hpos_f ()
+               - spanned_drul_[d]->relative_coordinate (0, X_AXIS);
+             /*
+               side attached to beamed stem
+              */
+             if (stem_l->beam_l () && (stem_l->beam_count (-d) >= 1))
+               {
+                 dy_f_drul_[d] = stem_l->extent (Y_AXIS)[my_dir];
+                 dy_f_drul_[d] += my_dir * 2 * y_gap_f;
+               }
+             /*
+               side attached to notehead, with stem getting in the way
+              */
              else
-               dx_f_drul_[d] += 0.25 * dir_ * notewidth_f;
+               {
+                 dx_f_drul_[d] -= d * x_gap_f;
+                 
+                 dy_f_drul_[d] = stem_l->chord_start_f ()
+                   + my_dir * half_staff_space;
+                 dy_f_drul_[d] += my_dir * y_gap_f;
+               }
            }
        }
-       else 
-         {
-           Real notewidth_f = extrema ()[d]->extent (X_AXIS).length ();
-           dy_f_drul_[d] = (int)rint (extrema ()[d]->head_positions_interval ()
-                                      [dir_]) * internote_f;
-           dx_f_drul_[d] += 0.5 * notewidth_f - d * gap_f;
+      /*
+       loose end
+      */
+      else
+       {
+         dx_f_drul_[d] = get_broken_left_end_align ();
+               
+         /*
+           broken: should get y from other piece, so that slur
+           continues up/down trend
+
+           for now: be horizontal..
+         */
+         fix_broken_b = true;
        }
-       dy_f_drul_[d] += dir_ * interline_f;
-       if (extrema ()[d]->stem_l_ && (dir_ == extrema ()[d]->stem_l_->dir_))
-         dy_f_drul_[d] -= dir_ * internote_f;
-      }
-  while (flip(&d) != LEFT);
+    }
+  while (flip (&d) != LEFT);
 
-  // now that both are set, do dependent
-  do 
-    {
-      if (broken_edge_b (d))
-        {
-         Direction u = d;
-         flip(&u);
+  int cross_count =  cross_staff_count ();
+  bool interstaff_b = (0 < cross_count) && (cross_count < encompass_arr.size ());
 
-         // postbreak
-         if (d == LEFT)
-           dy_f_drul_[u] += dir_ * internote_f;
+  Drul_array<Offset> info_drul;
+  Drul_array<Real> interstaff_interval;
 
-         dy_f_drul_[d] = dy_f_drul_[u];
-       }
-     }
-  while (flip(&d) != LEFT);
+  do
+    {
+      info_drul[d] = encompass_offset (encompass_arr.boundary (d, 0));
+      interstaff_interval[d] = - calc_interstaff_dist (encompass_arr.boundary (d,0),
+                                                    this);
+    }
+  while (flip (&d) != LEFT);
+  
+  Real interstaff_f = interstaff_interval[RIGHT] - interstaff_interval[LEFT];
 
-  /*
-    Slur should follow line of music
-   */
-  if (normal_edge_b (LEFT)
-      && normal_edge_b (RIGHT)
-      && (extrema ()[LEFT]->stem_l_ != extrema ()[RIGHT]->stem_l_))
+  if (fix_broken_b)
     {
-      Real note_dy = extrema ()[RIGHT]->stem_l_->head_positions ()[dir_]
-       - extrema ()[LEFT]->stem_l_->head_positions ()[dir_];
-      Real dy = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT];
-      /*
-       Should we always follow note-heads, (like a tie)?
-       For now, only if the note_dy != slur_dy, we'll do
-       slur_dy := note_dy * factor.
-      */
-      if (sign (dy) != sign (note_dy))
+      Direction d = (encompass_arr.top () != spanned_drul_[RIGHT]) ?
+       RIGHT : LEFT;
+      dy_f_drul_[d] = info_drul[d][Y_AXIS];
+      if (!interstaff_b)
        {
-         Real damp_f = paper_l ()->get_var ("slur_slope_follow_music_factor");
-         Real realdy = note_dy * damp_f;
-         Direction adjust_dir = (Direction)(- dir_ * sign (realdy));
-         if (!adjust_dir)
-           adjust_dir = -dir_;
-         /*
-           adjust only if no beam gets in the way
-          */
-         if (!extrema ()[adjust_dir]->stem_l_->beam_l_
-             || (adjust_dir == extrema ()[adjust_dir]->stem_l_->dir_)
-             || (extrema ()[adjust_dir]->stem_l_->beams_i_drul_[-adjust_dir] < 1))
+         dy_f_drul_[d] -= interstaff_interval[d];
+         if (cross_count)      // interstaff_i  ? 
            {
-             dy_f_drul_[adjust_dir] = dy_f_drul_[-adjust_dir]
-               + 2 * adjust_dir * realdy;
-             Real dx = notewidth_f / 2;
-             if (adjust_dir != extrema ()[adjust_dir]->stem_l_->dir_)
-               dx /= 2;
-             dx_f_drul_[adjust_dir] -= adjust_dir * dx;
+             dy_f_drul_[LEFT] += interstaff_interval[d];
+             dy_f_drul_[RIGHT] += interstaff_interval[d];
            }
        }
     }
+       
 
   /*
-    Avoid too steep slurs.
+    Now we've got a fine slur
+    Catch and correct some ugly cases
    */
-  Real damp_f = paper_l ()->get_var ("slur_slope_damping");
-  Offset d_off = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
-    dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
-  d_off[X_AXIS] += extent (X_AXIS).length ();
-
-  Real ratio_f = abs (d_off[Y_AXIS] / d_off[X_AXIS]);
-  if (ratio_f > damp_f)
-    dy_f_drul_[(Direction)(- dir_ * sign (d_off[Y_AXIS]))] +=
-      dir_ * (ratio_f - damp_f) * d_off[X_AXIS];
-}
+  String infix = interstaff_b ? "interstaff_" : "";
+  Real height_damp_f = paper_l ()->get_var ("slur_"+infix +"height_damping");
+  Real slope_damp_f = paper_l ()->get_var ("slur_"+infix +"slope_damping");
+  Real snap_f = paper_l ()->get_var ("slur_"+infix +"snap_to_stem");
+  Real snap_max_dy_f = paper_l ()->get_var ("slur_"+infix +"snap_max_slope_change");
 
-Array<Offset>
-Slur::get_encompass_offset_arr () const
-{
-  Real notewidth = paper_l ()->note_width () * 0.8;
-  Real gap = paper_l ()->get_var ("slur_x_gap");
+  if (!fix_broken_b)
+    dy_f_drul_[RIGHT] += interstaff_f;
+
+  Real dy_f = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT];
+  if (!fix_broken_b)
+    dy_f -= interstaff_f;
+  Real dx_f = spanner_length ()+ dx_f_drul_[RIGHT] - dx_f_drul_[LEFT];
 
   /*
-  urg.  Calcs done wrt the leftmost note.  Fixme.
+    Avoid too steep slurs.
+   */
+  Real slope_ratio_f = abs (dy_f / dx_f);
+  if (slope_ratio_f > slope_damp_f)
+    {
+      Direction d = (Direction)(- my_dir * (sign (dy_f)));
+      if (!d)
+       d = LEFT;
+      Real damp_f = (slope_ratio_f - slope_damp_f) * dx_f;
+      /*
+       must never change sign of dy
+       */
+      damp_f = damp_f <? abs (dy_f);
+      dy_f_drul_[d] += my_dir * damp_f;
+    }
 
-  Calcs ignore possibility of pre/postbreak.
+  /*
+   Avoid too high slurs 
 
+   Wierd slurs may look a lot better after they have been
+   adjusted a bit.
+   So, we'll do this in 3 steps
+   */
+  for (int i = 0; i < 3; i++)
+    {
+      Real height_f = curve_extent (Y_AXIS).length ();
+      Real width_f = curve_extent (X_AXIS).length ();
+      
+      dy_f = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT];
+      if (!fix_broken_b)
+       dy_f -= interstaff_f;
+
+      Real height_ratio_f = abs (height_f / width_f);
+      if (height_ratio_f > height_damp_f)
+       {
+         Direction d = (Direction)(- my_dir * (sign (dy_f)));
+         if (!d)
+           d = LEFT;
+         /* take third step */
+         Real damp_f = (height_ratio_f - height_damp_f) * width_f / 3;
+         /*
+           if y positions at about the same height, correct both ends
+         */
+         if (abs (dy_f / dx_f ) < slope_damp_f)
+           {
+             dy_f_drul_[-d] += my_dir * damp_f;
+             dy_f_drul_[d] += my_dir * damp_f;
+           }
+         /*
+           don't change slope too much, would have been catched by slope damping
+         */
+         else
+           {
+             damp_f = damp_f <? abs (dy_f/2);
+             dy_f_drul_[d] += my_dir * damp_f;
+           }
+       }
+    }
 
+  /*
+    If, after correcting, we're close to stem-end...
   */
+  Drul_array<Real> snapy_f_drul;
+  snapy_f_drul[LEFT] = snapy_f_drul[RIGHT] = 0;
+  Drul_array<Real> snapx_f_drul;
+  snapx_f_drul[LEFT] = snapx_f_drul[RIGHT] = 0;
+  Drul_array<bool> snapped_b_drul;
+  snapped_b_drul[LEFT] = snapped_b_drul[RIGHT] = false;
+  do
+    {
+      Note_column * nc = note_column_drul[d];
+      if (nc == spanned_drul_[d]
+         && nc->stem_l ()
+         && nc->stem_l ()->get_direction () == my_dir
+         && abs (nc->stem_l ()->extent (Y_AXIS)[my_dir]
+                 - dy_f_drul_[d] + (d == LEFT ? 0 : interstaff_f))
+             <= snap_f)
+       {
+         /*
+           prepare to attach to stem-end
+         */
+         snapx_f_drul[d] = nc->stem_l ()->hpos_f ()
+           - spanned_drul_[d]->relative_coordinate (0, X_AXIS);
+
+         snapy_f_drul[d] = nc->stem_l ()->extent (Y_AXIS)[my_dir]
+           + interstaff_interval[d]
+           + my_dir * 2 * y_gap_f;
+         
+         snapped_b_drul[d] = true;
+       }
+    }
+  while (flip (&d) != LEFT);
 
-  Offset left = Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]);
-  left[X_AXIS] += encompass_arr_[0]->stem_l_->hpos_f ();
+  /*
+    only use snapped positions if sign (dy) will not change
+    and dy doesn't change too much
+    */
+  if (!fix_broken_b)
+    dy_f += interstaff_f;
 
-  Real internote = encompass_arr_[0]->stem_l_->staff_line_leading_f ()/2.0;
 
   /*
-    <URG>
-    i don't understand these two, but *must* for symmetry 
-    look at encompass array: 
-       lilypond -D input/test/slur-symmetry*.ly
-       lilypond -D input/test/sleur.ly
-
-    do_post_processing should have calculated these into
-    dx_f_drul_[], no??
+    (sigh)
 
+    More refactoring could be done.
    */
+  Real maxsnap = abs (dy_f * snap_max_dy_f);
+  if (snapped_b_drul[LEFT] && snapped_b_drul[RIGHT]
+      && ((sign (snapy_f_drul[RIGHT] - snapy_f_drul[LEFT]) == sign (dy_f)))
+      && (!dy_f || (abs (snapy_f_drul[RIGHT] - snapy_f_drul[LEFT] - dy_f)
+                   < maxsnap)))
+    {
+      dy_f_drul_ = snapy_f_drul;
+      dx_f_drul_ = snapx_f_drul;
+    }
+  else
+    do
+      {
+       Direction od = (Direction)-d;
+       if (snapped_b_drul[d]
+           && d * sign (snapy_f_drul[d] - dy_f_drul_[od]) == sign (dy_f)
+           && (!dy_f || (abs (snapy_f_drul[d] - dy_f_drul_[od]  - d * dy_f)
+                         < maxsnap)))
+         {
+           dy_f_drul_[d] = snapy_f_drul[d];
+           dx_f_drul_[d] = snapx_f_drul[d];
+         }
+      }
+    while (flip (&d) != LEFT);
+}
+
+
+int
+Slur::cross_staff_count ()const
+{
+  Link_array<Note_column> encompass_arr =
+    Group_interface__extract_elements (this, (Note_column*)0, "note-columns");
 
-  if (dir_ != encompass_arr_[0]->stem_l_->dir_)
-    left[X_AXIS] += - 0.5 * notewidth * encompass_arr_[0]->stem_l_->dir_
-      + gap;
-  else if (encompass_arr_[0]->stem_l_->dir_ == UP)
-    left[X_AXIS] -= notewidth;
+  int k=0;
+
+  for (int i = 0; i < encompass_arr.size (); i++)
+    {
+      if (calc_interstaff_dist (encompass_arr[i], this))
+       k++;
+    }
+  return k;
+}
 
-  if ((dir_ == encompass_arr_[0]->stem_l_->dir_) 
-    && (encompass_arr_[0]->stem_l_->dir_ == DOWN))
-    left[Y_AXIS] -= internote * encompass_arr_[0]->stem_l_->dir_;
-  /* </URG> */
 
-  Offset d = Offset (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
-    dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
-  d[X_AXIS] += extent (X_AXIS).length ();
+Array<Offset>
+Slur::get_encompass_offset_arr () const
+{
+  Link_array<Note_column> encompass_arr =
+    Group_interface__extract_elements (this, (Note_column*)0, "note-columns");
+  
+  Array<Offset> offset_arr;
+#if 0
+  /*
+    check non-disturbed slur
+    FIXME: x of ends off by a tiny bit!!
+  */
+  offset_arr.push (Offset (0, dy_f_drul_[LEFT]));
+  offset_arr.push (Offset (0, dy_f_drul_[RIGHT]));
+  return offset_arr;
+#endif
+  
+  Offset origin (relative_coordinate (0, X_AXIS), 0);
 
   int first = 1;
-  int last = encompass_arr_.size () - 1;
+  int last = encompass_arr.size () - 2;
 
+  offset_arr.push (Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]));
 
-  Array<Offset> notes;
-  notes.push (Offset (0,0));
+  /*
+    left is broken edge
+  */
 
-  // prebreak
-  if (broken_edge_b (RIGHT))
-    last++;
-  else
-    {
-      Encompass_info info (encompass_arr_.top (), dir_, this);
-      d[Y_AXIS] += info.interstaff_f_;
-    }
-  
-  // postbreak
-  if (broken_edge_b (LEFT))
+  int cross_count  = cross_staff_count ();
+  bool cross_b = cross_count && cross_count < encompass_arr.size ();
+  if (encompass_arr[0] != spanned_drul_[LEFT])
     {
       first--;
-      /*
-        interstaff postbreak: slur begins at height of last note
-       */
-      Encompass_info info (encompass_arr_[0], dir_, this);
-      notes[0][Y_AXIS] += info.interstaff_f_;
+      Real is   = calc_interstaff_dist (encompass_arr[0], this);
+      if (cross_b)
+       offset_arr[0][Y_AXIS] += is;
     }
-  else
+
+  /*
+    right is broken edge
+  */
+  if (encompass_arr.top () != spanned_drul_[RIGHT])
     {
-      Encompass_info info (encompass_arr_[0], dir_, this);
-      notes[0][Y_AXIS] += info.interstaff_f_;
+      last++;
     }
 
-  for (int i = first; i < last; i++)
+  for (int i = first; i <= last; i++)
     {
-      Encompass_info info (encompass_arr_[i], dir_, this);
-      notes.push (info.o_ - left);
+      Offset o (encompass_offset (encompass_arr[i]));
+      offset_arr.push (o - origin);
     }
 
-  /*
-    interstaff prebreak: slur ends at height of last note
-   */
-  if (broken_edge_b (RIGHT))
-    d[Y_AXIS] = notes.top ()[Y_AXIS];
+  offset_arr.push (Offset (spanner_length ()+  dx_f_drul_[RIGHT],
+                          dy_f_drul_[RIGHT]));
 
-  notes.push (d);
-  
-  return notes;
+  return offset_arr;
 }
 
 
@@ -378,3 +522,4 @@ Slur::get_rods () const
   return a;
 }
 
+