]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-engraver.cc
* lily/engraver.cc (internal_make_item): centralize item/spanner
[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--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "engraver.hh"
11 #include "event.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_music ();
27   
28 public:
29   TRANSLATOR_DECLARATIONS(Lyric_engraver);
30 private:
31   Music * req_;
32   Item* text_;
33 };
34
35
36
37
38 Lyric_engraver::Lyric_engraver ()
39 {
40   text_ =0;
41   req_ =0;
42 }
43
44 bool
45 Lyric_engraver::try_music (Music*r)
46 {
47   if (r->is_mus_type ("lyric-event"))
48     {
49       if (req_)
50         return false;
51       req_ =r;
52       return true;
53     }
54   return false;
55 }
56
57 void
58 Lyric_engraver::process_music ()
59 {
60   if (req_)
61     {
62       text_=  make_item ("LyricText");
63       
64       text_->set_grob_property ("text", req_->get_mus_property ("text"));
65       announce_grob (text_, req_->self_scm());
66     }
67 }
68
69 void
70 Lyric_engraver::stop_translation_timestep ()
71 {
72   if (text_)
73     {
74       typeset_grob (text_);
75       text_ =0;
76     }
77   req_ =0;
78 }
79
80
81 ENTER_DESCRIPTION(Lyric_engraver,
82 /* descr */       "",
83 /* creats*/       "",
84 /* accepts */     "lyric-event",
85 /* acks  */      "",
86 /* reads */       "",
87 /* write */       "");