]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-performer.cc
3fd9900e7e97d18ae2ce0e72cce57fbafc080815
[lilypond.git] / lily / lyric-performer.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2012 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "audio-item.hh"
21 #include "performer.hh"
22 #include "stream-event.hh"
23 #include "translator.icc"
24
25 class Lyric_performer : public Performer
26 {
27 public:
28   TRANSLATOR_DECLARATIONS (Lyric_performer);
29 protected:
30
31   void stop_translation_timestep ();
32   void process_music ();
33   DECLARE_TRANSLATOR_LISTENER (lyric);
34 private:
35   vector<Stream_event *> events_;
36   Audio_text *audio_;
37 };
38
39 Lyric_performer::Lyric_performer ()
40 {
41   audio_ = 0;
42 }
43
44 void
45 Lyric_performer::process_music ()
46 {
47   // FIXME: won't work with fancy lyrics
48   if (events_.size ()
49       && scm_is_string (events_[0]->get_property ("text"))
50       && ly_scm2string (events_[0]->get_property ("text")).length ())
51     {
52       audio_ = new Audio_text (Audio_text::LYRIC,
53                                ly_scm2string (events_[0]->get_property ("text")));
54       Audio_element_info info (audio_, events_[0]);
55       announce_element (info);
56     }
57   events_.clear ();
58 }
59
60 void
61 Lyric_performer::stop_translation_timestep ()
62 {
63   if (audio_)
64     {
65       audio_ = 0;
66     }
67   events_.clear ();
68 }
69
70 IMPLEMENT_TRANSLATOR_LISTENER (Lyric_performer, lyric);
71 void
72 Lyric_performer::listen_lyric (Stream_event *event)
73 {
74   events_.push_back (event);
75 }
76
77 ADD_TRANSLATOR (Lyric_performer,
78                 /* doc */
79                 "",
80
81                 /* create */
82                 "",
83
84                 /* read */
85                 "",
86
87                 /* write */
88                 ""
89                );