2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2011--2012 Mike Solomon <mike@apollinemike.com>
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 "stream-event.hh"
24 #include "pointer-group-interface.hh"
28 #include "translator.icc"
30 class Footnote_engraver : public Engraver
32 TRANSLATOR_DECLARATIONS (Footnote_engraver);
34 DECLARE_TRANSLATOR_LISTENER (footnote);
35 DECLARE_ACKNOWLEDGER (grob);
36 DECLARE_END_ACKNOWLEDGER (grob);
37 vector<Stream_event *> events_;
38 vector<Drul_array<Spanner *> > annotated_spanners_;
40 void stop_translation_timestep ();
43 void footnotify (Grob *, Stream_event *);
46 IMPLEMENT_TRANSLATOR_LISTENER (Footnote_engraver, footnote);
48 Footnote_engraver::listen_footnote (Stream_event *ev)
50 events_.push_back (ev);
54 Footnote_engraver::stop_translation_timestep ()
60 Footnote_engraver::finalize ()
62 annotated_spanners_.resize (0);
65 Footnote_engraver::Footnote_engraver ()
70 Footnote_engraver::footnotify (Grob *g, Stream_event *event)
72 Spanner *s = dynamic_cast<Spanner *>(g);
76 Spanner *b = make_spanner ("FootnoteSpanner", event->self_scm ());
77 b->set_parent (s, Y_AXIS);
78 b->set_parent (s, X_AXIS);
79 Grob *bound = unsmob_grob (get_property ("currentMusicalColumn"));
80 b->set_bound (LEFT, bound);
81 annotated_spanners_.push_back (Drul_array<Spanner *> (s, b));
85 Grob *b = make_item ("FootnoteItem", event->self_scm ());
86 b->set_parent (g, Y_AXIS);
87 b->set_parent (g, X_AXIS);
92 Footnote_engraver::acknowledge_grob (Grob_info info)
94 Stream_event *cause = info.event_cause ();
96 SCM arts = cause ? cause->get_property ("articulations") : SCM_EOL;
97 for (SCM s = arts; scm_is_pair (s); s = scm_cdr (s))
99 Stream_event *e = unsmob_stream_event (scm_car (s));
100 if (e->in_event_class ("footnote-event"))
101 footnotify (info.grob (), e);
104 for (vsize i = 0; i < events_.size (); i++)
106 if (info.grob ()->name () == ly_symbol2string (events_[i]->get_property ("symbol")))
107 footnotify (info.grob (), events_[i]);
112 Footnote_engraver::acknowledge_end_grob (Grob_info info)
114 Spanner *s = dynamic_cast<Spanner *>(info.grob ());
117 for (vsize i = 0; i < annotated_spanners_.size (); i++)
119 if (annotated_spanners_[i][LEFT] == s)
121 Grob *bound = unsmob_grob (get_property ("currentMusicalColumn"));
122 annotated_spanners_[i][RIGHT]->set_bound (RIGHT, bound);
128 ADD_ACKNOWLEDGER (Footnote_engraver, grob);
129 ADD_END_ACKNOWLEDGER (Footnote_engraver, grob);
131 ADD_TRANSLATOR (Footnote_engraver,
133 "Create footnote texts.",
140 "currentMusicalColumn ",