2002->2003
[lilypond.git] / lily / extender-engraver.cc
blob08c8a52f4ed65184a4fedcaeab84218812f14ee6
1 /*
2 extender-engraver.cc -- implement Extender_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999-2002 Glen Prideaux <glenprideaux@iname.com>,
7 Han-Wen Nienhuys, Jan Nieuwenhuizen.
9 */
11 #include "flower-proto.hh"
12 #include "event.hh"
13 #include "lyric-extender.hh"
14 #include "paper-column.hh"
15 #include "item.hh"
16 #include "engraver.hh"
17 #include "drul-array.hh"
18 #include "lyric-extender.hh"
19 #include "pqueue.hh"
22 /**
23 Generate an centred extender. Should make a Extender_spanner that
24 typesets a nice centred extender of varying length depending on the
25 gap between syllables.
27 We remember the last Item that come across. When we get a
28 event, we create the spanner, and attach the left point to the
29 last lyrics, and the right point to any lyrics we receive by
30 then. */
31 class Extender_engraver : public Engraver
33 Grob *last_lyric_;
34 Grob *current_lyric_;
35 Music* req_;
36 Spanner* extender_;
37 public:
38 TRANSLATOR_DECLARATIONS(Extender_engraver);
40 protected:
41 virtual void acknowledge_grob (Grob_info);
42 virtual void finalize ();
43 virtual bool try_music (Music*);
44 virtual void stop_translation_timestep ();
45 virtual void start_translation_timestep ();
46 virtual void process_music ();
47 private:
54 Extender_engraver::Extender_engraver ()
56 current_lyric_ = 0;
57 last_lyric_ = 0;
58 extender_ = 0;
59 req_ = 0;
62 void
63 Extender_engraver::acknowledge_grob (Grob_info i)
65 // -> text_item
66 if (i.grob_->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
68 current_lyric_ = i.grob_;
69 if (extender_
70 && !extender_->get_bound (RIGHT)
73 Lyric_extender::set_textitem (extender_, RIGHT, dynamic_cast<Item*> (i.grob_));
79 bool
80 Extender_engraver::try_music (Music* r)
82 if (req_)
83 return false;
85 req_ = r;
86 return true;
89 void
90 Extender_engraver::finalize ()
92 if (extender_)
94 req_->origin ()->warning (_ ("unterminated extender"));
95 extender_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
99 void
100 Extender_engraver::process_music ()
102 if (req_ && ! extender_)
104 if (!last_lyric_)
106 req_->origin ()->warning (_ ("Nothing to connect extender to on the left. Ignoring extender event."));
107 return;
110 extender_ = new Spanner (get_property ("LyricExtender"));
113 Lyric_extender::set_textitem (extender_, LEFT, last_lyric_);
114 announce_grob(extender_, req_->self_scm());
119 void
120 Extender_engraver::stop_translation_timestep ()
122 if (extender_)
124 typeset_grob (extender_);
125 extender_ = 0;
128 if (current_lyric_)
130 last_lyric_ = current_lyric_;
131 current_lyric_ =0;
135 void
136 Extender_engraver::start_translation_timestep ()
138 req_ = 0;
142 ENTER_DESCRIPTION(Extender_engraver,
143 /* descr */ "Create lyric extenders",
144 /* creats*/ "LyricExtender",
145 /* accepts */ "extender-event",
146 /* acks */ "lyric-syllable-interface",
147 /* reads */ "",
148 /* write */ "");