]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/trill-spanner-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / trill-spanner-engraver.cc
index 2857a123c57ea6985bd50e3ccadd1a769cf4f6ae..914b3fa21fbe6d20a7de2f8d2c49cdd42f3d9e80 100644 (file)
 /*
-  trill-spanner-engraver.cc -- implement Trill_spanner_engraver
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 2000--2014 Jan Nieuwenhuizen <janneke@gnu.org>
 
-  (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /*
   C&P from text-spanner.cc
 
   - todo: ending should be detected automatically? a new note
-    automatically is the end of the trill?
-  
- */
+  automatically is the end of the trill?
+*/
 
+#include "engraver.hh"
+
+#include "international.hh"
 #include "note-column.hh"
+#include "pointer-group-interface.hh"
 #include "side-position-interface.hh"
-#include "engraver.hh"
+#include "stream-event.hh"
+#include "spanner.hh"
+
+#include "translator.icc"
 
 class Trill_spanner_engraver : public Engraver
 {
 public:
-  TRANSLATOR_DECLARATIONS (Trill_spanner_engraver);  
+  TRANSLATOR_DECLARATIONS (Trill_spanner_engraver);
 protected:
   virtual void finalize ();
-  virtual void acknowledge_grob (Grob_info);
-  virtual bool try_music (Music *);
-  virtual void stop_translation_timestep ();
-  virtual void process_music ();
+  DECLARE_TRANSLATOR_LISTENER (trill_span);
+  DECLARE_ACKNOWLEDGER (note_column);
+
+  void stop_translation_timestep ();
+  void process_music ();
 
 private:
   Spanner *span_;
   Spanner *finished_;
-  Music *current_req_;
-  Drul_array<Music*> req_drul_;
+  Stream_event *current_event_;
+  Drul_array<Stream_event *> event_drul_;
   void typeset_all ();
 };
 
-
 Trill_spanner_engraver::Trill_spanner_engraver ()
 {
   finished_ = 0;
-  current_req_ = 0;
-  span_ =0;
-  req_drul_[START] = 0;
-  req_drul_[STOP] = 0;
+  current_event_ = 0;
+  span_ = 0;
+  event_drul_.set (0, 0);
 }
 
-bool
-Trill_spanner_engraver::try_music (Music *m)
+IMPLEMENT_TRANSLATOR_LISTENER (Trill_spanner_engraver, trill_span);
+void
+Trill_spanner_engraver::listen_trill_span (Stream_event *ev)
 {
-  if (m->is_mus_type ("trill-span-event"))
-    {
-      Direction d = to_dir (m->get_property ("span-direction"));
-      req_drul_[d] = m;
-      return true;
-    }
-
-  return false;
+  Direction d = to_dir (ev->get_property ("span-direction"));
+  ASSIGN_EVENT_ONCE (event_drul_[d], ev);
 }
 
 void
-Trill_spanner_engraver::process_music ()
+Trill_spanner_engraver::acknowledge_note_column (Grob_info info)
 {
-  if (req_drul_[STOP])
+  if (span_)
     {
-      if (!span_)
-       {
-         req_drul_[STOP]->origin ()->warning (_ ("can't find start of trill spanner"));
-       }
-      else
-       {
-         finished_ = span_;
-         span_ = 0;
-         current_req_ = 0;
-       }
+      Pointer_group_interface::add_grob (span_,
+                                         ly_symbol2scm ("note-columns"),
+                                         info.grob ());
+      if (!span_->get_bound (LEFT))
+        add_bound_item (span_, info.grob ());
     }
-
-  if (req_drul_[START])
+  else if (finished_)
     {
-      if (current_req_)
-       {
-         req_drul_[START]->origin ()->warning (_ ("already have a trill spanner"));
-       }
-      else
-       {
-         current_req_ = req_drul_[START];
-         span_  = make_spanner ("TrillSpanner", req_drul_[START]->self_scm ());
-         Side_position_interface::set_axis (span_, Y_AXIS);
-         req_drul_[START] = 0;
-       }
+      Pointer_group_interface::add_grob (finished_, ly_symbol2scm ("note-columns"),
+                                         info.grob ());
+      if (!finished_->get_bound (RIGHT))
+        add_bound_item (finished_, info.grob ());
     }
 }
 
 void
-Trill_spanner_engraver::acknowledge_grob (Grob_info info)
+Trill_spanner_engraver::process_music ()
 {
-  Spanner * spans[2] ={span_, finished_};
-  for (int i = 0;  i < 2 ; i++)
+  if (span_
+      && (event_drul_[STOP] || event_drul_[START]))
+    {
+      Stream_event *ender = event_drul_[STOP];
+      if (!ender)
+        ender = event_drul_[START];
+      finished_ = span_;
+      announce_end_grob (finished_, ender->self_scm ());
+      span_ = 0;
+      current_event_ = 0;
+    }
+
+  if (event_drul_[START])
     {
-      if (spans[i] && Note_column::has_interface (info.grob_))
-       {
-         Side_position_interface::add_support (spans[i], info.grob_);
-         add_bound_item (spans[i], dynamic_cast<Item*> (info.grob_));
-       }
+      current_event_ = event_drul_[START];
+      span_ = make_spanner ("TrillSpanner", event_drul_[START]->self_scm ());
+      Side_position_interface::set_axis (span_, Y_AXIS);
     }
 }
 
 void
 Trill_spanner_engraver::typeset_all ()
-{  
+{
   if (finished_)
     {
       if (!finished_->get_bound (RIGHT))
-       {
-         Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
-         finished_->set_bound (RIGHT, e);
-       }
+        {
+          Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
+          finished_->set_bound (RIGHT, e);
+        }
       finished_ = 0;
     }
 }
@@ -126,13 +133,12 @@ Trill_spanner_engraver::stop_translation_timestep ()
 {
   if (span_ && !span_->get_bound (LEFT))
     {
-      Grobe = unsmob_grob (get_property ("currentMusicalColumn"));
+      Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
       span_->set_bound (LEFT, e);
     }
 
   typeset_all ();
-  req_drul_[START] = 0;
-  req_drul_[STOP] = 0;
+  event_drul_.set (0, 0);
 }
 
 void
@@ -141,16 +147,24 @@ Trill_spanner_engraver::finalize ()
   typeset_all ();
   if (span_)
     {
-      current_req_->origin ()->warning (_ ("unterminated trill spanner"));
-      span_->suicide ();
-      span_ = 0;
+      Grob *e = unsmob_grob (get_property ("currentCommandColumn"));
+      span_->set_bound (RIGHT, e);
     }
 }
 
-ENTER_DESCRIPTION (Trill_spanner_engraver,
-/* descr */       "Create trill spanner from a Music.",
-/* creats*/       "TrillSpanner",
-/* accepts */     "trill-span-event",
-/* acks  */      "note-column-interface",
-/* reads */       "",
-/* write */       "");
+ADD_ACKNOWLEDGER (Trill_spanner_engraver, note_column);
+
+ADD_TRANSLATOR (Trill_spanner_engraver,
+                /* doc */
+                "Create trill spanner from an event.",
+
+                /* create */
+                "TrillSpanner ",
+
+                /* read */
+                "currentCommandColumn "
+                "currentMusicalColumn ",
+
+                /* write */
+                ""
+               );