]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/slur.cc
release: 1.1.18
[lilypond.git] / lily / slur.cc
index 14edd7b3e2146d21354fd5955bbfe51fc554a32c..465102e6af68084b38c3da7c9fe4e32bdd6e65d9 100644 (file)
@@ -29,7 +29,7 @@
 #include "encompass-info.hh"
 #include "main.hh"
 
-IMPLEMENT_IS_TYPE_B1(Slur,Bow);
+
 
 Slur::Slur ()
 {
@@ -38,6 +38,8 @@ Slur::Slur ()
 void
 Slur::add_column (Note_column*n)
 {
+  if (!n->head_l_arr_.size ())
+    warning (_ ("Putting slur over rest."));
   encompass_arr_.push (n);
   add_dependency (n);
 }
@@ -74,10 +76,10 @@ void
 Slur::do_substitute_dependency (Score_element*o, Score_element*n)
 {
   int i;
-  while ((i = encompass_arr_.find_i ((Note_column*)o->access_Item ())) >=0) 
+  while ((i = encompass_arr_.find_i (dynamic_cast<Note_column *> (o))) >=0) 
     {
       if (n)
-       encompass_arr_[i] = (Note_column*)n->access_Item ();
+       encompass_arr_[i] = dynamic_cast<Note_column *> (n);
       else
        encompass_arr_.del (i);
     }
@@ -98,7 +100,8 @@ Slur::do_post_processing ()
 
   Real interline_f = paper ()->interline_f ();
   Real internote_f = interline_f / 2;
-  Real notewidth_f = paper ()->note_width ();
+  // URG
+  Real notewidth_f = paper ()->note_width () * 0.8;
   Real slur_min = paper ()->get_var ("slur_x_minimum");
 
   /* 
@@ -129,12 +132,12 @@ Slur::do_post_processing ()
        {
          // ugh -- check if needed
          dx_f_drul_[d] = -d 
-           *(spanned_drul_[d]->width ().length () - 0.5 * notewidth_f);
+           *(spanned_drul_[d]->extent (X_AXIS).length () - 0.5 * notewidth_f);
 
          // prebreak
          if (d == RIGHT)
            {
-             dx_f_drul_[LEFT] = spanned_drul_[LEFT]->width ().length ();
+             dx_f_drul_[LEFT] = spanned_drul_[LEFT]->extent (X_AXIS).length ();
 
              // urg -- check if needed
              if (encompass_arr_.size () > 1)
@@ -144,10 +147,11 @@ Slur::do_post_processing ()
       /*
         normal slur
        */
-      else if (extrema[d]->stem_l_ && !extrema[d]->stem_l_->transparent_b_) 
+      else if (extrema[d]->stem_l_ && !extrema[d]->stem_l_->transparent_b_ 
+              && extrema[d]->head_l_arr_.size ()) 
         {
-         Real notewidth_f = extrema[d]->width ().length ();
-         dy_f_drul_[d] = (int)rint (extrema[d]->stem_l_->height ()[dir_]);
+         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_)
            {
@@ -157,17 +161,17 @@ Slur::do_post_processing ()
                dx_f_drul_[d] += 0.25 * (dir_ * d) * d * notewidth_f;
            }
        }
-      else 
-        {
-         Real notewidth_f = extrema[d]->width ().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;
+       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;
        }
-      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;
-    }
+       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);
 
   // now that both are set, do dependent
@@ -205,7 +209,7 @@ Slur::do_post_processing ()
   Real damp_f = paper ()->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 () += width ().length ();
+  d_off.x () += extent (X_AXIS).length ();
 
   Real ratio_f = abs (d_off.y () / d_off.x ());
   if (ratio_f > damp_f)
@@ -216,12 +220,39 @@ Slur::do_post_processing ()
 Array<Offset>
 Slur::get_encompass_offset_arr () const
 {
+  Real notewidth = paper ()->note_width () * 0.8;
+  Real gap = paper ()->get_var ("slur_x_gap");
+  Real internote = paper ()->internote_f ();
+
   Offset left = Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]);
   left.x () += encompass_arr_[0]->stem_l_->hpos_f ();
 
+  /*
+    <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??
+
+   */
+
+  if (dir_ != encompass_arr_[0]->stem_l_->dir_)
+    left.x () += - 0.5 * notewidth * encompass_arr_[0]->stem_l_->dir_
+      + gap;
+  else if (encompass_arr_[0]->stem_l_->dir_ == UP)
+    left.x () -= notewidth;
+
+  if ((dir_ == encompass_arr_[0]->stem_l_->dir_) 
+    && (encompass_arr_[0]->stem_l_->dir_ == DOWN))
+    left.y () -= 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 () += width ().length ();
+  d.x () += extent (X_AXIS).length ();
 
   int first = 1;
   int last = encompass_arr_.size () - 1;
@@ -234,38 +265,16 @@ Slur::get_encompass_offset_arr () const
   if (encompass_arr_.top () != spanned_drul_[RIGHT])
     last++;
 
-#define RESIZE_ICE
-#ifndef RESIZE_ICE
-
   Array<Offset> notes;
   notes.push (Offset (0,0));
-//  notes.push (left);
 
   for (int i = first; i < last; i++)
     {
       Encompass_info info (encompass_arr_[i], dir_);
       notes.push (info.o_ - left);
-//      notes.push (info.o_ - left);
     }
   notes.push (d);
 
-#else
-
-  int n = last - first + 2;
-  Array<Offset> notes (n);
-  notes[0] = Offset (0,0);
-//  notes[0] = left;
-
-  for (int i = first; i < last; i++)
-    {
-      Encompass_info info (encompass_arr_[i], dir_);
-      notes[i - first + 1] = info.o_ - left;
-//     notes[i - first + 1] = info.o_;
-    }
-  notes[n - 1] = Offset (d);
-
-#endif
-
   return notes;
 }