]> git.donarmstrong.com Git - lilypond.git/commitdiff
Nicer fix for 59.
authorJoe Neeman <joeneeman@gmail.com>
Thu, 15 Jan 2009 06:06:49 +0000 (22:06 -0800)
committerJoe Neeman <joeneeman@gmail.com>
Fri, 16 Jan 2009 08:18:01 +0000 (00:18 -0800)
Use busyGrobs instead of keeping track within the Rest_collision_engraver.

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

index e37fc94302bba8e1c2012db54952ee0287fa5e63..a3f41a856d3a6c90a01bfb8e8dfd11354b24b3bc 100644 (file)
@@ -702,17 +702,6 @@ 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 0eb7067b91beaecc8eae3c0ed4b1210b77cf14e6..66cc0530b73a0221f8f74cb93489bea5c80e0737 100644 (file)
@@ -128,7 +128,6 @@ public:
   void fixup_refpoint ();
 
   virtual Interval_t<int> spanned_rank_interval () const;
-  Stream_event *event_cause ();
 };
 
 /* smob utilities */
index 23a351c2f150e03bb9acd8426606d8946547f1f6..7156409d51dd0adb7140b9171d3babef6255472d 100644 (file)
@@ -6,27 +6,27 @@
   (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
-#include <list>
+#include <set>
 
 #include "duration.hh"
 #include "engraver.hh"
 #include "item.hh"
 #include "moment.hh"
 #include "note-column.hh"
+#include "paper-column.hh"
+#include "rest.hh"
 #include "rest-collision.hh"
+#include "rhythmic-head.hh"
 #include "stream-event.hh"
 #include "warn.hh"
 
 class Rest_collision_engraver : public Engraver
 {
-  Item *rest_collision_;
-  vsize rest_count_;
-  list<pair<Grob*, Moment> > note_columns_;
 protected:
-  DECLARE_ACKNOWLEDGER (note_column);
+  Grob *rest_collision_;
+
   void process_acknowledged ();
   void stop_translation_timestep ();
-  void start_translation_timestep ();
 public:
   TRANSLATOR_DECLARATIONS (Rest_collision_engraver);
 };
@@ -34,74 +34,52 @@ public:
 Rest_collision_engraver::Rest_collision_engraver ()
 {
   rest_collision_ = 0;
-  rest_count_ = 0;
 }
 
 void
 Rest_collision_engraver::process_acknowledged ()
 {
-  if (rest_collision_
-      || note_columns_.empty ()
-      || !rest_count_
-      || (note_columns_.size () == rest_count_
-         && rest_count_ < 2))
-    return;
-
-  rest_collision_ = make_item ("RestCollision", SCM_EOL);
-
-  list<pair<Grob*, Moment> >::iterator i;
-  for (i = note_columns_.begin (); i != note_columns_.end (); i++)
-    Rest_collision::add_column (rest_collision_, i->first);
-}
+  vsize rest_count = 0;
+  set<Grob*> columns;
+  Moment now = now_mom ();
 
-void
-Rest_collision_engraver::acknowledge_note_column (Grob_info i)
-{
-  Moment end = now_mom ();
-  if (Note_column::has_rests (i.grob ()))
-    rest_count_++;
-  else
+  for (SCM s = get_property ("busyGrobs"); scm_is_pair (s); s = scm_cdr (s))
     {
-      // 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)
+      Grob *g = unsmob_grob (scm_cdar (s));
+      Moment *m = unsmob_moment (scm_caar (s));
+      if (!g || !m)
+       continue;
+
+      if (Rhythmic_head::has_interface (g) && (*m) > now)
        {
-         if (end.grace_part_)
-           end.grace_part_ += dur_ptr->get_length ();
-         else
-           end.main_part_ += dur_ptr->get_length ();
+         Grob *column = g->get_parent (X_AXIS);
+
+         // Only include rests that start now. Include notes that started any time.
+         Paper_column *paper_column = dynamic_cast<Item*> (column)->get_column ();
+         if (!Rest::has_interface (g) || !paper_column || Paper_column::when_mom (paper_column) == now)
+           {
+             columns.insert (column);
+             rest_count += Note_column::has_rests (column);
+           }
        }
     }
-  note_columns_.push_back (pair<Grob*, Moment> (i.grob (), end));
+
+  if (!rest_collision_ && rest_count && columns.size () > 1)
+    {
+      rest_collision_ = make_item ("RestCollision", SCM_EOL);
+      for (set<Grob*>::iterator i = columns.begin (); i != columns.end (); ++i)
+       Rest_collision::add_column (rest_collision_, *i);
+    }
 }
 
 void
 Rest_collision_engraver::stop_translation_timestep ()
 {
   rest_collision_ = 0;
-  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);
 ADD_TRANSLATOR (Rest_collision_engraver,
                /* doc */
                "Handle collisions of rests.",
@@ -110,7 +88,7 @@ ADD_TRANSLATOR (Rest_collision_engraver,
                "RestCollision ",
 
                /* read */
-               "",
+               "busyGrobs ",
 
                /* write */
                ""
index 1b4537290ed59f180086bc4472df0f4064427f86..cebd9b8637373e81baf80935dcddd68a87ed1812 100644 (file)
@@ -48,6 +48,7 @@
   \consists "Ledger_line_engraver" 
   \consists "Staff_symbol_engraver"
   \consists "Collision_engraver"
+  \consists "Grob_pq_engraver"
   \consists "Rest_collision_engraver"
   \consists "Accidental_engraver"
   \consists "Piano_pedal_engraver"