]> git.donarmstrong.com Git - lilypond.git/blob - lily/stanza-number-engraver.cc
* lily/include/translator.icc: new file.
[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   PRECOMPUTED_VIRTUAL void process_music ();
25   PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
26   virtual void acknowledge_grob (Grob_info);
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_grob (Grob_info inf)
56 {
57   if (text_
58       && inf.grob ()->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
59     {
60       Side_position_interface::add_support (text_, inf.grob ());
61     }
62 }
63
64 void
65 Stanza_number_engraver::stop_translation_timestep ()
66 {
67   text_ = 0;
68 }
69
70 #include "translator.icc"
71
72 ADD_TRANSLATOR (Stanza_number_engraver,
73                 /* descr */ "",
74                 /* creats*/ "StanzaNumber",
75                 /* accepts */ "",
76                 /* acks  */ "lyric-syllable-interface",
77                 /* reads */ "stanza",
78                 /* write */ "");