lilypond-1.3.145
[lilypond.git] / lily / lyric-engraver.cc
blob929ebf819172910baca6953dfaa9a7ccee5af495
1 /*
2 lyric-engraver.cc -- implement Lyric_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
10 #include "engraver.hh"
11 #include "musical-request.hh"
12 #include "item.hh"
13 #include "paper-def.hh"
14 #include "font-metric.hh"
15 #include "side-position-interface.hh"
17 /**
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
23 protected:
24 virtual void stop_translation_timestep ();
25 virtual bool try_music (Music *);
26 virtual void create_grobs ();
27 virtual void start_translation_timestep ();
29 public:
30 Lyric_engraver ();
31 VIRTUAL_COPY_CONS (Translator);
33 private:
34 Lyric_req * req_l_;
35 Item* text_p_;
38 ADD_THIS_TRANSLATOR (Lyric_engraver);
41 Lyric_engraver::Lyric_engraver ()
43 text_p_ =0;
44 req_l_ =0;
47 bool
48 Lyric_engraver::try_music (Music*r)
50 if (Lyric_req* l = dynamic_cast <Lyric_req *> (r))
52 if (req_l_)
53 return false;
54 req_l_ =l;
55 return true;
57 return false;
60 void
61 Lyric_engraver::create_grobs ()
63 if (req_l_)
65 text_p_= new Item (get_property ("LyricText"));
67 text_p_->set_grob_property ("text", req_l_->get_mus_property ("text"));
70 We can't reach the notehead where we're centered from here. So
71 we kludge.
73 (UGH UGH, pulled amount of space out of thin air)
76 text_p_->translate_axis (0.66, X_AXIS);
78 announce_grob (text_p_, req_l_);
79 req_l_ = 0;
83 void
84 Lyric_engraver::stop_translation_timestep ()
86 if (text_p_)
88 typeset_grob (text_p_);
89 text_p_ =0;
93 void
94 Lyric_engraver::start_translation_timestep ()
96 req_l_ =0;