]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tie-column.cc
*** empty log message ***
[lilypond.git] / lily / tie-column.cc
index 082cc619df1afa89917eda3ced56ae6762827601..76d45004cba8fc0ed34e35e765bf8c8c173a888c 100644 (file)
@@ -7,19 +7,20 @@
 */
 
 #include "tie-column.hh"
+
+#include <cmath>
+
+#include "skyline.hh"
+#include "warn.hh"
 #include "paper-column.hh"
 #include "spanner.hh"
 #include "pointer-group-interface.hh"
 #include "tie.hh"
 #include "directional-element-interface.hh"
-#include "rhythmic-head.hh"
+#include "tie-column-format.hh"
+
+using namespace std;
 
-/*
-  tie dir depends on what Tie_column does.
-*/
-/*
-  TODO: this doesn't follow standard pattern. Regularize.
-*/
 void
 Tie_column::add_tie (Grob *me, Grob *tie)
 {
@@ -41,104 +42,20 @@ Tie_column::add_tie (Grob *me, Grob *tie)
 void
 Tie_column::set_directions (Grob *me)
 {
-  werner_directions (me);
-}
-
-int
-tie_compare (Grob *const &s1,
-            Grob *const &s2)
-{
-  return sign (Tie::get_position (s1) - Tie::get_position (s2));
-}
-
-/*
-  Werner:
-
-  . The algorithm to choose the direction of the ties doesn't work
-  properly.  I suggest the following for applying ties sequentially
-  from top to bottom:
-
-  + The topmost tie is always `up'.
-
-  + If there is a vertical gap to the last note above larger than
-  or equal to a fifth (or sixth?), the tie is `up', otherwise it
-  is `down'.
-
-  + The bottommost tie is always `down'.
-*/
-void
-Tie_column::werner_directions (Grob *me)
-{
-  extract_grob_set (me, "ties", ro_ties);
-  Link_array<Grob> ties (ro_ties);
-  if (!ties.size ())
-    return;
-
-  ties.sort (tie_compare);
-
-  Direction d = get_grob_direction (me);
-  if (d)
+  if (!to_boolean (me->get_property ("positioning-done")))
     {
-      for (int i = ties.size (); i--;)
-       {
-         Grob *t = ties[i];
-         if (!get_grob_direction (t))
-           set_grob_direction (t, d);
-       }
-      return;
+      me->set_property ("positioning-done", SCM_BOOL_T); 
+      new_directions (me);
     }
+}
 
-  if (ties.size () == 1)
-    {
-      Grob *t = ties[0];
-      if (t->is_live ()
-         && !get_grob_direction (t))
-       set_grob_direction (t, Tie::get_default_dir (t));
-      return;
-    }
-
-  Real last_down_pos = 10000;
-  if (!get_grob_direction (ties[0]))
-    set_grob_direction (ties[0], DOWN);
-
-  /*
-    Go downward.
-  */
-  Grob *last_tie = 0;
-  for (int i = ties.size (); i--;)
-    {
-      Grob *t = ties[i];
-
-      Direction d = get_grob_direction (t);
-      Real p = Tie::get_position (t);
-      if (!d)
-       {
-         if (last_tie
-             && Tie::get_column_rank (t, LEFT)
-             < Tie::get_column_rank (last_tie, LEFT))
-           d = DOWN;
-         else if (last_down_pos - p > 5)
-           d = UP;
-         else
-           d = DOWN;
-
-         set_grob_direction (t, d);
-       }
-
-      if (d == DOWN)
-       last_down_pos = p;
-
-      last_tie = t;
-    }
 
-  return;
-}
 
 MAKE_SCHEME_CALLBACK (Tie_column, after_line_breaking, 1);
 SCM
 Tie_column::after_line_breaking (SCM smob)
 {
-  werner_directions (unsmob_grob (smob));
+  set_directions (unsmob_grob (smob));
   return SCM_UNSPECIFIED;
 }
 
@@ -165,7 +82,109 @@ Tie_column::before_line_breaking (SCM smob)
   return SCM_UNSPECIFIED;
 }
 
+
+void
+Tie_column::new_directions (Grob *me)
+{
+  extract_grob_set (me, "ties", ro_ties);
+  Link_array<Grob> ties (ro_ties);
+  if (!ties.size ())
+    return;
+
+  if (ties.size() == 1)
+    {
+      Tie::set_default_control_points (ties[0]);
+      return;
+    }
+  
+  ties.sort (&Tie::compare);
+
+  Array<Tie_configuration> tie_configs;
+  for (int i = 0; i < ties.size (); i++)
+    {
+      Tie_configuration conf;
+      conf.dir_ = get_grob_direction (ties[i]);
+      conf.position_ = Tie::get_position (ties[i]);
+      tie_configs.push (conf);
+    }
+
+  SCM manual_configs = me->get_property ("tie-configuration");
+  bool manual_override = false;
+  set_manual_tie_configuration (&tie_configs,
+                               &manual_override,
+                               manual_configs);
+  set_tie_config_directions (&tie_configs);
+
+  Grob *common = me;
+  for (int i = 0; i < ties.size (); i++)
+    {
+      common = dynamic_cast<Spanner*> (ties[i])->get_bound (LEFT)->common_refpoint (common, X_AXIS); 
+      common = dynamic_cast<Spanner*> (ties[i])->get_bound (RIGHT)->common_refpoint (common, X_AXIS); 
+    }
+
+  Drul_array< Array<Skyline_entry> > skylines;
+  set_chord_outlines (&skylines, ties, common);
+  
+  Tie_details details;
+  details.init (ties[0]);
+
+  /*
+    Let the ties flow out, according to our single-tie formatting.
+   */
+  if (!manual_override)
+    {
+      Tie::get_configuration (ties[0], common, &tie_configs.elem_ref (0),
+                             &skylines,
+                             details
+                             );
+      Tie::get_configuration (ties.top (), common,
+                             &tie_configs.elem_ref (tie_configs.size()-1),
+                             &skylines,
+                             details
+                             );
+    }
+
+  /*
+    Calculate final width and shape of the ties.
+   */
+  for (int i = 0; i < ties.size(); i++)
+    {
+      if (!manual_override
+         && (i == 0 || i == ties.size () -1))
+       continue;
+
+
+      final_shape_adjustment (tie_configs[i],
+                             skylines,
+                             ties[0],
+                             details);
+    }
+
+  
+  /*
+    Try to shift small ties into available spaces.
+   */
+  if (!manual_override)
+    {
+      shift_small_ties (&tie_configs, ties[0], details);
+    }
+  
+  for (int i = 0; i < ties.size(); i++)
+    {
+      Tie::set_control_points (ties[i], common, tie_configs[i],
+                              details
+                              );
+      set_grob_direction (ties[i], tie_configs[i].dir_);
+    }
+}
+
+
+
 ADD_INTERFACE (Tie_column, "tie-column-interface",
               "Object that sets directions of multiple ties in a tied chord",
-              "direction");
+
+              /* properties */
+              "positioning-done "
+              "tie-configuration "
+              );