]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/slur.cc
patch::: 1.3.79.jcn3
[lilypond.git] / lily / slur.cc
index 9b751ab6e87f75268f45b611d30e9ce2ad31cd23..a2228c73ce13da30d21186a27ce28401b7a197a7 100644 (file)
@@ -37,9 +37,7 @@
 void
 Slur::set_interface (Score_element*me)
 {
-  me-> set_elt_property ("attachment", gh_cons (SCM_BOOL_F, SCM_BOOL_F));
-  me->set_elt_property ("note-columns", SCM_EOL);
-  me->set_elt_property ("control-points", SCM_EOL);
+  me->set_elt_property ("attachment", gh_cons (SCM_BOOL_F, SCM_BOOL_F));
   me->set_interface (ly_symbol2scm ("slur-interface"));
 }
 
@@ -139,10 +137,12 @@ Slur::encompass_offset (Score_element*me,
       && !stem_l->extent (Y_AXIS).empty_b ())
     {
       o[Y_AXIS] = stem_l->relative_coordinate (common[Y_AXIS], Y_AXIS); // iuhg
+      o[Y_AXIS] += stem_l->extent (Y_AXIS)[dir];
     }
   else
     {
       o[Y_AXIS] = col->relative_coordinate (common[Y_AXIS], Y_AXIS);   // ugh
+      o[Y_AXIS] += col->extent (Y_AXIS)[dir];
     }
 
   /*
@@ -152,15 +152,19 @@ Slur::encompass_offset (Score_element*me,
   return o;
 }
 
-MAKE_SCHEME_CALLBACK(Slur,after_line_breaking);
-
+MAKE_SCHEME_CALLBACK (Slur, after_line_breaking);
 SCM
 Slur::after_line_breaking (SCM smob)
 {
   Score_element *me = unsmob_element (smob);
+  if (!gh_scm2int(scm_length (me->get_elt_property ("note-columns"))))
+    {
+      me->suicide ();
+      return SCM_UNSPECIFIED;
+    }
   set_extremities (me);
   set_control_points (me);
-  return SCM_UNDEFINED;
+  return SCM_UNSPECIFIED;
 } 
 
 void
@@ -179,7 +183,7 @@ Slur::set_extremities (Score_element*me)
          for (SCM s = scm_eval (ly_symbol2scm ("slur-extremity-rules"));
               s != SCM_EOL; s = gh_cdr (s))
            {
-             SCM r = gh_call2 (gh_caar (s), me->self_scm_,
+             SCM r = gh_call2 (gh_caar (s), me->self_scm (),
                                 gh_int2scm ((int)dir));
              if (r != SCM_BOOL_F)
                {
@@ -204,17 +208,17 @@ Slur::get_attachment (Score_element*me,Direction dir,
   Real ss = Staff_symbol_referencer::staff_space ((Score_element*)me);
   Real hs = ss / 2.0;
   Offset o;
-
-
+  
+  Score_element *stem = 0;
   if (Note_column::has_interface (sp->get_bound (dir)))
     {
       Score_element * n =sp->get_bound (dir);
-      if (Score_element*st = Note_column::stem_l (n))
+      if (Score_element *stem = Note_column::stem_l (n))
        {
 
          if (str == "head")
            {
-             o = Offset (0, Stem::chord_start_f (st ));
+             o = Offset (0, Stem::chord_start_f (stem));
              /*
                Default position is centered in X, on outer side of head Y
               */
@@ -223,50 +227,48 @@ Slur::get_attachment (Score_element*me,Direction dir,
            }
          else if (str == "alongside-stem")
            {
-             o = Offset (0, Stem::chord_start_f (st ));
+             o = Offset (0, Stem::chord_start_f (stem));
              /*
                Default position is on stem X, on outer side of head Y
               */
              o += Offset (n->extent (X_AXIS).length ()
-                          * (1 + Stem::get_direction (st )),
+                          * (1 + Stem::get_direction (stem)),
                           0.5 * ss * Directional_element_interface (me).get ());
            }
          else if (str == "stem")
            {
-             o = Offset (0, Stem::stem_end_position (st ) * hs);
+             o = Offset (0, Stem::stem_end_position (stem) * hs);
              /*
                Default position is on stem X, at stem end Y
               */
              o += Offset (0.5 *
                           (n->extent (X_AXIS).length ()
-                           - st->extent (X_AXIS).length ())
-                           * (1 + Stem::get_direction (st )),
+                           - stem->extent (X_AXIS).length ())
+                           * (1 + Stem::get_direction (stem)),
                            0);
            }
-         else if (str == "loose-end")
-           {
-             SCM other_a = dir == LEFT ? gh_cdr (s) : gh_car (s);
-             if (ly_symbol2string (other_a) != "loose-end")
-               {
-                 o = Offset (0, get_attachment (me, -dir, common)[Y_AXIS]);
-               }
-           }
-
-         
-         SCM l = scm_assoc
-           (scm_listify (a,
-                         gh_int2scm (Stem::get_direction (st ) * dir),
-                         gh_int2scm (Directional_element_interface (me).get () * dir),
-                         SCM_UNDEFINED),
-            scm_eval (ly_symbol2scm ("slur-extremity-offset-alist")));
-         
-         if (l != SCM_BOOL_F)
-           {
-             o += ly_scm2offset (gh_cdr (l)) * ss * dir;
-           }
        }
     }
-
+  else if (str == "loose-end")
+    {
+      SCM other_a = dir == LEFT ? gh_cdr (s) : gh_car (s);
+      if (ly_symbol2string (other_a) != "loose-end")
+       {
+         o = Offset (0, get_attachment (me, -dir, common)[Y_AXIS]);
+       }
+    }
+         
+  SCM l = scm_assoc
+    (scm_listify (a,
+                 gh_int2scm (stem ? Stem::get_direction (stem) : 1 * dir),
+                 gh_int2scm (Directional_element_interface (me).get () * dir),
+                 SCM_UNDEFINED),
+     scm_eval (ly_symbol2scm ("slur-extremity-offset-alist")));
+  
+  if (l != SCM_BOOL_F)
+    {
+      o += ly_scm2offset (gh_cdr (l)) * ss * dir;
+    }
 
   /*
     What if get_bound () is not a note-column?
@@ -277,13 +279,14 @@ Slur::get_attachment (Score_element*me,Direction dir,
       o[Y_AXIS] += sp->get_bound (dir)->relative_coordinate (common[Y_AXIS], Y_AXIS) 
        - me->relative_coordinate (common[Y_AXIS], Y_AXIS);
     }
+
   return o;
 }
 
 Array<Offset>
 Slur::get_encompass_offset_arr (Score_element*me) 
 {
-    Spanner*sp = dynamic_cast<Spanner*>(me);
+  Spanner*sp = dynamic_cast<Spanner*>(me);
   SCM eltlist = me->get_elt_property ("note-columns");
   Score_element *common[] = {me->common_refpoint (eltlist,X_AXIS),
                             me->common_refpoint (eltlist,Y_AXIS)};
@@ -361,22 +364,31 @@ Slur::set_spacing_rods (SCM smob)
   Spanner*sp = dynamic_cast<Spanner*>(me);
   r.item_l_drul_[LEFT] = sp->get_bound (LEFT);
   r.item_l_drul_[RIGHT] = sp->get_bound (RIGHT);
-  r.distance_f_ = me->paper_l ()->get_var ("slur_x_minimum");
+  r.distance_f_ =
+    gh_scm2double (me->get_elt_property ("minimum-length"))
+    * me->paper_l ()->get_var ("staffspace");
 
   r.add_to_cols ();
-  return SCM_UNDEFINED;
+  return SCM_UNSPECIFIED;
 }
 
 
 /*
   Ugh should have dash-length + dash-period
  */
-MAKE_SCHEME_CALLBACK(Slur,brew_molecule);
+MAKE_SCHEME_CALLBACK (Slur, brew_molecule);
 SCM
 Slur::brew_molecule (SCM smob)
 {
   Score_element * me = unsmob_element (smob);
-  Real thick = me->paper_l ()->get_var ("slur_thickness");
+  if (!gh_scm2int(scm_length (me->get_elt_property ("note-columns"))))
+    {
+      me->suicide ();
+      return SCM_EOL;
+    }
+
+  Real thick = me->paper_l ()->get_var ("stafflinethickness") *
+    gh_scm2double (me->get_elt_property ("thickness"));
   Bezier one = get_curve (me);
 
   Molecule a;
@@ -392,20 +404,20 @@ Slur::brew_molecule (SCM smob)
 void
 Slur::set_control_points (Score_element*me)
 {
-  Slur_bezier_bow bb (get_encompass_offset_arr (me),
-                     Directional_element_interface (me).get ());
-
-  Real staff_space = Staff_symbol_referencer::staff_space (me);
-  Real h_inf = me->paper_l ()->get_var ("slur_height_limit_factor") * staff_space;
+  Real staff_space = Staff_symbol_referencer::staff_space ((Score_element*)me);  
+  Real h_inf = me->paper_l ()->get_var ("slur_height_limit_factor") *
+    staff_space;
   Real r_0 = me->paper_l ()->get_var ("slur_ratio");
-
-  bb.set_default_bezier (h_inf, r_0);
+  
+  Slur_bezier_bow bb (get_encompass_offset_arr (me),
+                     Directional_element_interface (me).get (),
+                     h_inf, r_0);
 
   if (bb.fit_factor () > 1.0)
     {
       Real length = bb.curve_.control_[3][X_AXIS]; 
-      Real default_height = bb.get_default_height (h_inf, r_0, length);
-      bb.minimise_enclosed_area (me->paper_l(), default_height);
+      Real default_height = slur_height (length, h_inf, r_0);
+      bb.minimise_enclosed_area (me->paper_l());
       
       Real bff = me->paper_l ()->get_var ("slur_force_blowfit");
       bb.curve_.control_[1][Y_AXIS] *= bff;
@@ -428,12 +440,19 @@ Slur::set_control_points (Score_element*me)
 
   SCM controls = SCM_EOL;
   for (int i= 4; i--;)
-    controls = gh_cons ( ly_offset2scm (b.control_[i]), controls);
+    {
+      controls = gh_cons ( ly_offset2scm (b.control_[i]), controls);
+      /*
+       BRRR WHURG.
+       All these null control-points, where do they all come from?
+      */
+      if (i && b.control_[i][X_AXIS] == 0)
+       me->suicide ();
+    }
 
   me->set_elt_property ("control-points", controls);
 }
   
-  
 Bezier
 Slur::get_curve (Score_element*me) 
 {
@@ -446,20 +465,19 @@ Slur::get_curve (Score_element*me)
   
   if (!gh_pair_p (me->get_elt_property ("control-points")))
     set_control_points (me);
-  
-  
+
   for (SCM s= me->get_elt_property ("control-points"); s != SCM_EOL; s = gh_cdr (s))
     {
       b.control_[i] = ly_scm2offset (gh_car (s));
       i++;
     }
-  
+
   Array<Offset> enc (get_encompass_offset_arr (me));
   Direction dir = Directional_element_interface (me).get ();
   
   Real x1 = enc[0][X_AXIS];
   Real x2 = enc.top ()[X_AXIS];
-  
+
   Real off = 0.0;
   for (int i=1; i < enc.size ()-1; i++)
     {
@@ -478,7 +496,7 @@ Slur::get_curve (Score_element*me)
 bool
 Slur::has_interface (Score_element*me)
 {
-  return me->has_interface ("slur-interface");
+  return me->has_interface (ly_symbol2scm ("slur-interface"));
 }