]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tie.cc
* The grand 2005-2006 replace.
[lilypond.git] / lily / tie.cc
index 78caff41885fd3de965bc0941acc35b8de4c36fb..d79ffccd55c327d7e0583a8a965aebc8efe55759 100644 (file)
@@ -3,13 +3,10 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include "tie.hh"
-
-#include <math.h>
-
 #include "spanner.hh"
 #include "lookup.hh"
 #include "output-def.hh"
 #include "stem.hh"
 #include "note-head.hh"
 #include "tie-column.hh"
+#include "grob-array.hh"
+#include "tie-formatting-problem.hh"
+#include "tie-configuration.hh"
 
-/*
-  tie: Connect two noteheads.
-
-  What if we have
-
-  c4 ~ \clef bass ; c4 or
-
-  c4 \staffchange c4
-
-  do we have non-horizontal ties then?
-*/
 
-void
-Tie::set_head (Grob *me, Direction d, Grob *h)
+int
+Tie::compare (Grob *const &s1,
+             Grob *const &s2)
 {
-  assert (!head (me, d));
-  index_set_cell (me->get_property ("head-pair"), d, h->self_scm ());
-
-  dynamic_cast<Spanner *> (me)->set_bound (d, h);
-  me->add_dependency (h);
+  return sign (Tie::get_position (s1) - Tie::get_position (s2));
 }
 
 void
-Tie::set_interface (Grob *me)
+Tie::set_head (Grob *me, Direction d, Grob *h)
 {
-  me->set_property ("head-pair", scm_cons (SCM_EOL, SCM_EOL));
+  dynamic_cast<Spanner *> (me)->set_bound (d, h);
 }
 
 Grob *
 Tie::head (Grob *me, Direction d)
 {
-  SCM c = me->get_property ("head-pair");
-
-  if (scm_is_pair (c))
-    return unsmob_grob (index_get_cell (c, d));
+  Item *it = dynamic_cast<Spanner*> (me)->get_bound (d);
+  if (Note_head::has_interface (it))
+    return it;
   else
     return 0;
 }
@@ -75,11 +60,27 @@ Tie::get_column_rank (Grob *me, Direction d)
   return Paper_column::get_rank (col);
 }
 
-Real
+int
 Tie::get_position (Grob *me)
 {
-  Direction d = head (me, LEFT) ? LEFT : RIGHT;
-  return Staff_symbol_referencer::get_position (head (me, d));
+  Direction d = LEFT;
+  do
+    {
+      Grob *h = head (me, d);
+      if (h)
+       return (int) Staff_symbol_referencer::get_position (h);
+    }
+  while (flip (&d) != LEFT);
+
+  /*
+
+  TODO: this is theoretically possible for ties across more than 2
+  systems.. We should look at the first broken copy.
+  
+  */
+  programming_error ("Tie without heads. Suicide");
+  me->suicide ();
+  return 0;
 }
 
 /*
@@ -112,33 +113,100 @@ Tie::get_default_dir (Grob *me)
   return UP;
 }
 
+
+MAKE_SCHEME_CALLBACK(Tie, calc_direction, 1);
+SCM
+Tie::calc_direction (SCM smob)
+{
+  Grob *me = unsmob_grob (smob);
+  Grob *yparent = me->get_parent (Y_AXIS);
+  if (Tie_column::has_interface (yparent)
+      && unsmob_grob_array (yparent->get_object ("ties"))
+      && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1)
+    {
+      /* trigger positioning. */
+      (void) yparent->get_property ("positioning-done");
+    }
+  else
+    set_grob_direction (me, Tie::get_default_dir (me));
+
+  return SCM_UNSPECIFIED;
+}
+
+
+void
+Tie::set_default_control_points (Grob *me_grob)
+{
+  Spanner *me = dynamic_cast<Spanner*> (me_grob);
+  Grob *common  = me;
+  common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS); 
+  common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS); 
+  
+  Tie_formatting_problem problem;
+  problem.from_tie (me);
+  
+  // get_configuration (me,  &conf, problem);
+  int tie_position = (int) Tie::get_position (me);
+  Tie_configuration conf
+    = problem.find_optimal_tie_configuration (tie_position, get_grob_direction (me));
+  set_control_points (me, problem.common_x_refpoint (),
+                     conf, problem.details_);
+}
+
 void
-Tie::set_direction (Grob *me)
+Tie::set_control_points (Grob *me,
+                        Grob *common,
+                        Tie_configuration const &conf,
+                        Tie_details const &details
+                        )
 {
-  if (!get_grob_direction (me))
+  Bezier b = conf.get_transformed_bezier (details);
+  b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
+
+  SCM controls = SCM_EOL;
+  for (int i = 4; i--;)
     {
-      if (Tie_column::has_interface (me->get_parent (Y_AXIS)))
-       Tie_column::set_directions (me->get_parent (Y_AXIS));
-      else
-       set_grob_direction (me, Tie::get_default_dir (me));
+      if (!b.control_[i].is_sane ())
+       programming_error ("Insane offset");
+      controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
     }
+  me->set_property ("control-points", controls);
 }
 
-MAKE_SCHEME_CALLBACK (Tie, print, 1);
+MAKE_SCHEME_CALLBACK(Tie, calc_control_points, 1);
 SCM
-Tie::print (SCM smob)
+Tie::calc_control_points (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
 
-  SCM cp = me->get_property ("control-points");
-  if (!scm_is_pair (cp))               // list is more accurate
+  // trigger Tie-column
+  (void)  get_grob_direction (me);
+
+  Grob *yparent = me->get_parent (Y_AXIS);
+  if (Tie_column::has_interface (yparent)
+      && unsmob_grob_array (yparent->get_object ("ties"))
+      && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1)
+    {
+      /* trigger positioning. */
+      (void) yparent->get_property ("positioning-done");
+    }
+
+  if (!scm_is_pair (me->get_property ("control-points")))
     {
-      cp = get_control_points (smob);
-      me->set_property ("control-points", cp);
+      set_default_control_points (me);
     }
 
-  if (!scm_is_pair (cp))
-    return Stencil ().smobbed_copy ();
+  return SCM_UNSPECIFIED;
+}
+
+
+MAKE_SCHEME_CALLBACK (Tie, print, 1);
+SCM
+Tie::print (SCM smob)
+{
+  Grob *me = unsmob_grob (smob);
+  
+  SCM cp = me->get_property ("control-points");
 
   Real staff_thick = Staff_symbol_referencer::line_thickness (me);
   Real base_thick = robust_scm2double (me->get_property ("thickness"), 1);
@@ -171,8 +239,21 @@ Tie::print (SCM smob)
 
 ADD_INTERFACE (Tie,
               "tie-interface",
-              "A tie connecting two noteheads.\n",
+              
+              "A tie connecting two noteheads. \n\n"
+              ,
+              
+
+              /* properties */
+              "avoid-slur "    //  UGH.
+              "control-points "
+              "dash-fraction "
+              "dash-period "
+              "details "
+              "direction "
+              "thickness "
+              "x-gap ");
+
+
+
 
-              "y-offset dash-period dash-fraction "
-              "staffline-clearance control-points head-pair "
-              "details thickness x-gap direction minimum-length");