/*
- text-spanner-engraver.cc -- implement Text_spanner_engraver
+ This file is part of LilyPond, the GNU music typesetter.
- source file of the GNU LilyPond music typesetter
+ Copyright (C) 2000--2015 Jan Nieuwenhuizen <janneke@gnu.org>
- (c) 2000--2001 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/>.
*/
-#include "dimensions.hh"
-#include "musical-request.hh"
-#include "paper-column.hh"
+#include "engraver.hh"
+
+#include "international.hh"
#include "note-column.hh"
-#include "item.hh"
+#include "pointer-group-interface.hh"
#include "side-position-interface.hh"
-#include "engraver.hh"
-#include "group-interface.hh"
-#include "directional-element-interface.hh"
-#include "translator-group.hh"
-#include "axis-group-interface.hh"
+#include "spanner.hh"
+#include "stream-event.hh"
+#include "translator.icc"
class Text_spanner_engraver : public Engraver
{
public:
- TRANSLATOR_DECLARATIONS(Text_spanner_engraver);
+ TRANSLATOR_DECLARATIONS (Text_spanner_engraver);
protected:
virtual void finalize ();
- virtual void acknowledge_grob (Grob_info);
- virtual bool try_music (Music *);
- virtual void stop_translation_timestep ();
- virtual void start_translation_timestep ();
- virtual void create_grobs ();
+ void listen_text_span (Stream_event *);
+ void acknowledge_note_column (Grob_info);
+ void stop_translation_timestep ();
+ void process_music ();
private:
Spanner *span_;
Spanner *finished_;
- Span_req *current_req_;
- Drul_array<Span_req*> req_drul_;
+ Stream_event *current_event_;
+ Drul_array<Stream_event *> event_drul_;
void typeset_all ();
};
-
-
-
-Text_spanner_engraver::Text_spanner_engraver ()
+Text_spanner_engraver::Text_spanner_engraver (Context *c)
+ : Engraver (c)
{
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);
}
void
-Text_spanner_engraver::start_translation_timestep ()
-{
- req_drul_[START] = 0;
- req_drul_[STOP] = 0;
-}
-
-bool
-Text_spanner_engraver::try_music (Music *m)
+Text_spanner_engraver::listen_text_span (Stream_event *ev)
{
- if (Span_req *s = dynamic_cast <Span_req*> (m))
- {
- String t = ly_scm2string (s->get_mus_property ("span-type"));
- if (t == "abort")
- {
- req_drul_[LEFT] = 0;
- req_drul_[RIGHT] = 0;
- if (span_)
- span_->suicide ();
- span_ = 0;
- }
- else if (t == "text")
- {
- req_drul_[s->get_span_dir ()] = s;
- return true;
- }
- }
- return false;
+ Direction d = to_dir (ev->get_property ("span-direction"));
+ ASSIGN_EVENT_ONCE (event_drul_[d], ev);
}
void
-Text_spanner_engraver::create_grobs ()
+Text_spanner_engraver::process_music ()
{
- if (req_drul_[STOP])
+ if (event_drul_[STOP])
{
if (!span_)
- {
- req_drul_[STOP]->origin ()->warning
- (_ ("can't find start of text spanner"));
- }
+ event_drul_[STOP]->origin ()->warning (_ ("cannot find start of text spanner"));
else
- {
- assert (!finished_);
- Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
- span_->set_bound (RIGHT, e);
-
- finished_ = span_;
- span_ = 0;
- current_req_ = 0;
- req_drul_[STOP] = 0;
- }
+ {
+ finished_ = span_;
+ announce_end_grob (finished_, SCM_EOL);
+ span_ = 0;
+ current_event_ = 0;
+ }
}
- if (req_drul_[START])
+ if (event_drul_[START])
{
- if (current_req_)
- {
- req_drul_[START]->origin ()->warning
- (_ ("already have a text spanner"));
- }
+ if (current_event_)
+ event_drul_[START]->origin ()->warning (_ ("already have a text spanner"));
else
- {
- current_req_ = req_drul_[START];
- span_ = new Spanner (get_property ("TextSpanner"));
-
- /* Ugh. Reset (de)cresc. specific properties */
- span_->set_grob_property ("outer", SCM_BOOL_T);
- span_->set_grob_property ("if-text-padding", gh_double2scm (0));
- span_->set_grob_property ("width-correct", gh_double2scm (0));
-
- Side_position_interface::set_axis (span_, Y_AXIS);
- Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
- span_->set_bound (LEFT, e);
-
- announce_grob (span_, req_drul_[START]);
- req_drul_[START] = 0;
- }
- }
-}
-
-void
-Text_spanner_engraver::acknowledge_grob (Grob_info info)
-{
- if (span_ && Note_column::has_interface (info.grob_l_))
- {
- Side_position_interface::add_support (span_, info.grob_l_);
- add_bound_item (span_, dynamic_cast<Item*> (info.grob_l_));
+ {
+ current_event_ = event_drul_[START];
+ span_ = make_spanner ("TextSpanner", event_drul_[START]->self_scm ());
+ if (Direction d = to_dir (current_event_->get_property ("direction")))
+ span_->set_property ("direction", scm_from_int (d));
+
+ Side_position_interface::set_axis (span_, Y_AXIS);
+ event_drul_[START] = 0;
+ }
}
}
void
Text_spanner_engraver::typeset_all ()
-{
+{
if (finished_)
{
- Side_position_interface::add_staff_support (finished_);
- typeset_grob (finished_);
+ if (!finished_->get_bound (RIGHT))
+ {
+ Grob *e = unsmob<Grob> (get_property ("currentMusicalColumn"));
+ finished_->set_bound (RIGHT, e);
+ }
finished_ = 0;
}
}
void
Text_spanner_engraver::stop_translation_timestep ()
{
+ if (span_ && !span_->get_bound (LEFT))
+ {
+ Grob *e = unsmob<Grob> (get_property ("currentMusicalColumn"));
+ span_->set_bound (LEFT, e);
+ }
+
typeset_all ();
+ event_drul_.set (0, 0);
}
void
typeset_all ();
if (span_)
{
- current_req_->origin ()->warning (_ ("unterminated text spanner"));
+ current_event_->origin ()->warning (_ ("unterminated text spanner"));
span_->suicide ();
span_ = 0;
}
}
-ENTER_DESCRIPTION(Text_spanner_engraver,
-/* descr */ "Create text spanner from a Span_req ",
-/* creats*/ "TextSpanner",
-/* acks */ "note-column-interface",
-/* reads */ "",
-/* write */ "");
+void
+Text_spanner_engraver::acknowledge_note_column (Grob_info info)
+{
+ if (span_)
+ {
+ Pointer_group_interface::add_grob (span_,
+ ly_symbol2scm ("note-columns"),
+ info.grob ());
+ if (!span_->get_bound (LEFT))
+ add_bound_item (span_, info.grob ());
+ }
+ else if (finished_)
+ {
+ Pointer_group_interface::add_grob (finished_,
+ ly_symbol2scm ("note-columns"),
+ info.grob ());
+ if (!finished_->get_bound (RIGHT))
+ add_bound_item (finished_, info.grob ());
+ }
+}
+
+
+void
+Text_spanner_engraver::boot ()
+{
+ ADD_LISTENER (Text_spanner_engraver, text_span);
+ ADD_ACKNOWLEDGER (Text_spanner_engraver, note_column);
+}
+
+ADD_TRANSLATOR (Text_spanner_engraver,
+ /* doc */
+ "Create text spanner from an event.",
+
+ /* create */
+ "TextSpanner ",
+
+ /* read */
+ "currentMusicalColumn ",
+
+ /* write */
+ ""
+ );