]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tie.cc
* lily/align-interface.cc (find_fixed_alignment_parent): new function.
[lilypond.git] / lily / tie.cc
index ec11531206098f38a06ae346ed74eee4d4963876..99cf426d5c77a5ce8d09aa7d2e89ae8f1b72543a 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 #include <math.h>
 
@@ -15,7 +15,7 @@
 #include "rhythmic-head.hh"
 #include "bezier.hh"
 #include "paper-column.hh"
-#include "debug.hh"
+#include "warn.hh"
 #include "staff-symbol-referencer.hh"
 #include "directional-element-interface.hh"
 #include "molecule.hh"
 
 
 void
-Tie::set_head (Grob*me,Direction d, Item * head_l)
+Tie::set_head (Grob*me,Direction d, Grob * h)
 {
   assert (!head (me,d));
-  index_set_cell (me->get_grob_property ("heads"), d, head_l->self_scm ());
+  index_set_cell (me->get_grob_property ("heads"), d, h->self_scm ());
   
-  dynamic_cast<Spanner*> (me)->set_bound (d, head_l);
-  me->add_dependency (head_l);
+  dynamic_cast<Spanner*> (me)->set_bound (d, h);
+  me->add_dependency (h);
 }
 
 void
@@ -57,16 +57,16 @@ Grob*
 Tie::head (Grob*me, Direction d) 
 {
   SCM c = me->get_grob_property ("heads");
-  c = index_cell (c, d);
+  c = index_get_cell (c, d);
 
   return unsmob_grob (c);
 }
 
 Real
-Tie::position_f (Grob*me) 
+Tie::get_position (Grob*me) 
 {
   Direction d = head (me,LEFT) ? LEFT:RIGHT;
-  return Staff_symbol_referencer::position_f (head (me,d));
+  return Staff_symbol_referencer::get_position (head (me,d));
 }
 
 
@@ -81,8 +81,8 @@ Tie::position_f (Grob*me)
 Direction
 Tie::get_default_dir (Grob*me) 
 {
-  Item * sl =  head (me,LEFT) ? Rhythmic_head::stem_l (head (me,LEFT)) :0;
-  Item * sr =  head (me,RIGHT) ? Rhythmic_head::stem_l (head (me,RIGHT)) :0;  
+  Item * sl =  head (me,LEFT) ? Rhythmic_head::get_stem (head (me,LEFT)) :0;
+  Item * sr =  head (me,RIGHT) ? Rhythmic_head::get_stem (head (me,RIGHT)) :0;  
 
   if (sl && sr)
     {
@@ -116,9 +116,11 @@ Tie::get_control_points (SCM smob)
       me->suicide ();
       return SCM_UNSPECIFIED;
     }
+
   
   if (!Directional_element_interface::get (me))
     Directional_element_interface::set (me, Tie::get_default_dir (me));
+  Direction dir = Directional_element_interface::get (me);
   
   Real staff_space = Staff_symbol_referencer::staff_space (me);
 
@@ -140,7 +142,17 @@ Tie::get_control_points (SCM smob)
   Real lambda = 0.9;           
   
   if (Note_head::has_interface (l))
-    left_x = l->extent (l, X_AXIS)[RIGHT] + x_gap_f;
+    {
+      Real where = RIGHT;
+
+      /*
+       This correction is due te the shape of the black note head.
+       */
+      if (Rhythmic_head::duration_log (l) == 2)
+       where += dir* 0.2;
+      left_x = l->extent (l, X_AXIS).linear_combination (where)
+       + x_gap_f;
+    }
   else
     left_x = l->extent (l, X_AXIS).linear_combination (lambda);
   
@@ -166,7 +178,7 @@ Tie::get_control_points (SCM smob)
          - 2 * x_gap_f;
     }
   
-  Direction dir = Directional_element_interface::get (me);
+
 
   SCM details = me->get_grob_property ("details");
 
@@ -186,16 +198,16 @@ Tie::get_control_points (SCM smob)
 
   */
 
-  Real ypos = Tie::position_f (me) * staff_space/2
+  Real ypos = Tie::get_position (me) * staff_space/2
     + dir * gh_scm2double (me->get_grob_property ("y-offset"));;
 
   /*
     Make sure we don't start on a dots
    */
-  if (Note_head::has_interface (l) && Rhythmic_head::dots_l (l))
+  if (Note_head::has_interface (l) && Rhythmic_head::get_dots (l))
     {
-      Grob* dots = Rhythmic_head::dots_l(l);
-      if(fabs (staff_space * Staff_symbol_referencer::position_f (dots) /2
+      Grob* dots = Rhythmic_head::get_dots (l);
+      if(fabs (staff_space * Staff_symbol_referencer::get_position (dots) /2
               - ypos) < 0.5)
        {
          ypos += 0.5 * dir ;
@@ -237,11 +249,24 @@ Tie::get_control_points (SCM smob)
 
       Real clear = staff_space * gh_scm2double (me->get_grob_property ("staffline-clearance"));
 
-      if (fabs (y) <= Staff_symbol_referencer::staff_radius (me)
+      if (fabs (y) <=
+         Staff_symbol_referencer::staff_radius (me) * staff_space + clear
          && fabs (diff) < clear)
        {
          Real y1 = ry + clear;
          Real y2 = ry - clear;
+
+         /*
+           ugh, we shove the 0.5 out of our sleeves.
+
+           Any way. This test is to make sure that staffline
+           collision avoidance does not result in completely flat
+           ties.
+          */
+         if (fabs (y1 - ypos) < 0.5)
+           y1 = y2;
+         else if (fabs (y2 - ypos) < 0.5)
+           y2 = y1;
          
          newy = (fabs (y1 - y) < fabs (y2 - y)) ? y1 : y2;
          
@@ -288,7 +313,7 @@ Tie::brew_molecule (SCM smob)
   
   Real thick =
     gh_scm2double (me->get_grob_property ("thickness"))
-    * me->paper_l ()->get_var ("linethickness");
+    * me->get_paper ()->get_var ("linethickness");
 
   Bezier b;
   int i = 0;
@@ -306,6 +331,6 @@ Tie::brew_molecule (SCM smob)
 
 
 ADD_INTERFACE (Tie,"tie-interface",
-  "A tie connecting two noteheads.
-direction = Forced direction for all ties",
+  "A tie connecting two noteheads.\n"
+"direction = Forced direction for all ties",
   "y-offset staffline-clearance control-points heads details thickness x-gap direction minimum-length");