]> git.donarmstrong.com Git - lilypond.git/commitdiff
collision note head merge
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 19 May 2002 10:37:05 +0000 (10:37 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 19 May 2002 10:37:05 +0000 (10:37 +0000)
19 files changed:
ChangeLog
Documentation/regression-test.tely
Documentation/user/refman.itely
input/regression/collision-heads.ly [new file with mode: 0644]
lily/accidental-placement.cc
lily/collision-engraver.cc
lily/collision.cc [deleted file]
lily/include/collision.hh [deleted file]
lily/include/note-collision.hh [new file with mode: 0644]
lily/include/note-head.hh
lily/include/rhythmic-head.hh
lily/mensural-ligature-engraver.cc
lily/note-collision.cc [new file with mode: 0644]
lily/note-head.cc
lily/rest-collision-engraver.cc
lily/rhythmic-head.cc
lily/stem.cc
scm/grob-property-description.scm
scripts/lilypond-book.py

index 4c62d7d994980974446d760d8b478a88446ae243..887100f5b1c3e06b273027ca98d57e128e2bed5e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2002-05-19  Han-Wen  <hanwen@cs.uu.nl>
+
+       * lily/note-collision.cc (check_meshing_chords): move file from
+       collision.cc, implement merged note heads (there you go, Drarn :-)
+
+       * input/regression/collision-heads.ly: new file
+
 2002-05-18  Juergen Reuter  <reuter@ipd.uka.de>
 
        * mf/parmesan-heads.mf, scm/grob-description.scm,
index a546114a64b55191772d940a45ae7de777a34bb2..775d1df6a5f7eff575c56c5acea2d788a20fded3 100644 (file)
@@ -248,6 +248,8 @@ Grace note do weird things with timing. Fragile.
 
 @lilypondfile[printfilename]{collision-dots.ly}
 
+@lilypondfile[printfilename]{collision-heads.ly}
+
 @lilypondfile[printfilename]{collision-mesh.ly}
 
 @lilypondfile[printfilename]{number-staff-lines.ly}
index ea6a73ff374a189b946192e262c34335ec2cfdf2..b0baf887d70b15a243f94ceb38e73b98378e0f39 100644 (file)
@@ -1458,7 +1458,7 @@ Unbeamed eighth notes and shorter by default have a slash through the
 stem.
 
 @lilypond[fragment,verbatim]
-\relative c'' {
+\relative c'' \context Voice {
   \grace c8 c4 \grace { [c16 c16] } c4
   \grace { 
     \property Voice.Stem \override #'flag-style = #'() 
diff --git a/input/regression/collision-heads.ly b/input/regression/collision-heads.ly
new file mode 100644 (file)
index 0000000..04ef2f7
--- /dev/null
@@ -0,0 +1,29 @@
+\header {
+    texidoc =
+
+    "If @code{merge-differently-headed}, then
+open note heads may be merged with black noteheads, but only
+if the black note heads are from 8th or shorter notes.
+"
+    
+}
+\score { \notes \context Staff\relative c''<
+\context Voice = VA {
+    \voiceOne
+    c2 c8 c4.
+    
+    \property Staff.NoteCollision \override #'merge-differently-headed = ##t
+    c2
+    c4. c8
+    c2
+}
+\context Voice = VB {
+    \voiceTwo
+    c8 c4.
+    c2
+    c8 c4.
+    c2
+    c4
+}
+    >
+        }
index f4576cb02257b3a6c26aabf76c099a79067ce824..edefc20fb221a5584c580ba5406a3c95b138d0b3 100644 (file)
@@ -17,7 +17,7 @@ source file of the GNU LilyPond music typesetter
 #include "accidental-placement.hh"
 #include "note-column.hh"
 #include "group-interface.hh"
-#include "collision.hh"
+#include "note-collision.hh"
 
 MAKE_SCHEME_CALLBACK(Accidental_placement,extent_callback, 2);
 SCM
@@ -206,7 +206,7 @@ Accidental_placement::position_accidentals (Grob * me)
   for (int i = note_cols.size() ; i--;)
     {
       Grob *c = note_cols[i]->get_parent (X_AXIS);
-      if (Collision::has_interface (c))
+      if (Note_collision_interface::has_interface (c))
        {
          Link_array<Grob> gs =
            Pointer_group_interface__extract_grobs (c, (Grob*)0, "elements");
index 2b8c4923feb5b6e67558a054386bbfc2d817b1a1..8e8c0f4fa0b0cacba474295c2efe841da630d1d3 100644 (file)
@@ -7,7 +7,7 @@
 */
 
 #include "note-column.hh"
-#include "collision.hh"
+#include "note-collision.hh"
 
 #include "engraver.hh"
 #include "axis-group-interface.hh"
@@ -40,7 +40,7 @@ Collision_engraver::create_grobs ()
     }
   
   for (int i=0; i< note_column_l_arr_.size (); i++)
-    Collision::add_column (col_p_,note_column_l_arr_[i]);
+    Note_collision_interface::add_column (col_p_,note_column_l_arr_[i]);
 }
 
 void
diff --git a/lily/collision.cc b/lily/collision.cc
deleted file mode 100644 (file)
index ee4b039..0000000
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
-  collision.cc -- implement Collision
-
-  source file of the GNU LilyPond music typesetter
-
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
-
-#include "debug.hh"
-#include "collision.hh"
-#include "note-column.hh"
-#include "rhythmic-head.hh"
-#include "paper-def.hh"
-#include "axis-group-interface.hh"
-#include "item.hh"
-#include "stem.hh"
-
-MAKE_SCHEME_CALLBACK (Collision,force_shift_callback,2);
-
-SCM
-Collision::force_shift_callback (SCM element_smob, SCM axis)
-{
-  Grob *me = unsmob_grob (element_smob);
-  Axis a = (Axis) gh_scm2int (axis);
-  assert (a == X_AXIS);
-  
-   me = me->get_parent (a);
-
-   if (! to_boolean (me->get_grob_property ("collision-done")))
-    {
-      me->set_grob_property ("collision-done", SCM_BOOL_T);
-      do_shifts (me);
-    }
-  
-  return gh_double2scm (0.0);
-}
-
-
-void
-check_meshing_chords (Grob*me,
-                     Drul_array< Array < Real > > *offsets,
-                     Drul_array< Array < Slice > > const &extents,
-                     Drul_array<Link_array<Grob> > const &clash_groups)
-       
-{
-  if (!extents[UP].size () || ! extents[DOWN].size ())
-    return ;
-  
-  
-  Grob *cu =clash_groups[UP][0];
-  Grob *cd =clash_groups[DOWN][0];
-
-  Grob * nu_l= Note_column::first_head (cu);
-  Grob * nd_l = Note_column::first_head (cd);
-      
-     
-
-  /*
-    this case (distant half collide), 
-    
-        |
-      x |
-     | x
-     |
-
-   the noteheads may be closer than this case (close half collide)
-
-       |
-       |
-      x 
-     x
-    |
-    |
-    
-   */
-  
-  bool close_half_collide = false;
-  bool distant_half_collide = false;  
-  bool full_collide = false;  
-
-  /*
-    TODO:
-
-    filter out the 'o's in this configuration, since they're no part
-    in the collision.
-
-     |
-    x|o
-    x|o
-    x
-
-    
-   */
-  Array<int> ups = Stem::note_head_positions (Note_column::stem_l (cu));
-  Array<int> dps = Stem::note_head_positions (Note_column::stem_l (cd));
-
-  /*
-    they're too far apart to collide. 
-    
-   */
-
-  if (ups[0] > dps.top () + 1)
-    return ; 
-
-  bool touch = (ups[0] - dps.top () >= 0);
-  
-  bool merge_possible = (ups[0] >= dps[0]) && (ups.top () >= dps.top ());
-
-  merge_possible = merge_possible &&
-    Rhythmic_head::balltype_i (nu_l) == Rhythmic_head::balltype_i (nd_l);
-
-
-  /*
-    don't merge whole notes (or longer, like breve, longa, maxima) 
-   */
-  merge_possible = merge_possible && (Rhythmic_head::balltype_i (nu_l) > 0);
-
-  if (!to_boolean (me->get_grob_property ("merge-differently-dotted")))
-    merge_possible = merge_possible && Rhythmic_head::dot_count (nu_l) == Rhythmic_head::dot_count (nd_l);
-  
-  int i = 0, j=0;
-  while (i < ups.size () && j < dps.size ())
-  {
-    if (abs (ups[i] - dps[j]) == 1)
-      {
-       merge_possible = false;
-       if (ups[i] > dps[j])
-         close_half_collide = true;
-       else
-         distant_half_collide = true;
-      }
-    else if (ups[i]==dps[j])
-      full_collide = true;
-    else if (ups[i] >dps[0] && ups[i] < dps.top ())
-      merge_possible = false;
-    else if (dps[j] >ups[0] && dps[j] < ups.top ())
-      merge_possible = false;
-    
-    if (ups[i] < dps[j])
-      i++;
-    else if (ups[i] > dps[j])
-      j++;
-    else
-      {
-       i++;
-       j++;
-      }
-  }
-
-  Drul_array<Real> center_note_shifts;
-  center_note_shifts[LEFT] = 0.0;
-  center_note_shifts[RIGHT] = 0.0;
-
-  
-  Real shift_amount = 1;
-
-  if (touch)
-    shift_amount *= -1;
-
-  /*
-    for full collisions, the right hand head may obscure dots, so
-    make sure the dotted heads go to the right.
-   */
-  if ((Rhythmic_head::dot_count (nu_l) > Rhythmic_head::dot_count (nd_l)
-       && full_collide))
-    shift_amount = 1;
-
-  /*
-    TODO: these numbers are magic; should devise a set of grob props
-    to tune this behavior.  */
-  
-  if (merge_possible)
-    shift_amount *= 0.0;
-  else if (close_half_collide && !touch)
-    shift_amount *= 0.52;
-  else if (distant_half_collide && !touch)
-    shift_amount *= 0.4;
-  else if (distant_half_collide || close_half_collide || full_collide)
-    shift_amount *= 0.5;
-  
-  /*
-    we're meshing.
-  */
-  else if (Rhythmic_head::dot_count (nu_l) || Rhythmic_head::dot_count (nd_l))
-    shift_amount *= 0.1;
-  else
-    shift_amount *= 0.25;
-
-  Direction d = UP;
-  do
-    {
-      for (int i=0; i < clash_groups[d].size (); i++)
-       (*offsets)[d][i] += d * shift_amount;
-    }
-  while ((flip (&d))!= UP);
-}
-
-
-/*
-  TODO: make callback of this.
-
-  TODO:
-
-  note-width is hardcoded, making it difficult to handle all note
-  heads sanely. We should really look at the widths of the colliding
-  columns, and have a separate setting for "align stems".
-
-  
- */
-void
-Collision::do_shifts (Grob* me)
-{
-  SCM autos (automatic_shift (me));
-  SCM hand (forced_shift (me));
-  
-  Link_array<Grob> done;
-
-
-  Real wid
-    = gh_scm2double (me->get_grob_property ("note-width"));
-  
-  for (; gh_pair_p (hand); hand =ly_cdr (hand))
-    {
-      Grob * s = unsmob_grob (ly_caar (hand));
-      Real amount = gh_scm2double (ly_cdar (hand));
-      
-      s->translate_axis (amount *wid, X_AXIS);
-      done.push (s);
-    }
-  for (; gh_pair_p (autos); autos =ly_cdr (autos))
-    {
-      Grob * s = unsmob_grob (ly_caar (autos));
-      Real amount = gh_scm2double (ly_cdar (autos));
-      
-      if (!done.find_l (s))
-       s->translate_axis (amount * wid, X_AXIS);
-    }
-}
-
-/** This complicated routine moves note columns around horizontally to
-  ensure that notes don't clash.
-
-  This should be put into Scheme.  
-  */
-SCM
-Collision::automatic_shift (Grob *me)
-{
-  Drul_array<Link_array<Grob> > clash_groups;
-  Drul_array<Array<int> > shifts;
-  SCM  tups = SCM_EOL;
-
-  SCM s = me->get_grob_property ("elements");
-  for (; gh_pair_p (s); s = ly_cdr (s))
-    {
-      SCM car = ly_car (s);
-
-      Grob * se = unsmob_grob (car);
-      if (Note_column::has_interface (se))
-       clash_groups[Note_column::dir (se)].push (se);
-    }
-
-  
-  Direction d = UP;
-  do
-    {
-      Array<int> & shift (shifts[d]);
-      Link_array<Grob> & clashes (clash_groups[d]);
-
-      clashes.sort (Note_column::shift_compare);
-
-      for (int i=0; i < clashes.size (); i++)
-       {
-         SCM sh
-           = clashes[i]->get_grob_property ("horizontal-shift");
-
-         if (gh_number_p (sh))
-           shift.push (gh_scm2int (sh));
-         else
-           shift.push (0);
-       }
-      
-      for (int i=1; i < shift.size (); i++)
-       {
-         if (shift[i-1] == shift[i])
-           {
-             me->warning (_ ("Too many clashing notecolumns.  Ignoring them."));
-             return tups;
-           }
-       }
-    }
-  while ((flip (&d))!= UP);
-
-  Drul_array< Array < Slice > > extents;
-  Drul_array< Array < Real > > offsets;
-  d = UP;
-  do
-    {
-      for (int i=0; i < clash_groups[d].size (); i++)
-       {
-         Slice s (Note_column::head_positions_interval (clash_groups[d][i]));
-         s[LEFT] --;
-         s[RIGHT]++;
-         extents[d].push (s);
-         offsets[d].push (d * 0.5 * i);
-       }
-    }
-  while ((flip (&d))!= UP);
-
-  /*
-    do horizontal shifts of each direction 
-
-       | 
-      x||
-       x||
-        x|
-   */
-  
-  do
-    {
-      for (int i=1; i < clash_groups[d].size (); i++)
-       {
-         Slice prev =extents[d][i-1];
-         prev.intersect (extents[d][i]);
-         if (prev.length ()> 0 ||
- (extents[-d].size () && d * (extents[d][i][-d] - extents[-d][0][d]) < 0))
-           for (int j = i; j <  clash_groups[d].size (); j++)
-             offsets[d][j] += d * 0.5;
-       }
-    }  
-  while ((flip (&d))!= UP);
-
-
-  /*
-    Check if chords are meshing
-   */
-
-  check_meshing_chords (me, &offsets, extents, clash_groups);
-  
-  do
-    {
-      for (int i=0; i < clash_groups[d].size (); i++)
-       tups = gh_cons (gh_cons (clash_groups[d][i]->self_scm (), gh_double2scm (offsets[d][i])),
-                                tups);
-    }
-  while (flip (&d) != UP);
-  return tups;
-}
-
-
-SCM
-Collision::forced_shift (Grob *me)
-{
-  SCM tups = SCM_EOL;
-  
-  SCM s = me->get_grob_property ("elements");
-  for (; gh_pair_p (s); s = ly_cdr (s))
-    {
-      Grob * se = unsmob_grob (ly_car (s));
-
-      SCM force =  se->remove_grob_property ("force-hshift");
-      if (gh_number_p (force))
-       {
-         tups = gh_cons (gh_cons (se->self_scm (), force),
-                         tups);
-       }
-    }
-  return tups;
-}
-
-void
-Collision::add_column (Grob*me,Grob* ncol_l)
-{
-  ncol_l->add_offset_callback (Collision::force_shift_callback_proc, X_AXIS);
-  Axis_group_interface::add_element (me, ncol_l);
-  me->add_dependency (ncol_l);
-}
-
-
-ADD_INTERFACE (Collision, "note-collision-interface",
-  "An object that handles collisions between notes with different
-stem directions and horizontal shifts. Most of the interesting
-properties are to be set in @ref{note-column-interface}",
-  "merge-differently-dotted note-width collision-done");
diff --git a/lily/include/collision.hh b/lily/include/collision.hh
deleted file mode 100644 (file)
index 5704ca9..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-  collision.hh -- declare Collision
-
-  source file of the GNU LilyPond music typesetter
-
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
-
-
-#ifndef COLLISION_HH
-#define COLLISION_HH
-
-#include "lily-proto.hh"
-#include "lily-guile.hh"
-
-
-/**
-  Resolve conflicts between various Note_columns (chords).
-  
-  TODO 
-
-  * multistaff support (see Chlapik: equal noteheads should be on the
-  same hpos.)  
-
-  * Make interface of this, similar to align-interface.
-  
-*/
-class Collision                        // interface
-{
-public:
-  static SCM automatic_shift (Grob*);
-  static SCM forced_shift (Grob*);
-  DECLARE_SCHEME_CALLBACK (force_shift_callback, (SCM element, SCM axis));
-  static void do_shifts (Grob*);
-  static void add_column (Grob*me,Grob*ncol_l);
-  static bool has_interface(Grob*);
-};
-#endif // COLLISION_HH
diff --git a/lily/include/note-collision.hh b/lily/include/note-collision.hh
new file mode 100644 (file)
index 0000000..e8674d9
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  collision.hh -- declare Collision
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+
+#ifndef COLLISION_HH
+#define COLLISION_HH
+
+#include "lily-proto.hh"
+#include "lily-guile.hh"
+
+
+/**
+  Resolve conflicts between various Note_columns (chords).
+  
+  TODO 
+
+  * multistaff support (see Chlapik: equal noteheads should be on the
+  same hpos.)  
+
+  * Make interface of this, similar to align-interface.
+  
+*/
+class Note_collision_interface
+{
+public:
+  static SCM automatic_shift (Grob*, Drul_array< Link_array <Grob>  >);
+  static SCM forced_shift (Grob*);
+  
+  static Drul_array< Link_array <Grob>  > get_clash_groups (Grob *me);
+  DECLARE_SCHEME_CALLBACK (force_shift_callback, (SCM element, SCM axis));
+  static void do_shifts (Grob*);
+  static void add_column (Grob*me,Grob*ncol_l);
+  static bool has_interface(Grob*);
+};
+#endif // COLLISION_HH
index 55a9aa0b5aaef3e8ee9e2e19f9899001342ae79a..aba379dec6ec4bf19643b939e9ef6a2dcc880336 100644 (file)
@@ -27,7 +27,7 @@ public:
   DECLARE_SCHEME_CALLBACK (brew_ez_molecule, (SCM ));
   static bool has_interface (Grob*);
   static Real stem_attachment_coordinate (Grob *, Axis a);
-  
+  static int balltype_i (Grob*) ;  
 };
 #endif // NOTEHEAD_HH
 
index af4af02ae8838d906996470fe433ac1bc3748626..1da23356b1bad40f313916e71a1681bffa2ddd99 100644 (file)
@@ -16,7 +16,7 @@
 class Rhythmic_head
 {
 public:
-  static int balltype_i (Grob*) ;
+  static int duration_log (Grob*);
   static void set_dots (Grob*,Item *);
   static Item * stem_l (Grob*) ;
   static Item * dots_l (Grob*) ;
index 9adb710d8f45fce3fa46daea86cbf61d2afccd32..9be0e8a0cfc48d43ee4aff2f3b3568a4e6d82f26 100644 (file)
@@ -340,7 +340,7 @@ Mensural_ligature_engraver::transform_heads ()
     have_last_pitch = have_pitch;
     Grob_info info = primitives_arr_[i];
     int duration_log =
-      Rhythmic_head::balltype_i (dynamic_cast<Item*> (info.grob_l_));
+      Note_head::balltype_i (dynamic_cast<Item*> (info.grob_l_));
     Note_req *nr = dynamic_cast<Note_req*> (info.music_cause ());
     if (!nr)
       {
diff --git a/lily/note-collision.cc b/lily/note-collision.cc
new file mode 100644 (file)
index 0000000..fa977fd
--- /dev/null
@@ -0,0 +1,431 @@
+
+/*
+  collision.cc -- implement Collision
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+#include "debug.hh"
+#include "note-collision.hh"
+#include "note-column.hh"
+#include "note-head.hh"
+#include "rhythmic-head.hh"
+#include "paper-def.hh"
+#include "axis-group-interface.hh"
+#include "item.hh"
+#include "stem.hh"
+
+MAKE_SCHEME_CALLBACK (Note_collision_interface,force_shift_callback,2);
+
+SCM
+Note_collision_interface::force_shift_callback (SCM element_smob, SCM axis)
+{
+  Grob *me = unsmob_grob (element_smob);
+  Axis a = (Axis) gh_scm2int (axis);
+  assert (a == X_AXIS);
+  
+   me = me->get_parent (a);
+
+   if (! to_boolean (me->get_grob_property ("collision-done")))
+    {
+      me->set_grob_property ("collision-done", SCM_BOOL_T);
+      do_shifts (me);
+    }
+  
+  return gh_double2scm (0.0);
+}
+
+
+void
+check_meshing_chords (Grob*me,
+                     Drul_array< Array < Real > > *offsets,
+                     Drul_array< Array < Slice > > const &extents,
+                     Drul_array<Link_array<Grob> > const &clash_groups)
+       
+{
+  if (!extents[UP].size () || ! extents[DOWN].size ())
+    return ;
+  
+  
+  Grob *cu =clash_groups[UP][0];
+  Grob *cd =clash_groups[DOWN][0];
+
+  Grob * nu_l= Note_column::first_head (cu);
+  Grob * nd_l = Note_column::first_head (cd);
+      
+     
+
+  /*
+    this case (distant half collide), 
+    
+        |
+      x |
+     | x
+     |
+
+   the noteheads may be closer than this case (close half collide)
+
+       |
+       |
+      x 
+     x
+    |
+    |
+    
+   */
+  
+  bool close_half_collide = false;
+  bool distant_half_collide = false;  
+  bool full_collide = false;  
+
+  /*
+    TODO:
+
+    filter out the 'o's in this configuration, since they're no part
+    in the collision.
+
+     |
+    x|o
+    x|o
+    x
+
+    
+   */
+  Array<int> ups = Stem::note_head_positions (Note_column::stem_l (cu));
+  Array<int> dps = Stem::note_head_positions (Note_column::stem_l (cd));
+
+  /*
+    they're too far apart to collide. 
+    
+   */
+
+  if (ups[0] > dps.top () + 1)
+    return ; 
+
+  bool touch = (ups[0] - dps.top () >= 0);
+  
+  bool merge_possible = (ups[0] >= dps[0]) && (ups.top () >= dps.top ());
+
+  /*
+    don't merge whole notes (or longer, like breve, longa, maxima) 
+   */
+
+  int upball_type = Note_head::balltype_i (nu_l);
+  int dnball_type = Note_head::balltype_i (nd_l);
+  
+  merge_possible = merge_possible && (upball_type > 0);
+
+  if (!to_boolean (me->get_grob_property ("merge-differently-dotted")))
+    merge_possible = merge_possible && Rhythmic_head::dot_count (nu_l) == Rhythmic_head::dot_count (nd_l);
+
+  
+  if (!to_boolean (me->get_grob_property ("merge-differently-headed")))
+    merge_possible = merge_possible &&
+      upball_type == dnball_type;
+  else
+    /*
+      Can't merge quarter and half notes.
+     */
+    merge_possible = merge_possible &&
+      !((Rhythmic_head::duration_log (nu_l) == 1
+        && Rhythmic_head::duration_log (nd_l) == 2)
+       ||(Rhythmic_head::duration_log (nu_l) == 2
+          && Rhythmic_head::duration_log (nd_l) == 1));
+
+  int i = 0, j=0;
+  while (i < ups.size () && j < dps.size ())
+  {
+    if (abs (ups[i] - dps[j]) == 1)
+      {
+       merge_possible = false;
+       if (ups[i] > dps[j])
+         close_half_collide = true;
+       else
+         distant_half_collide = true;
+      }
+    else if (ups[i]==dps[j])
+      full_collide = true;
+    else if (ups[i] >dps[0] && ups[i] < dps.top ())
+      merge_possible = false;
+    else if (dps[j] >ups[0] && dps[j] < ups.top ())
+      merge_possible = false;
+    
+    if (ups[i] < dps[j])
+      i++;
+    else if (ups[i] > dps[j])
+      j++;
+    else
+      {
+       i++;
+       j++;
+      }
+  }
+
+  Drul_array<Real> center_note_shifts;
+  center_note_shifts[LEFT] = 0.0;
+  center_note_shifts[RIGHT] = 0.0;
+
+  
+  Real shift_amount = 1;
+
+  if (touch)
+    shift_amount *= -1;
+
+  /*
+    for full collisions, the right hand head may obscure dots, so
+    make sure the dotted heads go to the right.
+   */
+  if ((Rhythmic_head::dot_count (nu_l) > Rhythmic_head::dot_count (nd_l)
+       && full_collide))
+    shift_amount = 1;
+
+  /*
+    TODO: these numbers are magic; should devise a set of grob props
+    to tune this behavior.  */
+  
+  if (merge_possible)
+    {
+      shift_amount *= 0.0;
+      Grob *wipe_ball = 0;
+      
+      if (upball_type  <  dnball_type)
+       wipe_ball = nd_l;
+      else if (upball_type > dnball_type)
+       wipe_ball = nu_l;
+
+      if (wipe_ball)
+       {
+         wipe_ball->set_grob_property ("transparent", SCM_BOOL_T);
+         wipe_ball->set_grob_property ("molecule", SCM_EOL);     
+       }
+    }
+  else if (close_half_collide && !touch)
+    shift_amount *= 0.52;
+  else if (distant_half_collide && !touch)
+    shift_amount *= 0.4;
+  else if (distant_half_collide || close_half_collide || full_collide)
+    shift_amount *= 0.5;
+  
+  /*
+    we're meshing.
+  */
+  else if (Rhythmic_head::dot_count (nu_l) || Rhythmic_head::dot_count (nd_l))
+    shift_amount *= 0.1;
+  else
+    shift_amount *= 0.25;
+
+  Direction d = UP;
+  do
+    {
+      for (int i=0; i < clash_groups[d].size (); i++)
+       (*offsets)[d][i] += d * shift_amount;
+    }
+  while ((flip (&d))!= UP);
+}
+
+void
+Note_collision_interface::do_shifts (Grob* me)
+{
+  Drul_array< Link_array <Grob>  > cg = get_clash_groups (me);
+
+  SCM autos (automatic_shift (me, cg));
+  SCM hand (forced_shift (me));
+
+  
+  
+  Direction d = UP;
+  Real wid = 0.0;
+  do
+    {
+      if(cg[d].size())
+       {
+         Grob  *h = cg[d][0];
+         wid = Note_column::first_head(h)->extent(h,X_AXIS).length() ;
+       }
+    }
+  
+  while (flip (&d) != UP);
+
+  
+  Link_array<Grob> done;
+  for (; gh_pair_p (hand); hand =ly_cdr (hand))
+    {
+      Grob * s = unsmob_grob (ly_caar (hand));
+      Real amount = gh_scm2double (ly_cdar (hand));
+      
+      s->translate_axis (amount *wid, X_AXIS);
+      done.push (s);
+    }
+  for (; gh_pair_p (autos); autos =ly_cdr (autos))
+    {
+      Grob * s = unsmob_grob (ly_caar (autos));
+      Real amount = gh_scm2double (ly_cdar (autos));
+      
+      if (!done.find_l (s))
+       s->translate_axis (amount * wid, X_AXIS);
+    }
+}
+
+Drul_array< Link_array <Grob>  >
+Note_collision_interface::get_clash_groups (Grob *me)
+{
+  Drul_array<Link_array<Grob> > clash_groups;
+  SCM s = me->get_grob_property ("elements");
+  for (; gh_pair_p (s); s = ly_cdr (s))
+    {
+      SCM car = ly_car (s);
+
+      Grob * se = unsmob_grob (car);
+      if (Note_column::has_interface (se))
+       clash_groups[Note_column::dir (se)].push (se);
+    }
+  
+  Direction d = UP;
+  do
+    {
+      Link_array<Grob> & clashes (clash_groups[d]);
+      clashes.sort (Note_column::shift_compare);
+    }
+  while ((flip (&d))!= UP);
+
+  return clash_groups;
+}
+
+/** This complicated routine moves note columns around horizontally to
+  ensure that notes don't clash.
+
+  This should be put into Scheme.  
+  */
+SCM
+Note_collision_interface::automatic_shift (Grob *me,
+                           Drul_array< Link_array <Grob> > 
+                           clash_groups)
+{
+  Drul_array<Array<int> > shifts;
+  SCM  tups = SCM_EOL;
+
+  
+  Direction d = UP;
+  do
+    {
+      Array<int> & shift (shifts[d]);
+      Link_array<Grob> & clashes (clash_groups[d]);
+
+      for (int i=0; i < clashes.size (); i++)
+       {
+         SCM sh
+           = clashes[i]->get_grob_property ("horizontal-shift");
+
+         if (gh_number_p (sh))
+           shift.push (gh_scm2int (sh));
+         else
+           shift.push (0);
+       }
+      
+      for (int i=1; i < shift.size (); i++)
+       {
+         if (shift[i-1] == shift[i])
+           {
+             me->warning (_ ("Too many clashing notecolumns.  Ignoring them."));
+             return tups;
+           }
+       }
+    }
+  while ((flip (&d))!= UP);
+
+  Drul_array< Array < Slice > > extents;
+  Drul_array< Array < Real > > offsets;
+  d = UP;
+  do
+    {
+      for (int i=0; i < clash_groups[d].size (); i++)
+       {
+         Slice s (Note_column::head_positions_interval (clash_groups[d][i]));
+         s[LEFT] --;
+         s[RIGHT]++;
+         extents[d].push (s);
+         offsets[d].push (d * 0.5 * i);
+       }
+    }
+  while ((flip (&d))!= UP);
+
+  /*
+    do horizontal shifts of each direction 
+
+       | 
+      x||
+       x||
+        x|
+   */
+  
+  do
+    {
+      for (int i=1; i < clash_groups[d].size (); i++)
+       {
+         Slice prev =extents[d][i-1];
+         prev.intersect (extents[d][i]);
+         if (prev.length ()> 0 ||
+ (extents[-d].size () && d * (extents[d][i][-d] - extents[-d][0][d]) < 0))
+           for (int j = i; j <  clash_groups[d].size (); j++)
+             offsets[d][j] += d * 0.5;
+       }
+    }  
+  while ((flip (&d))!= UP);
+
+
+  /*
+    Check if chords are meshing
+   */
+
+  check_meshing_chords (me, &offsets, extents, clash_groups);
+  
+  do
+    {
+      for (int i=0; i < clash_groups[d].size (); i++)
+       tups = gh_cons (gh_cons (clash_groups[d][i]->self_scm (), gh_double2scm (offsets[d][i])),
+                                tups);
+    }
+  while (flip (&d) != UP);
+  return tups;
+}
+
+
+SCM
+Note_collision_interface::forced_shift (Grob *me)
+{
+  SCM tups = SCM_EOL;
+  
+  SCM s = me->get_grob_property ("elements");
+  for (; gh_pair_p (s); s = ly_cdr (s))
+    {
+      Grob * se = unsmob_grob (ly_car (s));
+
+      SCM force =  se->remove_grob_property ("force-hshift");
+      if (gh_number_p (force))
+       {
+         tups = gh_cons (gh_cons (se->self_scm (), force),
+                         tups);
+       }
+    }
+  return tups;
+}
+
+void
+Note_collision_interface::add_column (Grob*me,Grob* ncol_l)
+{
+  ncol_l->add_offset_callback (Note_collision_interface::force_shift_callback_proc, X_AXIS);
+  Axis_group_interface::add_element (me, ncol_l);
+  me->add_dependency (ncol_l);
+}
+
+
+ADD_INTERFACE (Note_collision_interface, "note-collision-interface",
+  "An object that handles collisions between notes with different stem
+directions and horizontal shifts. Most of the interesting properties
+are to be set in @ref{note-column-interface}: these are
+@code{force-hshift} and @{horizontal-shift}.
+",
+  "merge-differently-dotted merge-differently-headed collision-done");
index 01ecae6a330d3cfd4733bf67243e8598c35a3b1c..1967691f0e2247424072ea50b570e3691cae8b49 100644 (file)
@@ -121,7 +121,7 @@ internal_brew_molecule (Grob *me,  bool ledger_take_space)
 
     UGH: use grob-property.
   */
-  SCM log = gh_int2scm (Rhythmic_head::balltype_i (me));
+  SCM log = gh_int2scm (Note_head::balltype_i (me));
   SCM exp = scm_list_n (ly_symbol2scm ("find-notehead-symbol"), log,
                        ly_quote_scm (style),
                        SCM_UNDEFINED);
@@ -191,7 +191,7 @@ SCM
 Note_head::brew_ez_molecule (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
-  int l = Rhythmic_head::balltype_i (me);
+  int l = Note_head::balltype_i (me);
 
   int b = (l >= 2);
 
@@ -246,6 +246,15 @@ Note_head::stem_attachment_coordinate (Grob *me, Axis a)
   return gh_number_p (result) ?  gh_scm2double (result) : 0.0;
 }
 
+
+int
+Note_head::balltype_i (Grob*me) 
+{
+  SCM s = me->get_grob_property ("duration-log");
+  return gh_number_p (s) ? gh_scm2int (s) <? 2 : 0;
+}
+
 ADD_INTERFACE (Note_head,"note-head-interface",
   "Note head",
   "accidental-grob style stem-attachment-function");
+
index 339540123bca9c16a52483b17b8c1220f1be5db3..de2985c37cab13ccf5c8bf59d83198e592169447 100644 (file)
@@ -9,7 +9,7 @@
 #include "debug.hh"
 #include "rest-collision.hh"
 #include "engraver.hh"
-#include "collision.hh"
+#include "note-collision.hh"
 #include "note-column.hh"
 
 class Rest_collision_engraver : public Engraver
index b9bf752f71c5a50a0371df10b1912972aba055ce..9f6b18ca1ccfb82e8bd1a8884551f7b50ec9af22 100644 (file)
@@ -21,13 +21,6 @@ Rhythmic_head::dots_l (Grob*me)
   return unsmob_item (s);
 }
 
-int
-Rhythmic_head::balltype_i (Grob*me) 
-{
-  SCM s = me->get_grob_property ("duration-log");
-  return gh_number_p (s) ? gh_scm2int (s) <? 2 : 0;
-}
-
 Item*
 Rhythmic_head::stem_l (Grob*me) 
 {
@@ -50,6 +43,13 @@ Rhythmic_head::set_dots (Grob*me,Item *dot_l)
 
 
 
+int
+Rhythmic_head::duration_log (Grob*me) 
+{
+  SCM s = me->get_grob_property ("duration-log");
+  return gh_number_p (s) ? gh_scm2int (s) : 0;
+}
+
 
 
 ADD_INTERFACE (Rhythmic_head,"rhythmic-head-interface",
index 7b8db24062a4917260c107045fb029fd571139f5..2b1ad6440a9beb249938ea20d943cfb8fd24fd99 100644 (file)
@@ -122,7 +122,7 @@ Stem::set_stemend (Grob*me, Real se)
 int
 Stem::type_i (Grob*me) 
 {
-  return first_head (me) ?  Rhythmic_head::balltype_i (first_head (me)) : 2;
+  return first_head (me) ?  Note_head::balltype_i (first_head (me)) : 2;
 }
 
 /*
@@ -238,7 +238,7 @@ Stem::add_head (Grob*me, Grob *n)
 bool
 Stem::invisible_b (Grob*me)
 {
-  return ! (head_count (me) && Rhythmic_head::balltype_i (support_head (me)) >= 1);
+  return ! (head_count (me) && Note_head::balltype_i (support_head (me)) >= 1);
 }
 
 Direction
index 22fc2fc0d2e9175b63b863e756d38c83d473184c..7f5e9b11ccd0f1edf34f90f1dcd3df4c16d2ed4c 100644 (file)
@@ -223,7 +223,17 @@ and will have no effect.
 (grob-property-description 'measure-length moment? "Length of a
 measure. Used in some spacing situations.")
 (grob-property-description 'measure-count integer? "number of measures for a multimeasure rest.")
-(grob-property-description 'merge-differently-dotted boolean? " Merge noteheads in collisions, even if they have a different number of dots. This normal notation for some types of polyphonic music. The value of this setting is used by @ref{note-collision-interface} .")
+
+(grob-property-description 'merge-differently-headed boolean? "Merge
+noteheads in collisions, even if they have different note heads. The
+smaller of the two heads will be rendered invisible. This used
+polyphonic guitar notation. The value of this setting is used by
+@ref{note-collision-interface} .")
+
+(grob-property-description 'merge-differently-dotted boolean? " Merge
+noteheads in collisions, even if they have a different number of
+dots. This normal notation for some types of polyphonic music. The
+value of this setting is used by @ref{note-collision-interface} .")
 
 (grob-property-description 'meta list? "Alist of meta information of this grob.")
 (grob-property-description 'minimum-distance number? "minimum distance between notes and rests.")
@@ -254,7 +264,6 @@ FIXME: also pair? (cons LEFT RIGHT)
 (grob-property-description 'no-spacing-rods boolean? "read from grobs: boolean that makes Separation_item ignore this item (MOVE ME TO ITEM).")
 (grob-property-description 'no-stem-extend boolean? "should stem not be extended to middle staff line?.")
 (grob-property-description 'non-default boolean? "not set because of existence of a bar?.")
-(grob-property-description 'note-width number? "unit for horizontal translation, measured in staff-space.")
 (grob-property-description 'note-heads list? "List of note head grobs")
 (grob-property-description 'number-threshold number? "only put numbers bigger than this threshold over multi measuer rest.")
 (grob-property-description 'old-accidentals list? "list of (pitch, accidental) pairs.")
index cd0191b0c7cc96be47ce9a10103f756fc5e1b7fe..aaa1f5737031b95f84f508127bec5c911af0ffad 100644 (file)
@@ -1246,6 +1246,7 @@ def compile_all_files (chunks):
                texfiles = string.join (tex, ' ')
                cmd = 'lilypond --header=texidoc %s %s %s' \
                      % (lilyopts, g_extra_opts, texfiles)
+
                system (cmd)
 
                #