From a9aa7e95c8f53ebd3307bd4b68da66cdbda90343 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Wed, 14 Jan 2009 22:06:49 -0800 Subject: [PATCH] Nicer fix for 59. Use busyGrobs instead of keeping track within the Rest_collision_engraver. --- lily/grob.cc | 11 ----- lily/include/grob.hh | 1 - lily/rest-collision-engraver.cc | 88 +++++++++++++-------------------- ly/engraver-init.ly | 1 + 4 files changed, 34 insertions(+), 67 deletions(-) diff --git a/lily/grob.cc b/lily/grob.cc index e37fc94302..a3f41a856d 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -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) diff --git a/lily/include/grob.hh b/lily/include/grob.hh index 0eb7067b91..66cc0530b7 100644 --- a/lily/include/grob.hh +++ b/lily/include/grob.hh @@ -128,7 +128,6 @@ public: void fixup_refpoint (); virtual Interval_t spanned_rank_interval () const; - Stream_event *event_cause (); }; /* smob utilities */ diff --git a/lily/rest-collision-engraver.cc b/lily/rest-collision-engraver.cc index 23a351c2f1..7156409d51 100644 --- a/lily/rest-collision-engraver.cc +++ b/lily/rest-collision-engraver.cc @@ -6,27 +6,27 @@ (c) 1997--2009 Han-Wen Nienhuys */ -#include +#include #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 > 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 >::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 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 (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 (i.grob (), end)); + + if (!rest_collision_ && rest_count && columns.size () > 1) + { + rest_collision_ = make_item ("RestCollision", SCM_EOL); + for (set::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 >::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 */ "" diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index 1b4537290e..cebd9b8637 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -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" -- 2.39.2