]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-engraver.cc
* scm/engraver-documentation-lib.scm
[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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "engraver.hh"
11 #include "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 process_acknowledged_grobs ();
27   virtual void start_translation_timestep ();
28   
29 public:
30   TRANSLATOR_DECLARATIONS(Lyric_engraver);
31 private:
32   Music * req_;
33   Item* text_;
34 };
35
36
37
38
39 Lyric_engraver::Lyric_engraver ()
40 {
41   text_ =0;
42   req_ =0;
43 }
44
45 bool
46 Lyric_engraver::try_music (Music*r)
47 {
48   if (r->is_mus_type ("lyric-event"))
49     {
50       if (req_)
51         return false;
52       req_ =r;
53       return true;
54     }
55   return false;
56 }
57
58 void
59 Lyric_engraver::process_acknowledged_grobs ()
60 {
61   if (req_)
62     {
63       text_=  new Item (get_property ("LyricText"));
64       
65       text_->set_grob_property ("text", req_->get_mus_property ("text"));
66
67       /*
68         We can't reach the notehead where we're centered from here. So
69         we kludge.
70
71  (UGH UGH, pulled amount of space out of thin air)
72       */
73       
74       text_->translate_axis (0.66, X_AXIS);
75       
76       announce_grob(text_, req_->self_scm());
77       req_ = 0;
78     }
79 }
80
81 void
82 Lyric_engraver::stop_translation_timestep ()
83 {
84   if (text_)
85     {
86       typeset_grob (text_);
87       text_ =0;
88     }
89 }
90
91 void
92 Lyric_engraver::start_translation_timestep ()
93 {
94   req_ =0;
95 }
96
97
98 ENTER_DESCRIPTION(Lyric_engraver,
99 /* descr */       "",
100 /* creats*/       "",
101 /* accepts */     "lyric-event",
102 /* acks  */      "",
103 /* reads */       "",
104 /* write */       "");