]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tie.cc
(get_control_points): also avoid staff lines on the
[lilypond.git] / lily / tie.cc
index bb011b973d0707439dbee616a8c98de153fce5fb..b59f8d21b5193960e9b38277e53a73dc7f0f3045 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2002 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, Item * 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
 Tie::set_interface (Grob*me)
 {
   me->set_grob_property ("heads", gh_cons (SCM_EOL, SCM_EOL));
-  me->set_interface (ly_symbol2scm ("tie-interface"));
 }
 
-bool
-Tie::has_interface (Grob*me)
-{
-  return me->has_interface (ly_symbol2scm ("tie-interface"));
-}
 
 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));
 }
 
 
@@ -87,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)
     {
@@ -110,7 +104,7 @@ Tie::get_default_dir (Grob*me)
 SCM
 Tie::get_control_points (SCM smob)
 {  
-  Spanner*me = dynamic_cast<Spanner*> (unsmob_grob (smob));
+  Spanner*me = unsmob_spanner (smob);
   Direction headdir = CENTER; 
   if (head (me,LEFT))
     headdir = LEFT;
@@ -122,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);
 
@@ -139,15 +135,24 @@ Tie::get_control_points (SCM smob)
   Real left_x;
 
   /*
-    this is a kludge: the tie has to be long enough to be
-    visible, but should not go through key sigs.
-
- (please fixme)
+     the tie has to be long enough to be visible, but should not go
+    through key sigs. In the 1.5 series the pref.matter - note
+    distance is fixed , so this won't be a problem anymore.
    */
-  Real lambda = 0.5;           
+  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);
   
@@ -173,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");
 
@@ -193,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 ;
@@ -244,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;
          
@@ -295,7 +313,7 @@ Tie::brew_molecule (SCM smob)
   
   Real thick =
     gh_scm2double (me->get_grob_property ("thickness"))
-    * me->paper_l ()->get_var ("stafflinethickness");
+    * me->get_paper ()->get_var ("linethickness");
 
   Bezier b;
   int i = 0;
@@ -311,3 +329,8 @@ Tie::brew_molecule (SCM smob)
 }
 
 
+
+ADD_INTERFACE (Tie,"tie-interface",
+  "A tie connecting two noteheads.
+direction = Forced direction for all ties",
+  "y-offset staffline-clearance control-points heads details thickness x-gap direction minimum-length");