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"
23 #include "stream-event.hh"
24 #include "international.hh"
26 #include "pointer-group-interface.hh"
30 #include "translator.icc"
32 class Footnote_engraver : public Engraver
34 TRANSLATOR_DECLARATIONS (Footnote_engraver);
36 DECLARE_TRANSLATOR_LISTENER (footnote);
37 DECLARE_ACKNOWLEDGER (grob);
38 DECLARE_END_ACKNOWLEDGER (grob);
39 vector<Stream_event *> events_;
40 vector<Drul_array<Spanner *> > annotated_spanners_;
42 void stop_translation_timestep ();
44 virtual void derived_mark () const;
46 void footnotify (Grob *, SCM);
49 IMPLEMENT_TRANSLATOR_LISTENER (Footnote_engraver, footnote);
51 Footnote_engraver::listen_footnote (Stream_event *ev)
53 events_.push_back (ev);
57 Footnote_engraver::stop_translation_timestep ()
63 Footnote_engraver::finalize ()
65 annotated_spanners_.clear ();
69 Footnote_engraver::derived_mark () const
71 for (vsize i = 0; i < events_.size (); ++i)
72 scm_gc_mark (events_[i]->self_scm ());
75 Footnote_engraver::Footnote_engraver ()
80 Footnote_engraver::footnotify (Grob *g, SCM cause)
82 Spanner *s = dynamic_cast<Spanner *>(g);
86 Spanner *b = make_spanner ("FootnoteSpanner", cause);
87 b->set_parent (s, Y_AXIS);
88 b->set_parent (s, X_AXIS);
89 Grob *bound = unsmob_grob (get_property ("currentMusicalColumn"));
90 b->set_bound (LEFT, bound);
91 annotated_spanners_.push_back (Drul_array<Spanner *> (s, b));
95 Grob *b = make_item ("FootnoteItem", cause);
96 b->set_parent (g, Y_AXIS);
97 b->set_parent (g, X_AXIS);
102 Footnote_engraver::acknowledge_grob (Grob_info info)
104 Music *mus = unsmob_music (info.grob ()->get_property ("footnote-music"));
108 if (!mus->is_mus_type ("footnote-event"))
110 mus->origin ()->programming_error (_ ("Must be footnote-event."));
114 footnotify (info.grob (), mus->to_event (context ())->unprotect ());
116 // This grob has exhausted its footnote
117 info.grob ()->set_property ("footnote-music", SCM_EOL);
121 if (!events_.empty ())
123 string grobname = info.grob ()->name ();
125 for (vsize i = 0; i < events_.size (); i++)
127 SCM name = events_[i]->get_property ("symbol");
128 if (scm_is_symbol (name)
129 && grobname == ly_symbol2string (name))
131 footnotify (info.grob (), events_[i]->self_scm ());
132 // Event has exhausted its footnote
133 events_[i]->set_property ("symbol", SCM_EOL);
140 Footnote_engraver::acknowledge_end_grob (Grob_info info)
142 Spanner *s = dynamic_cast<Spanner *>(info.grob ());
145 for (vsize i = 0; i < annotated_spanners_.size (); i++)
147 if (annotated_spanners_[i][LEFT] == s)
149 Grob *bound = unsmob_grob (get_property ("currentMusicalColumn"));
150 annotated_spanners_[i][RIGHT]->set_bound (RIGHT, bound);
156 ADD_ACKNOWLEDGER (Footnote_engraver, grob);
157 ADD_END_ACKNOWLEDGER (Footnote_engraver, grob);
159 ADD_TRANSLATOR (Footnote_engraver,
161 "Create footnote texts.",
168 "currentMusicalColumn ",