]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner-engraver.cc
Docs: Fix fixed IR compilation (copy @q and @qq from macros.itely)
[lilypond.git] / lily / text-spanner-engraver.cc
1 /*
2   text-spanner-engraver.cc -- implement Text_spanner_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2007 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "engraver.hh"
10
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"
17
18 #include "translator.icc"
19
20 class Text_spanner_engraver : public Engraver
21 {
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 ();
30
31 private:
32   Spanner *span_;
33   Spanner *finished_;
34   Stream_event *current_event_;
35   Drul_array<Stream_event *> event_drul_;
36   void typeset_all ();
37 };
38
39 Text_spanner_engraver::Text_spanner_engraver ()
40 {
41   finished_ = 0;
42   current_event_ = 0;
43   span_ = 0;
44   event_drul_[START] = 0;
45   event_drul_[STOP] = 0;
46 }
47
48 IMPLEMENT_TRANSLATOR_LISTENER (Text_spanner_engraver, text_span);
49 void
50 Text_spanner_engraver::listen_text_span (Stream_event *ev)
51 {
52   Direction d = to_dir (ev->get_property ("span-direction"));
53   ASSIGN_EVENT_ONCE (event_drul_[d], ev);
54 }
55
56 void
57 Text_spanner_engraver::process_music ()
58 {
59   if (event_drul_[STOP])
60     {
61       if (!span_)
62         event_drul_[STOP]->origin ()->warning (_ ("cannot find start of text spanner"));
63       else
64         {
65           finished_ = span_;
66           announce_end_grob (finished_, SCM_EOL);
67           span_ = 0;
68           current_event_ = 0;
69         }
70     }
71
72   if (event_drul_[START])
73     {
74       if (current_event_)
75         event_drul_[START]->origin ()->warning (_ ("already have a text spanner"));
76       else
77         {
78           current_event_ = event_drul_[START];
79           span_ = make_spanner ("TextSpanner", event_drul_[START]->self_scm ());
80
81           Side_position_interface::set_axis (span_, Y_AXIS);
82           event_drul_[START] = 0;
83         }
84     }
85 }
86
87 void
88 Text_spanner_engraver::typeset_all ()
89 {
90   if (finished_)
91     {
92       if (!finished_->get_bound (RIGHT))
93         {
94           Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
95           finished_->set_bound (RIGHT, e);
96         }
97       finished_ = 0;
98     }
99 }
100
101 void
102 Text_spanner_engraver::stop_translation_timestep ()
103 {
104   if (span_ && !span_->get_bound (LEFT))
105     {
106       Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
107       span_->set_bound (LEFT, e);
108     }
109
110   typeset_all ();
111   event_drul_[START] = 0;
112   event_drul_[STOP] = 0;
113 }
114
115 void
116 Text_spanner_engraver::finalize ()
117 {
118   typeset_all ();
119   if (span_)
120     {
121       current_event_->origin ()->warning (_ ("unterminated text spanner"));
122       span_->suicide ();
123       span_ = 0;
124     }
125 }
126
127
128 void
129 Text_spanner_engraver::acknowledge_note_column (Grob_info info)
130 {
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 ());
140   }
141 }
142
143 ADD_ACKNOWLEDGER (Text_spanner_engraver, note_column);
144
145 ADD_TRANSLATOR (Text_spanner_engraver,
146                 /* doc */
147                 "Create text spanner from an event.",
148
149                 /* create */
150                 "TextSpanner ",
151
152                 /* read */
153                 "",
154
155                 /* write */
156                 ""
157                 );