]> git.donarmstrong.com Git - lilypond.git/blob - lily/footnote-engraver.cc
20ee7c149fba5eb80f000c94f95b3a6e5f2ab565
[lilypond.git] / lily / footnote-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2011--2012 Mike Solomon <mike@mikesolomon.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 "music.hh"
23 #include "stream-event.hh"
24 #include "international.hh"
25 #include "item.hh"
26 #include "pointer-group-interface.hh"
27 #include "spanner.hh"
28 #include "system.hh"
29
30 #include "translator.icc"
31
32 class Footnote_engraver : public Engraver
33 {
34   TRANSLATOR_DECLARATIONS (Footnote_engraver);
35
36   DECLARE_ACKNOWLEDGER (grob);
37   DECLARE_END_ACKNOWLEDGER (grob);
38
39   vector<Drul_array<Spanner *> > annotated_spanners_;
40
41   void finalize ();
42
43   void footnotify (Grob *, SCM);
44 };
45
46 void
47 Footnote_engraver::finalize ()
48 {
49   annotated_spanners_.clear ();
50 }
51
52 Footnote_engraver::Footnote_engraver ()
53 {
54 }
55
56 void
57 Footnote_engraver::footnotify (Grob *g, SCM cause)
58 {
59   Spanner *s = dynamic_cast<Spanner *>(g);
60
61   if (s)
62     {
63       Spanner *b = make_spanner ("FootnoteSpanner", cause);
64       b->set_parent (s, Y_AXIS);
65       b->set_parent (s, X_AXIS);
66       Grob *bound = unsmob_grob (get_property ("currentMusicalColumn"));
67       b->set_bound (LEFT, bound);
68       annotated_spanners_.push_back (Drul_array<Spanner *> (s, b));
69     }
70   else
71     {
72       Grob *b = make_item ("FootnoteItem", cause);
73       b->set_parent (g, Y_AXIS);
74       b->set_parent (g, X_AXIS);
75     }
76 }
77
78 void
79 Footnote_engraver::acknowledge_grob (Grob_info info)
80 {
81   Music *mus = unsmob_music (info.grob ()->get_property ("footnote-music"));
82
83   if (mus)
84     {
85       if (!mus->is_mus_type ("footnote-event"))
86         {
87           mus->origin ()->programming_error (_ ("Must be footnote-event."));
88           return;
89         }
90
91       footnotify (info.grob (), mus->to_event ()->unprotect ());
92
93       // This grob has exhausted its footnote
94       info.grob ()->set_property ("footnote-music", SCM_EOL);
95
96       return;
97     }
98 }
99
100 void
101 Footnote_engraver::acknowledge_end_grob (Grob_info info)
102 {
103   Spanner *s = dynamic_cast<Spanner *>(info.grob ());
104
105   if (s)
106     for (vsize i = 0; i < annotated_spanners_.size (); i++)
107       {
108         if (annotated_spanners_[i][LEFT] == s)
109           {
110             Grob *bound = unsmob_grob (get_property ("currentMusicalColumn"));
111             annotated_spanners_[i][RIGHT]->set_bound (RIGHT, bound);
112             break;
113           }
114       }
115 }
116
117 ADD_ACKNOWLEDGER (Footnote_engraver, grob);
118 ADD_END_ACKNOWLEDGER (Footnote_engraver, grob);
119
120 ADD_TRANSLATOR (Footnote_engraver,
121                 /* doc */
122                 "Create footnote texts.",
123
124                 /* create */
125                 "FootnoteItem "
126                 "FootnoteSpanner ",
127
128                 /*read*/
129                 "currentMusicalColumn ",
130
131                 /*write*/
132                 ""
133                );