]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/staff-symbol-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / staff-symbol-engraver.cc
index 1c668ed8feb28a3704797744d118411d6b8dcb56..3a1a1fb32b55d695c04284d1716c8874aeef79a8 100644 (file)
 /*
-  staff-symbol-engraver.cc -- implement Staff_symbol_engraver
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  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/>.
 */
 
-#include "score.hh"
-#include "paper-column.hh"
-#include "output-def.hh"
-#include "side-position-interface.hh"
 #include "engraver.hh"
-#include "moment.hh"
+#include "international.hh"
+#include "spanner.hh"
+#include "stream-event.hh"
+#include "warn.hh"
+
+#include "translator.icc"
 
-/**
-   Manage the staff symbol.
-*/
 class Staff_symbol_engraver : public Engraver
 {
 public:
   TRANSLATOR_DECLARATIONS (Staff_symbol_engraver);
 
 protected:
+  Drul_array<Stream_event *> span_events_;
   Spanner *span_;
+  Spanner *finished_span_;
+  bool first_start_;
 
+protected:
+  virtual void start_spanner ();
+  virtual void stop_spanner ();
+
+  void stop_translation_timestep ();
   virtual ~Staff_symbol_engraver ();
-  virtual void acknowledge_grob (Grob_info);
+  DECLARE_ACKNOWLEDGER (grob);
+  DECLARE_TRANSLATOR_LISTENER (staff_span);
   virtual void finalize ();
-  virtual void process_music ();
+  void process_music ();
+  virtual void derived_mark () const;
 };
 
+void
+Staff_symbol_engraver::derived_mark () const
+{
+  for (LEFT_and_RIGHT (d))
+    {
+      if (span_events_[d])
+        scm_gc_mark (span_events_[d]->self_scm ());
+    }
+}
+
 Staff_symbol_engraver::~Staff_symbol_engraver ()
 {
-  assert (!span_);
+  if (span_)
+    {
+      // Somehow finalize() was not called?
+      programming_error ("Have a pending spanner in destructor.");
+    }
 }
 
 Staff_symbol_engraver::Staff_symbol_engraver ()
 {
+  finished_span_ = 0;
+  first_start_ = true;
   span_ = 0;
+  span_events_.set (0, 0);
+}
+
+IMPLEMENT_TRANSLATOR_LISTENER (Staff_symbol_engraver, staff_span);
+void
+Staff_symbol_engraver::listen_staff_span (Stream_event *ev)
+{
+  Direction d = to_dir (ev->get_property ("span-direction"));
+  if (d)
+    ASSIGN_EVENT_ONCE (span_events_[d], ev);
+  else
+    programming_error ("staff-span event has no direction");
 }
 
 void
 Staff_symbol_engraver::process_music ()
 {
-  if (!span_)
+  if (span_events_[STOP])
     {
-      span_ = make_spanner ("StaffSymbol", SCM_EOL);
-
-      span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
-
+      finished_span_ = span_;
+      span_ = 0;
+      if (first_start_)
+        first_start_ = false;
     }
+
+  if (span_events_[START]
+      || (first_start_ && !span_events_[STOP]))
+    start_spanner ();
 }
 
 void
-Staff_symbol_engraver::finalize ()
+Staff_symbol_engraver::start_spanner ()
 {
-  if (span_)
+  if (!span_)
     {
-      span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
+      span_ = make_spanner ("StaffSymbol", SCM_EOL);
+      span_->set_bound (LEFT,
+                        unsmob_grob (get_property ("currentCommandColumn")));
     }
-  span_ = 0;
 }
 
 void
-Staff_symbol_engraver::acknowledge_grob (Grob_info s)
+Staff_symbol_engraver::stop_spanner ()
 {
-  s.grob_->set_property ("staff-symbol", span_->self_scm ());
-}
+  if (!finished_span_)
+    return;
 
+  if (!finished_span_->get_bound (RIGHT))
+    finished_span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
 
-ADD_TRANSLATOR (Staff_symbol_engraver,
-               /* descr */ "Create the constellation of five (default) "
-               "staff lines.",
-               /* creats*/ "StaffSymbol",
-               /* accepts */ "",
-               /* acks  */ "grob-interface",
-               /* reads */ "",
-               /* write */ "");
+  announce_end_grob (finished_span_,
+                     span_events_[STOP]
+                     ? span_events_[STOP]->self_scm ()
+                     : SCM_EOL);
 
-/****************************************************************/
+  finished_span_ = 0;
+}
 
-class Tab_staff_symbol_engraver : public Staff_symbol_engraver
+void
+Staff_symbol_engraver::stop_translation_timestep ()
 {
-public:
-  TRANSLATOR_DECLARATIONS (Tab_staff_symbol_engraver);
-protected:
-  virtual void process_music ();
-};
+  if ((span_events_[START] || first_start_)
+      && span_)
+    first_start_ = false;
+
+  span_events_.set (0, 0);
+  stop_spanner ();
+}
 
 void
-Tab_staff_symbol_engraver::process_music ()
+Staff_symbol_engraver::finalize ()
 {
-  bool init = !span_;
-  Staff_symbol_engraver::process_music ();
-  if (init)
-    {
-      int k = scm_ilength (get_property ("stringTunings"));
-      if (k>= 0)
-       span_->set_property ("line-count", scm_int2num (k));
-    }
+  finished_span_ = span_;
+  span_ = 0;
+  stop_spanner ();
 }
 
-Tab_staff_symbol_engraver::Tab_staff_symbol_engraver ()
+/*
+  Todo: staff-symbol-referencer iface.
+*/
+void
+Staff_symbol_engraver::acknowledge_grob (Grob_info s)
 {
+  if (span_ || finished_span_)
+    {
+      Spanner *my = span_ ? span_ : finished_span_;
+      s.grob ()->set_object ("staff-symbol", my->self_scm ());
+    }
 }
 
-ADD_TRANSLATOR (Tab_staff_symbol_engraver,
-               /* descr */ "Create a staff-symbol, but look at stringTunings for the number of lines."
-               "staff lines.",
-               /* creats*/ "StaffSymbol",
-               /* accepts */ "",
-               /* acks  */ "grob-interface",
-               /* reads */ "stringTunings",
-               /* write */ "");
+ADD_ACKNOWLEDGER (Staff_symbol_engraver, grob);
+
+ADD_TRANSLATOR (Staff_symbol_engraver,
+                /* doc */
+                "Create the constellation of five (default) staff lines.",
+
+                /* create */
+                "StaffSymbol ",
+
+                /* read */
+                "",
+
+                /* write */
+                ""
+               );