]> git.donarmstrong.com Git - lilypond.git/blob - lily/stanza-number-engraver.cc
2003 -> 2004
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>, Glen Prideaux <glenprideaux@iname.com>
7
8 */
9
10 #include "engraver.hh"
11 #include "item.hh"
12 #include "side-position-interface.hh"
13
14 class Stanza_number_engraver : public Engraver
15 {
16   Item *text_;
17
18   /*
19     This is naughty, since last_stanza_ may be GCd from under us.  But
20     since we don't look at the contents, we are/should be (knock on
21     wood) OK.
22    */
23   SCM last_stanza_;
24 public:
25   TRANSLATOR_DECLARATIONS(Stanza_number_engraver);
26   virtual void process_music ();
27   virtual void stop_translation_timestep ();
28   virtual void acknowledge_grob (Grob_info);
29 };
30
31
32 /*
33   TODO: should make engraver that collects all the stanzas on a higher
34   level, and then groups them to the side. Stanza numbers should be
35   all aligned.
36  */
37
38 Stanza_number_engraver::Stanza_number_engraver ()
39 {
40   text_ = 0;
41 }
42
43 void
44 Stanza_number_engraver::process_music ()
45 {
46   SCM stanza = get_property ("stanza");
47   
48   if (gh_string_p (stanza) && stanza != last_stanza_)
49     {
50       last_stanza_ = stanza;
51       
52       text_ = make_item ("StanzaNumber");
53       text_->set_grob_property ("text", stanza);
54       announce_grob (text_, SCM_EOL);
55     }
56 }
57
58
59 void
60 Stanza_number_engraver::acknowledge_grob (Grob_info inf)
61 {
62   if (text_
63       && inf.grob_->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
64     {
65       Side_position_interface::add_support (text_, inf.grob_);
66     }
67 }
68
69 void
70 Stanza_number_engraver::stop_translation_timestep ()
71 {
72   if (text_)
73     {
74       typeset_grob (text_);
75       text_ = 0;
76     }
77 }
78
79
80 ENTER_DESCRIPTION(Stanza_number_engraver,
81 /* descr */       "",
82 /* creats*/       "StanzaNumber",
83 /* accepts */     "",
84 /* acks  */      "lyric-syllable-interface",
85 /* reads */       "stanza",
86 /* write */       "");