]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/hyphen-engraver.cc
* lily/text-item.cc (interpret_string): new file, select font with
[lilypond.git] / lily / hyphen-engraver.cc
index 013c9620b6b3e79292d23a44e32ea63383a916f2..9e87e8ecb1559f7c7816039159c5aa85929dc626 100644 (file)
 /*
   hyphen-engraver.cc -- implement Hyphen_engraver
 
-  (c) 1999 Glen Prideaux <glenprideaux@iname.com>
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 1999--2004 Glen Prideaux <glenprideaux@iname.com>,
+                  Han-Wen Nienhuys <hanwen@cs.uu.nl>,
+                  Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
-#include "proto.hh"
-#include "musical-request.hh"
-#include "hyphen-engraver.hh"
-#include "hyphen-spanner.hh"
-#include "score-column.hh"
-#include "text-item.hh"
-#include "extender-engraver.hh"
+#include "warn.hh"
+#include "item.hh"
+#include "engraver.hh"
+#include "spanner.hh"
+
+class Hyphen_engraver : public Engraver
+{
+  Music *ev_;
+  Spanner *hyphen_;
+  Spanner *finished_hyphen_;  
+public:
+  TRANSLATOR_DECLARATIONS (Hyphen_engraver);
+
+protected:
+  virtual void acknowledge_grob (Grob_info);
+  virtual void finalize ();
+  virtual bool try_music (Music*);
+  virtual void stop_translation_timestep ();
+  virtual void process_music ();
+private:
+
+};
+
+
 
-ADD_THIS_TRANSLATOR (Hyphen_engraver);
 
 Hyphen_engraver::Hyphen_engraver ()
 {
-  hyphen_spanner_p_ = 0;
-  req_l_ = 0;
+  hyphen_ = 0;
+  finished_hyphen_ = 0;
+  ev_ = 0;
 }
 
 void
-Hyphen_engraver::acknowledge_element (Score_element_info i)
+Hyphen_engraver::acknowledge_grob (Grob_info i)
 {
-  if (Text_item* t = dynamic_cast<Text_item*> (i.elem_l_))
+  Item * item =  dynamic_cast<Item*> (i.grob_);
+  // -> text_item
+  if (item && item->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
     {
-      Rhythmic_req * rh = dynamic_cast<Rhythmic_req*>  (i.req_l_);
-      if (!rh)
-       return;
-
-      now_lyrics_.push (Text_lyric_tuple (t, rh, now_mom () + rh->length_mom ()));
-      /*
-       UGH.  What do we do in case of multiple alternatives? 
-       */
-      if (hyphen_spanner_p_
-         && !hyphen_spanner_p_->spanned_drul_[RIGHT]
-           )
-         {
-           hyphen_spanner_p_->set_textitem (RIGHT, t);
-         }
+      if (hyphen_)
+       hyphen_->set_bound (LEFT, item);
+
+      if (finished_hyphen_)
+       finished_hyphen_->set_bound (RIGHT, item);
     }
 }
 
 
 bool
-Hyphen_engraver::do_try_music (Music* r)
+Hyphen_engraver::try_music (Music* r)
 {
-  if (Hyphen_req* p = dynamic_cast <Hyphen_req *> (r))
-    {
-      if (req_l_)
-       return false;
+  if (ev_)
+    return false;
 
-      req_l_ = p;
-      return true;
-    }
-  return false;
+  ev_ = r;
+  return true;
 }
 
 void
-Hyphen_engraver::do_removal_processing ()
+completize_hyphen (Spanner* sp)
 {
-  if (hyphen_spanner_p_)
+  if (!sp->get_bound (RIGHT))
     {
-      req_l_->warning (_ ("unterminated hyphen"));
-      hyphen_spanner_p_->set_bounds(RIGHT, get_staff_info ().command_pcol_l ());
+      SCM heads = sp->get_property ("heads");
+      if (is_pair (heads))
+       {
+         Item* it = dynamic_cast<Item*> (unsmob_grob (ly_car (heads)));
+         if (it)
+           sp->set_bound (RIGHT, it);
+       }
     }
 }
 
+  
+
 void
-Hyphen_engraver::do_process_requests ()
+Hyphen_engraver::finalize ()
 {
-  Array<Text_lyric_tuple> stopped_texts;
-  Moment now = now_mom ();
+  if (hyphen_)
+    {
+      completize_hyphen (hyphen_);
 
-  stopped_texts.clear ();
-  while (past_lyrics_pq_.size ()
-        && past_lyrics_pq_.front ().end_ == now)
-    stopped_texts.push (past_lyrics_pq_.get ());
+      if (!hyphen_->get_bound (RIGHT))
+       {
+         hyphen_->warning (_ ("removing unterminated hyphen"));
+         hyphen_->suicide ();
+       }
 
-  if (req_l_)
+      typeset_grob (hyphen_);
+      hyphen_ = 0;
+    }
+
+  if (finished_hyphen_)
     {
-      if (!stopped_texts.size ())
+      completize_hyphen (finished_hyphen_);
+
+      if (!finished_hyphen_->get_bound (RIGHT))
        {
-         req_l_->warning ("Nothing to connect hyphen to on the left. Ignoring hyphen request");
-         return;
+         finished_hyphen_->warning (_("unterminated hyphen; removing"));
+         finished_hyphen_->suicide ();
        }
-      
-      hyphen_spanner_p_ = new Hyphen_spanner;
-      hyphen_spanner_p_->set_textitem  (LEFT, stopped_texts[0].text_l_);
-      announce_element (Score_element_info (hyphen_spanner_p_, req_l_));
+      typeset_grob (finished_hyphen_);
+      finished_hyphen_ =0;
+    }
+}
+
+void
+Hyphen_engraver::process_music ()
+{
+  if (ev_)
+    {
+      hyphen_ = make_spanner ("LyricHyphen");
+      announce_grob (hyphen_, ev_->self_scm ());
     }
 }
 
 
 void
-Hyphen_engraver::do_pre_move_processing ()
+Hyphen_engraver::stop_translation_timestep ()
 {
-  for (int i=0; i < now_lyrics_.size (); i++)
+  if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT))
     {
-      past_lyrics_pq_.insert (now_lyrics_[i]);
+      typeset_grob (finished_hyphen_);
+      finished_hyphen_ = 0;
     }
-  now_lyrics_.clear ();
 
-  if (hyphen_spanner_p_)
+  if (finished_hyphen_ && hyphen_)
     {
-      typeset_element (hyphen_spanner_p_);
-      hyphen_spanner_p_ = 0;
+      programming_error ("Haven't finished hyphen yet.");
+      typeset_grob (finished_hyphen_);
+      finished_hyphen_ =0;
     }
-}
-void
-Hyphen_engraver::do_post_move_processing ()
-{
-  Moment now = now_mom ();
-  while (past_lyrics_pq_.size () && past_lyrics_pq_.front ().end_ < now)
-    past_lyrics_pq_.delmin ();
+  
+  if (hyphen_)
+    finished_hyphen_ = hyphen_;
+  hyphen_ = 0;
 
-  req_l_ =0;
+  ev_ = 0;
 }
 
 
+
+
+ENTER_DESCRIPTION (Hyphen_engraver,
+/* descr */       "Create lyric hyphens",
+/* creats*/       "LyricHyphen",
+/* accepts */     "hyphen-event",
+/* acks  */      "lyric-syllable-interface",
+/* reads */       "",
+/* write */       "");