- // 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 ();
- }
+ Grob *g = unsmob<Grob> (scm_cdar (s));
+ Moment *m = unsmob<Moment> (scm_caar (s));
+ if (!g || !m)
+ continue;
+
+ if (has_interface<Rhythmic_head> (g) && (*m) > now)
+ {
+ Grob *column = g->get_parent (X_AXIS);
+ if (!column)
+ continue;
+
+ // Only include rests that start now. Include notes that started any time.
+ Paper_column *paper_column = dynamic_cast<Item *> (column)->get_column ();
+ if (!has_interface<Rest> (g) || !paper_column || Paper_column::when_mom (paper_column) == now)
+ {
+ columns.insert (column);
+ rest_count += Note_column::has_rests (column);
+ }
+ }
+ }
+
+ 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);