]> git.donarmstrong.com Git - lilypond.git/blob - lily/footnote-engraver.cc
Merge branch 'master' into lilypond/translation
[lilypond.git] / lily / footnote-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2011 Mike Solomon <mike@apollinemike.com>
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 "stream-event.hh"
23 #include "item.hh"
24 #include "pointer-group-interface.hh"
25 #include "spanner.hh"
26 #include "system.hh"
27
28 #include "translator.icc"
29
30 class Footnote_engraver : public Engraver
31 {
32   TRANSLATOR_DECLARATIONS (Footnote_engraver);
33
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_;
39
40   void stop_translation_timestep ();
41   void finalize ();
42
43   void footnotify (Grob *, Stream_event *);
44 };
45
46 IMPLEMENT_TRANSLATOR_LISTENER (Footnote_engraver, footnote);
47 void
48 Footnote_engraver::listen_footnote (Stream_event *ev)
49 {
50   events_.push_back (ev);
51 }
52
53 void
54 Footnote_engraver::stop_translation_timestep ()
55 {
56   events_.clear ();
57 }
58
59 void
60 Footnote_engraver::finalize ()
61 {
62   annotated_spanners_.resize (0);
63 }
64
65 Footnote_engraver::Footnote_engraver ()
66 {
67 }
68
69 void
70 Footnote_engraver::footnotify (Grob *g, Stream_event *event)
71 {
72   Spanner *s = dynamic_cast<Spanner *>(g);
73
74   if (s)
75     {
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));
82     }
83   else
84     {
85       Grob *b = make_item ("FootnoteItem", event->self_scm ());
86       b->set_parent (g, Y_AXIS);
87       b->set_parent (g, X_AXIS);
88     }
89 }
90
91 void
92 Footnote_engraver::acknowledge_grob (Grob_info info)
93 {
94   Stream_event *cause = info.event_cause ();
95
96   SCM arts = cause ? cause->get_property ("articulations") : SCM_EOL;
97   for (SCM s = arts; scm_is_pair (s); s = scm_cdr (s))
98     {
99       Stream_event *e = unsmob_stream_event (scm_car (s));
100       if (e->in_event_class ("footnote-event"))
101         footnotify (info.grob (), e);
102     }
103
104   for (vsize i = 0; i < events_.size (); i++)
105     {
106       if (info.grob ()->name () == ly_symbol2string (events_[i]->get_property ("symbol")))
107         footnotify (info.grob (), events_[i]);
108     }
109 }
110
111 void
112 Footnote_engraver::acknowledge_end_grob (Grob_info info)
113 {
114   Spanner *s = dynamic_cast<Spanner *>(info.grob ());
115
116   if (s)
117     for (vsize i = 0; i < annotated_spanners_.size (); i++)
118       {
119         if (annotated_spanners_[i][LEFT] == s)
120           {
121             Grob *bound = unsmob_grob (get_property ("currentMusicalColumn"));
122             annotated_spanners_[i][RIGHT]->set_bound (RIGHT, bound);
123             break;
124           }
125       }
126 }
127
128 ADD_ACKNOWLEDGER (Footnote_engraver, grob);
129 ADD_END_ACKNOWLEDGER (Footnote_engraver, grob);
130
131 ADD_TRANSLATOR (Footnote_engraver,
132                 /* doc */
133                 "Create footnote texts.",
134
135                 /* create */
136                 "FootnoteItem "
137                 "FootnoteSpanner ",
138
139                 /*read*/
140                 "currentMusicalColumn ",
141
142                 /*write*/
143                 ""
144                );