Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / text-spanner-engraver.cc
blobb9c7b75fb94589b62f3d5bf9b421fdb0de19d2cf
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2011 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "engraver.hh"
22 #include "international.hh"
23 #include "note-column.hh"
24 #include "pointer-group-interface.hh"
25 #include "side-position-interface.hh"
26 #include "spanner.hh"
27 #include "stream-event.hh"
29 #include "translator.icc"
31 class Text_spanner_engraver : public Engraver
33 public:
34 TRANSLATOR_DECLARATIONS (Text_spanner_engraver);
35 protected:
36 virtual void finalize ();
37 DECLARE_TRANSLATOR_LISTENER (text_span);
38 DECLARE_ACKNOWLEDGER (note_column);
39 void stop_translation_timestep ();
40 void process_music ();
42 private:
43 Spanner *span_;
44 Spanner *finished_;
45 Stream_event *current_event_;
46 Drul_array<Stream_event *> event_drul_;
47 void typeset_all ();
50 Text_spanner_engraver::Text_spanner_engraver ()
52 finished_ = 0;
53 current_event_ = 0;
54 span_ = 0;
55 event_drul_[START] = 0;
56 event_drul_[STOP] = 0;
59 IMPLEMENT_TRANSLATOR_LISTENER (Text_spanner_engraver, text_span);
60 void
61 Text_spanner_engraver::listen_text_span (Stream_event *ev)
63 Direction d = to_dir (ev->get_property ("span-direction"));
64 ASSIGN_EVENT_ONCE (event_drul_[d], ev);
67 void
68 Text_spanner_engraver::process_music ()
70 if (event_drul_[STOP])
72 if (!span_)
73 event_drul_[STOP]->origin ()->warning (_ ("cannot find start of text spanner"));
74 else
76 finished_ = span_;
77 announce_end_grob (finished_, SCM_EOL);
78 span_ = 0;
79 current_event_ = 0;
83 if (event_drul_[START])
85 if (current_event_)
86 event_drul_[START]->origin ()->warning (_ ("already have a text spanner"));
87 else
89 current_event_ = event_drul_[START];
90 span_ = make_spanner ("TextSpanner", event_drul_[START]->self_scm ());
92 Side_position_interface::set_axis (span_, Y_AXIS);
93 event_drul_[START] = 0;
98 void
99 Text_spanner_engraver::typeset_all ()
101 if (finished_)
103 if (!finished_->get_bound (RIGHT))
105 Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
106 finished_->set_bound (RIGHT, e);
108 finished_ = 0;
112 void
113 Text_spanner_engraver::stop_translation_timestep ()
115 if (span_ && !span_->get_bound (LEFT))
117 Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
118 span_->set_bound (LEFT, e);
121 typeset_all ();
122 event_drul_[START] = 0;
123 event_drul_[STOP] = 0;
126 void
127 Text_spanner_engraver::finalize ()
129 typeset_all ();
130 if (span_)
132 current_event_->origin ()->warning (_ ("unterminated text spanner"));
133 span_->suicide ();
134 span_ = 0;
139 void
140 Text_spanner_engraver::acknowledge_note_column (Grob_info info)
142 if (span_) {
143 Pointer_group_interface::add_grob (span_,
144 ly_symbol2scm ("note-columns"),
145 info.grob());
146 add_bound_item (span_, info.grob ());
147 } else if (finished_) {
148 Pointer_group_interface::add_grob (finished_, ly_symbol2scm ("note-columns"),
149 info.grob());
150 add_bound_item (finished_, info.grob ());
154 ADD_ACKNOWLEDGER (Text_spanner_engraver, note_column);
156 ADD_TRANSLATOR (Text_spanner_engraver,
157 /* doc */
158 "Create text spanner from an event.",
160 /* create */
161 "TextSpanner ",
163 /* read */
166 /* write */