2 lyric-engraver.cc -- implement Lyric_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "engraver.hh"
14 #include "font-metric.hh"
15 #include "note-head.hh"
18 Generate texts for lyric syllables. We only do one lyric at a time.
19 Multiple copies of this engraver should be used to do multiple voices.
21 class Lyric_engraver
: public Engraver
24 virtual void stop_translation_timestep ();
25 virtual bool try_music (Music
*);
26 virtual void process_music ();
29 TRANSLATOR_DECLARATIONS (Lyric_engraver
);
34 Context
* get_voice_context ();
37 Lyric_engraver::Lyric_engraver ()
44 Lyric_engraver::try_music (Music
*r
)
46 if (r
->is_mus_type ("lyric-event"))
57 Lyric_engraver::process_music ()
61 text_
= make_item ("LyricText",event_
->self_scm ());
63 text_
->set_property ("text", event_
->get_property ("text"));
69 get_voice_to_lyrics (Context
*lyrics
)
71 SCM avc
= lyrics
->get_property ("associatedVoiceContext");
72 if (Context
*c
= unsmob_context (avc
))
75 SCM voice_name
= lyrics
->get_property ("associatedVoice");
76 String nm
= lyrics
->id_string ();
78 if (ly_c_string_p (voice_name
))
79 nm
= ly_scm2string (voice_name
);
82 int idx
= nm
.index_last ('-');
84 nm
= nm
.left_string (idx
);
87 Context
*parent
= lyrics
;
89 while (parent
&& !voice
)
91 voice
= find_context_below (parent
, ly_symbol2scm ("Voice"), nm
);
92 parent
= parent
->get_parent_context ();
100 while (parent
&& !voice
)
102 voice
= find_context_below (parent
, ly_symbol2scm ("Voice"), "");
103 parent
= parent
->get_parent_context ();
110 get_current_note_head (Context
* voice
)
112 for (SCM s
= voice
->get_property ("busyGrobs");
113 ly_c_pair_p (s
); s
= ly_cdr (s
))
115 Item
*g
= dynamic_cast<Item
*> (unsmob_grob (ly_cdar (s
)));
117 if (g
&& !g
->get_column ()
118 && Note_head::has_interface (g
))
126 Lyric_engraver::stop_translation_timestep ()
130 Context
* voice
= get_voice_to_lyrics (context ());
134 Grob
*head
= get_current_note_head (voice
);
138 text_
->set_parent (head
, X_AXIS
);
139 if (melisma_busy (voice
))
140 text_
->set_property ("self-alignment-X", scm_int2num (LEFT
));
150 ENTER_DESCRIPTION (Lyric_engraver
,
153 /* accepts */ "lyric-event",