1 /*
2 This file is part of LilyPond, the GNU music typesetter.
3
4 Copyright (C) 2000--2021 Han-Wen Nienhuys <hanwen@xs4all.nl>, Glen Prideaux <glenprideaux@iname.com>
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 "engraver.hh"
21 #include "side-position-interface.hh"
22 #include "text-interface.hh"
23 #include "item.hh"
24
25 class Stanza_number_engraver : public Engraver
26 {
27 Item *text_;
28
29 SCM last_stanza_;
30 public:
31 TRANSLATOR_DECLARATIONS (Stanza_number_engraver);
32 void process_music ();
33 void derived_mark () const override;
34 void stop_translation_timestep ();
35 void acknowledge_lyric_syllable (Grob_info);
36 };
37
38 void
derived_mark() const39 Stanza_number_engraver::derived_mark () const
40 {
41 scm_gc_mark (last_stanza_);
42 }
43
44 /*
45 TODO: should make engraver that collects all the stanzas on a higher
46 level, and then groups them to the side. Stanza numbers should be
47 all aligned.
48 */
49
Stanza_number_engraver(Context * c)50 Stanza_number_engraver::Stanza_number_engraver (Context *c)
51 : Engraver (c)
52 {
53 text_ = 0;
54 last_stanza_ = SCM_EOL;
55 }
56
57 void
process_music()58 Stanza_number_engraver::process_music ()
59 {
60 SCM stanza = get_property (this, "stanza");
61
62 if (Text_interface::is_markup (stanza)
63 && !scm_is_eq (stanza, last_stanza_))
64 {
65 last_stanza_ = stanza;
66
67 text_ = make_item ("StanzaNumber", SCM_EOL);
68 set_property (text_, "text", stanza);
69 }
70 }
71
72 void
acknowledge_lyric_syllable(Grob_info inf)73 Stanza_number_engraver::acknowledge_lyric_syllable (Grob_info inf)
74 {
75 if (text_)
76 Side_position_interface::add_support (text_, inf.grob ());
77 }
78
79 void
stop_translation_timestep()80 Stanza_number_engraver::stop_translation_timestep ()
81 {
82 text_ = 0;
83 }
84
85 #include "translator.icc"
86
87 void
boot()88 Stanza_number_engraver::boot ()
89 {
90 ADD_ACKNOWLEDGER (Stanza_number_engraver, lyric_syllable);
91 }
92
93 ADD_TRANSLATOR (Stanza_number_engraver,
94 /* doc */
95 "Engrave stanza numbers.",
96
97 /* create */
98 "StanzaNumber ",
99
100 /* read */
101 "stanza ",
102
103 /* write */
104 ""
105 );
106