]> git.donarmstrong.com Git - lilypond.git/blob - lily/extender-engraver.cc
* mf/GNUmakefile: always trace pfa fonts.
[lilypond.git] / lily / extender-engraver.cc
1 /*
2   extender-engraver.cc -- implement Extender_engraver
3
4   source file of the GNU LilyPond music typesetter
5   
6   (c)  1999--2003 Glen Prideaux <glenprideaux@iname.com>,
7                   Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8                   Jan Nieuwenhuizen <janneke@gnu.org>
9 */
10
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"
20
21
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.
26
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
32 {
33   Grob *last_lyric_;
34   Grob *current_lyric_;
35   Music* req_;
36   Spanner* extender_;
37 public:
38   TRANSLATOR_DECLARATIONS(Extender_engraver);
39
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:
48
49 };
50
51
52
53
54 Extender_engraver::Extender_engraver ()
55 {
56   current_lyric_ = 0;
57   last_lyric_ = 0;
58   extender_ = 0;
59   req_ = 0;
60 }
61
62 void
63 Extender_engraver::acknowledge_grob (Grob_info i)
64 {
65   // -> text_item
66   if (i.grob_->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
67     {
68       current_lyric_ = i.grob_;
69       if (extender_
70           && !extender_->get_bound (RIGHT)
71             )
72           {
73             Lyric_extender::set_textitem (extender_, RIGHT, dynamic_cast<Item*> (i.grob_));
74           }
75     }
76 }
77
78
79 bool
80 Extender_engraver::try_music (Music* r)
81 {
82   if (req_)
83     return false;
84
85   req_ = r;
86   return true;
87 }
88
89 void
90 Extender_engraver::finalize ()
91 {
92   if (extender_)
93     {
94       req_->origin ()->warning (_ ("unterminated extender"));
95       extender_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
96     }
97 }
98
99 void
100 Extender_engraver::process_music ()
101 {
102   if (req_ && ! extender_)
103     {
104       if (!last_lyric_)
105         {
106           req_->origin ()->warning (_ ("Nothing to connect extender to on the left.  Ignoring extender event."));
107           return;
108         }
109       
110       extender_ = new Spanner (get_property ("LyricExtender"));
111
112
113       Lyric_extender::set_textitem (extender_, LEFT, last_lyric_);
114       announce_grob(extender_, req_->self_scm());
115     }
116 }
117
118
119 void
120 Extender_engraver::stop_translation_timestep ()
121 {
122   if (extender_)
123     {
124       typeset_grob (extender_);
125       extender_ = 0;
126     }
127
128   if (current_lyric_)
129     {
130       last_lyric_ = current_lyric_;
131       current_lyric_ =0;
132     }
133 }
134
135 void
136 Extender_engraver::start_translation_timestep ()
137 {
138   req_ = 0;
139 }
140
141
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 */       "");