]> git.donarmstrong.com Git - lilypond.git/blob - lily/footnote-engraver.cc
bad
[lilypond.git] / lily / footnote-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2006--2011 Han-Wen Nienhuys <hanwen@lilypond.org>
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 "spanner.hh"
25
26 #include "translator.icc"
27
28 class Footnote_engraver : public Engraver
29 {
30   TRANSLATOR_DECLARATIONS (Footnote_engraver);
31
32   DECLARE_TRANSLATOR_LISTENER (footnote);
33   DECLARE_ACKNOWLEDGER (grob);
34   vector<Stream_event *> events_;
35
36   void stop_translation_timestep ();
37
38   void footnotify (Grob *, Stream_event *);
39 };
40
41 IMPLEMENT_TRANSLATOR_LISTENER (Footnote_engraver, footnote);
42 void
43 Footnote_engraver::listen_footnote (Stream_event *ev)
44 {
45   events_.push_back (ev);
46 }
47
48 void
49 Footnote_engraver::stop_translation_timestep ()
50 {
51   events_.clear ();
52 }
53
54 Footnote_engraver::Footnote_engraver ()
55 {
56 }
57
58 void
59 Footnote_engraver::footnotify (Grob *g, Stream_event *event)
60 {
61   Spanner *s = dynamic_cast<Spanner *>(g);
62   
63   if (s)
64     {
65       Spanner *b = make_spanner ("FootnoteSpanner", event->self_scm ());
66       b->set_property ("footnote-text", event->get_property ("footnote-text"));
67       b->set_property ("text", event->get_property ("text"));
68       b->set_parent (s, Y_AXIS);
69       b->set_parent (s, X_AXIS);
70       bool bar = scm_is_string (get_property ("whichBar"));
71       Grob *bound = unsmob_grob (bar
72                                  ? get_property ("currentCommandColumn")
73                                  : get_property ("currentMusicalColumn"));
74       b->set_bound (LEFT, bound);
75       b->set_bound (RIGHT, bound);
76       b->set_property ("parent-spanner", s->self_scm ());
77     }
78   else
79     {
80       Grob *b = make_item ("Footnote", event->self_scm ());
81       b->set_property ("footnote-text", event->get_property ("footnote-text"));
82       b->set_property ("text", event->get_property ("text"));
83       b->set_parent (g, Y_AXIS);
84       b->set_parent (g, X_AXIS);
85     }
86 }
87
88 void
89 Footnote_engraver::acknowledge_grob (Grob_info info)
90 {
91   Stream_event *cause = info.event_cause ();
92
93   SCM arts = cause ? cause->get_property ("articulations") : SCM_EOL;
94   for (SCM s = arts; scm_is_pair (s); s = scm_cdr (s))
95     {
96       Stream_event *e = unsmob_stream_event (scm_car (s));
97       if (e->in_event_class ("footnote-event"))
98         {
99           footnotify (info.grob (), e);
100         }
101     }
102
103   for (vsize i = 0; i < events_.size (); i++)
104     {
105       if (info.grob ()->name () == ly_symbol2string (events_[i]->get_property ("symbol")))
106         footnotify (info.grob (), events_[i]);
107     }
108 }
109
110
111
112 ADD_ACKNOWLEDGER (Footnote_engraver, grob);
113
114 ADD_TRANSLATOR (Footnote_engraver,
115                /* doc */
116                "Create footnote texts.",
117
118                /* create */
119                "Footnote ",
120
121                /*read*/
122                "",
123
124                /*write*/
125                ""
126                );