]> git.donarmstrong.com Git - lilypond.git/blob - lily/stanza-number-engraver.cc
370a4ac1aed301c2398d8a266533d8785320946e
[lilypond.git] / lily / stanza-number-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2012 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   virtual void derived_mark () const;
34   void stop_translation_timestep ();
35   DECLARE_ACKNOWLEDGER (lyric_syllable);
36 };
37
38 void
39 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
50 Stanza_number_engraver::Stanza_number_engraver ()
51 {
52   text_ = 0;
53   last_stanza_ = SCM_EOL;
54 }
55
56 void
57 Stanza_number_engraver::process_music ()
58 {
59   SCM stanza = get_property ("stanza");
60
61   if (Text_interface::is_markup (stanza)
62       && stanza != last_stanza_)
63     {
64       last_stanza_ = stanza;
65
66       text_ = make_item ("StanzaNumber", SCM_EOL);
67       text_->set_property ("text", stanza);
68     }
69 }
70
71 void
72 Stanza_number_engraver::acknowledge_lyric_syllable (Grob_info inf)
73 {
74   if (text_)
75     Side_position_interface::add_support (text_, inf.grob ());
76 }
77
78 void
79 Stanza_number_engraver::stop_translation_timestep ()
80 {
81   text_ = 0;
82 }
83
84 #include "translator.icc"
85
86 ADD_ACKNOWLEDGER (Stanza_number_engraver, lyric_syllable);
87 ADD_TRANSLATOR (Stanza_number_engraver,
88                 /* doc */
89                 "Engrave stanza numbers.",
90
91                 /* create */
92                 "StanzaNumber ",
93
94                 /* read */
95                 "stanza ",
96
97                 /* write */
98                 ""
99                );