]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-engraver.cc
patch::: 1.3.109.jcn1
[lilypond.git] / lily / lyric-engraver.cc
1 /*
2   lyric-engraver.cc -- implement Lyric_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
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"
16
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.
20  */
21 class Lyric_engraver : public Engraver 
22 {
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 ();
28   
29 public:
30   Lyric_engraver ();
31   VIRTUAL_COPY_CONS (Translator);
32
33 private:
34   Lyric_req * req_l_;
35   Item* text_p_;
36 };
37
38 ADD_THIS_TRANSLATOR (Lyric_engraver);
39
40
41 Lyric_engraver::Lyric_engraver()
42 {
43   text_p_ =0;
44   req_l_ =0;
45 }
46
47 bool
48 Lyric_engraver::try_music (Music*r)
49 {
50   if (Lyric_req* l = dynamic_cast <Lyric_req *> (r))
51     {
52       if (req_l_)
53         return false;
54       req_l_ =l;
55       return true;
56     }
57   return false;
58 }
59
60 void
61 Lyric_engraver::create_grobs ()
62 {
63   if (req_l_)
64     {
65       text_p_=  new Item (get_property ("LyricText"));
66       
67       text_p_->set_grob_property ("text", req_l_->get_mus_property ("text"));
68
69       /*
70         We can't reach the notehead where we're centered from here. So
71         we kludge.
72
73         (UGH UGH, pulled amount of space out of thin air)
74       */
75       
76       text_p_->translate_axis (0.66, X_AXIS);
77       
78       announce_grob (text_p_, req_l_);
79       req_l_ = 0;
80     }
81 }
82
83 void
84 Lyric_engraver::stop_translation_timestep()
85 {
86   if (text_p_)
87     {
88       typeset_grob (text_p_);
89       text_p_ =0;
90     }
91 }
92
93 void
94 Lyric_engraver::start_translation_timestep ()
95 {
96   req_l_ =0;
97 }
98
99