]> git.donarmstrong.com Git - lilypond.git/blob - lily/stanza-number-engraver.cc
* lily/include/translator.hh (class Translator): remove
[lilypond.git] / lily / stanza-number-engraver.cc
1 /*
2   lyric-number-engraver.cc -- implement Stanza_number_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>, Glen Prideaux <glenprideaux@iname.com>
7 */
8
9 #include "engraver.hh"
10 #include "side-position-interface.hh"
11
12 class Stanza_number_engraver : public Engraver
13 {
14   Item *text_;
15
16   /*
17     This is naughty, since last_stanza_ may be GCd from under us.  But
18     since we don't look at the contents, we are/should be (knock on
19     wood) OK.
20   */
21   SCM last_stanza_;
22 public:
23   TRANSLATOR_DECLARATIONS (Stanza_number_engraver);
24   void process_music ();
25   void stop_translation_timestep ();
26   DECLARE_ACKNOWLEDGER(lyric_syllable);
27 };
28
29 /*
30   TODO: should make engraver that collects all the stanzas on a higher
31   level, and then groups them to the side. Stanza numbers should be
32   all aligned.
33 */
34
35 Stanza_number_engraver::Stanza_number_engraver ()
36 {
37   text_ = 0;
38 }
39
40 void
41 Stanza_number_engraver::process_music ()
42 {
43   SCM stanza = get_property ("stanza");
44
45   if (scm_is_string (stanza) && stanza != last_stanza_)
46     {
47       last_stanza_ = stanza;
48
49       text_ = make_item ("StanzaNumber", SCM_EOL);
50       text_->set_property ("text", stanza);
51     }
52 }
53
54 void
55 Stanza_number_engraver::acknowledge_lyric_syllable (Grob_info inf)
56 {
57   if (text_)
58     {
59       Side_position_interface::add_support (text_, inf.grob ());
60     }
61 }
62
63 void
64 Stanza_number_engraver::stop_translation_timestep ()
65 {
66   text_ = 0;
67 }
68
69 #include "translator.icc"
70
71 ADD_ACKNOWLEDGER(Stanza_number_engraver,lyric_syllable);
72 ADD_TRANSLATOR (Stanza_number_engraver,
73                 /* descr */ "",
74                 /* creats*/ "StanzaNumber",
75                 /* accepts */ "",
76                 /* reads */ "stanza",
77                 /* write */ "");