]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lyric-engraver.cc
* lily/beam.cc (shift_region_to_valid): fix stupido bug.
[lilypond.git] / lily / lyric-engraver.cc
index 28d1086e0283a7745eb99d31678e213b30f97866..279fc1f141eff02de91c77d9141b4415510a0bce 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
-#include "lyric-engraver.hh"
+#include "engraver.hh"
 #include "musical-request.hh"
-#include "text-item.hh"
+#include "item.hh"
 #include "paper-def.hh"
-#include "lookup.hh"
+#include "font-metric.hh"
+#include "side-position-interface.hh"
 
-Lyric_engraver::Lyric_engraver()
+/**
+   Generate texts for lyric syllables.  We only do one lyric at a time.  
+   Multiple copies of this engraver should be used to do multiple voices.
+ */
+class Lyric_engraver : public Engraver 
 {
+protected:
+  virtual void stop_translation_timestep ();
+  virtual bool try_music (Music *);
+  virtual void create_grobs ();
+  virtual void start_translation_timestep ();
+  
+public:
+  TRANSLATOR_DECLARATIONS(Lyric_engraver);
+private:
+  Lyric_req * req_l_;
+  Item* text_p_;
+};
+
+
+
+
+Lyric_engraver::Lyric_engraver ()
+{
+  text_p_ =0;
+  req_l_ =0;
 }
 
 bool
-Lyric_engraver::do_try_request(Request*r)
+Lyric_engraver::try_music (Music*r)
 {
-    Musical_req * m =r->musical();
-    if (!m || ! m->lreq_l()) 
+  if (Lyric_req* l = dynamic_cast <Lyric_req *> (r))
+    {
+      if (req_l_)
        return false;
-    lreq_arr_.push(m->lreq_l());
+      req_l_ =l;
+      return true;
+    }
+  return false;
+}
+
+void
+Lyric_engraver::create_grobs ()
+{
+  if (req_l_)
+    {
+      text_p_=  new Item (get_property ("LyricText"));
+      
+      text_p_->set_grob_property ("text", req_l_->get_mus_property ("text"));
+
+      /*
+       We can't reach the notehead where we're centered from here. So
+       we kludge.
 
-    return true;
+ (UGH UGH, pulled amount of space out of thin air)
+      */
+      
+      text_p_->translate_axis (0.66, X_AXIS);
+      
+      announce_grob(text_p_, req_l_->self_scm());
+      req_l_ = 0;
+    }
 }
 
 void
-Lyric_engraver::do_process_requests()
+Lyric_engraver::stop_translation_timestep ()
 {
-    Text_item * last_item_l =0;
-    for (int i=0; i < lreq_arr_.size(); i++) {
-       Text_item *lp = new Text_item(lreq_arr_[i]->tdef_p_ );
-       lp->dir_i_ = -1;
-       lp->fat_b_ = true;
-       if (last_item_l)
-           lp->add_support(last_item_l);
-       last_item_l = lp;
-       typeset_element(lp);
+  if (text_p_)
+    {
+      typeset_grob (text_p_);
+      text_p_ =0;
     }
 }
 
 void
-Lyric_engraver::do_post_move_processing()
+Lyric_engraver::start_translation_timestep ()
 {
-    lreq_arr_.set_size(0);
+  req_l_ =0;
 }
 
 
-IMPLEMENT_STATIC_NAME(Lyric_engraver);
-IMPLEMENT_IS_TYPE_B1(Lyric_engraver,Engraver);
-ADD_THIS_ENGRAVER(Lyric_engraver);
+ENTER_DESCRIPTION(Lyric_engraver,
+/* descr */       "",
+/* creats*/       "",
+/* acks  */       "",
+/* reads */       "",
+/* write */       "");