]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/staff-symbol-engraver.cc
Run grand replace for 2015.
[lilypond.git] / lily / staff-symbol-engraver.cc
index c147d54dfff9bd1f7430c1ab5959bd21c4c12ca2..f9994d69541f0e3386c805ee107a2592415a12f1 100644 (file)
@@ -1,13 +1,29 @@
 /*
-  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--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.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 "spanner.hh"
 #include "engraver.hh"
+#include "international.hh"
+#include "spanner.hh"
+#include "stream-event.hh"
+#include "warn.hh"
+
+#include "translator.icc"
 
 class Staff_symbol_engraver : public Engraver
 {
@@ -15,7 +31,7 @@ public:
   TRANSLATOR_DECLARATIONS (Staff_symbol_engraver);
 
 protected:
-  Drul_array<Music *> span_events_;
+  Drul_array<Stream_event *> span_events_;
   Spanner *span_;
   Spanner *finished_span_;
   bool first_start_;
@@ -25,16 +41,31 @@ protected:
   virtual void stop_spanner ();
 
   void stop_translation_timestep ();
-  virtual bool try_music (Music *);
   virtual ~Staff_symbol_engraver ();
   DECLARE_ACKNOWLEDGER (grob);
+  DECLARE_TRANSLATOR_LISTENER (staff_span);
   virtual void finalize ();
   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 ()
@@ -42,21 +73,18 @@ Staff_symbol_engraver::Staff_symbol_engraver ()
   finished_span_ = 0;
   first_start_ = true;
   span_ = 0;
-  span_events_[LEFT] = 0;
-  span_events_[RIGHT] = 0;
+  span_events_.set (0, 0);
 }
 
-bool
-Staff_symbol_engraver::try_music (Music *music)
+IMPLEMENT_TRANSLATOR_LISTENER (Staff_symbol_engraver, staff_span);
+void
+Staff_symbol_engraver::listen_staff_span (Stream_event *ev)
 {
-  Direction d = to_dir (music->get_property ("span-direction"));
+  Direction d = to_dir (ev->get_property ("span-direction"));
   if (d)
-    {
-      span_events_[d] = music;
-      return true;
-    }
-
-  return false;
+    ASSIGN_EVENT_ONCE (span_events_[d], ev);
+  else
+    programming_error ("staff-span event has no direction");
 }
 
 void
@@ -67,7 +95,7 @@ Staff_symbol_engraver::process_music ()
       finished_span_ = span_;
       span_ = 0;
       if (first_start_)
-       first_start_ = false;
+        first_start_ = false;
     }
 
   if (span_events_[START]
@@ -82,7 +110,7 @@ Staff_symbol_engraver::start_spanner ()
     {
       span_ = make_spanner ("StaffSymbol", SCM_EOL);
       span_->set_bound (LEFT,
-                       unsmob_grob (get_property ("currentCommandColumn")));
+                        Grob::unsmob (get_property ("currentCommandColumn")));
     }
 }
 
@@ -93,13 +121,13 @@ Staff_symbol_engraver::stop_spanner ()
     return;
 
   if (!finished_span_->get_bound (RIGHT))
-    finished_span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
-  
+    finished_span_->set_bound (RIGHT, Grob::unsmob (get_property ("currentCommandColumn")));
+
   announce_end_grob (finished_span_,
-                    span_events_[STOP]
-                    ? span_events_[STOP]->self_scm ()
-                    : SCM_EOL);
-  
+                     span_events_[STOP]
+                     ? span_events_[STOP]->self_scm ()
+                     : SCM_EOL);
+
   finished_span_ = 0;
 }
 
@@ -108,12 +136,9 @@ Staff_symbol_engraver::stop_translation_timestep ()
 {
   if ((span_events_[START] || first_start_)
       && span_)
-    {
-      first_start_ = false;
-    }
+    first_start_ = false;
 
-  span_events_[START] = 0;
-  span_events_[STOP] = 0;
+  span_events_.set (0, 0);
   stop_spanner ();
 }
 
@@ -131,10 +156,6 @@ Staff_symbol_engraver::finalize ()
 void
 Staff_symbol_engraver::acknowledge_grob (Grob_info s)
 {
-  /*
-    Perhaps should try to take SeparationItem as bound of the staff
-    symbol?
-  */
   if (span_ || finished_span_)
     {
       Spanner *my = span_ ? span_ : finished_span_;
@@ -142,14 +163,18 @@ Staff_symbol_engraver::acknowledge_grob (Grob_info s)
     }
 }
 
-#include "translator.icc"
-
 ADD_ACKNOWLEDGER (Staff_symbol_engraver, grob);
 
 ADD_TRANSLATOR (Staff_symbol_engraver,
-               /* doc */ "Create the constellation of five (default) "
-               "staff lines.",
-               /* create */ "StaffSymbol",
-               /* accept */ "staff-span-event",
-               /* read */ "",
-               /* write */ "");
+                /* doc */
+                "Create the constellation of five (default) staff lines.",
+
+                /* create */
+                "StaffSymbol ",
+
+                /* read */
+                "",
+
+                /* write */
+                ""
+               );