]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix 59.
authorJoe Neeman <joeneeman@gmail.com>
Wed, 14 Jan 2009 19:11:44 +0000 (11:11 -0800)
committerJoe Neeman <joeneeman@gmail.com>
Thu, 15 Jan 2009 01:04:14 +0000 (17:04 -0800)
Keep track of note durations in the rest-collision-engraver.

lily/grob.cc
lily/include/grob.hh
lily/rest-collision-engraver.cc
lily/rest-collision.cc

index 698d40457c66a069132de3327f3e88fa78981d46..e37fc94302bba8e1c2012db54952ee0287fa5e63 100644 (file)
@@ -702,7 +702,17 @@ Grob::stencil_width (SCM smob)
   return grob_stencil_extent (me, X_AXIS);
 }
 
+Stream_event*
+Grob::event_cause ()
+{
+  SCM cause = get_property ("cause");
+  if (to_boolean (Stream_event::smob_p (cause)))
+    return unsmob_stream_event (cause);
+  else if (to_boolean (Grob::smob_p (cause)))
+    return unsmob_grob (cause)->event_cause ();
 
+  return 0;
+}
 
 Grob *
 common_refpoint_of_list (SCM elist, Grob *common, Axis a)
index 66cc0530b73a0221f8f74cb93489bea5c80e0737..0eb7067b91beaecc8eae3c0ed4b1210b77cf14e6 100644 (file)
@@ -128,6 +128,7 @@ public:
   void fixup_refpoint ();
 
   virtual Interval_t<int> spanned_rank_interval () const;
+  Stream_event *event_cause ();
 };
 
 /* smob utilities */
index d438566c02707e346154d10a2288fade48587c3c..23a351c2f150e03bb9acd8426606d8946547f1f6 100644 (file)
@@ -6,21 +6,27 @@
   (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
-#include "warn.hh"
+#include <list>
+
+#include "duration.hh"
 #include "engraver.hh"
-#include "rest-collision.hh"
-#include "note-column.hh"
 #include "item.hh"
+#include "moment.hh"
+#include "note-column.hh"
+#include "rest-collision.hh"
+#include "stream-event.hh"
+#include "warn.hh"
 
 class Rest_collision_engraver : public Engraver
 {
   Item *rest_collision_;
   vsize rest_count_;
-  vector<Grob*> note_columns_;
+  list<pair<Grob*, Moment> > note_columns_;
 protected:
   DECLARE_ACKNOWLEDGER (note_column);
   void process_acknowledged ();
   void stop_translation_timestep ();
+  void start_translation_timestep ();
 public:
   TRANSLATOR_DECLARATIONS (Rest_collision_engraver);
 };
@@ -43,26 +49,56 @@ Rest_collision_engraver::process_acknowledged ()
 
   rest_collision_ = make_item ("RestCollision", SCM_EOL);
 
-  for (vsize i = 0; i < note_columns_.size (); i++)
-    Rest_collision::add_column (rest_collision_, note_columns_[i]);
+  list<pair<Grob*, Moment> >::iterator i;
+  for (i = note_columns_.begin (); i != note_columns_.end (); i++)
+    Rest_collision::add_column (rest_collision_, i->first);
 }
 
 void
 Rest_collision_engraver::acknowledge_note_column (Grob_info i)
 {
-  note_columns_.push_back (i.grob ());
+  Moment end = now_mom ();
   if (Note_column::has_rests (i.grob ()))
     rest_count_++;
+  else
+    {
+      // We only keep track of ending moments for columns with notes.
+      // It is safe to add a column with notes to multiple RestCollisions, but
+      // it might not be safe to add a column with rests to multiple RestCollisions.
+      Grob *stem = Note_column::get_stem (i.grob ());
+      Stream_event *ev = stem ? stem->event_cause () : 0;
+      Duration *dur_ptr = ev ? unsmob_duration (ev->get_property ("duration")) : 0;
+      if (dur_ptr)
+       {
+         if (end.grace_part_)
+           end.grace_part_ += dur_ptr->get_length ();
+         else
+           end.main_part_ += dur_ptr->get_length ();
+       }
+    }
+  note_columns_.push_back (pair<Grob*, Moment> (i.grob (), end));
 }
 
 void
 Rest_collision_engraver::stop_translation_timestep ()
 {
   rest_collision_ = 0;
-  note_columns_.clear ();
   rest_count_ = 0;
 }
 
+void
+Rest_collision_engraver::start_translation_timestep ()
+{
+  list<pair<Grob*, Moment> >::iterator i = note_columns_.begin ();
+  while (i != note_columns_.end ())
+    {
+      if (i->second <= now_mom ())
+       i = note_columns_.erase (i);
+      else
+       i++;
+    }
+}
+
 #include "translator.icc"
 
 ADD_ACKNOWLEDGER (Rest_collision_engraver, note_column);
index f18c63a10cc466be2d2cfe5099decb0a8599c610..6448492b8f5f925b954fe9fb4064b4b0cb50cb2a 100644 (file)
@@ -14,6 +14,7 @@ using namespace std;
 #include "directional-element-interface.hh"
 #include "duration.hh"
 #include "international.hh"
+#include "item.hh"
 #include "note-column.hh"
 #include "output-def.hh"
 #include "pointer-group-interface.hh"
@@ -228,7 +229,10 @@ Rest_collision::calc_positioning_done (SCM smob)
       Interval notedim;
       for (vsize i = 0; i < notes.size (); i++)
        {
-         if (Note_column::dir (notes[i]) == -dir)
+         if (Note_column::dir (notes[i]) == -dir
+             // If the note has already happened (but it has a long duration, so there is a collision),
+             // don't look at the stem. If we do, the rest gets shifted down a lot and it looks bad.
+             || dynamic_cast<Item*> (notes[i])->get_column () != dynamic_cast<Item*> (rest)->get_column ())
            {
              /* try not to look at the stem, as looking at a beamed
                 note may trigger beam positioning prematurely.