]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-performer.cc
f9faa7269329258d016d41b969a76d8fb6e58b79
[lilypond.git] / lily / lyric-performer.cc
1 /*
2   lyric-performer.cc -- implement Lyric_performer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "audio-item.hh"
10 #include "performer.hh"
11
12 class Lyric_performer : public Performer
13 {
14 public:
15   TRANSLATOR_DECLARATIONS (Lyric_performer);
16 protected:
17
18   virtual bool try_music (Music *req);
19   virtual void stop_translation_timestep ();
20   virtual void create_audio_elements ();
21
22 private:
23   Link_array<Music> lreqs_;
24   Audio_text *audio_;
25 };
26
27 Lyric_performer::Lyric_performer ()
28 {
29   audio_ = 0;
30 }
31
32 void
33 Lyric_performer::create_audio_elements ()
34 {
35   // FIXME: won't work with fancy lyrics
36   if (lreqs_.size ()
37       && scm_is_string (lreqs_[0]->get_property ("text"))
38       && ly_scm2string (lreqs_[0]->get_property ("text")).length ())
39     {
40       audio_ = new Audio_text (Audio_text::LYRIC,
41                                ly_scm2string (lreqs_[0]->get_property ("text")));
42       Audio_element_info info (audio_, lreqs_[0]);
43       announce_element (info);
44     }
45   lreqs_.clear ();
46 }
47
48 void
49 Lyric_performer::stop_translation_timestep ()
50 {
51   if (audio_)
52     {
53       play_element (audio_);
54       audio_ = 0;
55     }
56   lreqs_.clear ();
57 }
58
59 bool
60 Lyric_performer::try_music (Music *req)
61 {
62   if (req->is_mus_type ("lyric-event"))
63     {
64       lreqs_.push (req);
65       return true;
66     }
67   return false;
68 }
69
70 ADD_TRANSLATOR (Lyric_performer, "", "", "lyric-event", "", "", "");