Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / text-spanner-engraver.cc
blobe5b9911810099f3100c24e5822fbb74e0e4399cc
1 /*
2 text-spanner-engraver.cc -- implement Text_spanner_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2009 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "engraver.hh"
11 #include "international.hh"
12 #include "note-column.hh"
13 #include "pointer-group-interface.hh"
14 #include "side-position-interface.hh"
15 #include "spanner.hh"
16 #include "stream-event.hh"
18 #include "translator.icc"
20 class Text_spanner_engraver : public Engraver
22 public:
23 TRANSLATOR_DECLARATIONS (Text_spanner_engraver);
24 protected:
25 virtual void finalize ();
26 DECLARE_TRANSLATOR_LISTENER (text_span);
27 DECLARE_ACKNOWLEDGER (note_column);
28 void stop_translation_timestep ();
29 void process_music ();
31 private:
32 Spanner *span_;
33 Spanner *finished_;
34 Stream_event *current_event_;
35 Drul_array<Stream_event *> event_drul_;
36 void typeset_all ();
39 Text_spanner_engraver::Text_spanner_engraver ()
41 finished_ = 0;
42 current_event_ = 0;
43 span_ = 0;
44 event_drul_[START] = 0;
45 event_drul_[STOP] = 0;
48 IMPLEMENT_TRANSLATOR_LISTENER (Text_spanner_engraver, text_span);
49 void
50 Text_spanner_engraver::listen_text_span (Stream_event *ev)
52 Direction d = to_dir (ev->get_property ("span-direction"));
53 ASSIGN_EVENT_ONCE (event_drul_[d], ev);
56 void
57 Text_spanner_engraver::process_music ()
59 if (event_drul_[STOP])
61 if (!span_)
62 event_drul_[STOP]->origin ()->warning (_ ("cannot find start of text spanner"));
63 else
65 finished_ = span_;
66 announce_end_grob (finished_, SCM_EOL);
67 span_ = 0;
68 current_event_ = 0;
72 if (event_drul_[START])
74 if (current_event_)
75 event_drul_[START]->origin ()->warning (_ ("already have a text spanner"));
76 else
78 current_event_ = event_drul_[START];
79 span_ = make_spanner ("TextSpanner", event_drul_[START]->self_scm ());
81 Side_position_interface::set_axis (span_, Y_AXIS);
82 event_drul_[START] = 0;
87 void
88 Text_spanner_engraver::typeset_all ()
90 if (finished_)
92 if (!finished_->get_bound (RIGHT))
94 Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
95 finished_->set_bound (RIGHT, e);
97 finished_ = 0;
101 void
102 Text_spanner_engraver::stop_translation_timestep ()
104 if (span_ && !span_->get_bound (LEFT))
106 Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
107 span_->set_bound (LEFT, e);
110 typeset_all ();
111 event_drul_[START] = 0;
112 event_drul_[STOP] = 0;
115 void
116 Text_spanner_engraver::finalize ()
118 typeset_all ();
119 if (span_)
121 current_event_->origin ()->warning (_ ("unterminated text spanner"));
122 span_->suicide ();
123 span_ = 0;
128 void
129 Text_spanner_engraver::acknowledge_note_column (Grob_info info)
131 if (span_) {
132 Pointer_group_interface::add_grob (span_,
133 ly_symbol2scm ("note-columns"),
134 info.grob());
135 add_bound_item (span_, info.grob ());
136 } else if (finished_) {
137 Pointer_group_interface::add_grob (finished_, ly_symbol2scm ("note-columns"),
138 info.grob());
139 add_bound_item (finished_, info.grob ());
143 ADD_ACKNOWLEDGER (Text_spanner_engraver, note_column);
145 ADD_TRANSLATOR (Text_spanner_engraver,
146 /* doc */
147 "Create text spanner from an event.",
149 /* create */
150 "TextSpanner ",
152 /* read */
155 /* write */