]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/slur-scoring.cc
Doc-es: various updates.
[lilypond.git] / lily / slur-scoring.cc
index fe7a273cd0c93c6bd537af1353153b8c22eaffb4..a3dad6fb5e9785888b05b119ac5320b24c0b36b0 100644 (file)
@@ -32,6 +32,7 @@
 #include "main.hh"
 #include "misc.hh"
 #include "note-column.hh"
+#include "note-head.hh"
 #include "output-def.hh"
 #include "paper-column.hh"
 #include "pitch.hh"
@@ -44,9 +45,6 @@
 #include "stem.hh"
 #include "warn.hh"
 
-using std::string;
-using std::vector;
-
 /*
   TODO:
 
@@ -203,11 +201,14 @@ Slur_score_state::get_bound_info () const
                                          ::staff_space (extremes[d].stem_);
             }
 
-          if (extremes[d].slur_head_)
-            extremes[d].slur_head_x_extent_
-              = extremes[d].slur_head_->extent (common_[X_AXIS], X_AXIS);
-
         }
+      else if (has_interface<Note_head> (extremes[d].bound_))
+        {
+          extremes[d].slur_head_ = extremes[d].bound_;
+        }
+      if (extremes[d].slur_head_)
+        extremes[d].slur_head_x_extent_
+          = extremes[d].slur_head_->extent (common_[X_AXIS], X_AXIS);
     }
 
   return extremes;
@@ -257,8 +258,8 @@ Slur_score_state::fill (Grob *me)
     }
 
   extremes_ = get_bound_info ();
-  is_broken_ = (!extremes_[LEFT].note_column_
-                || !extremes_[RIGHT].note_column_);
+  is_broken_ = (!(extremes_[LEFT].note_column_ || extremes_[LEFT].slur_head_)
+                || !(extremes_[RIGHT].note_column_ || extremes_[RIGHT].slur_head_));
 
   has_same_beam_
     = (extremes_[LEFT].stem_ && extremes_[RIGHT].stem_
@@ -468,11 +469,16 @@ Slur_score_state::get_y_attachment_range () const
             slur_->warning ("slur trying to encompass an empty note column.");
           else
             end_ys[d] = dir_
-                        * std::max (std::max (dir_ * (base_attachments_[d][Y_AXIS]
+                        * max (max (dir_ * (base_attachments_[d][Y_AXIS]
                                             + parameters_.region_size_ * dir_),
                                     dir_ * (dir_ + nc_extent[dir_])),
                                dir_ * base_attachments_[-d][Y_AXIS]);
         }
+      else if (extremes_[d].slur_head_)
+        {
+          // allow only minimal movement
+          end_ys[d] = base_attachments_[d][Y_AXIS] + 0.3 * dir_;
+        }
       else
         end_ys[d] = base_attachments_[d][Y_AXIS] + parameters_.region_size_ * dir_;
     }
@@ -531,12 +537,22 @@ Slur_score_state::get_base_attachments () const
                : extremes_[d].bound_->extent (common_[X_AXIS], X_AXIS))
               .linear_combination (CENTER);
         }
+      else if (head)
+        {
+          y = head->extent (common_[Y_AXIS], Y_AXIS)
+            .linear_combination (0.5*dir_);
+
+          // Don't "move_away_from_staffline" because that makes it
+          // harder to recognize the specific attachment point
+          x = head->extent (common_[X_AXIS], X_AXIS)[-d];
+        }
+
       base_attachment[d] = Offset (x, y);
     }
 
   for (LEFT_and_RIGHT (d))
     {
-      if (!extremes_[d].note_column_)
+      if (!extremes_[d].note_column_ && !extremes_[d].slur_head_)
         {
           Real x = 0;
           Real y = 0;
@@ -622,7 +638,7 @@ Slur_score_state::generate_avoid_offsets () const
         continue;
 
       Encompass_info inf (get_encompass_info (encompasses[i]));
-      Real y = dir_ * (std::max (dir_ * inf.head_, dir_ * inf.stem_));
+      Real y = dir_ * (max (dir_ * inf.head_, dir_ * inf.stem_));
 
       avoid.push_back (Offset (inf.x_, y + dir_ * parameters_.free_head_distance_));
     }
@@ -724,7 +740,7 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
                 }
             }
 
-          dz = os[RIGHT] - os[LEFT];
+          dz = (os[RIGHT] - os[LEFT]).direction ();
           for (LEFT_and_RIGHT (d))
             {
               if (extremes_[d].slur_head_
@@ -736,7 +752,7 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
                      TODO: parameter */
                   os[d][X_AXIS]
                   -= dir_ * extremes_[d].slur_head_x_extent_.length ()
-                     * sin (dz.arg ()) / 3;
+                    * dz[Y_AXIS] / 3;
                 }
             }