/*
- staff-sym-reg.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--1999 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 "staff-symbol.hh"
-#include "score.hh"
-#include "paper-column.hh"
-#include "paper-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 {
- Staff_symbol *span_p_;
+class Staff_symbol_engraver : public Engraver
+{
public:
- VIRTUAL_COPY_CONS(Translator);
- Staff_symbol_engraver();
-
+ TRANSLATOR_DECLARATIONS (Staff_symbol_engraver);
+
+protected:
+ Drul_array<Stream_event *> span_events_;
+ Spanner *span_;
+ Spanner *finished_span_;
+ bool first_start_;
+
protected:
- virtual ~Staff_symbol_engraver();
+ virtual void start_spanner ();
+ virtual void stop_spanner ();
- virtual void acknowledge_element (Score_element_info);
- virtual void do_removal_processing();
- virtual void do_creation_processing();
-
+ void stop_translation_timestep ();
+ virtual ~Staff_symbol_engraver ();
+ void acknowledge_grob (Grob_info);
+ void listen_staff_span (Stream_event *);
+ 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 ()
+{
+ if (span_)
+ {
+ // Somehow finalize() was not called?
+ programming_error ("Have a pending spanner in destructor.");
+ }
+}
+
+Staff_symbol_engraver::Staff_symbol_engraver (Context *c)
+ : Engraver (c)
+{
+ finished_span_ = 0;
+ first_start_ = true;
+ span_ = 0;
+ span_events_.set (0, 0);
+}
+
+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");
+}
-Staff_symbol_engraver::~Staff_symbol_engraver()
+void
+Staff_symbol_engraver::process_music ()
{
- assert (!span_p_);
+ if (span_events_[STOP])
+ {
+ finished_span_ = span_;
+ span_ = 0;
+ if (first_start_)
+ first_start_ = false;
+ }
+
+ if (span_events_[START]
+ || (first_start_ && !span_events_[STOP]))
+ start_spanner ();
}
-Staff_symbol_engraver::Staff_symbol_engraver()
+void
+Staff_symbol_engraver::start_spanner ()
{
- span_p_ = 0;
+ if (!span_)
+ {
+ span_ = make_spanner ("StaffSymbol", SCM_EOL);
+ span_->set_bound (LEFT,
+ unsmob<Grob> (get_property ("currentCommandColumn")));
+ }
}
void
-Staff_symbol_engraver::do_creation_processing()
+Staff_symbol_engraver::stop_spanner ()
{
- span_p_ = new Staff_symbol;
- span_p_->set_bounds(LEFT,get_staff_info().command_pcol_l ());
- announce_element (Score_element_info (span_p_, 0));
+ if (!finished_span_)
+ return;
+
+ if (!finished_span_->get_bound (RIGHT))
+ finished_span_->set_bound (RIGHT, unsmob<Grob> (get_property ("currentCommandColumn")));
+
+ announce_end_grob (finished_span_,
+ span_events_[STOP]
+ ? span_events_[STOP]->self_scm ()
+ : SCM_EOL);
+
+ finished_span_ = 0;
}
void
-Staff_symbol_engraver::do_removal_processing()
+Staff_symbol_engraver::stop_translation_timestep ()
{
- span_p_->set_bounds(RIGHT,get_staff_info().command_pcol_l ());
- typeset_element (span_p_);
- span_p_ =0;
+ if ((span_events_[START] || first_start_)
+ && span_)
+ first_start_ = false;
+
+ span_events_.set (0, 0);
+ stop_spanner ();
}
void
-Staff_symbol_engraver::acknowledge_element (Score_element_info s)
+Staff_symbol_engraver::finalize ()
{
- s.elem_l_->set_elt_property ("staff-symbol", span_p_->self_scm_);
- s.elem_l_->add_dependency (span_p_); // UGH. UGH. UGH
+ finished_span_ = span_;
+ span_ = 0;
+ stop_spanner ();
+}
- SCM ss =s.elem_l_->remove_elt_property ("staff-support");
- if (to_boolean (ss))
+/*
+ Todo: staff-symbol-referencer iface.
+*/
+void
+Staff_symbol_engraver::acknowledge_grob (Grob_info s)
+{
+ if (span_ || finished_span_)
{
- Side_position_interface si (s.elem_l_);
- if (si.has_interface_b ())
- si.add_support (span_p_);
+ Spanner *my = span_ ? span_ : finished_span_;
+ s.grob ()->set_object ("staff-symbol", my->self_scm ());
}
}
-ADD_THIS_TRANSLATOR(Staff_symbol_engraver);
+void
+Staff_symbol_engraver::boot ()
+{
+ ADD_LISTENER (Staff_symbol_engraver, staff_span);
+ ADD_ACKNOWLEDGER (Staff_symbol_engraver, grob);
+}
+
+ADD_TRANSLATOR (Staff_symbol_engraver,
+ /* doc */
+ "Create the constellation of five (default) staff lines.",
+
+ /* create */
+ "StaffSymbol ",
+
+ /* read */
+ "",
+ /* write */
+ ""
+ );