]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner-engraver.cc
Doc-es: various updates.
[lilypond.git] / lily / text-spanner-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2015 Jan Nieuwenhuizen <janneke@gnu.org>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "engraver.hh"
21
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"
28
29 #include "translator.icc"
30
31 class Text_spanner_engraver : public Engraver
32 {
33 public:
34   TRANSLATOR_DECLARATIONS (Text_spanner_engraver);
35 protected:
36   virtual void finalize ();
37   void listen_text_span (Stream_event *);
38   void acknowledge_note_column (Grob_info);
39   void stop_translation_timestep ();
40   void process_music ();
41
42 private:
43   Spanner *span_;
44   Spanner *finished_;
45   Stream_event *current_event_;
46   Drul_array<Stream_event *> event_drul_;
47   void typeset_all ();
48 };
49
50 Text_spanner_engraver::Text_spanner_engraver (Context *c)
51   : Engraver (c)
52 {
53   finished_ = 0;
54   current_event_ = 0;
55   span_ = 0;
56   event_drul_.set (0, 0);
57 }
58
59 void
60 Text_spanner_engraver::listen_text_span (Stream_event *ev)
61 {
62   Direction d = to_dir (ev->get_property ("span-direction"));
63   ASSIGN_EVENT_ONCE (event_drul_[d], ev);
64 }
65
66 void
67 Text_spanner_engraver::process_music ()
68 {
69   if (event_drul_[STOP])
70     {
71       if (!span_)
72         event_drul_[STOP]->origin ()->warning (_ ("cannot find start of text spanner"));
73       else
74         {
75           finished_ = span_;
76           announce_end_grob (finished_, SCM_EOL);
77           span_ = 0;
78           current_event_ = 0;
79         }
80     }
81
82   if (event_drul_[START])
83     {
84       if (current_event_)
85         event_drul_[START]->origin ()->warning (_ ("already have a text spanner"));
86       else
87         {
88           current_event_ = event_drul_[START];
89           span_ = make_spanner ("TextSpanner", event_drul_[START]->self_scm ());
90           if (Direction d = to_dir (current_event_->get_property ("direction")))
91             span_->set_property ("direction", scm_from_int (d));
92
93           Side_position_interface::set_axis (span_, Y_AXIS);
94           event_drul_[START] = 0;
95         }
96     }
97 }
98
99 void
100 Text_spanner_engraver::typeset_all ()
101 {
102   if (finished_)
103     {
104       if (!finished_->get_bound (RIGHT))
105         {
106           Grob *e = unsmob<Grob> (get_property ("currentMusicalColumn"));
107           finished_->set_bound (RIGHT, e);
108         }
109       finished_ = 0;
110     }
111 }
112
113 void
114 Text_spanner_engraver::stop_translation_timestep ()
115 {
116   if (span_ && !span_->get_bound (LEFT))
117     {
118       Grob *e = unsmob<Grob> (get_property ("currentMusicalColumn"));
119       span_->set_bound (LEFT, e);
120     }
121
122   typeset_all ();
123   event_drul_.set (0, 0);
124 }
125
126 void
127 Text_spanner_engraver::finalize ()
128 {
129   typeset_all ();
130   if (span_)
131     {
132       current_event_->origin ()->warning (_ ("unterminated text spanner"));
133       span_->suicide ();
134       span_ = 0;
135     }
136 }
137
138 void
139 Text_spanner_engraver::acknowledge_note_column (Grob_info info)
140 {
141   if (span_)
142     {
143       Pointer_group_interface::add_grob (span_,
144                                          ly_symbol2scm ("note-columns"),
145                                          info.grob ());
146       if (!span_->get_bound (LEFT))
147         add_bound_item (span_, info.grob ());
148     }
149   else if (finished_)
150     {
151       Pointer_group_interface::add_grob (finished_,
152                                          ly_symbol2scm ("note-columns"),
153                                          info.grob ());
154       if (!finished_->get_bound (RIGHT))
155         add_bound_item (finished_, info.grob ());
156     }
157 }
158
159
160 void
161 Text_spanner_engraver::boot ()
162 {
163   ADD_LISTENER (Text_spanner_engraver, text_span);
164   ADD_ACKNOWLEDGER (Text_spanner_engraver, note_column);
165 }
166
167 ADD_TRANSLATOR (Text_spanner_engraver,
168                 /* doc */
169                 "Create text spanner from an event.",
170
171                 /* create */
172                 "TextSpanner ",
173
174                 /* read */
175                 "currentMusicalColumn ",
176
177                 /* write */
178                 ""
179                );