1 /*
2 This file is part of LilyPond, the GNU music typesetter.
3
4 Copyright (C) 1997--2021 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 using std::vector;
26
27 class Lyric_performer : public Performer
28 {
29 public:
30 TRANSLATOR_DECLARATIONS (Lyric_performer);
31 protected:
32
33 void stop_translation_timestep ();
34 void process_music ();
35 void listen_lyric (Stream_event *);
36 private:
37 vector<Stream_event *> events_;
38 Audio_text *audio_;
39 };
40
Lyric_performer(Context * c)41 Lyric_performer::Lyric_performer (Context *c)
42 : Performer (c)
43 {
44 audio_ = 0;
45 }
46
47 void
process_music()48 Lyric_performer::process_music ()
49 {
50 // FIXME: won't work with fancy lyrics
51 if (events_.size ()
52 && scm_is_string (get_property (events_[0], "text"))
53 && ly_scm2string (get_property (events_[0], "text")).length ())
54 {
55 audio_ = new Audio_text (Audio_text::LYRIC,
56 ly_scm2string (get_property (events_[0], "text")));
57 Audio_element_info info (audio_, events_[0]);
58 announce_element (info);
59 }
60 events_.clear ();
61 }
62
63 void
stop_translation_timestep()64 Lyric_performer::stop_translation_timestep ()
65 {
66 if (audio_)
67 {
68 audio_ = 0;
69 }
70 events_.clear ();
71 }
72
73 void
listen_lyric(Stream_event * event)74 Lyric_performer::listen_lyric (Stream_event *event)
75 {
76 events_.push_back (event);
77 }
78
79 void
boot()80 Lyric_performer::boot ()
81 {
82 ADD_LISTENER (Lyric_performer, lyric);
83 }
84
85 ADD_TRANSLATOR (Lyric_performer,
86 /* doc */
87 "",
88
89 /* create */
90 "",
91
92 /* read */
93 "",
94
95 /* write */
96 ""
97 );
98