]> git.donarmstrong.com Git - lilypond.git/blob - lily/footnote-engraver.cc
Imported Upstream version 2.14.2
[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
27 #include "translator.icc"
28
29 class Footnote_engraver : public Engraver
30 {
31   TRANSLATOR_DECLARATIONS (Footnote_engraver);
32
33   DECLARE_TRANSLATOR_LISTENER (footnote);
34   DECLARE_ACKNOWLEDGER (grob);
35   DECLARE_END_ACKNOWLEDGER (grob);
36   vector<Stream_event *> events_;
37   vector<Drul_array<Spanner *> > annotated_spanners_;
38
39   void stop_translation_timestep ();
40
41   void footnotify (Grob *, Stream_event *);
42 };
43
44 IMPLEMENT_TRANSLATOR_LISTENER (Footnote_engraver, footnote);
45 void
46 Footnote_engraver::listen_footnote (Stream_event *ev)
47 {
48   events_.push_back (ev);
49 }
50
51 void
52 Footnote_engraver::stop_translation_timestep ()
53 {
54   events_.clear ();
55 }
56
57 Footnote_engraver::Footnote_engraver ()
58 {
59 }
60
61 void
62 Footnote_engraver::footnotify (Grob *g, Stream_event *event)
63 {
64   Spanner *s = dynamic_cast<Spanner *>(g);
65
66   if (s)
67     {
68       Spanner *b = make_spanner ("FootnoteSpanner", event->self_scm ());
69       b->set_parent (s, Y_AXIS);
70       b->set_parent (s, X_AXIS);
71       Grob *bound = unsmob_grob (get_property ("currentMusicalColumn"));
72       b->set_bound (LEFT, bound);
73       annotated_spanners_.push_back (Drul_array<Spanner *> (s,b));
74     }
75   else
76     {
77       Grob *b = make_item ("FootnoteItem", event->self_scm ());
78       b->set_parent (g, Y_AXIS);
79       b->set_parent (g, X_AXIS);
80     }
81 }
82
83 void
84 Footnote_engraver::acknowledge_grob (Grob_info info)
85 {
86   Stream_event *cause = info.event_cause ();
87
88   SCM arts = cause ? cause->get_property ("articulations") : SCM_EOL;
89   for (SCM s = arts; scm_is_pair (s); s = scm_cdr (s))
90     {
91       Stream_event *e = unsmob_stream_event (scm_car (s));
92       if (e->in_event_class ("footnote-event"))
93           footnotify (info.grob (), e);
94     }
95
96   for (vsize i = 0; i < events_.size (); i++)
97     {
98       if (info.grob ()->name () == ly_symbol2string (events_[i]->get_property ("symbol")))
99         footnotify (info.grob (), events_[i]);
100     }
101 }
102
103 void
104 Footnote_engraver::acknowledge_end_grob (Grob_info info)
105 {
106   Spanner *s = dynamic_cast<Spanner *>(info.grob ());
107
108   if (s)
109     for (vsize i = 0; i < annotated_spanners_.size (); i++)
110       {
111         if (annotated_spanners_[i][LEFT] == s)
112           {
113             Grob *bound = unsmob_grob (get_property ("currentMusicalColumn"));
114             annotated_spanners_[i][RIGHT]->set_bound (RIGHT, bound);
115             break;
116           }
117       }
118 }
119
120 ADD_ACKNOWLEDGER (Footnote_engraver, grob);
121 ADD_END_ACKNOWLEDGER (Footnote_engraver, grob);
122
123 ADD_TRANSLATOR (Footnote_engraver,
124                /* doc */
125                "Create footnote texts.",
126
127                /* create */
128                "FootnoteItem "
129                "FootnoteSpanner ",
130
131                /*read*/
132                "currentMusicalColumn ",
133
134                /*write*/
135                ""
136                );