+
+ SCM voice_type = lyrics->get_property ("associatedVoiceType");
+ if (!scm_is_symbol (voice_type))
+ return 0;
+
+ Context *voice = find_context_near (lyrics, voice_type, nm);
+ if (voice)
+ return voice;
+
+ return find_context_near (lyrics, voice_type, "");
+}
+
+Grob *
+get_current_note_head (Context *voice)
+{
+ Moment now = voice->now_mom ();
+ for (SCM s = voice->get_property ("busyGrobs");
+ scm_is_pair (s); s = scm_cdr (s))
+ {
+ Grob *g = unsmob<Grob> (scm_cdar (s));;
+ Moment *end_mom = unsmob<Moment> (scm_caar (s));
+ if (!end_mom || !g)
+ {
+ programming_error ("busyGrobs invalid");
+ continue;
+ }
+
+ // It's a bit irritating that we just have the length and
+ // duration of the Grob.
+ Moment end_from_now =
+ get_event_length (unsmob<Stream_event> (g->get_property ("cause")), now)
+ + now;
+ // We cannot actually include more than a single grace note
+ // using busyGrobs on ungraced lyrics since a grob ending on
+ // grace time will just have disappeared from busyGrobs by the
+ // time our ungraced lyrics appear. At best we may catch a
+ // single grace note.
+ //
+ // However, a single grace note ending on a non-grace time is
+ // indistinguishable from a proper note ending on a non-grace
+ // time. So we really have no way to obey includeGraceNotes
+ // here. Not with this mechanism.
+ if ((*end_mom == end_from_now)
+ && dynamic_cast<Item *> (g)
+ && has_interface<Note_head> (g))
+ {
+ return g;
+ }
+ }
+
+ return 0;