lilypond-1.5.10
[lilypond.git] / lily / extender-engraver.cc
blobd3ae21945fa40cecceb08272dbf30e8dcec32fa6
1 /*
2 extender-engraver.cc -- implement Extender_engraver
4 (c) 1999 Glen Prideaux <glenprideaux@iname.com>,
5 Han-Wen Nienhuys, Jan Nieuwenhuizen.
7 */
9 #include "flower-proto.hh"
10 #include "musical-request.hh"
11 #include "lyric-extender.hh"
12 #include "paper-column.hh"
13 #include "item.hh"
14 #include "engraver.hh"
15 #include "drul-array.hh"
16 #include "lyric-extender.hh"
17 #include "pqueue.hh"
20 /**
21 Generate an centred extender. Should make a Extender_spanner that
22 typesets a nice centred extender of varying length depending on the
23 gap between syllables.
25 We remember the last Item that come across. When we get a
26 request, we create the spanner, and attach the left point to the
27 last lyrics, and the right point to any lyrics we receive by
28 then. */
29 class Extender_engraver : public Engraver
31 Grob *last_lyric_l_;
32 Grob *current_lyric_l_;
33 Extender_req* req_l_;
34 Spanner* extender_p_;
35 public:
36 Extender_engraver ();
37 VIRTUAL_COPY_CONS (Translator);
39 protected:
40 virtual void acknowledge_grob (Grob_info);
41 virtual void finalize ();
42 virtual bool try_music (Music*);
43 virtual void stop_translation_timestep ();
44 virtual void start_translation_timestep ();
45 virtual void process_music ();
46 private:
51 ADD_THIS_TRANSLATOR (Extender_engraver);
53 Extender_engraver::Extender_engraver ()
55 current_lyric_l_ = 0;
56 last_lyric_l_ = 0;
57 extender_p_ = 0;
58 req_l_ = 0;
61 void
62 Extender_engraver::acknowledge_grob (Grob_info i)
64 // -> text_item
65 if (i.elem_l_->has_interface (ly_symbol2scm ("lyric-syllable-interface")))
67 current_lyric_l_ = i.elem_l_;
68 if (extender_p_
69 && !extender_p_->get_bound (RIGHT)
72 Lyric_extender::set_textitem (extender_p_, RIGHT, dynamic_cast<Item*> (i.elem_l_));
78 bool
79 Extender_engraver::try_music (Music* r)
81 if (Extender_req* p = dynamic_cast <Extender_req *> (r))
83 if (req_l_)
84 return false;
86 req_l_ = p;
87 return true;
89 return false;
92 void
93 Extender_engraver::finalize ()
95 if (extender_p_)
97 req_l_->origin ()->warning (_ ("unterminated extender"));
98 extender_p_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
102 void
103 Extender_engraver::process_music ()
105 if (req_l_ && ! extender_p_)
107 if (!last_lyric_l_)
109 req_l_->origin ()->warning (_ ("Nothing to connect extender to on the left. Ignoring extender request."));
110 return;
113 extender_p_ = new Spanner (get_property ("LyricExtender"));
116 Lyric_extender::set_textitem (extender_p_, LEFT, last_lyric_l_);
117 announce_grob (extender_p_, req_l_);
122 void
123 Extender_engraver::stop_translation_timestep ()
125 if (extender_p_)
127 typeset_grob (extender_p_);
128 extender_p_ = 0;
131 if (current_lyric_l_)
133 last_lyric_l_ = current_lyric_l_;
134 current_lyric_l_ =0;
138 void
139 Extender_engraver::start_translation_timestep ()
141 req_l_ = 0;