]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/tie-column.cc (werner_directions): new function
authorhanwen <hanwen>
Mon, 19 Jan 2004 13:45:36 +0000 (13:45 +0000)
committerhanwen <hanwen>
Mon, 19 Jan 2004 13:45:36 +0000 (13:45 +0000)
* lily/tie.cc (set_direction): call Tie_column::set_direction ()

* lily/axis-group-engraver.cc (process_acknowledged_grobs): give
empty objects group spanner as parent

ChangeLog
lily/axis-group-engraver.cc
lily/include/tie-column.hh
lily/include/tie.hh
lily/tie-column.cc
lily/tie-engraver.cc
lily/tie.cc
scm/define-grobs.scm

index 87d8afc3fa0f045923dac5fa4f8be2c3d449d77d..0d6fdd2e16ca5fecc0ac3e3967850f4b630fdb7a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2004-01-19  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+       * lily/tie-column.cc (werner_directions): new function
+
+       * lily/tie.cc (set_direction): call Tie_column::set_direction ()
+
+       * lily/axis-group-engraver.cc (process_acknowledged_grobs): give
+       empty objects group spanner as parent
+
        * lily/tuplet-bracket.cc (calc_position_and_height): check musical
        slope against graphical slope.
 
index 94a873bc9cf20104148f6779dbc8f572ea88b09a..0cff96e94679064decf5d4d1f4d4e8bbf8f5bc9d 100644 (file)
@@ -113,9 +113,18 @@ Axis_group_engraver::process_acknowledged_grobs ()
     {
       Grob *par = elts_[i]->get_parent (Y_AXIS);
 
-      if ((!par || !Axis_group_interface::has_interface (par))
-         && ! elts_[i]->empty_b (Y_AXIS))
-       add_element (elts_[i]);
+      if (!par || !Axis_group_interface::has_interface (par))
+       if (elts_[i]->empty_b (Y_AXIS))
+         {
+           /*
+             We have to do _something_, otherwise staff objects will
+             end up with System as parent.  
+             
+            */
+           elts_[i]->set_parent (staffline_, Y_AXIS);
+         }
+       else
+         add_element (elts_[i]);
     }
   elts_.clear ();
 }
index 5b2ec8e61d0c5afadee014d0f1ddef0cfa3338b5..10c26e8dab85e83548e3e2dd85e86ec0ed2ed278 100644 (file)
@@ -19,8 +19,10 @@ class Tie_column
 public:
   static bool has_interface (Grob*);
   static void add_tie (Grob*me,Grob*);
-  DECLARE_SCHEME_CALLBACK (after_line_breaking, (SCM ));
+  DECLARE_SCHEME_CALLBACK (after_line_breaking, (SCM));
   static void set_directions (Grob*me);
+  static void old_directions (Grob*me);
+  static void werner_directions (Grob*me);
 };
 
 #endif /* TIE_COLUMN_HH */
index 79c036b0b9798a12935a844319c3ea300a822150..3489c157d592b85d2d352f519b6a98d9726185a8 100644 (file)
@@ -20,6 +20,7 @@ public:
   static void set_head (Grob*,Direction, Grob*head);
   static void set_interface (Grob*);
   static bool has_interface (Grob*);
+  static void set_direction (Grob*);
   static Grob * head (Grob*,Direction) ;
   static Real get_position (Grob*) ;
   DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM ));
index 0f43e88515b00b155af51ac722d08c9d97dc3e40..0b76bbb362e4e6cb54b39f689fece523a8e22486 100644 (file)
 void
 Tie_column::add_tie (Grob*me,Grob *s)
 {
-  if (!  Pointer_group_interface ::count (me, "ties"))
+  if (s->get_parent (Y_AXIS)
+      && Tie_column::has_interface (s->get_parent (Y_AXIS)))
+    return ;
+  
+  if (!  Pointer_group_interface::count (me, "ties"))
     {
       dynamic_cast<Spanner*> (me)->set_bound (LEFT, Tie::head (s,LEFT));
       dynamic_cast<Spanner*> (me)->set_bound (RIGHT, Tie::head (s,RIGHT));
     }
-  
+  s->set_parent (me, Y_AXIS);
   Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), s);
   s->add_dependency (me);
 }
 
 
+void
+Tie_column::set_directions (Grob*me)
+{
+  werner_directions (me);
+}
+  
+
+
 int
 tie_compare (Grob* const & s1,
             Grob* const & s2)
@@ -54,7 +66,7 @@ tie_compare (Grob* const & s1,
   Ross forgets about the tie that is *on* the middle staff line. We
   assume it goes UP. (TODO: make me settable) */
 void
-Tie_column::set_directions (Grob*me)
+Tie_column::old_directions (Grob*me)
 {
   Link_array<Grob> ties =
     Pointer_group_interface__extract_grobs (me, (Grob*)0, "ties");
@@ -103,11 +115,88 @@ Tie_column::set_directions (Grob*me)
   
 }
 
+/*
+  
+% . 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)
+{
+  Link_array<Grob> ties =
+    Pointer_group_interface__extract_grobs (me, (Grob*)0, "ties");
+
+  if (!ties.size ())
+    return ;
+  
+  ties.sort (tie_compare);
+
+  Direction d = get_grob_direction (me);
+  if (d)
+    {
+      for (int i = ties.size (); i--;)
+       {
+         Grob *  t = ties[i];
+         if (!get_grob_direction (t))
+           set_grob_direction (t, d);
+       }
+      return ;
+    }
+  
+  if (ties.size () == 1)
+    {
+      Grob *  t = ties[0];      
+      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);
+  
+  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_down_pos - p  > 5)
+           {
+             d = UP;
+           }
+         else
+           {
+             d = DOWN;
+           }
+
+         set_grob_direction (t, d);
+       }
+
+      if (d == DOWN)
+       last_down_pos = p;
+    }
+
+  return ;
+}
+
+
 MAKE_SCHEME_CALLBACK (Tie_column,after_line_breaking,1);
 SCM
 Tie_column::after_line_breaking (SCM smob)
 {
-  set_directions (unsmob_grob (smob));
+  werner_directions (unsmob_grob (smob));
   return SCM_UNSPECIFIED;
 }
 
index cdc2bf0fb3a6bc40c205c0cceff26f8ed521265d..b3da14d39a5314013d540e3de02d0e9715b14231 100644 (file)
@@ -53,7 +53,6 @@ protected:
   virtual void acknowledge_grob (Grob_info);
   virtual bool try_music (Music*);
   virtual void process_music ();
-  virtual void process_acknowledged_grobs ();
   void typeset_tie (Grob*);
 public:
   TRANSLATOR_DECLARATIONS(Tie_engraver);
@@ -117,20 +116,16 @@ Tie_engraver::acknowledge_grob (Grob_info i)
              announce_grob(p, last_event_->self_scm());
            }
        }
-    }
-}
 
-void
-Tie_engraver::process_acknowledged_grobs ()
-{
-  if (ties_.size () > 1 && !tie_column_)
-    {
-      tie_column_ = new Spanner (get_property ("TieColumn"));
-      
-      for (int i = ties_.size (); i--;)
-       Tie_column::add_tie (tie_column_,ties_ [i]);
+      if (ties_.size () && ! tie_column_)
+       {
+         tie_column_ = new Spanner (get_property ("TieColumn"));
+         announce_grob(tie_column_, SCM_EOL);
+       }
 
-      announce_grob(tie_column_, SCM_EOL);
+      if (tie_column_)
+       for (int i = ties_.size (); i--;)
+         Tie_column::add_tie (tie_column_,ties_ [i]);
     }
 }
 
index 85d838f02d19a5684e512b519df66a0051d52866..bd569c4f87b68cb5880fed8c0fbc56af57f1e5e8 100644 (file)
@@ -22,6 +22,7 @@
 #include "bezier-bow.hh"
 #include "stem.hh"
 #include "note-head.hh"
+#include "tie-column.hh"
 
 /*
   tie: Connect two noteheads.
@@ -102,6 +103,19 @@ Tie::get_default_dir (Grob*me)
   return UP;
 }
 
+
+void
+Tie::set_direction (Grob*me)
+{
+  if (!get_grob_direction (me))
+    {
+      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));
+    }
+}
+
 /*
   TODO: we should also use thickness for computing the clearance
   between head and tie. Very thick ties will now touch the note head.
@@ -123,9 +137,8 @@ Tie::get_control_points (SCM smob)
       return SCM_UNSPECIFIED;
     }
 
-  
-  if (!get_grob_direction (me))
-    set_grob_direction (me, Tie::get_default_dir (me));
+  set_direction (me);
+
   Direction dir = get_grob_direction (me);
   
   Real staff_space = Staff_symbol_referencer::staff_space (me);
index d963bf5a7c2e0d6b0559a9a17b83ca343fa05acf..f9d50fdf775c1068430d441885ea432ea7b38e55 100644 (file)
     (TieColumn
      . (
        (after-line-breaking-callback . ,Tie_column::after_line_breaking)
-       (X-extent-callback . ())
-       (Yoo-extent-callback . ())      
+       (X-extent-callback . #f)
+       (Y-extent-callback . #f)        
        (meta . ((interfaces . (tie-column-interface spanner-interface))))
        ))